64
Towards a Smarter Bash

Bash Geekcamp

Embed Size (px)

DESCRIPTION

hack bash into something that addresses the concerns of Don Norman and Jef Raskin to make your bash smarter than you are.

Citation preview

Page 1: Bash Geekcamp

Towards a Smarter Bash

Page 2: Bash Geekcamp

HCI

Page 3: Bash Geekcamp

Human

Page 4: Bash Geekcamp

Computer

Page 5: Bash Geekcamp
Page 6: Bash Geekcamp

Barbara Blackburn

Page 7: Bash Geekcamp

200 wpm = 200 * 5 * 8 / 60

= 133 bits/s

Page 8: Bash Geekcamp

Towards a Smarter Bash

Page 9: Bash Geekcamp

Howard Stephen Berg

Page 10: Bash Geekcamp

25,000 wpm

Page 11: Bash Geekcamp

he's a freak

Page 12: Bash Geekcamp

2000 wpm = 1.3 kbits/s

Page 13: Bash Geekcamp

Towards a Smarter Bash

Page 14: Bash Geekcamp

V22.bis = Blazing Fast

Page 15: Bash Geekcamp

For 1988

Page 16: Bash Geekcamp

2:rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrsAXrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr2rXXXXXXXXXXXXXXXXXXXXXXXXXXXXX5@; B2222XXXXXXXXXXXXX22XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXhi2sXXXXXXXXXXXXXXXXXXXXXXXXXXX2h@@A,@@#A92XXXXXXXXXX2Xh22XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX3i2rXX22222222222222222252222222S#@@@@@@922222222225ShX3@S2222222222222222222222X22222222222222222222222222XXi2rX2222222222222222225HA522222Ss3B##A5:2X222222H&#MH @522222222222222222S2##X2222222222222222222222222222Xi2rX22222222222222222iBX,A2S5525Ssrrri;iX22222Xi5@@@@@@@@S222222222222225##@ #i522222222222222222222222222Xi2rX2222222222222222XB@S G#Hh9525SSSSSr922222X2;i2#@@@@#2S222222222225525@@@si#3522222222222222222222222222Xi2rX22222222222222225@@@@@@@Hh2222223ri3222223ri2isS22isS22222225555A#ASiG@@@@@#A52222222222222222222222222Xi2rX2222222222222222SiH@@@@M;sX222223rXX2222X5r925Ssssi5222222223h2H @iis2B##ASh52222222222222222222222222Xi2rX22222222222222225issiiir;X22222X5r9222223rSX225SS2222222225AM@@@,5@M5isrs;:s522222222222222222222222222Xi2rX222222222222222225Siii2rs322222Xsi3222222r3X25h#A355522222XrX@@@@@@#SS55r;XX222222222222222222222222222Xi2rX2222222222222222222222Xr2X222223r5X22223si322i@; &hh322222Xr;2H#MA2i52Xrs9X2222222222222222222222222222Xi2rX2222222222222222222222Xr32222223r2X22223rXX22#@#;M@@MA5222Xs;Srrrri523rs9X22222222222222222222222222222Xi2rX222222222222222222222X5r9222222Xr32222XSr922i&@@@@@@A:2222XirXSSS5223sr9X222222222222222222222222222222Xi2rX222222222222222222222Xir922222X2r322223riX222iSGHHG2s;X2223ssX22222X5r325222222222222222222222222222222Xi2rX2222222222222222222223si322222X5r922223rXX225SisrrrSss32223siX22252S:hHMAS22222222222222222222222222222Xi2rX2222222222222222222223si322222XSr9222X5r9222255SS553r5X2229r5X22XAAHh3 ;@i22222222222222222222222222222Xi2rX2222222222222222222223riX22222XSr3222Xis92222222222Xr32222XrX22XsA@@@M5@@AS2222222222222222222222222222Xi2rX2222222222222222222229riX22222XSr32223rSX222222222Xir9222X5r922X;iA@@@@@@XS2222222222222222222222222222Xi2rX2222222222222222222223si322222X5r92223r2X2222222223r5X2223si3225;3:ihG95iS22222222222222222222222222222Xi2rX2222222222222222222223is32222X32rh3X3Xr3X2222222222r322223r2X2XssX;SsrsiS2225X2222222222222222222222222Xi2rX222222222222222222222Xir9X9GAA&Gs&hGA9SBA&h3XX2223si3222X5r9229r25r355522555&A#SS2222222222222222222222Xi2rX222222222222222222222X5sH9i;. .:r59&AG3X3rXX2223ri3222r&2rXX222292#, #&X5222222222222222222222Xi2rX222222222222222222222h&:. ,s9H2ihX222XrXX2XiiH. hX222##@@AA@@#i222222222222222222222Xi2rX22222222222222222222&5 ;hHhX2Xis9223i5 &h22XiiM@@@@@#55222222222222222222222Xi2rX2222222222222222222Gr ,3H99;2X223; :B322Xrri5GAh5sS2222222222X22222222222Xi2rX222222222222222222Gr , :H2s922XX ;#9XXX;XSirrri52222222222253X222222222Xi2rX2222222222222222235 .. iA322&; 5HAH5XA32555222222222222X 53222222222Xi2rX22222222222222222G : 3GX2A ,,.:r2A9X22XXXXX22222XX ;AX22222222Xi2rX2222222222222222Gr : , AX93; h&&G3XGAA9XXXXM: :HX22222222Xi2rX2222222222222222& ., , XG9iM H; ;3AA&3: :HX22222222Xi2rX222222222222222X3 : ., SH5i#A SA222222222Xi2rX2222222222222223A5. : : sMrX&M#r .B9222222222Xi2rX2222222222222223&##G; ., ,. : rAsh9GB#&5r:,,. .H&X222222222Xi2rX222222222222222X9A2:SA3r. :;;. ., ., .233X3GhsH@@@@@@, ;, r#AX2222222222Xi2rX2222222222222222X3A5. rXGXs:. ; .: 5M9X39;iH&&&AB@ H@@M2;. ,;X##GX22222222222Xi2rX22222222222222222X9A#G; ;i3hhX5s;:,. .: .....,;,. rAHXSr393X9AM, r@AAB#@@###@@#A3X222222222222Xi2rX22222222222222222XX9GA##&s. .,,,,..,.. .r .... ;, .;9iHAA&3s ,#G339hGAAAAGh3X22222222222222Xi2rX222222222222222222XXX9h&H###&S;. : ..; .. :, :#GX222XXXXXXX22222222222222222Xi2rX222222222222222222222XX39hGAH####AXs;;. ,. :, . s#GX2222222222222222222222222222Xi2rX222222222222222222222222XXX39hG&AB#@@##BG2i;:; . . . .;H#GX22222222222222222222222222222Xi2rXG9XX2X2S222222G9XX2X2S22222XGh333h3Xh&AHM#@@@##MAX5isr,,;:,... ,:r3#@#&XX2X2S222222G9XX2X2S222222G9X2X3i2iA;iH32S2ASi529&;iH32S2ASi529G;iH32S2H5S23AHrX#HA&B@MB##@@2H@@BAM@MB#MBA;SA32S2ASi52hG:SA32S2ASi52hh:SH325S5. s2&@@@h5i: r2A@@@h5i: r2A@@@h5s: .s3H@@@A35; ,2H#@@@HXi: s2A@@@h5s: sXA@@@h5s: sXHH3, ..:3@@@@@@@G: ..:3@@@@@@@G, ..:3@@@@@@@h, ..:3@@@@@@@G:..,:h@@@@@@@h, ..:9@@@@@@@h, ..:9@@@@@@@h, ..:9@@M@M#####MBBBBBM#######MBBBBBM#######MBBBBBM#######MBBBBBM#######MBBBBBM#######MBBBBBM#######MBBBBBM#######MBH

