.zshrc 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856
  1. # The following lines were added by compinstall
  2. #zstyle ':completion:*' completer _complete _ignored
  3. #zstyle ':completion:*' menu select=long
  4. #zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
  5. #zstyle :compinstall filename '/home/ltc/.zshrc'
  6. #
  7. #[status]
  8. # showUntrackedFiles = no
  9. plot() { gnuplot -p -e 'set object rectangle from screen 0,0 to screen 1,1 behind fillcolor rgb "black" fillstyle solid noborder; set border lw 3 lc rgb "white"; set xtics textcolor rgb "white"; set xlabel "X" textcolor rgb "white"; set ylabel "Y" textcolor rgb "white"; set key textcolor rgb "white"; plot for [col='$1'] "< cat -" using '$2':col title "'$4'" with '$3' lw 2 pt 7' ; }
  10. smoothplot() { gnuplot -p -e 'set object rectangle from screen 0,0 to screen 1,1 behind fillcolor rgb "black" fillstyle solid noborder; set border lw 3 lc rgb "white"; set xtics textcolor rgb "white"; set xlabel "X" textcolor rgb "white"; set ylabel "Y" textcolor rgb "white"; set key textcolor rgb "white"; plot for [col='$1'] "< cat -" using '$2':col smooth cspline title "'$4'" with '$3' lw 2 pt 7' ; }
  11. calcpi() { echo "scale=$1; 16*a(1/5)-4*a(1/239)" | bc -l ; }
  12. vhsify() { ffmpeg -i "$1" -vf fps=24,scale="(iw*sar)*max(640/(iw*sar)\,480/ih):ih*max(640/(iw*sar)\,480/ih)",crop=640:480,setsar=1:1,convolution="-2 -1 0 -1 1 1 0 1 2:-2 -1 0 -1 1 1 0 1 2:-2 -1 0 -1 1 1 0 1 2:-2 -1 0 -1 1 1 0 1 2",curves="0/0 0.5/0.58 1/1",rgbashift=rh=-1:gh=1 -preset veryfast -c:a copy "$2" }
  13. base58gen() { echo $(base64 /dev/urandom | tr -d "\n/+Il0O$2" | head -c ${$(($1/5.*8+1))%.*}) }
  14. alias hexcat="catgirl -h irc.libera.chat -n xfnwtest -ec cert.pem -u"
  15. alias warc="wget -rpkm --warc-cdx --warc-file"
  16. alias ytdl="yt-dlp --extract-audio --audio-format mp3"
  17. alias ssk="ssh-keygen -l -f ~/.ssh/known_hosts | grep"
  18. alias qqemu="qemu-system-x86_64 -display gtk,zoom-to-fit=on -nic user -hdd"
  19. alias gitversion='printf "r%s.%s\n" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"'
  20. alias sydi="sudo"
  21. alias rn="rm -i"
  22. #autoload -Uz compinit
  23. #compinit
  24. # End of lines added by compinstall
  25. # Lines configured by zsh-newuser-install
  26. HISTFILE=~/.zsh_history
  27. HISTSIZE=10000000
  28. SAVEHIST=10000000
  29. setopt autocd
  30. unsetopt nomatch
  31. bindkey -v
  32. # End of lines configured by zsh-newuser-install
  33. # why wont it run my profile lol
  34. source ~/.profile
  35. #f1# are we running within an utf environment?
  36. function isutfenv () {
  37. case "$LANG $CHARSET $LANGUAGE" in
  38. *utf*) return 0 ;;
  39. *UTF*) return 0 ;;
  40. *) return 1 ;;
  41. esac
  42. }
  43. # check for user, if not running as root set $SUDO to sudo
  44. (( EUID != 0 )) && SUDO='sudo' || SUDO=''
  45. # change directory to home on first invocation of zsh
  46. # important for rungetty -> autologin
  47. # Thanks go to Bart Schaefer!
  48. function checkhome () {
  49. if [[ -z "$ALREADY_DID_CD_HOME" ]] ; then
  50. export ALREADY_DID_CD_HOME=$HOME
  51. cd
  52. fi
  53. }
  54. # check for zsh v3.1.7+
  55. if ! [[ ${ZSH_VERSION} == 3.1.<7->* \
  56. || ${ZSH_VERSION} == 3.<2->.<->* \
  57. || ${ZSH_VERSION} == <4->.<->* ]] ; then
  58. printf '-!-\n'
  59. printf '-!- In this configuration we try to make use of features, that only\n'
  60. printf '-!- require version 3.1.7 of the shell; That way this setup can be\n'
  61. printf '-!- used with a wide range of zsh versions, while using fairly\n'
  62. printf '-!- advanced features in all supported versions.\n'
  63. printf '-!-\n'
  64. printf '-!- However, you are running zsh version %s.\n' "$ZSH_VERSION"
  65. printf '-!-\n'
  66. printf '-!- While this *may* work, it might as well fail.\n'
  67. printf '-!- Please consider updating to at least version 3.1.7 of zsh.\n'
  68. printf '-!-\n'
  69. printf '-!- DO NOT EXPECT THIS TO WORK FLAWLESSLY!\n'
  70. printf '-!- If it does today, you'\''ve been lucky.\n'
  71. printf '-!-\n'
  72. printf '-!- Ye been warned!\n'
  73. printf '-!-\n'
  74. function zstyle () { : }
  75. fi
  76. # autoload wrapper - use this one instead of autoload directly
  77. # We need to define this function as early as this, because autoloading
  78. # 'is-at-least()' needs it.
  79. function zrcautoload () {
  80. emulate -L zsh
  81. setopt extended_glob
  82. local fdir ffile
  83. local -i ffound
  84. ffile=$1
  85. (( ffound = 0 ))
  86. for fdir in ${fpath} ; do
  87. [[ -e ${fdir}/${ffile} ]] && (( ffound = 1 ))
  88. done
  89. (( ffound == 0 )) && return 1
  90. if [[ $ZSH_VERSION == 3.1.<6-> || $ZSH_VERSION == <4->* ]] ; then
  91. autoload -U ${ffile} || return 1
  92. else
  93. autoload ${ffile} || return 1
  94. fi
  95. return 0
  96. }
  97. # The following is the ‘add-zsh-hook’ function from zsh upstream. It is
  98. # included here to make the setup work with older versions of zsh (prior to
  99. # 4.3.7) in which this function had a bug that triggers annoying errors during
  100. # shell startup. This is exactly upstreams code from f0068edb4888a4d8fe94def,
  101. # with just a few adjustments in coding style to make the function look more
  102. # compact. This definition can be removed as soon as we raise the minimum
  103. # version requirement to 4.3.7 or newer.
  104. function add-zsh-hook () {
  105. # Add to HOOK the given FUNCTION.
  106. # HOOK is one of chpwd, precmd, preexec, periodic, zshaddhistory,
  107. # zshexit, zsh_directory_name (the _functions subscript is not required).
  108. #
  109. # With -d, remove the function from the hook instead; delete the hook
  110. # variable if it is empty.
  111. #
  112. # -D behaves like -d, but pattern characters are active in the function
  113. # name, so any matching function will be deleted from the hook.
  114. #
  115. # Without -d, the FUNCTION is marked for autoload; -U is passed down to
  116. # autoload if that is given, as are -z and -k. (This is harmless if the
  117. # function is actually defined inline.)
  118. emulate -L zsh
  119. local -a hooktypes
  120. hooktypes=(
  121. chpwd precmd preexec periodic zshaddhistory zshexit
  122. zsh_directory_name
  123. )
  124. local usage="Usage: $0 hook function\nValid hooks are:\n $hooktypes"
  125. local opt
  126. local -a autoopts
  127. integer del list help
  128. while getopts "dDhLUzk" opt; do
  129. case $opt in
  130. (d) del=1 ;;
  131. (D) del=2 ;;
  132. (h) help=1 ;;
  133. (L) list=1 ;;
  134. ([Uzk]) autoopts+=(-$opt) ;;
  135. (*) return 1 ;;
  136. esac
  137. done
  138. shift $(( OPTIND - 1 ))
  139. if (( list )); then
  140. typeset -mp "(${1:-${(@j:|:)hooktypes}})_functions"
  141. return $?
  142. elif (( help || $# != 2 || ${hooktypes[(I)$1]} == 0 )); then
  143. print -u$(( 2 - help )) $usage
  144. return $(( 1 - help ))
  145. fi
  146. local hook="${1}_functions"
  147. local fn="$2"
  148. if (( del )); then
  149. # delete, if hook is set
  150. if (( ${(P)+hook} )); then
  151. if (( del == 2 )); then
  152. set -A $hook ${(P)hook:#${~fn}}
  153. else
  154. set -A $hook ${(P)hook:#$fn}
  155. fi
  156. # unset if no remaining entries --- this can give better
  157. # performance in some cases
  158. if (( ! ${(P)#hook} )); then
  159. unset $hook
  160. fi
  161. fi
  162. else
  163. if (( ${(P)+hook} )); then
  164. if (( ${${(P)hook}[(I)$fn]} == 0 )); then
  165. set -A $hook ${(P)hook} $fn
  166. fi
  167. else
  168. set -A $hook $fn
  169. fi
  170. autoload $autoopts -- $fn
  171. fi
  172. }
  173. # Load is-at-least() for more precise version checks Note that this test will
  174. # *always* fail, if the is-at-least function could not be marked for
  175. # autoloading.
  176. zrcautoload is-at-least || function is-at-least () { return 1 }
  177. # set some important options (as early as possible)
  178. # append history list to the history file; this is the default but we make sure
  179. # because it's required for share_history.
  180. setopt append_history
  181. # import new commands from the history file also in other zsh-session
  182. setopt share_history
  183. # save each command's beginning timestamp and the duration to the history file
  184. setopt extended_history
  185. # If a new command line being added to the history list duplicates an older
  186. # one, the older command is removed from the list
  187. setopt histignorealldups
  188. # remove command lines from the history list when the first character on the
  189. # line is a space
  190. setopt histignorespace
  191. # if a command is issued that can't be executed as a normal command, and the
  192. # command is the name of a directory, perform the cd command to that directory.
  193. setopt auto_cd
  194. # in order to use #, ~ and ^ for filename generation grep word
  195. # *~(*.gz|*.bz|*.bz2|*.zip|*.Z) -> searches for word not in compressed files
  196. # don't forget to quote '^', '~' and '#'!
  197. setopt extended_glob
  198. # display PID when suspending processes as well
  199. setopt longlistjobs
  200. # report the status of backgrounds jobs immediately
  201. setopt notify
  202. # whenever a command completion is attempted, make sure the entire command path
  203. # is hashed first.
  204. setopt hash_list_all
  205. # not just at the end
  206. setopt completeinword
  207. # Don't send SIGHUP to background processes when the shell exits.
  208. setopt nohup
  209. # make cd push the old directory onto the directory stack.
  210. setopt auto_pushd
  211. # avoid "beep"ing
  212. setopt nobeep
  213. # don't push the same dir twice.
  214. setopt pushd_ignore_dups
  215. # * shouldn't match dotfiles. ever.
  216. setopt noglobdots
  217. # use zsh style word splitting
  218. setopt noshwordsplit
  219. # don't error out when unset parameters are used
  220. setopt unset
  221. # setting some default values
  222. NOCOR=${NOCOR:-0}
  223. NOMENU=${NOMENU:-0}
  224. NOPRECMD=${NOPRECMD:-0}
  225. COMMAND_NOT_FOUND=${COMMAND_NOT_FOUND:-0}
  226. GRML_ZSH_CNF_HANDLER=${GRML_ZSH_CNF_HANDLER:-/usr/share/command-not-found/command-not-found}
  227. GRML_DISPLAY_BATTERY=${GRML_DISPLAY_BATTERY:-${BATTERY:-0}}
  228. GRMLSMALL_SPECIFIC=${GRMLSMALL_SPECIFIC:-1}
  229. ZSH_NO_DEFAULT_LOCALE=${ZSH_NO_DEFAULT_LOCALE:-0}
  230. typeset -ga ls_options
  231. typeset -ga grep_options
  232. # Colors on GNU ls(1)
  233. if ls --color=auto / >/dev/null 2>&1; then
  234. ls_options+=( --color=auto )
  235. # Colors on FreeBSD and OSX ls(1)
  236. elif ls -G / >/dev/null 2>&1; then
  237. ls_options+=( -G )
  238. fi
  239. # Natural sorting order on GNU ls(1)
  240. # OSX and IllumOS have a -v option that is not natural sorting
  241. if ls --version |& grep -q 'GNU' >/dev/null 2>&1 && ls -v / >/dev/null 2>&1; then
  242. ls_options+=( -v )
  243. fi
  244. # Color on GNU and FreeBSD grep(1)
  245. if grep --color=auto -q "a" <<< "a" >/dev/null 2>&1; then
  246. grep_options+=( --color=auto )
  247. fi
  248. # utility functions
  249. # this function checks if a command exists and returns either true
  250. # or false. This avoids using 'which' and 'whence', which will
  251. # avoid problems with aliases for which on certain weird systems. :-)
  252. # Usage: check_com [-c|-g] word
  253. # -c only checks for external commands
  254. # -g does the usual tests and also checks for global aliases
  255. function check_com () {
  256. emulate -L zsh
  257. local -i comonly gatoo
  258. comonly=0
  259. gatoo=0
  260. if [[ $1 == '-c' ]] ; then
  261. comonly=1
  262. shift 1
  263. elif [[ $1 == '-g' ]] ; then
  264. gatoo=1
  265. shift 1
  266. fi
  267. if (( ${#argv} != 1 )) ; then
  268. printf 'usage: check_com [-c|-g] <command>\n' >&2
  269. return 1
  270. fi
  271. if (( comonly > 0 )) ; then
  272. (( ${+commands[$1]} )) && return 0
  273. return 1
  274. fi
  275. if (( ${+commands[$1]} )) \
  276. || (( ${+functions[$1]} )) \
  277. || (( ${+aliases[$1]} )) \
  278. || (( ${+reswords[(r)$1]} )) ; then
  279. return 0
  280. fi
  281. if (( gatoo > 0 )) && (( ${+galiases[$1]} )) ; then
  282. return 0
  283. fi
  284. return 1
  285. }
  286. # creates an alias and precedes the command with
  287. # sudo if $EUID is not zero.
  288. function salias () {
  289. emulate -L zsh
  290. local only=0 ; local multi=0
  291. local key val
  292. while getopts ":hao" opt; do
  293. case $opt in
  294. o) only=1 ;;
  295. a) multi=1 ;;
  296. h)
  297. printf 'usage: salias [-hoa] <alias-expression>\n'
  298. printf ' -h shows this help text.\n'
  299. printf ' -a replace '\'' ; '\'' sequences with '\'' ; sudo '\''.\n'
  300. printf ' be careful using this option.\n'
  301. printf ' -o only sets an alias if a preceding sudo would be needed.\n'
  302. return 0
  303. ;;
  304. *) salias -h >&2; return 1 ;;
  305. esac
  306. done
  307. shift "$((OPTIND-1))"
  308. if (( ${#argv} > 1 )) ; then
  309. printf 'Too many arguments %s\n' "${#argv}"
  310. return 1
  311. fi
  312. key="${1%%\=*}" ; val="${1#*\=}"
  313. if (( EUID == 0 )) && (( only == 0 )); then
  314. alias -- "${key}=${val}"
  315. elif (( EUID > 0 )) ; then
  316. (( multi > 0 )) && val="${val// ; / ; sudo }"
  317. alias -- "${key}=sudo ${val}"
  318. fi
  319. return 0
  320. }
  321. # Check if we can read given files and source those we can.
  322. function xsource () {
  323. if (( ${#argv} < 1 )) ; then
  324. printf 'usage: xsource FILE(s)...\n' >&2
  325. return 1
  326. fi
  327. while (( ${#argv} > 0 )) ; do
  328. [[ -r "$1" ]] && source "$1"
  329. shift
  330. done
  331. return 0
  332. }
  333. # Check if we can read a given file and 'cat(1)' it.
  334. function xcat () {
  335. emulate -L zsh
  336. if (( ${#argv} != 1 )) ; then
  337. printf 'usage: xcat FILE\n' >&2
  338. return 1
  339. fi
  340. [[ -r $1 ]] && cat $1
  341. return 0
  342. }
  343. # Remove these functions again, they are of use only in these
  344. # setup files. This should be called at the end of .zshrc.
  345. function xunfunction () {
  346. emulate -L zsh
  347. local -a funcs
  348. local func
  349. funcs=(salias xcat xsource xunfunction zrcautoload zrcautozle)
  350. for func in $funcs ; do
  351. [[ -n ${functions[$func]} ]] \
  352. && unfunction $func
  353. done
  354. return 0
  355. }
  356. # this allows us to stay in sync with grml's zshrc and put own
  357. # modifications in ~/.zshrc.local
  358. function zrclocal () {
  359. xsource "/etc/zsh/zshrc.local"
  360. xsource "${ZDOTDIR:-${HOME}}/.zshrc.local"
  361. return 0
  362. }
  363. # locale setup
  364. if (( ZSH_NO_DEFAULT_LOCALE == 0 )); then
  365. xsource "/etc/default/locale"
  366. fi
  367. for var in LANG LC_ALL LC_MESSAGES ; do
  368. [[ -n ${(P)var} ]] && export $var
  369. done
  370. builtin unset -v var
  371. # set some variables
  372. if check_com -c vim ; then
  373. #v#
  374. export EDITOR=${EDITOR:-vim}
  375. else
  376. export EDITOR=${EDITOR:-vi}
  377. fi
  378. #v#
  379. export PAGER=${PAGER:-less}
  380. #v#
  381. export MAIL=${MAIL:-/var/mail/$USER}
  382. # color setup for ls:
  383. check_com -c dircolors && eval $(dircolors -b)
  384. # color setup for ls on OS X / FreeBSD:
  385. export CLICOLOR=1
  386. # load our function and completion directories
  387. for fdir in /usr/share/grml/zsh/completion /usr/share/grml/zsh/functions; do
  388. fpath=( ${fdir} ${fdir}/**/*(/N) ${fpath} )
  389. done
  390. typeset -aU ffiles
  391. ffiles=(/usr/share/grml/zsh/functions/**/[^_]*[^~](N.:t))
  392. (( ${#ffiles} > 0 )) && autoload -U "${ffiles[@]}"
  393. unset -v fdir ffiles
  394. # support colors in less
  395. export LESS_TERMCAP_mb=$'\E[01;31m'
  396. export LESS_TERMCAP_md=$'\E[01;31m'
  397. export LESS_TERMCAP_me=$'\E[0m'
  398. export LESS_TERMCAP_se=$'\E[0m'
  399. export LESS_TERMCAP_so=$'\E[01;44;33m'
  400. export LESS_TERMCAP_ue=$'\E[0m'
  401. export LESS_TERMCAP_us=$'\E[01;32m'
  402. # mailchecks
  403. MAILCHECK=30
  404. # report about cpu-/system-/user-time of command if running longer than
  405. # 5 seconds
  406. REPORTTIME=5
  407. # watch for everyone but me and root
  408. watch=(notme root)
  409. # automatically remove duplicates from these arrays
  410. typeset -U path PATH cdpath CDPATH fpath FPATH manpath MANPATH
  411. # Load a few modules
  412. for mod in parameter complist deltochar mathfunc ; do
  413. zmodload -i zsh/${mod} 2>/dev/null || print "Notice: no ${mod} available :("
  414. done && builtin unset -v mod
  415. # autoload zsh modules when they are referenced
  416. zmodload -a zsh/stat zstat
  417. zmodload -a zsh/zpty zpty
  418. zmodload -ap zsh/mapfile mapfile
  419. # completion system
  420. COMPDUMPFILE=${COMPDUMPFILE:-${ZDOTDIR:-${HOME}}/.zcompdump}
  421. if zrcautoload compinit ; then
  422. typeset -a tmp
  423. zstyle -a ':grml:completion:compinit' arguments tmp
  424. compinit -d ${COMPDUMPFILE} "${tmp[@]}" || print 'Notice: no compinit available :('
  425. unset tmp
  426. else
  427. print 'Notice: no compinit available :('
  428. function compdef { }
  429. fi
  430. # completion system
  431. # called later (via is4 && grmlcomp)
  432. # note: use 'zstyle' for getting current settings
  433. # press ^xh (control-x h) for getting tags in context; ^x? (control-x ?) to run complete_debug with trace output
  434. function grmlcomp () {
  435. # TODO: This could use some additional information
  436. # Make sure the completion system is initialised
  437. (( ${+_comps} )) || return 1
  438. # allow one error for every three characters typed in approximate completer
  439. zstyle ':completion:*:approximate:' max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )'
  440. # don't complete backup files as executables
  441. zstyle ':completion:*:complete:-command-::commands' ignored-patterns '(aptitude-*|*\~)'
  442. # start menu completion only if it could find no unambiguous initial string
  443. zstyle ':completion:*:correct:*' insert-unambiguous true
  444. zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}'
  445. zstyle ':completion:*:correct:*' original true
  446. # activate color-completion
  447. zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
  448. # format on completion
  449. zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}'
  450. # automatically complete 'cd -<tab>' and 'cd -<ctrl-d>' with menu
  451. # zstyle ':completion:*:*:cd:*:directory-stack' menu yes select
  452. # insert all expansions for expand completer
  453. zstyle ':completion:*:expand:*' tag-order all-expansions
  454. zstyle ':completion:*:history-words' list false
  455. # activate menu
  456. zstyle ':completion:*:history-words' menu yes
  457. # ignore duplicate entries
  458. zstyle ':completion:*:history-words' remove-all-dups yes
  459. zstyle ':completion:*:history-words' stop yes
  460. # match uppercase from lowercase
  461. zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
  462. # separate matches into groups
  463. zstyle ':completion:*:matches' group 'yes'
  464. zstyle ':completion:*' group-name ''
  465. if [[ "$NOMENU" -eq 0 ]] ; then
  466. # if there are more than 5 options allow selecting from a menu
  467. zstyle ':completion:*' menu select=5
  468. else
  469. # don't use any menus at all
  470. setopt no_auto_menu
  471. fi
  472. zstyle ':completion:*:messages' format '%d'
  473. zstyle ':completion:*:options' auto-description '%d'
  474. # describe options in full
  475. zstyle ':completion:*:options' description 'yes'
  476. # on processes completion complete all user processes
  477. zstyle ':completion:*:processes' command 'ps -au$USER'
  478. # offer indexes before parameters in subscripts
  479. zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
  480. # provide verbose completion information
  481. zstyle ':completion:*' verbose true
  482. # recent (as of Dec 2007) zsh versions are able to provide descriptions
  483. # for commands (read: 1st word in the line) that it will list for the user
  484. # to choose from. The following disables that, because it's not exactly fast.
  485. zstyle ':completion:*:-command-:*:' verbose false
  486. # set format for warnings
  487. zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for:%{\e[0m%} %d'
  488. # define files to ignore for zcompile
  489. zstyle ':completion:*:*:zcompile:*' ignored-patterns '(*~|*.zwc)'
  490. zstyle ':completion:correct:' prompt 'correct to: %e'
  491. # Ignore completion functions for commands you don't have:
  492. zstyle ':completion::(^approximate*):*:functions' ignored-patterns '_*'
  493. # Provide more processes in completion of programs like killall:
  494. zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq'
  495. # complete manual by their section
  496. zstyle ':completion:*:manuals' separate-sections true
  497. zstyle ':completion:*:manuals.*' insert-sections true
  498. zstyle ':completion:*:man:*' menu yes select
  499. # Search path for sudo completion
  500. zstyle ':completion:*:sudo:*' command-path /usr/local/sbin \
  501. /usr/local/bin \
  502. /usr/sbin \
  503. /usr/bin \
  504. /sbin \
  505. /bin \
  506. /usr/X11R6/bin
  507. # provide .. as a completion
  508. zstyle ':completion:*' special-dirs ..
  509. # run rehash on completion so new installed program are found automatically:
  510. function _force_rehash () {
  511. (( CURRENT == 1 )) && rehash
  512. return 1
  513. }
  514. ## correction
  515. # some people don't like the automatic correction - so run 'NOCOR=1 zsh' to deactivate it
  516. if [[ "$NOCOR" -gt 0 ]] ; then
  517. zstyle ':completion:*' completer _oldlist _expand _force_rehash _complete _files _ignored
  518. setopt nocorrect
  519. else
  520. # try to be smart about when to use what completer...
  521. setopt correct
  522. zstyle -e ':completion:*' completer '
  523. if [[ $_last_try != "$HISTNO$BUFFER$CURSOR" ]] ; then
  524. _last_try="$HISTNO$BUFFER$CURSOR"
  525. reply=(_complete _match _ignored _prefix _files)
  526. else
  527. if [[ $words[1] == (rm|mv) ]] ; then
  528. reply=(_complete _files)
  529. else
  530. reply=(_oldlist _expand _force_rehash _complete _ignored _correct _approximate _files)
  531. fi
  532. fi'
  533. fi
  534. # command for process lists, the local web server details and host completion
  535. zstyle ':completion:*:urls' local 'www' '/var/www/' 'public_html'
  536. # Some functions, like _apt and _dpkg, are very slow. We can use a cache in
  537. # order to speed things up
  538. if [[ ${GRML_COMP_CACHING:-yes} == yes ]]; then
  539. GRML_COMP_CACHE_DIR=${GRML_COMP_CACHE_DIR:-${ZDOTDIR:-$HOME}/.cache}
  540. if [[ ! -d ${GRML_COMP_CACHE_DIR} ]]; then
  541. command mkdir -p "${GRML_COMP_CACHE_DIR}"
  542. fi
  543. zstyle ':completion:*' use-cache yes
  544. zstyle ':completion:*:complete:*' cache-path "${GRML_COMP_CACHE_DIR}"
  545. fi
  546. # host completion
  547. [[ -r ~/.ssh/config ]] && _ssh_config_hosts=(${${(s: :)${(ps:\t:)${${(@M)${(f)"$(<$HOME/.ssh/config)"}:#Host *}#Host }}}:#*[*?]*}) || _ssh_config_hosts=()
  548. [[ -r ~/.ssh/known_hosts ]] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
  549. [[ -r /etc/hosts ]] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
  550. local localname
  551. if check_com hostname ; then
  552. localname=$(hostname)
  553. elif check_com hostnamectl ; then
  554. localname=$(hostnamectl --static)
  555. else
  556. localname="$(uname -n)"
  557. fi
  558. hosts=(
  559. "${localname}"
  560. "$_ssh_config_hosts[@]"
  561. "$_ssh_hosts[@]"
  562. "$_etc_hosts[@]"
  563. localhost
  564. )
  565. zstyle ':completion:*:hosts' hosts $hosts
  566. # TODO: so, why is this here?
  567. # zstyle '*' hosts $hosts
  568. # use generic completion system for programs not yet defined; (_gnu_generic works
  569. # with commands that provide a --help option with "standard" gnu-like output.)
  570. for compcom in cp deborphan df feh fetchipac gpasswd head hnb ipacsum mv \
  571. pal stow uname ; do
  572. [[ -z ${_comps[$compcom]} ]] && compdef _gnu_generic ${compcom}
  573. done; unset compcom
  574. # see upgrade function in this file
  575. compdef _hosts upgrade
  576. }
  577. # Keyboard setup: The following is based on the same code, we wrote for
  578. # debian's setup. It ensures the terminal is in the right mode, when zle is
  579. # active, so the values from $terminfo are valid. Therefore, this setup should
  580. # work on all systems, that have support for `terminfo'. It also requires the
  581. # zsh in use to have the `zsh/terminfo' module built.
  582. #
  583. # If you are customising your `zle-line-init()' or `zle-line-finish()'
  584. # functions, make sure you call the following utility functions in there:
  585. #
  586. # - zle-line-init(): zle-smkx
  587. # - zle-line-finish(): zle-rmkx
  588. # Use emacs-like key bindings by default:
  589. bindkey -e
  590. # Custom widgets:
  591. ## beginning-of-line OR beginning-of-buffer OR beginning of history
  592. ## by: Bart Schaefer <schaefer@brasslantern.com>, Bernhard Tittelbach
  593. function beginning-or-end-of-somewhere () {
  594. local hno=$HISTNO
  595. if [[ ( "${LBUFFER[-1]}" == $'\n' && "${WIDGET}" == beginning-of* ) || \
  596. ( "${RBUFFER[1]}" == $'\n' && "${WIDGET}" == end-of* ) ]]; then
  597. zle .${WIDGET:s/somewhere/buffer-or-history/} "$@"
  598. else
  599. zle .${WIDGET:s/somewhere/line-hist/} "$@"
  600. if (( HISTNO != hno )); then
  601. zle .${WIDGET:s/somewhere/buffer-or-history/} "$@"
  602. fi
  603. fi
  604. }
  605. zle -N beginning-of-somewhere beginning-or-end-of-somewhere
  606. zle -N end-of-somewhere beginning-or-end-of-somewhere
  607. # add a command line to the shells history without executing it
  608. function commit-to-history () {
  609. print -rs ${(z)BUFFER}
  610. zle send-break
  611. }
  612. zle -N commit-to-history
  613. # only slash should be considered as a word separator:
  614. function slash-backward-kill-word () {
  615. local WORDCHARS="${WORDCHARS:s@/@}"
  616. # zle backward-word
  617. zle backward-kill-word
  618. }
  619. zle -N slash-backward-kill-word
  620. # a generic accept-line wrapper
  621. # This widget can prevent unwanted autocorrections from command-name
  622. # to _command-name, rehash automatically on enter and call any number
  623. # of builtin and user-defined widgets in different contexts.
  624. #
  625. # For a broader description, see:
  626. # <http://bewatermyfriend.org/posts/2007/12-26.11-50-38-tooltime.html>
  627. #
  628. # The code is imported from the file 'zsh/functions/accept-line' from
  629. # <http://ft.bewatermyfriend.org/comp/zsh/zsh-dotfiles.tar.bz2>, which
  630. # distributed under the same terms as zsh itself.
  631. # A newly added command will may not be found or will cause false
  632. # correction attempts, if you got auto-correction set. By setting the
  633. # following style, we force accept-line() to rehash, if it cannot
  634. # find the first word on the command line in the $command[] hash.
  635. zstyle ':acceptline:*' rehash true
  636. function Accept-Line () {
  637. setopt localoptions noksharrays
  638. local -a subs
  639. local -xi aldone
  640. local sub
  641. local alcontext=${1:-$alcontext}
  642. zstyle -a ":acceptline:${alcontext}" actions subs
  643. (( ${#subs} < 1 )) && return 0
  644. (( aldone = 0 ))
  645. for sub in ${subs} ; do
  646. [[ ${sub} == 'accept-line' ]] && sub='.accept-line'
  647. zle ${sub}
  648. (( aldone > 0 )) && break
  649. done
  650. }
  651. function Accept-Line-getdefault () {
  652. emulate -L zsh
  653. local default_action
  654. zstyle -s ":acceptline:${alcontext}" default_action default_action
  655. case ${default_action} in
  656. ((accept-line|))
  657. printf ".accept-line"
  658. ;;
  659. (*)
  660. printf ${default_action}
  661. ;;
  662. esac
  663. }
  664. function Accept-Line-HandleContext () {
  665. zle Accept-Line
  666. default_action=$(Accept-Line-getdefault)
  667. zstyle -T ":acceptline:${alcontext}" call_default \
  668. && zle ${default_action}
  669. }
  670. function accept-line () {
  671. setopt localoptions noksharrays
  672. local -a cmdline
  673. local -x alcontext
  674. local buf com fname format msg default_action
  675. alcontext='default'
  676. buf="${BUFFER}"
  677. cmdline=(${(z)BUFFER})
  678. com="${cmdline[1]}"
  679. fname="_${com}"
  680. Accept-Line 'preprocess'
  681. zstyle -t ":acceptline:${alcontext}" rehash \
  682. && [[ -z ${commands[$com]} ]] \
  683. && rehash
  684. if [[ -n ${com} ]] \
  685. && [[ -n ${reswords[(r)$com]} ]] \
  686. || [[ -n ${aliases[$com]} ]] \
  687. || [[ -n ${functions[$com]} ]] \
  688. || [[ -n ${builtins[$com]} ]] \
  689. || [[ -n ${commands[$com]} ]] ; then
  690. # there is something sensible to execute, just do it.
  691. alcontext='normal'
  692. Accept-Line-HandleContext
  693. return
  694. fi
  695. if [[ -o correct ]] \
  696. || [[ -o correctall ]] \
  697. && [[ -n ${functions[$fname]} ]] ; then
  698. # nothing there to execute but there is a function called
  699. # _command_name; a completion widget. Makes no sense to
  700. # call it on the commandline, but the correct{,all} options
  701. # will ask for it nevertheless, so warn the user.
  702. if [[ ${LASTWIDGET} == 'accept-line' ]] ; then
  703. # Okay, we warned the user before, he called us again,
  704. # so have it his way.
  705. alcontext='force'
  706. Accept-Line-HandleContext
  707. return
  708. fi
  709. if zstyle -t ":acceptline:${alcontext}" nocompwarn ; then
  710. alcontext='normal'
  711. Accept-Line-HandleContext
  712. else
  713. # prepare warning message for the user, configurable via zstyle.
  714. zstyle -s ":acceptline:${alcontext}" compwarnfmt msg
  715. if [[ -z ${msg} ]] ; then
  716. msg="%c will not execute and completion %f exists."
  717. fi
  718. zformat -f msg "${msg}" "c:${com}" "f:${fname}"
  719. zle -M -- "${msg}"
  720. fi
  721. return
  722. elif [[ -n ${buf//[$' \t\n']##/} ]] ; then
  723. # If we are here, the commandline contains something that is not
  724. # executable, which is neither subject to _command_name correction
  725. # and is not empty. might be a variable assignment
  726. alcontext='misc'
  727. Accept-Line-HandleContext
  728. return
  729. fi
  730. # If we got this far, the commandline only contains whitespace, or is empty.
  731. alcontext='empty'
  732. Accept-Line-HandleContext
  733. }
  734. zle -N accept-line
  735. zle -N Accept-Line
  736. zle -N Accept-Line-HandleContext
  737. # power completion / abbreviation expansion / buffer expansion
  738. # see http://zshwiki.org/home/examples/zleiab for details
  739. # less risky than the global aliases but powerful as well
  740. # just type the abbreviation key and afterwards 'ctrl-x .' to expand it
  741. declare -A abk
  742. setopt extendedglob
  743. setopt interactivecomments
  744. abk=(
  745. # key # value (#d additional doc string)
  746. #A# start
  747. '...' '../..'
  748. '....' '../../..'
  749. 'BG' '& exit'
  750. 'C' '| wc -l'
  751. 'G' '|& grep '${grep_options:+"${grep_options[*]}"}
  752. 'H' '| head'
  753. 'Hl' ' --help |& less -r' #d (Display help in pager)
  754. 'L' '| less'
  755. 'LL' '|& less -r'
  756. 'M' '| most'
  757. 'N' '&>/dev/null' #d (No Output)
  758. 'R' '| tr A-z N-za-m' #d (ROT13)
  759. 'SL' '| sort | less'
  760. 'S' '| sort -u'
  761. 'T' '| tail'
  762. 'V' '|& vim -'
  763. #A# end
  764. 'co' './configure && make && sudo make install'
  765. )
  766. function zleiab () {
  767. emulate -L zsh
  768. setopt extendedglob
  769. local MATCH
  770. LBUFFER=${LBUFFER%%(#m)[.\-+:|_a-zA-Z0-9]#}
  771. LBUFFER+=${abk[$MATCH]:-$MATCH}
  772. }
  773. zle -N zleiab
  774. function help-show-abk () {
  775. zle -M "$(print "Available abbreviations for expansion:"; print -a -C 2 ${(kv)abk})"
  776. }
  777. zle -N help-show-abk
  778. # press "ctrl-x d" to insert the actual date in the form yyyy-mm-dd
  779. function insert-datestamp () { LBUFFER+=${(%):-'%D{%Y-%m-%d}'}; }
  780. zle -N insert-datestamp
  781. # press esc-m for inserting last typed word again (thanks to caphuso!)
  782. function insert-last-typed-word () { zle insert-last-word -- 0 -1 };
  783. zle -N insert-last-typed-word;
  784. function grml-zsh-fg () {
  785. if (( ${#jobstates} )); then
  786. zle .push-input
  787. [[ -o hist_ignore_space ]] && BUFFER=' ' || BUFFER=''
  788. BUFFER="${BUFFER}fg"
  789. zle .accept-line
  790. else
  791. zle -M 'No background jobs. Doing nothing.'
  792. fi
  793. }
  794. zle -N grml-zsh-fg
  795. # run command line as user root via sudo:
  796. function sudo-command-line () {
  797. [[ -z $BUFFER ]] && zle up-history
  798. if [[ $BUFFER != sudo\ * ]]; then
  799. BUFFER="sudo $BUFFER"
  800. CURSOR=$(( CURSOR+5 ))
  801. fi
  802. }
  803. zle -N sudo-command-line
  804. ### jump behind the first word on the cmdline.
  805. ### useful to add options.
  806. function jump_after_first_word () {
  807. local words
  808. words=(${(z)BUFFER})
  809. if (( ${#words} <= 1 )) ; then
  810. CURSOR=${#BUFFER}
  811. else
  812. CURSOR=${#${words[1]}}
  813. fi
  814. }
  815. zle -N jump_after_first_word
  816. #f5# Create directory under cursor or the selected area
  817. function inplaceMkDirs () {
  818. # Press ctrl-xM to create the directory under the cursor or the selected area.
  819. # To select an area press ctrl-@ or ctrl-space and use the cursor.
  820. # Use case: you type "mv abc ~/testa/testb/testc/" and remember that the
  821. # directory does not exist yet -> press ctrl-XM and problem solved
  822. local PATHTOMKDIR
  823. if ((REGION_ACTIVE==1)); then
  824. local F=$MARK T=$CURSOR
  825. if [[ $F -gt $T ]]; then
  826. F=${CURSOR}
  827. T=${MARK}
  828. fi
  829. # get marked area from buffer and eliminate whitespace
  830. PATHTOMKDIR=${BUFFER[F+1,T]%%[[:space:]]##}
  831. PATHTOMKDIR=${PATHTOMKDIR##[[:space:]]##}
  832. else
  833. local bufwords iword
  834. bufwords=(${(z)LBUFFER})
  835. iword=${#bufwords}
  836. bufwords=(${(z)BUFFER})
  837. PATHTOMKDIR="${(Q)bufwords[iword]}"
  838. fi
  839. [[ -z "${PATHTOMKDIR}" ]] && return 1
  840. PATHTOMKDIR=${~PATHTOMKDIR}
  841. if [[ -e "${PATHTOMKDIR}" ]]; then
  842. zle -M " path already exists, doing nothing"
  843. else
  844. zle -M "$(mkdir -p -v "${PATHTOMKDIR}")"
  845. zle end-of-line
  846. fi
  847. }
  848. zle -N inplaceMkDirs
  849. #v1# set number of lines to display per page
  850. HELP_LINES_PER_PAGE=20
  851. #v1# set location of help-zle cache file
  852. HELP_ZLE_CACHE_FILE=~/.cache/zsh_help_zle_lines.zsh
  853. # helper function for help-zle, actually generates the help text
  854. function help_zle_parse_keybindings () {
  855. emulate -L zsh
  856. setopt extendedglob
  857. unsetopt ksharrays #indexing starts at 1
  858. #v1# choose files that help-zle will parse for keybindings
  859. ((${+HELPZLE_KEYBINDING_FILES})) || HELPZLE_KEYBINDING_FILES=( /etc/zsh/zshrc ~/.zshrc.pre ~/.zshrc ~/.zshrc.local )
  860. if [[ -r $HELP_ZLE_CACHE_FILE ]]; then
  861. local load_cache=0
  862. local f
  863. for f ($HELPZLE_KEYBINDING_FILES) [[ $f -nt $HELP_ZLE_CACHE_FILE ]] && load_cache=1
  864. [[ $load_cache -eq 0 ]] && . $HELP_ZLE_CACHE_FILE && return
  865. fi
  866. #fill with default keybindings, possibly to be overwritten in a file later
  867. #Note that due to zsh inconsistency on escaping assoc array keys, we encase the key in '' which we will remove later
  868. local -A help_zle_keybindings
  869. help_zle_keybindings['<Ctrl>@']="set MARK"
  870. help_zle_keybindings['<Ctrl>x<Ctrl>j']="vi-join lines"
  871. help_zle_keybindings['<Ctrl>x<Ctrl>b']="jump to matching brace"
  872. help_zle_keybindings['<Ctrl>x<Ctrl>u']="undo"
  873. help_zle_keybindings['<Ctrl>_']="undo"
  874. help_zle_keybindings['<Ctrl>x<Ctrl>f<c>']="find <c> in cmdline"
  875. help_zle_keybindings['<Ctrl>a']="goto beginning of line"
  876. help_zle_keybindings['<Ctrl>e']="goto end of line"
  877. help_zle_keybindings['<Ctrl>t']="transpose charaters"
  878. help_zle_keybindings['<Alt>t']="transpose words"
  879. help_zle_keybindings['<Alt>s']="spellcheck word"
  880. help_zle_keybindings['<Ctrl>k']="backward kill buffer"
  881. help_zle_keybindings['<Ctrl>u']="forward kill buffer"
  882. help_zle_keybindings['<Ctrl>y']="insert previously killed word/string"
  883. help_zle_keybindings["<Alt>'"]="quote line"
  884. help_zle_keybindings['<Alt>"']="quote from mark to cursor"
  885. help_zle_keybindings['<Alt><arg>']="repeat next cmd/char <arg> times (<Alt>-<Alt>1<Alt>0a -> -10 times 'a')"
  886. help_zle_keybindings['<Alt>u']="make next word Uppercase"
  887. help_zle_keybindings['<Alt>l']="make next word lowercase"
  888. help_zle_keybindings['<Ctrl>xG']="preview expansion under cursor"
  889. help_zle_keybindings['<Alt>q']="push current CL into background, freeing it. Restore on next CL"
  890. help_zle_keybindings['<Alt>.']="insert (and interate through) last word from prev CLs"
  891. help_zle_keybindings['<Alt>,']="complete word from newer history (consecutive hits)"
  892. help_zle_keybindings['<Alt>m']="repeat last typed word on current CL"
  893. help_zle_keybindings['<Ctrl>v']="insert next keypress symbol literally (e.g. for bindkey)"
  894. help_zle_keybindings['!!:n*<Tab>']="insert last n arguments of last command"
  895. help_zle_keybindings['!!:n-<Tab>']="insert arguments n..N-2 of last command (e.g. mv s s d)"
  896. help_zle_keybindings['<Alt>h']="show help/manpage for current command"
  897. #init global variables
  898. unset help_zle_lines help_zle_sln
  899. typeset -g -a help_zle_lines
  900. typeset -g help_zle_sln=1
  901. local k v f cline
  902. local lastkeybind_desc contents #last description starting with #k# that we found
  903. local num_lines_elapsed=0 #number of lines between last description and keybinding
  904. #search config files in the order they a called (and thus the order in which they overwrite keybindings)
  905. for f in $HELPZLE_KEYBINDING_FILES; do
  906. [[ -r "$f" ]] || continue #not readable ? skip it
  907. contents="$(<$f)"
  908. for cline in "${(f)contents}"; do
  909. #zsh pattern: matches lines like: #k# ..............
  910. if [[ "$cline" == (#s)[[:space:]]#\#k\#[[:space:]]##(#b)(*)[[:space:]]#(#e) ]]; then
  911. lastkeybind_desc="$match[*]"
  912. num_lines_elapsed=0
  913. #zsh pattern: matches lines that set a keybinding using bind2map, bindkey or compdef -k
  914. # ignores lines that are commentend out
  915. # grabs first in '' or "" enclosed string with length between 1 and 6 characters
  916. elif [[ "$cline" == [^#]#(bind2maps[[:space:]](*)-s|bindkey|compdef -k)[[:space:]](*)(#b)(\"((?)(#c1,6))\"|\'((?)(#c1,6))\')(#B)(*) ]]; then
  917. #description previously found ? description not more than 2 lines away ? keybinding not empty ?
  918. if [[ -n $lastkeybind_desc && $num_lines_elapsed -lt 2 && -n $match[1] ]]; then
  919. #substitute keybinding string with something readable
  920. k=${${${${${${${match[1]/\\e\^h/<Alt><BS>}/\\e\^\?/<Alt><BS>}/\\e\[5~/<PageUp>}/\\e\[6~/<PageDown>}//(\\e|\^\[)/<Alt>}//\^/<Ctrl>}/3~/<Alt><Del>}
  921. #put keybinding in assoc array, possibly overwriting defaults or stuff found in earlier files
  922. #Note that we are extracting the keybinding-string including the quotes (see Note at beginning)
  923. help_zle_keybindings[${k}]=$lastkeybind_desc
  924. fi
  925. lastkeybind_desc=""
  926. else
  927. ((num_lines_elapsed++))
  928. fi
  929. done
  930. done
  931. unset contents
  932. #calculate length of keybinding column
  933. local kstrlen=0
  934. for k (${(k)help_zle_keybindings[@]}) ((kstrlen < ${#k})) && kstrlen=${#k}
  935. #convert the assoc array into preformated lines, which we are able to sort
  936. for k v in ${(kv)help_zle_keybindings[@]}; do
  937. #pad keybinding-string to kstrlen chars and remove outermost characters (i.e. the quotes)
  938. help_zle_lines+=("${(r:kstrlen:)k[2,-2]}${v}")
  939. done
  940. #sort lines alphabetically
  941. help_zle_lines=("${(i)help_zle_lines[@]}")
  942. [[ -d ${HELP_ZLE_CACHE_FILE:h} ]] || mkdir -p "${HELP_ZLE_CACHE_FILE:h}"
  943. echo "help_zle_lines=(${(q)help_zle_lines[@]})" >| $HELP_ZLE_CACHE_FILE
  944. zcompile $HELP_ZLE_CACHE_FILE
  945. }
  946. typeset -g help_zle_sln
  947. typeset -g -a help_zle_lines
  948. # Provides (partially autogenerated) help on keybindings and the zsh line editor
  949. function help-zle () {
  950. emulate -L zsh
  951. unsetopt ksharrays #indexing starts at 1
  952. #help lines already generated ? no ? then do it
  953. [[ ${+functions[help_zle_parse_keybindings]} -eq 1 ]] && {help_zle_parse_keybindings && unfunction help_zle_parse_keybindings}
  954. #already displayed all lines ? go back to the start
  955. [[ $help_zle_sln -gt ${#help_zle_lines} ]] && help_zle_sln=1
  956. local sln=$help_zle_sln
  957. #note that help_zle_sln is a global var, meaning we remember the last page we viewed
  958. help_zle_sln=$((help_zle_sln + HELP_LINES_PER_PAGE))
  959. zle -M "${(F)help_zle_lines[sln,help_zle_sln-1]}"
  960. }
  961. zle -N help-zle
  962. ## complete word from currently visible Screen or Tmux buffer.
  963. if check_com -c screen || check_com -c tmux; then
  964. function _complete_screen_display () {
  965. [[ "$TERM" != "screen" ]] && return 1
  966. local TMPFILE=$(mktemp)
  967. local -U -a _screen_display_wordlist
  968. trap "rm -f $TMPFILE" EXIT
  969. # fill array with contents from screen hardcopy
  970. if ((${+TMUX})); then
  971. #works, but crashes tmux below version 1.4
  972. #luckily tmux -V option to ask for version, was also added in 1.4
  973. tmux -V &>/dev/null || return
  974. tmux -q capture-pane \; save-buffer -b 0 $TMPFILE \; delete-buffer -b 0
  975. else
  976. screen -X hardcopy $TMPFILE
  977. # screen sucks, it dumps in latin1, apparently always. so recode it
  978. # to system charset
  979. check_com recode && recode latin1 $TMPFILE
  980. fi
  981. _screen_display_wordlist=( ${(QQ)$(<$TMPFILE)} )
  982. # remove PREFIX to be completed from that array
  983. _screen_display_wordlist[${_screen_display_wordlist[(i)$PREFIX]}]=""
  984. compadd -a _screen_display_wordlist
  985. }
  986. #m# k CTRL-x\,\,\,S Complete word from GNU screen buffer
  987. bindkey -r "^xS"
  988. compdef -k _complete_screen_display complete-word '^xS'
  989. fi
  990. # Load a few more functions and tie them to widgets, so they can be bound:
  991. function zrcautozle () {
  992. emulate -L zsh
  993. local fnc=$1
  994. zrcautoload $fnc && zle -N $fnc
  995. }
  996. function zrcgotwidget () {
  997. (( ${+widgets[$1]} ))
  998. }
  999. function zrcgotkeymap () {
  1000. [[ -n ${(M)keymaps:#$1} ]]
  1001. }
  1002. zrcautozle insert-files
  1003. zrcautozle edit-command-line
  1004. zrcautozle insert-unicode-char
  1005. if zrcautoload history-search-end; then
  1006. zle -N history-beginning-search-backward-end history-search-end
  1007. zle -N history-beginning-search-forward-end history-search-end
  1008. fi
  1009. zle -C hist-complete complete-word _generic
  1010. zstyle ':completion:hist-complete:*' completer _history
  1011. # The actual terminal setup hooks and bindkey-calls:
  1012. # An array to note missing features to ease diagnosis in case of problems.
  1013. typeset -ga grml_missing_features
  1014. function zrcbindkey () {
  1015. if (( ARGC )) && zrcgotwidget ${argv[-1]}; then
  1016. bindkey "$@"
  1017. fi
  1018. }
  1019. function bind2maps () {
  1020. local i sequence widget
  1021. local -a maps
  1022. while [[ "$1" != "--" ]]; do
  1023. maps+=( "$1" )
  1024. shift
  1025. done
  1026. shift
  1027. if [[ "$1" == "-s" ]]; then
  1028. shift
  1029. sequence="$1"
  1030. else
  1031. sequence="${key[$1]}"
  1032. fi
  1033. widget="$2"
  1034. [[ -z "$sequence" ]] && return 1
  1035. for i in "${maps[@]}"; do
  1036. zrcbindkey -M "$i" "$sequence" "$widget"
  1037. done
  1038. }
  1039. if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
  1040. function zle-smkx () {
  1041. emulate -L zsh
  1042. printf '%s' ${terminfo[smkx]}
  1043. }
  1044. function zle-rmkx () {
  1045. emulate -L zsh
  1046. printf '%s' ${terminfo[rmkx]}
  1047. }
  1048. function zle-line-init () {
  1049. zle-smkx
  1050. }
  1051. function zle-line-finish () {
  1052. zle-rmkx
  1053. }
  1054. zle -N zle-line-init
  1055. zle -N zle-line-finish
  1056. else
  1057. for i in {s,r}mkx; do
  1058. (( ${+terminfo[$i]} )) || grml_missing_features+=($i)
  1059. done
  1060. unset i
  1061. fi
  1062. typeset -A key
  1063. key=(
  1064. Home "${terminfo[khome]}"
  1065. End "${terminfo[kend]}"
  1066. Insert "${terminfo[kich1]}"
  1067. Delete "${terminfo[kdch1]}"
  1068. Up "${terminfo[kcuu1]}"
  1069. Down "${terminfo[kcud1]}"
  1070. Left "${terminfo[kcub1]}"
  1071. Right "${terminfo[kcuf1]}"
  1072. PageUp "${terminfo[kpp]}"
  1073. PageDown "${terminfo[knp]}"
  1074. BackTab "${terminfo[kcbt]}"
  1075. )
  1076. # Guidelines for adding key bindings:
  1077. #
  1078. # - Do not add hardcoded escape sequences, to enable non standard key
  1079. # combinations such as Ctrl-Meta-Left-Cursor. They are not easily portable.
  1080. #
  1081. # - Adding Ctrl characters, such as '^b' is okay; note that '^b' and '^B' are
  1082. # the same key.
  1083. #
  1084. # - All keys from the $key[] mapping are obviously okay.
  1085. #
  1086. # - Most terminals send "ESC x" when Meta-x is pressed. Thus, sequences like
  1087. # '\ex' are allowed in here as well.
  1088. bind2maps emacs -- Home beginning-of-somewhere
  1089. bind2maps viins vicmd -- Home vi-beginning-of-line
  1090. bind2maps emacs -- End end-of-somewhere
  1091. bind2maps viins vicmd -- End vi-end-of-line
  1092. bind2maps emacs viins -- Insert overwrite-mode
  1093. bind2maps vicmd -- Insert vi-insert
  1094. bind2maps emacs -- Delete delete-char
  1095. bind2maps viins vicmd -- Delete vi-delete-char
  1096. bind2maps emacs viins vicmd -- Up up-line-or-search
  1097. bind2maps emacs viins vicmd -- Down down-line-or-search
  1098. bind2maps emacs -- Left backward-char
  1099. bind2maps viins vicmd -- Left vi-backward-char
  1100. bind2maps emacs -- Right forward-char
  1101. bind2maps viins vicmd -- Right vi-forward-char
  1102. #k# Perform abbreviation expansion
  1103. bind2maps emacs viins -- -s '^x.' zleiab
  1104. #k# Display list of abbreviations that would expand
  1105. bind2maps emacs viins -- -s '^xb' help-show-abk
  1106. #k# mkdir -p <dir> from string under cursor or marked area
  1107. bind2maps emacs viins -- -s '^xM' inplaceMkDirs
  1108. #k# display help for keybindings and ZLE
  1109. bind2maps emacs viins -- -s '^xz' help-zle
  1110. #k# Insert files and test globbing
  1111. bind2maps emacs viins -- -s "^xf" insert-files
  1112. #k# Edit the current line in \kbd{\$EDITOR}
  1113. bind2maps emacs viins -- -s '\ee' edit-command-line
  1114. #k# search history backward for entry beginning with typed text
  1115. bind2maps emacs viins -- -s '^xp' history-beginning-search-backward-end
  1116. #k# search history forward for entry beginning with typed text
  1117. bind2maps emacs viins -- -s '^xP' history-beginning-search-forward-end
  1118. #k# search history backward for entry beginning with typed text
  1119. bind2maps emacs viins -- PageUp history-beginning-search-backward-end
  1120. #k# search history forward for entry beginning with typed text
  1121. bind2maps emacs viins -- PageDown history-beginning-search-forward-end
  1122. bind2maps emacs viins -- -s "^x^h" commit-to-history
  1123. #k# Kill left-side word or everything up to next slash
  1124. bind2maps emacs viins -- -s '\ev' slash-backward-kill-word
  1125. #k# Kill left-side word or everything up to next slash
  1126. bind2maps emacs viins -- -s '\e^h' slash-backward-kill-word
  1127. #k# Kill left-side word or everything up to next slash
  1128. bind2maps emacs viins -- -s '\e^?' slash-backward-kill-word
  1129. # Do history expansion on space:
  1130. bind2maps emacs viins -- -s ' ' magic-space
  1131. #k# Trigger menu-complete
  1132. bind2maps emacs viins -- -s '\ei' menu-complete # menu completion via esc-i
  1133. #k# Insert a timestamp on the command line (yyyy-mm-dd)
  1134. bind2maps emacs viins -- -s '^xd' insert-datestamp
  1135. #k# Insert last typed word
  1136. bind2maps emacs viins -- -s "\em" insert-last-typed-word
  1137. #k# A smart shortcut for \kbd{fg<enter>}
  1138. bind2maps emacs viins -- -s '^z' grml-zsh-fg
  1139. #k# prepend the current command with "sudo"
  1140. bind2maps emacs viins -- -s "^os" sudo-command-line
  1141. #k# jump to after first word (for adding options)
  1142. bind2maps emacs viins -- -s '^x1' jump_after_first_word
  1143. #k# complete word from history with menu
  1144. bind2maps emacs viins -- -s "^x^x" hist-complete
  1145. # insert unicode character
  1146. # usage example: 'ctrl-x i' 00A7 'ctrl-x i' will give you an §
  1147. # See for example http://unicode.org/charts/ for unicode characters code
  1148. #k# Insert Unicode character
  1149. bind2maps emacs viins -- -s '^xi' insert-unicode-char
  1150. # use the new *-pattern-* widgets for incremental history search
  1151. if zrcgotwidget history-incremental-pattern-search-backward; then
  1152. for seq wid in '^r' history-incremental-pattern-search-backward \
  1153. '^s' history-incremental-pattern-search-forward
  1154. do
  1155. bind2maps emacs viins vicmd -- -s $seq $wid
  1156. done
  1157. builtin unset -v seq wid
  1158. fi
  1159. if zrcgotkeymap menuselect; then
  1160. #m# k Shift-tab Perform backwards menu completion
  1161. bind2maps menuselect -- BackTab reverse-menu-complete
  1162. #k# menu selection: pick item but stay in the menu
  1163. bind2maps menuselect -- -s '\e^M' accept-and-menu-complete
  1164. # also use + and INSERT since it's easier to press repeatedly
  1165. bind2maps menuselect -- -s '+' accept-and-menu-complete
  1166. bind2maps menuselect -- Insert accept-and-menu-complete
  1167. # accept a completion and try to complete again by using menu
  1168. # completion; very useful with completing directories
  1169. # by using 'undo' one's got a simple file browser
  1170. bind2maps menuselect -- -s '^o' accept-and-infer-next-history
  1171. fi
  1172. # Finally, here are still a few hardcoded escape sequences; Special sequences
  1173. # like Ctrl-<Cursor-key> etc do suck a fair bit, because they are not
  1174. # standardised and most of the time are not available in a terminals terminfo
  1175. # entry.
  1176. #
  1177. # While we do not encourage adding bindings like these, we will keep these for
  1178. # backward compatibility.
  1179. ## use Ctrl-left-arrow and Ctrl-right-arrow for jumping to word-beginnings on
  1180. ## the command line.
  1181. # URxvt sequences:
  1182. bind2maps emacs viins vicmd -- -s '\eOc' forward-word
  1183. bind2maps emacs viins vicmd -- -s '\eOd' backward-word
  1184. # These are for xterm:
  1185. bind2maps emacs viins vicmd -- -s '\e[1;5C' forward-word
  1186. bind2maps emacs viins vicmd -- -s '\e[1;5D' backward-word
  1187. ## the same for alt-left-arrow and alt-right-arrow
  1188. # URxvt again:
  1189. bind2maps emacs viins vicmd -- -s '\e\e[C' forward-word
  1190. bind2maps emacs viins vicmd -- -s '\e\e[D' backward-word
  1191. # Xterm again:
  1192. bind2maps emacs viins vicmd -- -s '^[[1;3C' forward-word
  1193. bind2maps emacs viins vicmd -- -s '^[[1;3D' backward-word
  1194. # Also try ESC Left/Right:
  1195. bind2maps emacs viins vicmd -- -s '\e'${key[Right]} forward-word
  1196. bind2maps emacs viins vicmd -- -s '\e'${key[Left]} backward-word
  1197. # autoloading
  1198. zrcautoload zmv
  1199. zrcautoload zed
  1200. # we don't want to quote/espace URLs on our own...
  1201. # if autoload -U url-quote-magic ; then
  1202. # zle -N self-insert url-quote-magic
  1203. # zstyle ':url-quote-magic:*' url-metas '*?[]^()~#{}='
  1204. # else
  1205. # print 'Notice: no url-quote-magic available :('
  1206. # fi
  1207. alias url-quote='autoload -U url-quote-magic ; zle -N self-insert url-quote-magic'
  1208. #m# k ESC-h Call \kbd{run-help} for the 1st word on the command line
  1209. alias run-help >&/dev/null && unalias run-help
  1210. for rh in run-help{,-ip,-openssl,-p4,-sudo,-svk,-svn}; do
  1211. zrcautoload $rh
  1212. done; unset rh
  1213. # command not found handling
  1214. command_not_found_handler() {
  1215. local pkgs cmd="$1"
  1216. pkgs=(${(f)"$(pkgfile -b -v -- "$cmd" 2>/dev/null)"})
  1217. if [[ -n "$pkgs" ]]; then
  1218. printf '%s may be found in the following packages:\n' "$cmd"
  1219. printf ' %s\n' $pkgs[@]
  1220. else
  1221. printf 'zsh: command not found: %s\n' "$cmd"
  1222. fi 1>&2
  1223. return 127
  1224. }
  1225. # history
  1226. #v#
  1227. HISTFILE=${HISTFILE:-${ZDOTDIR:-${HOME}}/.zsh_history}
  1228. # dirstack handling
  1229. DIRSTACKSIZE=${DIRSTACKSIZE:-20}
  1230. DIRSTACKFILE=${DIRSTACKFILE:-${ZDOTDIR:-${HOME}}/.zdirs}
  1231. if zstyle -T ':grml:chpwd:dirstack' enable; then
  1232. typeset -gaU GRML_PERSISTENT_DIRSTACK
  1233. function grml_dirstack_filter () {
  1234. local -a exclude
  1235. local filter entry
  1236. if zstyle -s ':grml:chpwd:dirstack' filter filter; then
  1237. $filter $1 && return 0
  1238. fi
  1239. if zstyle -a ':grml:chpwd:dirstack' exclude exclude; then
  1240. for entry in "${exclude[@]}"; do
  1241. [[ $1 == ${~entry} ]] && return 0
  1242. done
  1243. fi
  1244. return 1
  1245. }
  1246. function chpwd () {
  1247. (( ZSH_SUBSHELL )) && return
  1248. (( $DIRSTACKSIZE <= 0 )) && return
  1249. [[ -z $DIRSTACKFILE ]] && return
  1250. grml_dirstack_filter $PWD && return
  1251. GRML_PERSISTENT_DIRSTACK=(
  1252. $PWD "${(@)GRML_PERSISTENT_DIRSTACK[1,$DIRSTACKSIZE]}"
  1253. )
  1254. builtin print -l ${GRML_PERSISTENT_DIRSTACK} >! ${DIRSTACKFILE}
  1255. }
  1256. if [[ -f ${DIRSTACKFILE} ]]; then
  1257. # Enabling NULL_GLOB via (N) weeds out any non-existing
  1258. # directories from the saved dir-stack file.
  1259. dirstack=( ${(f)"$(< $DIRSTACKFILE)"}(N) )
  1260. # "cd -" won't work after login by just setting $OLDPWD, so
  1261. [[ -d $dirstack[1] ]] && cd -q $dirstack[1] && cd -q $OLDPWD
  1262. fi
  1263. if zstyle -t ':grml:chpwd:dirstack' filter-on-load; then
  1264. for i in "${dirstack[@]}"; do
  1265. if ! grml_dirstack_filter "$i"; then
  1266. GRML_PERSISTENT_DIRSTACK=(
  1267. "${GRML_PERSISTENT_DIRSTACK[@]}"
  1268. $i
  1269. )
  1270. fi
  1271. done
  1272. else
  1273. GRML_PERSISTENT_DIRSTACK=( "${dirstack[@]}" )
  1274. fi
  1275. fi
  1276. # directory based profiles
  1277. # Prompt setup for grml:
  1278. # set colors for use in prompts (modern zshs allow for the use of %F{red}foo%f
  1279. # in prompts to get a red "foo" embedded, but it's good to keep these for
  1280. # backwards compatibility).
  1281. BLUE="%F{blue}"
  1282. RED="%F{red}"
  1283. GREEN="%F{green}"
  1284. CYAN="%F{cyan}"
  1285. MAGENTA="%F{magenta}"
  1286. YELLOW="%F{yellow}"
  1287. WHITE="%F{white}"
  1288. NO_COLOR="%f"
  1289. # First, the easy ones: PS2..4:
  1290. # secondary prompt, printed when the shell needs more information to complete a
  1291. # command.
  1292. PS2='\`%_> '
  1293. # selection prompt used within a select loop.
  1294. PS3='?# '
  1295. # the execution trace prompt (setopt xtrace). default: '+%N:%i>'
  1296. PS4='+%N:%i:%_> '
  1297. # Some additional features to use with our prompt:
  1298. #
  1299. # - battery status
  1300. # - debian_chroot
  1301. # - vcs_info setup and version specific fixes
  1302. # display battery status on right side of prompt using 'GRML_DISPLAY_BATTERY=1' in .zshrc.pre
  1303. function battery () {
  1304. if [[ $GRML_DISPLAY_BATTERY -gt 0 ]] ; then
  1305. batterylinux
  1306. fi
  1307. }
  1308. function batterylinux () {
  1309. GRML_BATTERY_LEVEL=''
  1310. local batteries bat capacity
  1311. batteries=( /sys/class/power_supply/BAT*(N) )
  1312. if (( $#batteries > 0 )) ; then
  1313. for bat in $batteries ; do
  1314. if [[ -e $bat/capacity ]]; then
  1315. capacity=$(< $bat/capacity)
  1316. else
  1317. typeset -F energy_full=$(< $bat/energy_full)
  1318. typeset -F energy_now=$(< $bat/energy_now)
  1319. typeset -i capacity=$(( 100 * $energy_now / $energy_full))
  1320. fi
  1321. case $(< $bat/status) in
  1322. Charging)
  1323. GRML_BATTERY_LEVEL+=" ^"
  1324. ;;
  1325. Discharging)
  1326. if (( capacity < 20 )) ; then
  1327. GRML_BATTERY_LEVEL+=" !v"
  1328. else
  1329. GRML_BATTERY_LEVEL+=" v"
  1330. fi
  1331. ;;
  1332. *) # Full, Unknown
  1333. GRML_BATTERY_LEVEL+=" ="
  1334. ;;
  1335. esac
  1336. GRML_BATTERY_LEVEL+="${capacity}%%"
  1337. done
  1338. fi
  1339. }
  1340. function batteryopenbsd () {
  1341. GRML_BATTERY_LEVEL=''
  1342. local bat batfull batwarn batnow num
  1343. for num in 0 1 ; do
  1344. bat=$(sysctl -n hw.sensors.acpibat${num} 2>/dev/null)
  1345. if [[ -n $bat ]]; then
  1346. batfull=${"$(sysctl -n hw.sensors.acpibat${num}.amphour0)"%% *}
  1347. batwarn=${"$(sysctl -n hw.sensors.acpibat${num}.amphour1)"%% *}
  1348. batnow=${"$(sysctl -n hw.sensors.acpibat${num}.amphour3)"%% *}
  1349. case "$(sysctl -n hw.sensors.acpibat${num}.raw0)" in
  1350. *" discharging"*)
  1351. if (( batnow < batwarn )) ; then
  1352. GRML_BATTERY_LEVEL+=" !v"
  1353. else
  1354. GRML_BATTERY_LEVEL+=" v"
  1355. fi
  1356. ;;
  1357. *" charging"*)
  1358. GRML_BATTERY_LEVEL+=" ^"
  1359. ;;
  1360. *)
  1361. GRML_BATTERY_LEVEL+=" ="
  1362. ;;
  1363. esac
  1364. GRML_BATTERY_LEVEL+="${$(( 100 * batnow / batfull ))%%.*}%%"
  1365. fi
  1366. done
  1367. }
  1368. function batteryfreebsd () {
  1369. GRML_BATTERY_LEVEL=''
  1370. local num
  1371. local -A table
  1372. for num in 0 1 ; do
  1373. table=( ${=${${${${${(M)${(f)"$(acpiconf -i $num 2>&1)"}:#(State|Remaining capacity):*}%%( ##|%)}//:[ $'\t']##/@}// /-}//@/ }} )
  1374. if [[ -n $table ]] && [[ $table[State] != "not-present" ]] ; then
  1375. case $table[State] in
  1376. *discharging*)
  1377. if (( $table[Remaining-capacity] < 20 )) ; then
  1378. GRML_BATTERY_LEVEL+=" !v"
  1379. else
  1380. GRML_BATTERY_LEVEL+=" v"
  1381. fi
  1382. ;;
  1383. *charging*)
  1384. GRML_BATTERY_LEVEL+=" ^"
  1385. ;;
  1386. *)
  1387. GRML_BATTERY_LEVEL+=" ="
  1388. ;;
  1389. esac
  1390. GRML_BATTERY_LEVEL+="$table[Remaining-capacity]%%"
  1391. fi
  1392. done
  1393. }
  1394. function batterydarwin () {
  1395. GRML_BATTERY_LEVEL=''
  1396. local -a table
  1397. table=( ${$(pmset -g ps)[(w)8,9]%%(\%|);} )
  1398. if [[ -n $table[2] ]] ; then
  1399. case $table[2] in
  1400. charging)
  1401. GRML_BATTERY_LEVEL+=" ^"
  1402. ;;
  1403. discharging)
  1404. if (( $table[1] < 20 )) ; then
  1405. GRML_BATTERY_LEVEL+=" !v"
  1406. else
  1407. GRML_BATTERY_LEVEL+=" v"
  1408. fi
  1409. ;;
  1410. *)
  1411. GRML_BATTERY_LEVEL+=" ="
  1412. ;;
  1413. esac
  1414. GRML_BATTERY_LEVEL+="$table[1]%%"
  1415. fi
  1416. }
  1417. # set variable debian_chroot if running in a chroot with /etc/debian_chroot
  1418. if [[ -z "$debian_chroot" ]] && [[ -r /etc/debian_chroot ]] ; then
  1419. debian_chroot=$(</etc/debian_chroot)
  1420. fi
  1421. # gather version control information for inclusion in a prompt
  1422. if zrcautoload vcs_info; then
  1423. # `vcs_info' in zsh versions 4.3.10 and below have a broken `_realpath'
  1424. # function, which can cause a lot of trouble with our directory-based
  1425. # profiles. So:
  1426. if [[ ${ZSH_VERSION} == 4.3.<-10> ]] ; then
  1427. function VCS_INFO_realpath () {
  1428. setopt localoptions NO_shwordsplit chaselinks
  1429. ( builtin cd -q $1 2> /dev/null && pwd; )
  1430. }
  1431. fi
  1432. zstyle ':vcs_info:*' max-exports 2
  1433. if [[ -o restricted ]]; then
  1434. zstyle ':vcs_info:*' enable NONE
  1435. fi
  1436. fi
  1437. typeset -A grml_vcs_coloured_formats
  1438. typeset -A grml_vcs_plain_formats
  1439. grml_vcs_plain_formats=(
  1440. format "(%s%)-[%b] " "zsh: %r"
  1441. actionformat "(%s%)-[%b|%a] " "zsh: %r"
  1442. rev-branchformat "%b:%r"
  1443. )
  1444. grml_vcs_coloured_formats=(
  1445. format "${MAGENTA}(${NO_COLOR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${MAGENTA}]${NO_COLOR} "
  1446. actionformat "${MAGENTA}(${NO_COLOR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${YELLOW}|${RED}%a${MAGENTA}]${NO_COLOR} "
  1447. rev-branchformat "%b${RED}:${YELLOW}%r"
  1448. )
  1449. # Change vcs_info formats for the grml prompt. The 2nd format sets up
  1450. # $vcs_info_msg_1_ to contain "zsh: repo-name" used to set our screen title.
  1451. function grml_prompt_setup () {
  1452. emulate -L zsh
  1453. autoload -Uz vcs_info
  1454. # The following autoload is disabled for now, since this setup includes a
  1455. # static version of the ‘add-zsh-hook’ function above. It needs to be
  1456. # re-enabled as soon as that static definition is removed again.
  1457. #autoload -Uz add-zsh-hook
  1458. add-zsh-hook precmd prompt_$1_precmd
  1459. }
  1460. function prompt_grml_setup () {
  1461. grml_prompt_setup grml
  1462. }
  1463. function prompt_grml-chroot_setup () {
  1464. grml_prompt_setup grml-chroot
  1465. }
  1466. function prompt_grml-large_setup () {
  1467. grml_prompt_setup grml-large
  1468. }
  1469. # Now for the fun part: The grml prompt themes in `promptsys' mode of operation
  1470. # This actually defines three prompts:
  1471. #
  1472. # - grml
  1473. # - grml-large
  1474. # - grml-chroot
  1475. #
  1476. # They all share the same code and only differ with respect to which items they
  1477. # contain. The main source of documentation is the `prompt_grml_help' function
  1478. # below, which gets called when the user does this: prompt -h grml
  1479. # These maps define default tokens and pre-/post-decoration for items to be
  1480. # used within the themes. All defaults may be customised in a context sensitive
  1481. # matter by using zsh's `zstyle' mechanism.
  1482. typeset -gA grml_prompt_pre_default \
  1483. grml_prompt_post_default \
  1484. grml_prompt_token_default \
  1485. grml_prompt_token_function
  1486. grml_prompt_pre_default=(
  1487. at ''
  1488. battery ' '
  1489. change-root ''
  1490. date '%F{blue}'
  1491. grml-chroot '%F{red}'
  1492. history '%F{green}'
  1493. host '%F{blue}'
  1494. jobs '%F{cyan}'
  1495. newline ''
  1496. path '%B'
  1497. percent ''
  1498. rc '%B%F{red}'
  1499. rc-always ''
  1500. sad-smiley ''
  1501. shell-level '%F{red}'
  1502. time '%F{blue}'
  1503. user '%B%F{green}'
  1504. vcs ''
  1505. )
  1506. grml_prompt_post_default=(
  1507. at ''
  1508. battery ''
  1509. change-root ''
  1510. date '%f'
  1511. grml-chroot '%f '
  1512. history '%f'
  1513. host '%f'
  1514. jobs '%f'
  1515. newline ''
  1516. path '%b'
  1517. percent ''
  1518. rc '%f%b'
  1519. rc-always ''
  1520. sad-smiley ''
  1521. shell-level '%f'
  1522. time '%f'
  1523. user '%f%b'
  1524. vcs ''
  1525. )
  1526. grml_prompt_token_default=(
  1527. at '@'
  1528. battery 'GRML_BATTERY_LEVEL'
  1529. change-root 'debian_chroot'
  1530. date '%D{%Y-%m-%d}'
  1531. grml-chroot 'GRML_CHROOT'
  1532. history '{history#%!} '
  1533. host '%m '
  1534. jobs '[%j running job(s)] '
  1535. newline $'\n'
  1536. path '%40<..<%~%<< '
  1537. percent '$ '
  1538. rc '%(?..%? )'
  1539. rc-always '%?'
  1540. sad-smiley '%(?..:()'
  1541. shell-level '%(3L.+ .)'
  1542. time '%D{%H:%M:%S} '
  1543. user '%n'
  1544. vcs '0'
  1545. )
  1546. function grml_theme_has_token () {
  1547. if (( ARGC != 1 )); then
  1548. printf 'usage: grml_theme_has_token <name>\n'
  1549. return 1
  1550. fi
  1551. (( ${+grml_prompt_token_default[$1]} ))
  1552. }
  1553. function GRML_theme_add_token_usage () {
  1554. <<__EOF0__
  1555. Usage: grml_theme_add_token <name> [-f|-i] <token/function> [<pre> <post>]
  1556. <name> is the name for the newly added token. If the \`-f' or \`-i' options
  1557. are used, <token/function> is the name of the function (see below for
  1558. details). Otherwise it is the literal token string to be used. <pre> and
  1559. <post> are optional.
  1560. Options:
  1561. -f <function> Use a function named \`<function>' each time the token
  1562. is to be expanded.
  1563. -i <function> Use a function named \`<function>' to initialise the
  1564. value of the token _once_ at runtime.
  1565. The functions are called with one argument: the token's new name. The
  1566. return value is expected in the \$REPLY parameter. The use of these
  1567. options is mutually exclusive.
  1568. There is a utility function \`grml_theme_has_token', which you can use
  1569. to test if a token exists before trying to add it. This can be a guard
  1570. for situations in which a \`grml_theme_add_token' call may happen more
  1571. than once.
  1572. Example:
  1573. To add a new token \`day' that expands to the current weekday in the
  1574. current locale in green foreground colour, use this:
  1575. grml_theme_add_token day '%D{%A}' '%F{green}' '%f'
  1576. Another example would be support for \$VIRTUAL_ENV:
  1577. function virtual_env_prompt () {
  1578. REPLY=\${VIRTUAL_ENV+\${VIRTUAL_ENV:t} }
  1579. }
  1580. grml_theme_add_token virtual-env -f virtual_env_prompt
  1581. After that, you will be able to use a changed \`items' style to
  1582. assemble your prompt.
  1583. __EOF0__
  1584. }
  1585. function grml_theme_add_token () {
  1586. emulate -L zsh
  1587. local name token pre post
  1588. local -i init funcall
  1589. if (( ARGC == 0 )); then
  1590. GRML_theme_add_token_usage
  1591. return 0
  1592. fi
  1593. init=0
  1594. funcall=0
  1595. pre=''
  1596. post=''
  1597. name=$1
  1598. shift
  1599. if [[ $1 == '-f' ]]; then
  1600. funcall=1
  1601. shift
  1602. elif [[ $1 == '-i' ]]; then
  1603. init=1
  1604. shift
  1605. fi
  1606. if (( ARGC == 0 )); then
  1607. printf '
  1608. grml_theme_add_token: No token-string/function-name provided!\n\n'
  1609. GRML_theme_add_token_usage
  1610. return 1
  1611. fi
  1612. token=$1
  1613. shift
  1614. if (( ARGC != 0 && ARGC != 2 )); then
  1615. printf '
  1616. grml_theme_add_token: <pre> and <post> need to by specified _both_!\n\n'
  1617. GRML_theme_add_token_usage
  1618. return 1
  1619. fi
  1620. if (( ARGC )); then
  1621. pre=$1
  1622. post=$2
  1623. shift 2
  1624. fi
  1625. if grml_theme_has_token $name; then
  1626. printf '
  1627. grml_theme_add_token: Token `%s'\'' exists! Giving up!\n\n' $name
  1628. GRML_theme_add_token_usage
  1629. return 2
  1630. fi
  1631. if (( init )); then
  1632. REPLY=''
  1633. $token $name
  1634. token=$REPLY
  1635. fi
  1636. grml_prompt_pre_default[$name]=$pre
  1637. grml_prompt_post_default[$name]=$post
  1638. if (( funcall )); then
  1639. grml_prompt_token_function[$name]=$token
  1640. grml_prompt_token_default[$name]=23
  1641. else
  1642. grml_prompt_token_default[$name]=$token
  1643. fi
  1644. }
  1645. function grml_wrap_reply () {
  1646. emulate -L zsh
  1647. local target="$1"
  1648. local new="$2"
  1649. local left="$3"
  1650. local right="$4"
  1651. if (( ${+parameters[$new]} )); then
  1652. REPLY="${left}${(P)new}${right}"
  1653. else
  1654. REPLY=''
  1655. fi
  1656. }
  1657. function grml_prompt_addto () {
  1658. emulate -L zsh
  1659. local target="$1"
  1660. local lr it apre apost new v REPLY
  1661. local -a items
  1662. shift
  1663. [[ $target == PS1 ]] && lr=left || lr=right
  1664. zstyle -a ":prompt:${grmltheme}:${lr}:setup" items items || items=( "$@" )
  1665. typeset -g "${target}="
  1666. for it in "${items[@]}"; do
  1667. zstyle -s ":prompt:${grmltheme}:${lr}:items:$it" pre apre \
  1668. || apre=${grml_prompt_pre_default[$it]}
  1669. zstyle -s ":prompt:${grmltheme}:${lr}:items:$it" post apost \
  1670. || apost=${grml_prompt_post_default[$it]}
  1671. zstyle -s ":prompt:${grmltheme}:${lr}:items:$it" token new \
  1672. || new=${grml_prompt_token_default[$it]}
  1673. if (( ${+grml_prompt_token_function[$it]} )); then
  1674. REPLY=''
  1675. ${grml_prompt_token_function[$it]} $it
  1676. else
  1677. case $it in
  1678. battery)
  1679. grml_wrap_reply $target $new '' ''
  1680. ;;
  1681. change-root)
  1682. grml_wrap_reply $target $new '(' ')'
  1683. ;;
  1684. grml-chroot)
  1685. if [[ -n ${(P)new} ]]; then
  1686. REPLY="$CHROOT"
  1687. else
  1688. REPLY=''
  1689. fi
  1690. ;;
  1691. vcs)
  1692. v="vcs_info_msg_${new}_"
  1693. if (( ! vcscalled )); then
  1694. vcs_info
  1695. vcscalled=1
  1696. fi
  1697. if (( ${+parameters[$v]} )) && [[ -n "${(P)v}" ]]; then
  1698. REPLY="${(P)v}"
  1699. else
  1700. REPLY=''
  1701. fi
  1702. ;;
  1703. *) REPLY="$new" ;;
  1704. esac
  1705. fi
  1706. # Strip volatile characters per item. This is off by default. See the
  1707. # global stripping code a few lines below for details.
  1708. if [[ -o prompt_subst ]] && zstyle -t ":prompt:${grmltheme}:${lr}:items:$it" \
  1709. strip-sensitive-characters
  1710. then
  1711. REPLY="${REPLY//[$\`]/}"
  1712. fi
  1713. typeset -g "${target}=${(P)target}${apre}${REPLY}${apost}"
  1714. done
  1715. # Per default, strip volatile characters (in the prompt_subst case)
  1716. # globally. If the option is off, the style has no effect. For more
  1717. # control, this can be turned off and stripping can be configured on a
  1718. # per-item basis (see above).
  1719. if [[ -o prompt_subst ]] && zstyle -T ":prompt:${grmltheme}:${lr}:setup" \
  1720. strip-sensitive-characters
  1721. then
  1722. typeset -g "${target}=${${(P)target}//[$\`]/}"
  1723. fi
  1724. }
  1725. function prompt_grml_precmd () {
  1726. emulate -L zsh
  1727. local grmltheme=grml
  1728. local -a left_items right_items
  1729. left_items=(rc change-root user at host path percent)
  1730. right_items=(sad-smiley)
  1731. prompt_grml_precmd_worker
  1732. }
  1733. function prompt_grml-chroot_precmd () {
  1734. emulate -L zsh
  1735. local grmltheme=grml-chroot
  1736. local -a left_items right_items
  1737. left_items=(grml-chroot user at host path percent)
  1738. right_items=()
  1739. prompt_grml_precmd_worker
  1740. }
  1741. function prompt_grml-large_precmd () {
  1742. emulate -L zsh
  1743. local grmltheme=grml-large
  1744. local -a left_items right_items
  1745. left_items=(rc jobs history shell-level change-root time date newline
  1746. user at host path percent)
  1747. right_items=(sad-smiley)
  1748. prompt_grml_precmd_worker
  1749. }
  1750. function prompt_grml_precmd_worker () {
  1751. emulate -L zsh
  1752. local -i vcscalled=0
  1753. grml_prompt_addto PS1 "${left_items[@]}"
  1754. if zstyle -T ":prompt:${grmltheme}:right:setup" use-rprompt; then
  1755. grml_prompt_addto RPS1 "${right_items[@]}"
  1756. fi
  1757. }
  1758. function grml_prompt_fallback () {
  1759. setopt prompt_subst
  1760. local p0 p1
  1761. p0="${RED}%(?..%? )${WHITE}${debian_chroot:+($debian_chroot)}"
  1762. p1="${GREEN}%n${NO_COLOR}@%m %40<...<%B%~%b%<< "'${vcs_info_msg_0_}'"%# "
  1763. if (( EUID == 0 )); then
  1764. PROMPT="${BLUE}${p0}${RED}${p1}"
  1765. else
  1766. PROMPT="${RED}${p0}${BLUE}${p1}"
  1767. fi
  1768. }
  1769. if zrcautoload promptinit && promptinit 2>/dev/null ; then
  1770. # Since we define the required functions in here and not in files in
  1771. # $fpath, we need to stick the theme's name into `$prompt_themes'
  1772. # ourselves, since promptinit does not pick them up otherwise.
  1773. prompt_themes+=( grml grml-chroot grml-large )
  1774. # Also, keep the array sorted...
  1775. prompt_themes=( "${(@on)prompt_themes}" )
  1776. else
  1777. print 'Notice: no promptinit available :('
  1778. grml_prompt_fallback
  1779. function precmd () { (( ${+functions[vcs_info]} )) && vcs_info; }
  1780. fi
  1781. # The prompt themes use modern features of zsh, that require at least
  1782. # version 4.3.7 of the shell. Use the fallback otherwise.
  1783. if [[ $GRML_DISPLAY_BATTERY -gt 0 ]]; then
  1784. zstyle ':prompt:grml:right:setup' items sad-smiley battery
  1785. add-zsh-hook precmd battery
  1786. fi
  1787. if [[ "$TERM" == dumb ]] ; then
  1788. zstyle ":prompt:grml(|-large|-chroot):*:items:grml-chroot" pre ''
  1789. zstyle ":prompt:grml(|-large|-chroot):*:items:grml-chroot" post ' '
  1790. for i in rc user path jobs history date time shell-level; do
  1791. zstyle ":prompt:grml(|-large|-chroot):*:items:$i" pre ''
  1792. zstyle ":prompt:grml(|-large|-chroot):*:items:$i" post ''
  1793. done
  1794. unset i
  1795. zstyle ':prompt:grml(|-large|-chroot):right:setup' use-rprompt false
  1796. elif (( EUID == 0 )); then
  1797. zstyle ':prompt:grml(|-large|-chroot):*:items:user' pre '%B%F{red}'
  1798. fi
  1799. # Finally enable one of the prompts.
  1800. if [[ -n $GRML_CHROOT ]]; then
  1801. prompt grml-chroot
  1802. elif [[ $GRMLPROMPT -gt 0 ]]; then
  1803. prompt grml-large
  1804. else
  1805. prompt grml
  1806. fi
  1807. # Terminal-title wizardry
  1808. function ESC_print () {
  1809. info_print $'\ek' $'\e\\' "$@"
  1810. }
  1811. function set_title () {
  1812. info_print $'\e]0;' $'\a' "$@"
  1813. }
  1814. function info_print () {
  1815. local esc_begin esc_end
  1816. esc_begin="$1"
  1817. esc_end="$2"
  1818. shift 2
  1819. printf '%s' ${esc_begin}
  1820. printf '%s' "$*"
  1821. printf '%s' "${esc_end}"
  1822. }
  1823. function grml_reset_screen_title () {
  1824. # adjust title of xterm
  1825. # see http://www.faqs.org/docs/Linux-mini/Xterm-Title.html
  1826. [[ ${NOTITLE:-} -gt 0 ]] && return 0
  1827. case $TERM in
  1828. (xterm*|rxvt*)
  1829. set_title ${(%):-"%n@%m: %~"}
  1830. ;;
  1831. esac
  1832. }
  1833. function grml_vcs_to_screen_title () {
  1834. if [[ $TERM == screen* ]] ; then
  1835. if [[ -n ${vcs_info_msg_1_} ]] ; then
  1836. ESC_print ${vcs_info_msg_1_}
  1837. else
  1838. ESC_print "zsh"
  1839. fi
  1840. fi
  1841. }
  1842. function grml_maintain_name () {
  1843. local localname
  1844. localname="$(uname -n)"
  1845. # set hostname if not running on local machine
  1846. if [[ -n "$HOSTNAME" ]] && [[ "$HOSTNAME" != "${localname}" ]] ; then
  1847. NAME="@$HOSTNAME"
  1848. fi
  1849. }
  1850. function grml_cmd_to_screen_title () {
  1851. # get the name of the program currently running and hostname of local
  1852. # machine set screen window title if running in a screen
  1853. if [[ "$TERM" == screen* ]] ; then
  1854. local CMD="${1[(wr)^(*=*|sudo|ssh|-*)]}$NAME"
  1855. ESC_print ${CMD}
  1856. fi
  1857. }
  1858. function grml_control_xterm_title () {
  1859. case $TERM in
  1860. (xterm*|rxvt*)
  1861. set_title "${(%):-"%n@%m:"}" "$2"
  1862. ;;
  1863. esac
  1864. }
  1865. # do we have GNU ls with color-support?
  1866. if [[ "$TERM" != dumb ]]; then
  1867. #a1# List files with colors (\kbd{ls \ldots})
  1868. alias ls="command ls ${ls_options:+${ls_options[*]}}"
  1869. #a1# List all files, with colors (\kbd{ls -la \ldots})
  1870. alias la="command ls -la ${ls_options:+${ls_options[*]}}"
  1871. #lh hooman
  1872. alias lh="command ls -lah ${ls_options:+${ls_options[*]}}"
  1873. #a1# List files with long colored list, without dotfiles (\kbd{ls -l \ldots})
  1874. alias ll="command ls -l ${ls_options:+${ls_options[*]}}"
  1875. #a1# List files with long colored list, human readable sizes (\kbd{ls -hAl \ldots})
  1876. alias lh="command ls -hAl ${ls_options:+${ls_options[*]}}"
  1877. #a1# List files with long colored list, append qualifier to filenames (\kbd{ls -l \ldots})\\&\quad(\kbd{/} for directories, \kbd{@} for symlinks ...)
  1878. alias l="command ls -l ${ls_options:+${ls_options[*]}}"
  1879. else
  1880. alias la='command ls -la'
  1881. alias ll='command ls -l'
  1882. alias lh='command ls -hAl'
  1883. alias l='command ls -l'
  1884. fi
  1885. if [[ -r /proc/mdstat ]]; then
  1886. alias mdstat='cat /proc/mdstat'
  1887. fi
  1888. alias ...='cd ../../'
  1889. # generate alias named "$KERNELVERSION-reboot" so you can use boot with kexec:
  1890. if [[ -x /sbin/kexec ]] && [[ -r /proc/cmdline ]] ; then
  1891. alias "$(uname -r)-reboot"="kexec -l --initrd=/boot/initrd.img-"$(uname -r)" --command-line=\"$(cat /proc/cmdline)\" /boot/vmlinuz-"$(uname -r)""
  1892. fi
  1893. # see http://www.cl.cam.ac.uk/~mgk25/unicode.html#term for details
  1894. alias term2iso="echo 'Setting terminal to iso mode' ; print -n '\e%@'"
  1895. alias term2utf="echo 'Setting terminal to utf-8 mode'; print -n '\e%G'"
  1896. # make sure it is not assigned yet
  1897. [[ -n ${aliases[utf2iso]} ]] && unalias utf2iso
  1898. function utf2iso () {
  1899. if isutfenv ; then
  1900. local ENV
  1901. for ENV in $(env | command grep -i '.utf') ; do
  1902. eval export "$(echo $ENV | sed 's/UTF-8/iso885915/ ; s/utf8/iso885915/')"
  1903. done
  1904. fi
  1905. }
  1906. # make sure it is not assigned yet
  1907. [[ -n ${aliases[iso2utf]} ]] && unalias iso2utf
  1908. function iso2utf () {
  1909. if ! isutfenv ; then
  1910. local ENV
  1911. for ENV in $(env | command grep -i '\.iso') ; do
  1912. eval export "$(echo $ENV | sed 's/iso.*/UTF-8/ ; s/ISO.*/UTF-8/')"
  1913. done
  1914. fi
  1915. }
  1916. # especially for roadwarriors using GNU screen and ssh:
  1917. if ! check_com asc &>/dev/null ; then
  1918. function asc () { autossh -t "$@" 'screen -RdU' }
  1919. compdef asc=ssh
  1920. fi
  1921. # use /var/log/syslog iff present, fallback to journalctl otherwise
  1922. if [ -e /var/log/syslog ] ; then
  1923. #a1# Take a look at the syslog: \kbd{\$PAGER /var/log/syslog || journalctl}
  1924. salias llog="$PAGER /var/log/syslog" # take a look at the syslog
  1925. #a1# Take a look at the syslog: \kbd{tail -f /var/log/syslog || journalctl}
  1926. salias tlog="tail -f /var/log/syslog" # follow the syslog
  1927. elif check_com -c journalctl ; then
  1928. salias llog="journalctl"
  1929. salias tlog="journalctl -f"
  1930. fi
  1931. # wonderful idea of using "e" glob qualifier by Peter Stephenson
  1932. # You use it as follows:
  1933. # $ NTREF=/reference/file
  1934. # $ ls -l *(e:nt:)
  1935. # This lists all the files in the current directory newer than the reference file.
  1936. # You can also specify the reference file inline; note quotes:
  1937. # $ ls -l *(e:'nt ~/.zshenv':)
  1938. function nt () {
  1939. if [[ -n $1 ]] ; then
  1940. local NTREF=${~1}
  1941. fi
  1942. [[ $REPLY -nt $NTREF ]]
  1943. }
  1944. # shell functions
  1945. #f1# Provides useful information on globbing
  1946. function H-Glob () {
  1947. echo -e "
  1948. / directories
  1949. . plain files
  1950. @ symbolic links
  1951. = sockets
  1952. p named pipes (FIFOs)
  1953. * executable plain files (0100)
  1954. % device files (character or block special)
  1955. %b block special files
  1956. %c character special files
  1957. r owner-readable files (0400)
  1958. w owner-writable files (0200)
  1959. x owner-executable files (0100)
  1960. A group-readable files (0040)
  1961. I group-writable files (0020)
  1962. E group-executable files (0010)
  1963. R world-readable files (0004)
  1964. W world-writable files (0002)
  1965. X world-executable files (0001)
  1966. s setuid files (04000)
  1967. S setgid files (02000)
  1968. t files with the sticky bit (01000)
  1969. print *(m-1) # Files modified up to a day ago
  1970. print *(a1) # Files accessed a day ago
  1971. print *(@) # Just symlinks
  1972. print *(Lk+50) # Files bigger than 50 kilobytes
  1973. print *(Lk-50) # Files smaller than 50 kilobytes
  1974. print **/*.c # All *.c files recursively starting in \$PWD
  1975. print **/*.c~file.c # Same as above, but excluding 'file.c'
  1976. print (foo|bar).* # Files starting with 'foo' or 'bar'
  1977. print *~*.* # All Files that do not contain a dot
  1978. chmod 644 *(.^x) # make all plain non-executable files publically readable
  1979. print -l *(.c|.h) # Lists *.c and *.h
  1980. print **/*(g:users:) # Recursively match all files that are owned by group 'users'
  1981. echo /proc/*/cwd(:h:t:s/self//) # Analogous to >ps ax | awk '{print $1}'<"
  1982. }
  1983. alias help-zshglob=H-Glob
  1984. # grep for running process, like: 'any vim'
  1985. function any () {
  1986. emulate -L zsh
  1987. unsetopt KSH_ARRAYS
  1988. if [[ -z "$1" ]] ; then
  1989. echo "any - grep for process(es) by keyword" >&2
  1990. echo "Usage: any <keyword>" >&2 ; return 1
  1991. else
  1992. ps xauwww | grep -i "${grep_options[@]}" "[${1[1]}]${1[2,-1]}"
  1993. fi
  1994. }
  1995. # a wrapper for vim, that deals with title setting
  1996. # VIM_OPTIONS
  1997. # set this array to a set of options to vim you always want
  1998. # to have set when calling vim (in .zshrc.local), like:
  1999. # VIM_OPTIONS=( -p )
  2000. # This will cause vim to send every file given on the
  2001. # commandline to be send to it's own tab (needs vim7).
  2002. if check_com vim; then
  2003. function vim () {
  2004. VIM_PLEASE_SET_TITLE='yes' command vim ${VIM_OPTIONS} "$@"
  2005. }
  2006. fi
  2007. # make sure our environment is clean regarding colors
  2008. builtin unset -v BLUE RED GREEN CYAN YELLOW MAGENTA WHITE NO_COLOR
  2009. # "persistent history"
  2010. # just write important commands you always need to $GRML_IMPORTANT_COMMANDS
  2011. # defaults for backward compatibility to ~/.important_commands
  2012. if [[ -r ~/.important_commands ]] ; then
  2013. GRML_IMPORTANT_COMMANDS=~/.important_commands
  2014. else
  2015. GRML_IMPORTANT_COMMANDS=${GRML_IMPORTANT_COMMANDS:-${ZDOTDIR:-${HOME}}/.important_commands}
  2016. fi
  2017. [[ -r ${GRML_IMPORTANT_COMMANDS} ]] && builtin fc -R ${GRML_IMPORTANT_COMMANDS}
  2018. # load the lookup subsystem if it's available on the system
  2019. zrcautoload lookupinit && lookupinit
  2020. # variables
  2021. # set terminal property (used e.g. by msgid-chooser)
  2022. export COLORTERM="yes"
  2023. # aliases
  2024. # general
  2025. #a2# Execute \kbd{du -sch}
  2026. # some useful aliases
  2027. #a2# Remove current empty directory. Execute \kbd{cd ..; rmdir \$OLDCWD}
  2028. # useful functions
  2029. #f5# Backup \kbd{file_or_folder {\rm to} file_or_folder\_timestamp}
  2030. function bk () {
  2031. emulate -L zsh
  2032. local current_date=$(date -u "+%Y%m%dT%H%M%SZ")
  2033. local clean keep move verbose result all to_bk
  2034. setopt extended_glob
  2035. keep=1
  2036. while getopts ":hacmrv" opt; do
  2037. case $opt in
  2038. a) (( all++ ));;
  2039. c) unset move clean && (( ++keep ));;
  2040. m) unset keep clean && (( ++move ));;
  2041. r) unset move keep && (( ++clean ));;
  2042. v) verbose="-v";;
  2043. h) <<__EOF0__
  2044. bk [-hcmv] FILE [FILE ...]
  2045. bk -r [-av] [FILE [FILE ...]]
  2046. Backup a file or folder in place and append the timestamp
  2047. Remove backups of a file or folder, or all backups in the current directory
  2048. Usage:
  2049. -h Display this help text
  2050. -c Keep the file/folder as is, create a copy backup using cp(1) (default)
  2051. -m Move the file/folder, using mv(1)
  2052. -r Remove backups of the specified file or directory, using rm(1). If none
  2053. is provided, remove all backups in the current directory.
  2054. -a Remove all (even hidden) backups.
  2055. -v Verbose
  2056. The -c, -r and -m options are mutually exclusive. If specified at the same time,
  2057. the last one is used.
  2058. The return code is the sum of all cp/mv/rm return codes.
  2059. __EOF0__
  2060. return 0;;
  2061. \?) bk -h >&2; return 1;;
  2062. esac
  2063. done
  2064. shift "$((OPTIND-1))"
  2065. if (( keep > 0 )); then
  2066. if islinux ; then
  2067. for to_bk in "$@"; do
  2068. cp $verbose -a "${to_bk%/}" "${to_bk%/}_$current_date"
  2069. (( result += $? ))
  2070. done
  2071. else
  2072. for to_bk in "$@"; do
  2073. cp $verbose -pR "${to_bk%/}" "${to_bk%/}_$current_date"
  2074. (( result += $? ))
  2075. done
  2076. fi
  2077. elif (( move > 0 )); then
  2078. while (( $# > 0 )); do
  2079. mv $verbose "${1%/}" "${1%/}_$current_date"
  2080. (( result += $? ))
  2081. shift
  2082. done
  2083. elif (( clean > 0 )); then
  2084. if (( $# > 0 )); then
  2085. for to_bk in "$@"; do
  2086. rm $verbose -rf "${to_bk%/}"_[0-9](#c8)T([0-1][0-9]|2[0-3])([0-5][0-9])(#c2)Z
  2087. (( result += $? ))
  2088. done
  2089. else
  2090. if (( all > 0 )); then
  2091. rm $verbose -rf *_[0-9](#c8)T([0-1][0-9]|2[0-3])([0-5][0-9])(#c2)Z(D)
  2092. else
  2093. rm $verbose -rf *_[0-9](#c8)T([0-1][0-9]|2[0-3])([0-5][0-9])(#c2)Z
  2094. fi
  2095. (( result += $? ))
  2096. fi
  2097. fi
  2098. return $result
  2099. }
  2100. #f5# cd to directory and list files
  2101. function cl () {
  2102. emulate -L zsh
  2103. cd $1 && ls -a
  2104. }
  2105. # smart cd function, allows switching to /etc when running 'cd /etc/fstab'
  2106. function cd () {
  2107. if (( ${#argv} == 1 )) && [[ -f ${1} ]]; then
  2108. [[ ! -e ${1:h} ]] && return 1
  2109. print "Correcting ${1} to ${1:h}"
  2110. builtin cd ${1:h}
  2111. else
  2112. builtin cd "$@"
  2113. fi
  2114. }
  2115. #f5# Create Directory and \kbd{cd} to it
  2116. function mkcd () {
  2117. if (( ARGC != 1 )); then
  2118. printf 'usage: mkcd <new-directory>\n'
  2119. return 1;
  2120. fi
  2121. if [[ ! -d "$1" ]]; then
  2122. command mkdir -p "$1"
  2123. else
  2124. printf '`%s'\'' already exists: cd-ing.\n' "$1"
  2125. fi
  2126. builtin cd "$1"
  2127. }
  2128. #f5# Create temporary directory and \kbd{cd} to it
  2129. function cdt () {
  2130. builtin cd "$(mktemp -d)"
  2131. builtin pwd
  2132. }
  2133. #f5# List files which have been accessed within the last {\it n} days, {\it n} defaults to 1
  2134. function accessed () {
  2135. emulate -L zsh
  2136. print -l -- *(a-${1:-1})
  2137. }
  2138. #f5# List files which have been changed within the last {\it n} days, {\it n} defaults to 1
  2139. function changed () {
  2140. emulate -L zsh
  2141. print -l -- *(c-${1:-1})
  2142. }
  2143. #f5# List files which have been modified within the last {\it n} days, {\it n} defaults to 1
  2144. function modified () {
  2145. emulate -L zsh
  2146. print -l -- *(m-${1:-1})
  2147. }
  2148. # modified() was named new() in earlier versions, add an alias for backwards compatibility
  2149. check_com new || alias new=modified
  2150. # use colors when GNU grep with color-support
  2151. if (( $#grep_options > 0 )); then
  2152. o=${grep_options:+"${grep_options[*]}"}
  2153. #a2# Execute \kbd{grep -{}-color=auto}
  2154. alias grep='grep '$o
  2155. alias egrep='egrep '$o
  2156. unset o
  2157. fi
  2158. # Usage: simple-extract <file>
  2159. # Using option -d deletes the original archive file.
  2160. #f5# Smart archive extractor
  2161. function simple-extract () {
  2162. emulate -L zsh
  2163. setopt extended_glob noclobber
  2164. local ARCHIVE DELETE_ORIGINAL DECOMP_CMD USES_STDIN USES_STDOUT GZTARGET WGET_CMD
  2165. local RC=0
  2166. zparseopts -D -E "d=DELETE_ORIGINAL"
  2167. for ARCHIVE in "${@}"; do
  2168. case $ARCHIVE in
  2169. *(tar.bz2|tbz2|tbz))
  2170. DECOMP_CMD="tar -xvjf -"
  2171. USES_STDIN=true
  2172. USES_STDOUT=false
  2173. ;;
  2174. *(tar.gz|tgz))
  2175. DECOMP_CMD="tar -xvzf -"
  2176. USES_STDIN=true
  2177. USES_STDOUT=false
  2178. ;;
  2179. *(tar.xz|txz|tar.lzma))
  2180. DECOMP_CMD="tar -xvJf -"
  2181. USES_STDIN=true
  2182. USES_STDOUT=false
  2183. ;;
  2184. *tar.zst)
  2185. DECOMP_CMD="tar --zstd -xvf -"
  2186. USES_STDIN=true
  2187. USES_STDOUT=false
  2188. ;;
  2189. *tar)
  2190. DECOMP_CMD="tar -xvf -"
  2191. USES_STDIN=true
  2192. USES_STDOUT=false
  2193. ;;
  2194. *rar)
  2195. DECOMP_CMD="unrar x"
  2196. USES_STDIN=false
  2197. USES_STDOUT=false
  2198. ;;
  2199. *lzh)
  2200. DECOMP_CMD="lha x"
  2201. USES_STDIN=false
  2202. USES_STDOUT=false
  2203. ;;
  2204. *7z)
  2205. DECOMP_CMD="7z x"
  2206. USES_STDIN=false
  2207. USES_STDOUT=false
  2208. ;;
  2209. *(zip|jar))
  2210. DECOMP_CMD="unzip"
  2211. USES_STDIN=false
  2212. USES_STDOUT=false
  2213. ;;
  2214. *deb)
  2215. DECOMP_CMD="ar -x"
  2216. USES_STDIN=false
  2217. USES_STDOUT=false
  2218. ;;
  2219. *bz2)
  2220. DECOMP_CMD="bzip2 -d -c -"
  2221. USES_STDIN=true
  2222. USES_STDOUT=true
  2223. ;;
  2224. *(gz|Z))
  2225. DECOMP_CMD="gzip -d -c -"
  2226. USES_STDIN=true
  2227. USES_STDOUT=true
  2228. ;;
  2229. *(xz|lzma))
  2230. DECOMP_CMD="xz -d -c -"
  2231. USES_STDIN=true
  2232. USES_STDOUT=true
  2233. ;;
  2234. *zst)
  2235. DECOMP_CMD="zstd -d -c -"
  2236. USES_STDIN=true
  2237. USES_STDOUT=true
  2238. ;;
  2239. *)
  2240. print "ERROR: '$ARCHIVE' has unrecognized archive type." >&2
  2241. RC=$((RC+1))
  2242. continue
  2243. ;;
  2244. esac
  2245. if ! check_com ${DECOMP_CMD[(w)1]}; then
  2246. echo "ERROR: ${DECOMP_CMD[(w)1]} not installed." >&2
  2247. RC=$((RC+2))
  2248. continue
  2249. fi
  2250. GZTARGET="${ARCHIVE:t:r}"
  2251. if [[ -f $ARCHIVE ]] ; then
  2252. print "Extracting '$ARCHIVE' ..."
  2253. if $USES_STDIN; then
  2254. if $USES_STDOUT; then
  2255. ${=DECOMP_CMD} < "$ARCHIVE" > $GZTARGET
  2256. else
  2257. ${=DECOMP_CMD} < "$ARCHIVE"
  2258. fi
  2259. else
  2260. if $USES_STDOUT; then
  2261. ${=DECOMP_CMD} "$ARCHIVE" > $GZTARGET
  2262. else
  2263. ${=DECOMP_CMD} "$ARCHIVE"
  2264. fi
  2265. fi
  2266. [[ $? -eq 0 && -n "$DELETE_ORIGINAL" ]] && rm -f "$ARCHIVE"
  2267. elif [[ "$ARCHIVE" == (#s)(https|http|ftp)://* ]] ; then
  2268. if check_com curl; then
  2269. WGET_CMD="curl -L -s -o -"
  2270. elif check_com wget; then
  2271. WGET_CMD="wget -q -O -"
  2272. elif check_com fetch; then
  2273. WGET_CMD="fetch -q -o -"
  2274. else
  2275. print "ERROR: neither wget, curl nor fetch is installed" >&2
  2276. RC=$((RC+4))
  2277. continue
  2278. fi
  2279. print "Downloading and Extracting '$ARCHIVE' ..."
  2280. if $USES_STDIN; then
  2281. if $USES_STDOUT; then
  2282. ${=WGET_CMD} "$ARCHIVE" | ${=DECOMP_CMD} > $GZTARGET
  2283. RC=$((RC+$?))
  2284. else
  2285. ${=WGET_CMD} "$ARCHIVE" | ${=DECOMP_CMD}
  2286. RC=$((RC+$?))
  2287. fi
  2288. else
  2289. if $USES_STDOUT; then
  2290. ${=DECOMP_CMD} =(${=WGET_CMD} "$ARCHIVE") > $GZTARGET
  2291. else
  2292. ${=DECOMP_CMD} =(${=WGET_CMD} "$ARCHIVE")
  2293. fi
  2294. fi
  2295. else
  2296. print "ERROR: '$ARCHIVE' is neither a valid file nor a supported URI." >&2
  2297. RC=$((RC+8))
  2298. fi
  2299. done
  2300. return $RC
  2301. }
  2302. function __archive_or_uri () {
  2303. _alternative \
  2304. 'files:Archives:_files -g "*.(#l)(tar.bz2|tbz2|tbz|tar.gz|tgz|tar.xz|txz|tar.lzma|tar|rar|lzh|7z|zip|jar|deb|bz2|gz|Z|xz|lzma)"' \
  2305. '_urls:Remote Archives:_urls'
  2306. }
  2307. function _simple_extract () {
  2308. _arguments \
  2309. '-d[delete original archivefile after extraction]' \
  2310. '*:Archive Or Uri:__archive_or_uri'
  2311. }
  2312. compdef _simple_extract simple-extract
  2313. [[ -n "$GRML_NO_SMALL_ALIASES" ]] || alias se=simple-extract
  2314. #f5# Change the xterm title from within GNU-screen
  2315. function xtrename () {
  2316. emulate -L zsh
  2317. if [[ $1 != "-f" ]] ; then
  2318. if [[ -z ${DISPLAY} ]] ; then
  2319. printf 'xtrename only makes sense in X11.\n'
  2320. return 1
  2321. fi
  2322. else
  2323. shift
  2324. fi
  2325. if [[ -z $1 ]] ; then
  2326. printf 'usage: xtrename [-f] "title for xterm"\n'
  2327. printf ' renames the title of xterm from _within_ screen.\n'
  2328. printf ' also works without screen.\n'
  2329. printf ' will not work if DISPLAY is unset, use -f to override.\n'
  2330. return 0
  2331. fi
  2332. print -n "\eP\e]0;${1}\C-G\e\\"
  2333. return 0
  2334. }
  2335. zpst () { curl -F'file=@-' https://va.furryplace.eu }
  2336. # upload to ttm
  2337. function zup () {
  2338. emulate -L zsh
  2339. setopt extended_glob
  2340. if [[ -z $1 ]]; then
  2341. print "USAGE: zup <FILE>"
  2342. return 1
  2343. fi
  2344. local PN url prog api json contenttype item
  2345. local -a data
  2346. PN=$0
  2347. url=$1
  2348. if check_com -c curl; then
  2349. prog=curl
  2350. else
  2351. print "curl is not available, but mandatory for ${PN}. Aborting."
  2352. return 1
  2353. fi
  2354. api='https://va.furryplace.eu/'
  2355. curl -F"file=@${url}" $api
  2356. }
  2357. # bypass them nasty blocks
  2358. function zpost () {
  2359. emulate -L zsh
  2360. setopt extended_glob
  2361. if [[ -z $1 ]]; then
  2362. print "USAGE: zpost <URL>"
  2363. return 1
  2364. fi
  2365. local PN url prog api json contenttype item
  2366. local -a data
  2367. PN=$0
  2368. url=$1
  2369. # Prepend 'http://' to given URL where necessary for later output.
  2370. if [[ ${url} != http(s|)://* ]]; then
  2371. url='https://'${url}
  2372. fi
  2373. if check_com -c curl; then
  2374. prog=curl
  2375. else
  2376. print "curl is not available, but mandatory for ${PN}. Aborting."
  2377. return 1
  2378. fi
  2379. api='https://va.furryplace.eu/'
  2380. curl -F"url=${url}" $api
  2381. }
  2382. # ttmsh > goo.gl
  2383. function zurl () {
  2384. emulate -L zsh
  2385. setopt extended_glob
  2386. if [[ -z $1 ]]; then
  2387. print "USAGE: zurl <URL>"
  2388. return 1
  2389. fi
  2390. local PN url prog api json contenttype item
  2391. local -a data
  2392. PN=$0
  2393. url=$1
  2394. # Prepend 'http://' to given URL where necessary for later output.
  2395. if [[ ${url} != http(s|)://* ]]; then
  2396. url='https://'${url}
  2397. fi
  2398. if check_com -c curl; then
  2399. prog=curl
  2400. else
  2401. print "curl is not available, but mandatory for ${PN}. Aborting."
  2402. return 1
  2403. fi
  2404. api='https://va.furryplace.eu/'
  2405. curl -F"shorten=${url}" $api
  2406. }
  2407. #f2# Find history events by search pattern and list them by date.
  2408. function whatwhen () {
  2409. emulate -L zsh
  2410. local usage help ident format_l format_s first_char remain first last
  2411. usage='USAGE: whatwhen [options] <searchstring> <search range>'
  2412. help='Use `whatwhen -h'\'' for further explanations.'
  2413. ident=${(l,${#${:-Usage: }},, ,)}
  2414. format_l="${ident}%s\t\t\t%s\n"
  2415. format_s="${format_l//(\\t)##/\\t}"
  2416. # Make the first char of the word to search for case
  2417. # insensitive; e.g. [aA]
  2418. first_char=[${(L)1[1]}${(U)1[1]}]
  2419. remain=${1[2,-1]}
  2420. # Default search range is `-100'.
  2421. first=${2:-\-100}
  2422. # Optional, just used for `<first> <last>' given.
  2423. last=$3
  2424. case $1 in
  2425. ("")
  2426. printf '%s\n\n' 'ERROR: No search string specified. Aborting.'
  2427. printf '%s\n%s\n\n' ${usage} ${help} && return 1
  2428. ;;
  2429. (-h)
  2430. printf '%s\n\n' ${usage}
  2431. print 'OPTIONS:'
  2432. printf $format_l '-h' 'show help text'
  2433. print '\f'
  2434. print 'SEARCH RANGE:'
  2435. printf $format_l "'0'" 'the whole history,'
  2436. printf $format_l '-<n>' 'offset to the current history number; (default: -100)'
  2437. printf $format_s '<[-]first> [<last>]' 'just searching within a give range'
  2438. printf '\n%s\n' 'EXAMPLES:'
  2439. printf ${format_l/(\\t)/} 'whatwhen grml' '# Range is set to -100 by default.'
  2440. printf $format_l 'whatwhen zsh -250'
  2441. printf $format_l 'whatwhen foo 1 99'
  2442. ;;
  2443. (\?)
  2444. printf '%s\n%s\n\n' ${usage} ${help} && return 1
  2445. ;;
  2446. (*)
  2447. # -l list results on stout rather than invoking $EDITOR.
  2448. # -i Print dates as in YYYY-MM-DD.
  2449. # -m Search for a - quoted - pattern within the history.
  2450. fc -li -m "*${first_char}${remain}*" $first $last
  2451. ;;
  2452. esac
  2453. }
  2454. # disable bracketed paste mode for dumb terminals
  2455. [[ "$TERM" == dumb ]] && unset zle_bracketed_paste
  2456. PATH=$PATH:$HOME/.local/bin
  2457. alias t="topydo"
  2458. alias sysu='systemctl --user'
  2459. alias mkdir='mkdir -p'
  2460. source ~/.zsh/fzf-tab/fzf-tab.plugin.zsh
  2461. source ~/.zsh/zsh-autosuggestions.zsh
  2462. zrclocal
  2463. ## genrefcard.pl settings
  2464. ### doc strings for external functions from files
  2465. #m# f5 grml-wallpaper() Sets a wallpaper (try completion for possible values)
  2466. ### example: split functions-search 8,16,24,32
  2467. #@# split functions-search 8
  2468. ## END OF FILE #################################################################
  2469. # vim:filetype=zsh foldmethod=marker autoindent expandtab shiftwidth=4
  2470. # Local variables:
  2471. # mode: sh
  2472. # End: