mattfoster (owner)

Revisions

gist: 51050 Download_button fork
public
Public Clone URL: git://gist.github.com/51050.git
Embed All Files: show embed
zsh_abbreviations.sh #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Seen at: http://github.com/strcat/dotfiles/ and in grml.
# Robust replacement for global aliases, and you can edit them too.
# requires extended globbing.
 
typeset -A abbrevs
abbrevs=('...' '../..'
         '....' '../../..'
         'BG' '& exit'
         'C' '| wc -l'
         'G' '|& grep --color=auto'
         'H' '| head'
         'L' '| less'
         'LL' '|& less -r'
         'N' '&>/dev/null'
         'R' '| tr A-z N-za-m'
         'SL' '| sort | less'
         'S' '| sort -u'
         'T' '| tail'
         'da' 'du -sch'
         'j' 'jobs -l'
         'co' "./configure && make && sudo make install"
         'CH' "./configure --help"
         'dir' 'ls -lSrah'
         'lad' $'ls -d .*(/)\n# only show dot-directories'
         'lsa' $'ls -a .*(.)\n# only show dot-files'
         'lss' $'ls -l *(s,S,t)\n# only files with setgid/setuid/sticky flag'
         'lsl' $'ls -l *(@[1,10])\n# only symlinks'
         'lsx' $'ls -l *(*[1,10])\n# only executables'
         'lsw' $'ls -ld *(R,W,X.^ND/)\n# world-{readable,writable,executable} files'
         'lsbig' $'ls -flh *(.OL[1,10])\n# display the biggest files'
         'lsd' $'ls -d *(/)\n# only show directories'
         'lse' $'ls -d *(/^F)\n# only show empty directories'
         'lsnew' $'ls -rl *(D.om[1,10])\n# display the newest files'
         'lsold' $'ls -rtlh *(D.om[-11,-1])\n# display the oldest files'
         'lssmall' $'ls -Srl *(.oL[1,10])\n# display the smallest files'
         'rw-' 'chmod 600'
         '600' 'chmod u+rw-x,g-rwx,o-rwx'
         'rwx' 'chmod u+rwx'
         '700' 'chmod u+rwx,g-rwx,o-rwx'
         'r--' 'chmod u+r-wx,g-rwx,o-rwx'
         '644' $'chmod u+rw-x,g+r-wx,o+r-wx\n # 4=r,2=w,1=x'
         '755' 'chmod u+rwx,g+r-w+x,o+r-w+x'
         'md' 'mkdir -p '
         'insecssh' 'ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"'
         'insecscp' 'scp -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"'
         'cx' 'chmod +x'
         'e' 'print -l'
         'se' 'setopt interactivecomments'
 )
 
# Create global aliases from the abbreviations.
for abbr in ${(k)abbrevs}; do
alias -g $abbr="${abbrevs[$abbr]}"
done
 
globalias() {
   local MATCH
   LBUFFER=${LBUFFER%%(#m)[_a-zA-Z0-9]#}
   LBUFFER+=${abbrevs[$MATCH]:-$MATCH}
   zle self-insert
}
 
zle -N globalias
 
# List abbreviations and abbr binding, picks out help in green.
H-Abbrevs() {
  echo "Displaying shell abbreviations"
  echo "Keybinding is:" ${$(bindabbr | grep globalias)[1]}
  for abbr in ${(ok)abbrevs}; do
printf "%-20s: %s" $abbr ${abbrevs[$abbr]:s/
/$fg[green] /} # Replaces newlines with spaces
    print -l $reset_color
  done
}
 
bindkey " " globalias
bindkey " " magic-space