Page 17: Bash Geekcamp

Other Criticisms?

Page 18: Bash Geekcamp

Towards a Smarter Bash

Page 19: Bash Geekcamp
Page 20: Bash Geekcamp

The Truth about UNIX:

the user interface is horrid (1981)

Page 21: Bash Geekcamp

Inconsistent Syntax & Usage

Names do not map to Functionality

Feedback only occurs on Error

High Cognitive Load

Page 22: Bash Geekcamp

He was absolutely correct

Page 23: Bash Geekcamp

For 1981.

Page 24: Bash Geekcamp

Bash 4.0

Page 25: Bash Geekcamp

file.newfile.deletefile.properties

directory.newdirectory.deletedirectory.properties

...

Page 26: Bash Geekcamp

alias file.new=”touch”alias file.delete=”rm”alias file.properties=”stat”

alias directory.new=”mkdir”alias directory.delete=”rmdir”alias directory.properties=”stat”

...

Page 27: Bash Geekcamp

Mnemonics = Bash Completion

Page 28: Bash Geekcamp

Alert Only On Error

He was wrong ;)

Page 29: Bash Geekcamp

Written by Monkeys on Crack?

Snopes says True.

Page 30: Bash Geekcamp
Page 31: Bash Geekcamp
Page 32: Bash Geekcamp

A computer shall not harm your work or, through inactivity, allow

your work to come to harm.

Page 33: Bash Geekcamp

function rm() { mv $* ${TMP_DIR}/.}

set -C

Page 34: Bash Geekcamp

A computer shall not waste your time or require you to do more work

than is strictly necessary

Page 35: Bash Geekcamp

Shannon's Law

bits/s = frequency * log (1+S/N)

N = our typing error rate

Page 36: Bash Geekcamp

shopt -s dirspell shopt -s cdspell

set completion-ignore-case on

Page 37: Bash Geekcamp

To get any lazier, we need to do some real work

Page 38: Bash Geekcamp

Huffman Coding

Vary storage size inversely with frequency

Page 39: Bash Geekcamp

sort .bash_history | awk '{ print $1 }' | uniq -c | sort -rn | less

Create tiny aliases for the most common

Page 40: Bash Geekcamp

me$ cd /var/tmpme$ ls

Page 41: Bash Geekcamp

cd() { builtin cd "$@" # list first bunch of entries directory.contents.wide | head }

Page 42: Bash Geekcamp

me$ chmod 0 lamers_fileme$ ls -l lamers_file

Page 43: Bash Geekcamp

[[ ${PS1} = “” ]] && return file_change() { IFS= $@ shift for f in "$*" ; do if file.is_file "${f}"; then file.properties "${f}" fi done}

Page 44: Bash Geekcamp

mv() { file_change command mv "$@"; }

chmod() { file_change command chmod "$@"; }

chown() { file_change command chown "$@"; }

touch() { file_change command touch "$@"; }

Page 45: Bash Geekcamp

Smart Prompts

know that attention is precious

Page 46: Bash Geekcamp

Seeing is believing?

Page 47: Bash Geekcamp

sane_prompt() { export PROMPT_LAST_CMD_EXIT_CODE=$? history -a prompt_screen_shelltitle local pkts=$( prompt_pad

${TEXT_RED} prompt_network_loss ) # wifi, directory size # SVN/CVS/GIT repo status # disk usage, cpu usage, … PS1="${hms}${box}${disk}${cpu}${wifi}${pkts}${dirsize}${repo}${err}${wd}" [[ ${#PS1} -gt ${PROMPT_MAX_LENGTH} ]] &&

PS1="${PS1}\n" export PS1="${PS1}${sigil}${TEXT_BLACK} " export PROMPT_PREVIOUS_TIME=${SECONDS}}export PROMPT_COMMAND=sane_prompt

Page 48: Bash Geekcamp

What about the Third Law?

Page 49: Bash Geekcamp

sane_prompt() { ... # disabled by operator? [[ -e ${PROMPT_KILL_FILE} ]] && return

# box too busy, be nice local load=$( cpu_usage_as_int ) [[ ${load} -gt ${PROMPT_LOAD_MAX} ]] && { echo CPU LOAD ABOVE ${PROMPT_LOAD_MAX} return } ...}

Page 50: Bash Geekcamp

2:rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrsAXrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr2rXXXXXXXXXXXXXXXXXXXXXXXXXXXXX5@; B2222XXXXXXXXXXXXX22XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXhi2sXXXXXXXXXXXXXXXXXXXXXXXXXXX2h@@A,@@#A92XXXXXXXXXX2Xh22XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX3i2rXX22222222222222222252222222S#@@@@@@922222222225ShX3@S2222222222222222222222X22222222222222222222222222XXi2rX2222222222222222225HA522222Ss3B##A5:2X222222H&#MH @522222222222222222S2##X2222222222222222222222222222Xi2rX22222222222222222iBX,A2S5525Ssrrri;iX22222Xi5@@@@@@@@S222222222222225##@ #i522222222222222222222222222Xi2rX2222222222222222XB@S G#Hh9525SSSSSr922222X2;i2#@@@@#2S222222222225525@@@si#3522222222222222222222222222Xi2rX22222222222222225@@@@@@@Hh2222223ri3222223ri2isS22isS22222225555A#ASiG@@@@@#A52222222222222222222222222Xi2rX2222222222222222SiH@@@@M;sX222223rXX2222X5r925Ssssi5222222223h2H @iis2B##ASh52222222222222222222222222Xi2rX22222222222222225issiiir;X22222X5r9222223rSX225SS2222222225AM@@@,5@M5isrs;:s522222222222222222222222222Xi2rX222222222222222225Siii2rs322222Xsi3222222r3X25h#A355522222XrX@@@@@@#SS55r;XX222222222222222222222222222Xi2rX2222222222222222222222Xr2X222223r5X22223si322i@; &hh322222Xr;2H#MA2i52Xrs9X2222222222222222222222222222Xi2rX2222222222222222222222Xr32222223r2X22223rXX22#@#;M@@MA5222Xs;Srrrri523rs9X22222222222222222222222222222Xi2rX222222222222222222222X5r9222222Xr32222XSr922i&@@@@@@A:2222XirXSSS5223sr9X222222222222222222222222222222Xi2rX222222222222222222222Xir922222X2r322223riX222iSGHHG2s;X2223ssX22222X5r325222222222222222222222222222222Xi2rX2222222222222222222223si322222X5r922223rXX225SisrrrSss32223siX22252S:hHMAS22222222222222222222222222222Xi2rX2222222222222222222223si322222XSr9222X5r9222255SS553r5X2229r5X22XAAHh3 ;@i22222222222222222222222222222Xi2rX2222222222222222222223riX22222XSr3222Xis92222222222Xr32222XrX22XsA@@@M5@@AS2222222222222222222222222222Xi2rX2222222222222222222229riX22222XSr32223rSX222222222Xir9222X5r922X;iA@@@@@@XS2222222222222222222222222222Xi2rX2222222222222222222223si322222X5r92223r2X2222222223r5X2223si3225;3:ihG95iS22222222222222222222222222222Xi2rX2222222222222222222223is32222X32rh3X3Xr3X2222222222r322223r2X2XssX;SsrsiS2225X2222222222222222222222222Xi2rX222222222222222222222Xir9X9GAA&Gs&hGA9SBA&h3XX2223si3222X5r9229r25r355522555&A#SS2222222222222222222222Xi2rX222222222222222222222X5sH9i;. .:r59&AG3X3rXX2223ri3222r&2rXX222292#, #&X5222222222222222222222Xi2rX222222222222222222222h&:. ,s9H2ihX222XrXX2XiiH. hX222##@@AA@@#i222222222222222222222Xi2rX22222222222222222222&5 ;hHhX2Xis9223i5 &h22XiiM@@@@@#55222222222222222222222Xi2rX2222222222222222222Gr ,3H99;2X223; :B322Xrri5GAh5sS2222222222X22222222222Xi2rX222222222222222222Gr , :H2s922XX ;#9XXX;XSirrri52222222222253X222222222Xi2rX2222222222222222235 .. iA322&; 5HAH5XA32555222222222222X 53222222222Xi2rX22222222222222222G : 3GX2A ,,.:r2A9X22XXXXX22222XX ;AX22222222Xi2rX2222222222222222Gr : , AX93; h&&G3XGAA9XXXXM: :HX22222222Xi2rX2222222222222222& ., , XG9iM H; ;3AA&3: :HX22222222Xi2rX222222222222222X3 : ., SH5i#A SA222222222Xi2rX2222222222222223A5. : : sMrX&M#r .B9222222222Xi2rX2222222222222223&##G; ., ,. : rAsh9GB#&5r:,,. .H&X222222222Xi2rX222222222222222X9A2:SA3r. :;;. ., ., .233X3GhsH@@@@@@, ;, r#AX2222222222Xi2rX2222222222222222X3A5. rXGXs:. ; .: 5M9X39;iH&&&AB@ H@@M2;. ,;X##GX22222222222Xi2rX22222222222222222X9A#G; ;i3hhX5s;:,. .: .....,;,. rAHXSr393X9AM, r@AAB#@@###@@#A3X222222222222Xi2rX22222222222222222XX9GA##&s. .,,,,..,.. .r .... ;, .;9iHAA&3s ,#G339hGAAAAGh3X22222222222222Xi2rX222222222222222222XXX9h&H###&S;. : ..; .. :, :#GX222XXXXXXX22222222222222222Xi2rX222222222222222222222XX39hGAH####AXs;;. ,. :, . s#GX2222222222222222222222222222Xi2rX222222222222222222222222XXX39hG&AB#@@##BG2i;:; . . . .;H#GX22222222222222222222222222222Xi2rXG9XX2X2S222222G9XX2X2S22222XGh333h3Xh&AHM#@@@##MAX5isr,,;:,... ,:r3#@#&XX2X2S222222G9XX2X2S222222G9X2X3i2iA;iH32S2ASi529&;iH32S2ASi529G;iH32S2H5S23AHrX#HA&B@MB##@@2H@@BAM@MB#MBA;SA32S2ASi52hG:SA32S2ASi52hh:SH325S5. s2&@@@h5i: r2A@@@h5i: r2A@@@h5s: .s3H@@@A35; ,2H#@@@HXi: s2A@@@h5s: sXA@@@h5s: sXHH3, ..:3@@@@@@@G: ..:3@@@@@@@G, ..:3@@@@@@@h, ..:3@@@@@@@G:..,:h@@@@@@@h, ..:9@@@@@@@h, ..:9@@@@@@@h, ..:9@@M@M#####MBBBBBM#######MBBBBBM#######MBBBBBM#######MBBBBBM#######MBBBBBM#######MBBBBBM#######MBBBBBM#######MBH

Page 51: Bash Geekcamp

Towards a Smarter Bash

Page 52: Bash Geekcamp
Page 53: Bash Geekcamp
Page 54: Bash Geekcamp

echo 0.102.83.12.74.96 |sed 's/\./ /g' | each word printf '”%02x:”' {}

Page 55: Bash Geekcamp

Any Ruby Fans Here?

Page 56: Bash Geekcamp

each() { ... if [[ "$1" = "word" ]]; then shift while read line; do for word in ${line}; do eval "${@/\{\}/\"${word}\"}" done done fi}

Page 57: Bash Geekcamp

Completion = Speed

Page 58: Bash Geekcamp

export TWITS=”${HOME}/.twits”twit() { url="https://twitter.com/statuses/update.xml" __add() { grep -q ^$1\$ ${TWITS} || echo $1 >> ${TWITS} } for word in $*; do [[ '@' = "${word/[^@]*/}" ]] && __add ${word} done output=$(curl -v -n -d status="$*" ${url} 2>&1) [[ $? != 0 ]] && echo ${output}}complete_twit() { local cur=${COMP_WORDS[COMP_CWORD]} COMPREPLY=( $( grep -i ${cur} ${TWITS} ) )}complete -F complete_twit twit

Page 59: Bash Geekcamp

Future Work

Page 60: Bash Geekcamp

# bash 4.0 error trappingcommand_not_found_handle() { local cmd="$*" read -p "errors> " \ -e \ -i "${cmd}" cmd ${cmd}}

Page 61: Bash Geekcamp

Towards a Smarter Bash

Page 62: Bash Geekcamp

Towards a Smarter Human

Page 63: Bash Geekcamp
Page 64: Bash Geekcamp

Thanks!

http://haller.ws/projects/bash