Guest User

.zshrc

a guest
Apr 23rd, 2010
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 49.69 KB | None | 0 0
  1. ## .zshrc
  2. #
  3.  
  4. ####################
  5. # GENERAL SETTINGS #
  6. ####################
  7.  
  8. PATH=$HOME/.bin:$PATH
  9. umask 022
  10.  
  11. ## display?
  12. if [ "$DISPLAY" ]; then
  13.   export EDITOR=gvim        \
  14.      EXCEL=oocalc       \
  15.      OFFICE=oowriter    \
  16.      PDF="q epdfview"   \
  17.      PICSHOW="q mirage" \
  18.  
  19.   alias e="$EDITOR -p"
  20.   alias eb="e $HOME/{.bashtweaks,.bashrc}"             # open bash files
  21.   alias en="e $HOME/.notes"                            # edit notes (also see function note() below)
  22.   alias eo="e $HOME/.config/openbox/{rc.xml,menu.xml}" # edit openbox files
  23.   alias ez="e $HOME/.zshrc"                            # edit zsh files
  24.   alias m="q medit"
  25.   alias mb="m $HOME/{.bashtweaks,.bashrc}"             # open bash files
  26.   alias mn="m $HOME/.notes"                            # medit notes (also see function note() below)
  27.   alias mo="m $HOME/.config/openbox/{rc.xml,menu.xml}" # medit openbox files
  28.   alias mz="m $HOME/.zshrc"                            # medit zsh files
  29.   alias xp='xprop | grep "WM_WINDOW_ROLE\|WM_CLASS" && echo "WM_CLASS(STRING) = \"NAME\", \"CLASS\""' # get xprop CLASS and NAME
  30.  
  31.   ### set window title
  32.   case $TERM in
  33.     *xterm*|rxvt|rxvt-unicode|rxvt-256color|(dt|k|E)term)
  34.         precmd() { print -Pn "\e]0;[%n@%M] [%~]\a" }
  35.         preexec() { print -Pn "\e]0;[%n@%M] [%~] ($1)\a" }
  36.     ;;
  37.     screen)
  38.             precmd() {
  39.             print -Pn "\e]83;title \"$1\"\a"
  40.             print -Pn "\e]0;[%n@%M] [%~]\a"
  41.         }
  42.         preexec() {
  43.             print -Pn "\e]83;title \"$1\"\a"
  44.             print -Pn "\e]0;[%n@%M]%# [%~] ($1)\a"
  45.         }
  46.     ;;
  47.   esac
  48.  
  49.   es() { # use $EDITOR to edit a file but create a backup first
  50.     cp -iv $1 ${1}.backup && gvim $1
  51.   }
  52.   t() {
  53.     if ((LINES < 48));then
  54.       printf %b "\033[8;48;80t"
  55.     else
  56.       printf %b "\033[8;24;80t"
  57.     fi
  58.     #sleep .1
  59.     #echo "\$LINES = $LINES"
  60.   }
  61.   timer() { # remind me in n (s/m/h/d) about x
  62.     (sleep "$1" && zenity --info --text "$2") &
  63.   }
  64. fi
  65.  
  66. ### environment
  67. ## exports
  68. LS_COLORS="no=00:fi=00:rs=0:di=04:ex=00:";
  69. export  CC=/usr/bin/gcc         \
  70.     DIRSTACKSIZE=20         \
  71.     GREP_OPTIONS=--color=auto   \
  72.     GREP_COLOR="1;36"       \
  73.     HISTFILE="$HOME/.zhistory"  \
  74.     HISTSIZE=5000           \
  75.     LANG="en_US.utf8"       \
  76.     LC_ALL="en_US.utf8"     \
  77.     LC="en_US.utf8"         \
  78.     LESS="-MWi -x4 --shift 5"   \
  79.     LESSHISTFILE="-"        \
  80.     LS_COLORS           \
  81.     MPD_HOST=192.168.0.2        \
  82.     MPD_PORT=6600           \
  83.     SAVEHIST=$HISTSIZE      \
  84.     SHELL=/bin/zsh          \
  85.     VISUAL=vim
  86.  
  87. ## setopt (see http://zsh.sourceforge.net/Doc/Release/zsh_15.html)
  88. setopt NO_ALL_EXPORT            \
  89.           ALWAYS_LAST_PROMPT        \
  90.       ALWAYS_TO_END         \
  91.       AUTO_CD           \
  92.        NO_AUTO_CONTINUE         \
  93.       AUTO_LIST         \
  94.       AUTO_PUSHD            \
  95.        NO_BEEP              \
  96.        NO_BG_NICE           \
  97.           BRACE_CCL         \
  98.       CASE_GLOB         \
  99.       CDABLE_VARS           \
  100.       CHASE_LINKS           \
  101.        NO_CHECK_JOBS            \
  102.           CLOBBER           \
  103.       COMPLETE_IN_WORD      \
  104.       CORRECT_ALL           \
  105.       DOT_GLOB          \
  106.       EXTENDED_GLOB         \
  107.       GLOB              \
  108.       GLOB_COMPLETE         \
  109.       HASH_LIST_ALL         \
  110.       HIST_APPEND           \
  111.        NO_HIST_BEEP         \
  112.       HIST_EXPIRE_DUPS_FIRST    \
  113.       HIST_FIND_NO_DUPS     \
  114.       HIST_IGNORE_ALL_DUPS      \
  115.       HIST_IGNORE_SPACE     \
  116.       HIST_NO_STORE         \
  117.       HIST_NO_FUNCTIONS     \
  118.       HIST_REDUCE_BLANKS        \
  119.       HIST_VERIFY           \
  120.        NO_HUP               \
  121.       IGNORE_EOF            \
  122.       INC_APPEND_HISTORY        \
  123.        NO_LIST_BEEP         \
  124.       LIST_PACKED           \
  125.       LIST_TYPES            \
  126.        NO_LONG_LIST_JOBS        \
  127.       MENU_COMPLETE         \
  128.       MULTIOS           \
  129.        NO_NOMATCH           \
  130.        NO_NOTIFY            \
  131.       NUMERIC_GLOB_SORT     \
  132.       NULL_GLOB         \
  133.       PROMPT_VARS           \
  134.       PUSHD_IGNORE_DUPS     \
  135.       PUSHD_SILENT          \
  136.       PUSHD_TO_HOME         \
  137.        NO_RM_STAR_WAIT          \
  138.       SHARE_HISTORY         \
  139.        NO_SH_WORD_SPLIT         \
  140.        NO_TRANSIENT_RPROMPT
  141.  
  142. ### keybindings
  143. typeset -g -A key
  144. bindkey -e # use emacs keymap (cdp needs it too?)
  145. bindkey '^[OH' beginning-of-line      # home
  146. bindkey '^[OF' end-of-line            # end
  147. bindkey '^[[A'  up-line-or-history    # up
  148. bindkey '^[[D'  backward-char         # left
  149. bindkey '^[[B'  down-line-or-history  # down
  150. bindkey '^[[C'  forward-char          # right
  151. bindkey -M viins '^?' backward-delete-char # traditional backspace
  152. bindkey -M viins '^H' backward-delete-char
  153. bindkey '^[[1;3D' backward-word       # alt + LEFT
  154. bindkey '^[[1;3C' forward-word        # alt + RIGHT
  155. bindkey '^[[1;2D' beginning-of-line   # shift + left
  156. bindkey '^[[1;2C' end-of-line         # shift + right
  157. bindkey '^[[3~' delete-char           # del
  158. bindkey '^[[3;3~' delete-word         # alt + delete
  159. bindkey '^[[3;2~' delete-word         # shift + delete
  160. bindkey '_^?' backward-delete-word    # alt + backspace
  161. bindkey '^[' self-insert              # alt + enter
  162. bindkey '^z' undo                     # ctrl + Z
  163. bindkey '^L' push-line                # push current command into a buffer, allows you to do another command then returns to previous command
  164. ##bindkey '^t' 'if ((LINES < 48)); then printf %b "\033[8;48;80t"; else printf %b "\033[8;24;80t"; fi; sleep .1; echo "\$LINES = $LINES"'
  165.  
  166. ### completion
  167. ## load
  168. autoload -Uz compinit
  169. compinit
  170.  
  171. ## general completion settings
  172. zstyle ':completion:*:approximate:'                 max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )' # allow one error for every three characters typed in approximate completer
  173. zstyle ':completion:*:*:cd:*:directory-stack'       menu yes select           # complete 'cd -<tab>' with menu
  174. zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'        # don't complete backup files as executables
  175. #zstyle ':completion:*'                 completer _complete _correct _approximate
  176. zstyle ':completion:*:correct:*'            insert-unambiguous true               # start menu completion only if it could find no unambiguous initial string
  177. zstyle ':completion:*:corrections'          format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}'
  178. zstyle ':completion:*:correct:*'            original true                         #
  179. zstyle ':completion:*:default'              list-colors ${(s.:.)LS_COLORS}        # activate color-completion(!)
  180. zstyle ':completion:*:descriptions'         format $'%{\e[0;33m%}%B%d%b%{\e[0m%}' # format on completion
  181. zstyle ':completion:*:expand:*'             tag-order all-expansions              # insert all expansions for expand completer
  182. #zstyle ':completion:*'                 expand prefix suffix
  183. zstyle ':completion:*:history-words'            list false
  184. zstyle ':completion:*:history-words'            menu yes                              # activate menu
  185. zstyle ':completion:*:history-words'            remove-all-dups yes                   # ignore duplicate entries
  186. zstyle ':completion:*:history-words'            stop yes
  187. zstyle ':completion:*'                  insert-tab pending                    # tab, don't annoy me
  188. #zstyle ':completion:*'                 list-prompt '%SAt %p: Hit TAB for more or BACKSPACE to get out.%s'
  189. zstyle ':completion:*'                  matcher-list 'm:{a-z}={A-Z}'          # match uppercase from lowercase
  190. zstyle ':completion:*:matches'              group 'yes'                           # separate matches into groups
  191. zstyle ':completion:*'                  group-name ''
  192. zstyle ':completion:*'                  menu select=0 _complete _ignored _approximate
  193. zstyle ':completion:*:messages'             format '%d'
  194. zstyle ':completion:*:options'              auto-description '%d'
  195. zstyle ':completion:*:options'              description 'yes'                     # describe options in full
  196. #zstyle ':completion:*:processes'           command 'ps -au$USER'                 # on processes completion complete all user processes
  197. zstyle ':completion:*'                  select-prompt 'Scrolling active: current selection at %p. Hit BACKSPACE to get out.'
  198. zstyle ':completion:*:*:-subscript-:*'          tag-order indexes parameters          # offer indexes before parameters in subscripts
  199. zstyle ':completion:*'                  verbose true                          # provide verbose completion information
  200. zstyle ':completion:*:warnings'             format $'%{\e[0;31m%}No matches for:%{\e[0m%} %d' # set format for warnings
  201. zstyle ':completion:*:*:zcompile:*'         ignored-patterns '(*~|*.zwc)'         # define files to ignore for zcompile
  202. zstyle ':completion:correct:'               prompt 'correct to: %e'               #
  203. zstyle ':completion::(^approximate*):*:functions'   ignored-patterns '_*'         # Ignore completion functions for commands you don't have:
  204.  
  205. ## commands
  206. zstyle ':completion:*:manuals'              separate-sections true
  207. zstyle ':completion:*:manuals.*'            insert-sections   true
  208. zstyle ':completion:*:man:*'                    menu yes select
  209. zstyle ':completion:*:rm:*'             ignore-line yes
  210. zstyle ':completion:*:cp:*'             ignore-line yes
  211. zstyle ':completion:*:mv:*'             ignore-line yes
  212. zstyle ':completion:*:*:kill:*:processes'       list-colors '=(#b) #([0-9]#)*=0=01;31'
  213. zstyle ':completion:*:processes-names'          command 'ps axho command'
  214. zstyle ':completion:*:*:killall:*:processes'        list-colors '=(#b) #([0-9]#)*=0=01;31'
  215. zstyle ':completion:*:*:killall:*:processes'        command 'ps --forest -A -o pid,user,cmd'
  216. zstyle ':completion:*:processes'            command 'ps -au$USER -o pid,time,cmd|grep -v "ps -au$USER -o pid,time,cmd"'
  217. #zstyle ':completion:*:*:kill:*:processes'      list-colors '=(#b) #([0-9]#)[ 0-9:]#([^ ]#)*=01;30=01;31=01;38'
  218. #zstyle ':completion:*:*:kill:*:processes'      command 'ps --forest -A -o pid,user,cmd'
  219.  
  220. _force_rehash() { # run rehash on completion
  221.    (( CURRENT == 1 )) && rehash
  222.       return 1 # Because we didn't really complete anything
  223. }
  224.  
  225. # completion for "man" by Gossamer 980827
  226. compctl -f -x 'S[1][2][3][4][5][6][7][8][9]' -k '(1 2 3 4 5 6 7 8 9)' \
  227.   - 'R[[1-9nlo]|[1-9](|[a-z]),^*]' -K 'match-man' \
  228.   - 's[-M],c[-1,-M]' -g '*(-/)' \
  229.   - 's[-P],c[-1,-P]' -c \
  230.   - 's[-S],s[-1,-S]' -k '( )' \
  231.   - 's[-]' -k '(a d f h k t M P)' \
  232.   - 'p[1,-1]' -c + -K 'match-man' \
  233.   -- man
  234.  
  235. ### system wide functions
  236. ## backup
  237. bu() { # create backup in working directory
  238.  cp "$1" ${1}-`date +%Y%m%d%H%M`.backup
  239. }
  240. buh() { # create backup in $HOME/.backup
  241.   bakdir="$HOME/.backup"
  242.   [ ! -d "$bakdir" ] && mkdir -p -m 700 "$bakdir"
  243.   for f in "$@"; do
  244.     f="`echo "$f" | sed 's!/\+$!!'`"   # strip trailing slashes
  245.       command cp -ai "$f" "$HOME/.backup/$f-`date +'%Y%m%d%H%M'`"
  246.   done
  247. }
  248. bur() { # create recursive backup in $HOME/.backup maintaining file system structure
  249.   if [ "`dirname $1`" == "." ]; then
  250.       mkdir -p $HOME/.backup/`pwd`;
  251.       cp -r "$1" $HOME/.backup/`pwd`/$1-`date +%Y%m%d%H%M`.backup;
  252.   else
  253.       mkdir -p $HOME/.backup/`dirname $*`;
  254.       cp -r "$1" $HOME/.backup/$1-`date +%Y%m%d%H%M`.backup;
  255.   fi
  256. }
  257.  
  258. ## pushd and cdp
  259. cd() { # always ls when cd'ing, also use pushd so i can retrace my steps via popd
  260.   if [ "$1" ]
  261.   then builtin pushd "$@" && ls
  262.   else builtin pushd && ls
  263.   fi
  264. }
  265.  
  266. cdp() { # change directory (Author W.Friebel friebel@ifh.de 13/04/95)
  267. TRAPINT() {
  268.   bindkey "^M" accept-line
  269.   setopt +B
  270.   trap - INT
  271.   builtin let "$1 > 0" && return $[128+$1]
  272. }
  273. setopt -B
  274. bindkey -s "^M" "^X^W"
  275. bindkey "^[k" kill-region
  276. # Select_Key definition:
  277. # to column 2; to begin of line; insert  cd ;
  278. # to begin of line; mark position; to begin of buffer; delete up to mark
  279. # to end of line; mark position; to end of buffer; to end of line
  280. # delete up to mark; put cd command into input buffer and execute
  281. bindkey -s "^X^W" "^[2^[|^A cd ^A^@^[<^[k^E^@^[>^E^[k^[a^X^K"
  282. cdp_var=`builtin print "### Select (and Edit) directory, Enter to accept it, ^C to quit ###"
  283. builtin print -l \`dirs \``
  284. vared cdp_var
  285. bindkey "^M" accept-line
  286. setopt +B
  287. eval $cdp_var
  288. }
  289.  
  290. ## system wide functions
  291. # daemon control
  292. dreload() { # reload a daemon
  293.   if [ "$UID" = 0 ];then
  294.     for arg in $*; do
  295.       /etc/rc.d/$arg reload
  296.     done
  297.   else
  298.     for arg in $*; do
  299.       sudo /etc/rc.d/$arg reload
  300.     done
  301.   fi  
  302. }
  303. drestart() { # reload a daemon
  304.   if [ "$UID" = 0 ];then
  305.     for arg in $*; do
  306.       /etc/rc.d/$arg restart
  307.     done
  308.   else
  309.     for arg in $*; do
  310.       sudo /etc/rc.d/$arg restart
  311.     done
  312.   fi
  313. }
  314. dstart() { # reload a daemon
  315.   if [ "$UID" = 0 ];then
  316.     for arg in $*; do
  317.       /etc/rc.d/$arg start
  318.     done
  319.   else
  320.     for arg in $*; do
  321.       sudo /etc/rc.d/$arg start
  322.     done  
  323.   fi
  324. }
  325. dstat() { # reload a daemon
  326.   if [ "$UID" = 0 ];then
  327.     for arg in $*; do
  328.       /etc/rc.d/$arg status
  329.     done
  330.   else
  331.     for arg in $*; do
  332.       sudo /etc/rc.d/$arg status
  333.     done  
  334.   fi
  335. }
  336. dstop() { # reload a daemon
  337.   if [ "$UID" = 0 ];then
  338.     for arg in $*; do
  339.       /etc/rc.d/$arg stop
  340.     done
  341.   else
  342.     for arg in $*; do
  343.       sudo /etc/rc.d/$arg stop
  344.     done  
  345.   fi
  346. }
  347. # file operations
  348. dirsize() { # show size of all directories in current working directory
  349.   du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \
  350.   egrep '^ *[0-9.]*[MG]' | sort -n > /tmp/list
  351.   egrep '^ *[0-9.]*M' /tmp/list
  352.   egrep '^ *[0-9.]*G' /tmp/list
  353.   rm /tmp/list
  354. }
  355. f() { # find a file
  356.   find 2>/dev/null | grep -is "$1"
  357. }
  358. fc() { # search content
  359.       if [ $# -eq 0 ]; then
  360.               echo "findcontent: No arguments entered."; return 1
  361.       else
  362.              # "{.[a-zA-Z],}*" instead of "." makes the output cleaner
  363.              find {.[a-zA-Z],}* -type f 2>/dev/null | xargs grep -is --color=always -n "$@"
  364.       fi
  365. }
  366. fcd() { # search content and specify the path to look
  367.       if [ $# -eq 0 ]; then
  368.         echo "findcontent: No arguments entered."; return 1
  369.       else
  370.         # "{.[a-zA-Z],}*" instead of "." makes the output cleaner
  371.         find "$1" -type f 2>/dev/null | xargs grep -is --color=always -n "$2"
  372.       fi
  373. }
  374. fd() { # specify where find should look
  375.   find "$1" 2>/dev/null | grep -is "$2"
  376. }
  377. ff() { # find a file in my filesystem
  378.   find / 2>/dev/null | grep -is "$1"
  379. }
  380. cdiff() { # create a diff
  381.   diff -udrP "$1" "$2" > diff.$(date "+%Y-%m-%d")."$1"
  382. }
  383. lf() { # list files only
  384.   ls -a1p $@ | grep -v '\/$'
  385. }
  386. sanitize() { # change mode and users of files to safe default
  387.   chmod -R u=rwX,go=rX "$@"
  388.   chown -R ${USER}:users "$@"
  389. }
  390. vs() { # use vim to edit a file but create a backup first
  391.   cp -iv $1 ${1}.backup && $VISUAL $1
  392. }
  393. wgp() { # paste file at paste.pocoo.org
  394.     wgetpaste "$@"
  395. }
  396.  
  397. ### system wide aliases
  398. ## globals and suffixes
  399. alias -s {conf,java,txt,TXT,README,PKGBUILD}=$VISUAL
  400. alias -g G="| grep"
  401. alias -g M="| most"
  402. alias -g X="| xargs"
  403. alias -g H="| head"
  404. alias -g T="| tail"
  405. alias -g S="| sort"
  406. alias -g SU='|sort -u'
  407. alias -g SN='|sort -n'
  408. alias -g SNR='|sort -nr'
  409. alias -g W="| wc -l"
  410. alias -g N="&>/dev/null"
  411. alias -g 1N="1>/dev/null"
  412. alias -g 2N="2>/dev/null"
  413.  
  414. ## mpd
  415. alias cmpd="ncmpc --host=192.168.0.2"
  416. alias lock="pause && slock && play"
  417. alias mt="amixer -q set Master toggle"
  418. alias mvol="mpc --no-status volume $1"
  419. alias nxt="mpc --no-status next"
  420. alias pause="mpc --no-status pause"
  421. alias pl="mpc --no-status playlist"
  422. alias play="mpc --no-status play"
  423. alias rnd="mpc random G random"
  424. alias rpt="mpc repeat G repeat"
  425. alias shfl="mpc --no-status shuffle"
  426. alias sta="mpc status"
  427. alias svol="amixer set Master $1"
  428. alias tog="mpc --no-status toggle"
  429.  
  430. alias la="ll -A"                                 # list all but not . and ..
  431. alias lh="ls -ld .*"                             # list only hidden files and folders
  432. alias ld="ls -ld *(-/DN)"                        # list only directories and link to them (see also lf())
  433. alias ll="ls -l"                                 # list detailed with human-readable sizes
  434. alias lsd="ll /var/run/daemons"                  # list running daemons
  435. alias lsdev="ls /dev | grep sd"                  # list sata devices
  436. alias rm="rm -Iv"                                # secure remove but less annoying than -i
  437. alias rmr="rm -r"                                # including folders
  438.  
  439. #################
  440. # ROOT SETTINGS #
  441. #################
  442.  
  443. if [[ $UID == 0 ]]; then
  444.   # close root shell after n seconds for security reasons
  445.   export TMOUT=180
  446.  
  447.   # root prompt
  448.   PROMPT=$'%{\e[0;31m%} #%{\e[0m%} '
  449.   RPROMPT='[%~] %*'
  450.  
  451.   # root aliases
  452.   alias hlt="shutdown -h now"                # halt now
  453.   alias hltin="shutdown -h"                  # halt in n minutes
  454.   alias mnt="mount"                          # mount
  455.   alias rbt="shutdown -r now"                # reboot now
  456.   alias rbtin="shutdown -r"                  # reboot in n minutes
  457.   alias showlog="tail -f /var/log/everything.log"
  458.   #alias sublimation="pacman -R $(pacman -Qq | grep -v "$(pacman -Qqg base)")" # careful! deletes every package except for those in the base group
  459.   alias suspend="pm-suspend"                 # suspend
  460.   alias umnt="umount"                        # umount
  461.  
  462.   if [ $HOST = 13 ]; then
  463.     fan() { # control fan
  464.       if [ $# = 0 ];then
  465.         cat /proc/acpi/ibm/fan
  466.       elif [ $1 = off ];then
  467.         echo disable > /proc/acpi/ibm/fan
  468.       elif [ $1 = on ];then
  469.         echo level auto > /proc/acpi/ibm/fan
  470.       elif [ $1 = 1 ];then
  471.         echo level 1 > /proc/acpi/ibm/fan
  472.       else
  473.         echo "$@" > /proc/acpi/ibm/fan
  474.       fi
  475.     }
  476.   fi
  477.    
  478.   lamb() { # beep the children's song
  479.     beep -f 10
  480.       echo "Marry Had A Little Lamb"
  481.         beep -f 466.2 -l 250 -D 20 -n -f 415.3 -l 250 -D 20 -n -f 370.0 -l 250 -D 20 -n -f 415.3 -l 250 -D 20 -n -f 466.2 -l 250 -r 2 -d 0 -D 20 -n -f 466.2 -l 500 -n -f 10 -l 20
  482.       echo "Little Lamb, Little Lamb"
  483.         beep -f 415.3 -l 250 -r 2 -d 0 -D 20 -n -f 415.3 -l 500 -D 20 -n -f 466.2 -l 250 -D 20 -n -f 568.8 -l 250 -D 20 -n -f 568.8 -l 500 -n -f 10 -l 20
  484.       echo "Marry Had A Little Lamb"
  485.         beep -f 466.2 -l 250 -D 20 -n -f 415.3 -l 250 -D 20 -n -f 370.0 -l 250 -D 20 -n -f 415.3 -l 250 -D 20 -n -f 466.2 -l 250 -r 2 -d 0 -D 20 -n -f 466.2 -l 250 -n -f 10 -l 20
  486.       echo "Whose Fleece Was White As Snow"
  487.         beep -f 415.3 -l 250 -r 3 -D 20 -n -f 466.2 -l 250 -D 20 -n -f 415.3 -l 250 -D 20 -n -f 370.0 -l 500
  488.   }
  489.  
  490.   setup() { # setup choosing between demian and slave
  491.     echo -n "intial-setup: demian or slave? "
  492.     read answer
  493.     case "$answer" in
  494.         demian|d|1|"") echo "Proceeding with setup for demian"
  495.     echo "Creating user demian, directories and password"
  496.     useradd -m -G users,audio,lp,optical,storage,video,wheel,power -s /bin/zsh demian ; passwd demian ; mkdir /media/share /media/daten
  497.     echo "Downloading and installing packages"
  498.     ## Base System
  499.     pacman -Syy irssi grc unace zenity zsh cpufrequtils nfs-utils rpcbind rsync wgetpaste tree calc vim bc htop scrot curl unzip rar p7zip unrar screen clamav dosfstools ntfsprogs alsa-utils powertop laptop-mode-tools acpid pm-utils abs cups pmount samba openssh ntfs-3g slock mpc moc ethtool imagemagick yaourt lm_sensors stress reflector lzop cowsay fortune-mod ; yaourt -Sy --aur fortune-mod-tbbt fortune-mod-montypython fortune-mod-himym fortune-mod-buffy fortune-mod-chucknorris tupac zsh-tupac zsh-yaourt zsh-lovers
  500.     ## GUI
  501.     pacman -S ttf-dejavu ttf-ms-fonts ttf-bitstream-vera xorg xf86-input-evdev xf86-video-intel gamin openbox openbox-themes obconf obmenu xcompmgr terminal feh pcmanfm gmrun medit xarchiver epdfview mirage conky sonata gmpc firefox thunderbird flashplugin galculator vlc transset-df gxmessage xdg-user-dirs gvim ; yaourt -S aurvote firebrand thunderbrand sir
  502.     ## LCD-Fonts
  503.     pacman -Rd libxft cairo ; yaourt -S fontconfig-lcd cairo-lcd ; pacman -S libxft-lcd
  504.         ;;
  505.     slave|s|2|"") echo "Proceeding with install for slave"
  506.     echo "Creating user slave, directories and password"
  507.     useradd -m -G users,audio,lp,optical,storage,video,wheel,power -s /bin/zsh slave ; passwd slave ; mkdir /media/movies /media/music /media/series /media/share /media/usbhdd
  508.     echo "Downloading and installing packages"
  509.     ## Base System
  510.     pacman -Syy lighttpd fcgi php php-cgi mpd rtorrent irssi grc unace zenity zsh cpufrequtils nfs-utils rpcbind rsync wgetpaste tree calc vim bc htop scrot curl unzip rar p7zip unrar screen clamav dosfstools ntfsprogs alsa-utils powertop laptop-mode-tools acpid pm-utils abs cups pmount samba openssh ntfs-3g slock mpc moc gmpc ethtool imagemagick yaourt lm_sensors stress reflector lzop cowsay fortune-mod ; yaourt -Sy --aur fortune-mod-tbbt fortune-mod-montypython fortune-mod-himym fortune-mod-buffy fortune-mod-chucknorris tupac eaccelerator zsh-tupac zsh-yaourt zsh-lovers
  511.     ## GUI
  512.     pacman -S ttf-dejavu ttf-ms-fonts ttf-bitstream-vera xorg xf86-input-evdev xf86-video-intel gamin openbox openbox-themes obconf obmenu xcompmgr terminal feh pcmanfm gmrun medit xarchiver epdfview mirage conky sonata gmpc firefox thunderbird flashplugin galculator vlc transset-df gxmessage xbmc xdg-user-dirs gvim ; yaourt -S aurvote firebrand thunderbrand sir
  513.     ## LCD-Fonts
  514.     pacman -Rd libxft cairo ; yaourt -S fontconfig-lcd cairo-lcd ; pacman -S libxft-lcd
  515.         ;;
  516.             *) echo "Error. Please go away."
  517.             ;;
  518.     esac
  519.   }
  520.   # root stops parsing this file here
  521.   return 0
  522. fi
  523.  
  524. #################
  525. # USER SETTINGS #
  526. #################
  527.  
  528. ### general settings
  529. ## user prompt
  530. PROMPT=" > "
  531. RPROMPT="[%~] %*"
  532.  
  533. ## greeting
  534. dir="/usr/share/cows"
  535. file=`/bin/ls -1 "$dir" | sort --random-sort | head -1`
  536. cow="$(echo "$file" | sed -e "s/\.cow//")"
  537. fortune | cowsay -W 75 -f $cow
  538.  
  539. ## exports
  540. export    XAUTHORITY="$HOME/.Xauthority"    \
  541.      XDG_CACHE_HOME="$HOME/.cache"      \
  542.      XDG_CONFIG_DIR="$HOME/.config"     \
  543.      XDG_CONFIG_DIRS="$HOME/.config:/etc"   \
  544.      XDG_DATA_HOME="$HOME/.config/share"    \
  545.      XDG_DESKTOP_DIR="$HOME"        \
  546.      XDG_DOCUMENTS_DIR="$HOME/doc"      \
  547.      XDG_DOWNLOAD_DIR="$HOME/down"      \
  548.      XDG_MUSIC_DIR="$HOME"          \
  549.      XDG_PICTURES_DIR="$HOME/pics"      \
  550.      XDG_PUBLICSHARE_DIR="$HOME"        \
  551.      XDG_TEMPLATES_DIR="$HOME"      \
  552.      XDG_VIDEOS_DIR="$HOME"
  553.      
  554. if [ "$DISPLAY" ]; then
  555.   export BROWSER=.bin/firefox   \
  556.      VIDEO=vlc
  557.  
  558.   alias -s {PDF,pdf}=$PDF
  559.   alias -s {docx,DOCX,doc,DOC,odt,ODT,sxw}=$OFFICE
  560.   alias -s {ods,xls}=$EXCEL
  561.   alias -s {jpg,JPG,jpeg,JPEG,png,PNG,gif,GIF}=$PICSHOW
  562.   alias -s xcf="q gimp"
  563.   alias -s svg="q inkscape"
  564.   alias -s {MP3,mp3,ogg,wav,WAV,flac,FLAC,mpg,mpeg,avi,AVI,ogm,wmv,m4v,mp4,mov,mkv,MKV}=$VIDEO
  565.   alias -s {com,net,org,uk,html,php,url}=$BROWSER
  566.  
  567.   alias firefox="q .bin/firefox"                       # firefox
  568.   alias pc="q mirage"                                  # start mirage disowned with no stdout
  569.   alias pf="q epdfview"                                # start epdfview disowned with no stdout
  570.   alias regex="pc $HOME/.local/regex.png"              # show regex cheatsheet
  571.   alias se="sudo e"                                    # $EDITOR
  572.   alias session="q session"                            # .bin/session
  573.   alias sm="sudo m"                                    # medit
  574.   alias vlc="q vlc"                                    # run vlc quietly
  575.   ses() { # es but with sudo privileges
  576.     sudo cp -iv "$1" ${1}.backup && sudo $EDITOR "$1"
  577.   }
  578. fi
  579.  
  580. ## which host?   
  581. if [ $HOST = 2 ]; then
  582.   alias cdi="cd /media/music/incoming"          # change directory to incoming
  583.   alias cdmo="cd /media/movies"             # change directory to movies  
  584.   alias cdmu="cd /media/music"              # change directory to music
  585.   alias cds="cd /media/series"              # change directory to series
  586.   alias cdu="cd /media/usbhdd"              # change directory to usbhdd
  587.   alias lsi="lx /media/music/incoming"          # list incoming
  588.   alias mntu="mount /media/usbhdd"          # mount usbhdd
  589. elif [ $HOST = 13 ]; then
  590.   alias bats="c /proc/acpi/battery/BAT0/state"          # show battery state
  591.   alias cdd="cd /media/daten/down"                      # change directory to incoming
  592.   alias mnth="mount 192.168.0.2:/home/slave $HOME/.shares/home ; cd $HOME/.shares/home" # mount NFS home
  593.   alias mntm="mount 192.168.0.2:/media $HOME/.shares/media ; cd $HOME/.shares/media"    # mount NFS media
  594.   alias ssh2="ssh slave@192.168.0.2"                    # ssh into 2
  595.   alias umnth="sudo umount.nfs 192.168.0.2:/home/slave" # umount nfs home
  596.   alias umntm="sudo umount.nfs 192.168.0.2:/media"  # umount nfs media
  597.   alias wc="wicd-curses"                                # wicd
  598.   alias wup="ifconfig wlan0 up"                         # ifconfig
  599. fi
  600.  
  601. ### aliases
  602. ## short ones
  603. alias a=cat
  604. alias b=popd
  605. alias c=cd
  606. alias d=pwd
  607. #f: find in wd
  608. alias g=grep
  609. alias h=history
  610. alias k="kill"
  611. alias l=ls
  612. alias n=note
  613. #t: toggle terminal size
  614. #q: run quietly and disowned
  615. alias v="$VISUAL -p"
  616. alias x=exit
  617. #y: yaourt
  618.  
  619. ## system
  620. alias ..="cd ../"                                # move up one directory
  621. alias ...="cd ../../"                            # move up two directories
  622. alias ....="cd ../../../"                        # move up three directories
  623. alias 000="chmod 000"
  624. alias 644="chmod 644"
  625. alias 755="chmod 755"
  626. alias cdb="cd $HOME/.backup"             # change directory to $HOME/.backup
  627. alias cdbin="cd $HOME/.bin"                      # change directory to .bin
  628. alias cdt="cd /tmp"                              # change directory to /tmp  
  629. alias chr="chmod a+r"                            # add read permissions for all users
  630. alias chw="chmod a+w"                            # add write permissions for all users
  631. alias cd.s="cd $HOME/.shares"                    # change directory to .shares
  632. alias cdm="cd /media"                            # change directory to media
  633. alias cdscr="cd $HOME/.local/screenshots"        # change directory to screenshots
  634. alias cdsh="cd /media/share"                     # change directory to share
  635. alias cdwp="cd $HOME/.local/wallpapers"          # change directory to wallpapers
  636. alias cl="clear"                                 # clear screen    
  637. alias clam="clamscan --bell -i"                  # scan a file
  638. alias clami="clam -r /media/music/incoming"  # scan incoming files
  639. alias clamt="clam -r /tmp"           # scan /tmp
  640. alias cm="chmod"                 # chmod
  641. alias cpr="cp -r"                    # copy recursively
  642. alias cpv="rsync -P"                             # use rsync as cp alternative due to more information
  643. alias co="chown"                 # chown
  644. alias cx="chmod a+x"                             # make file executable for everyone
  645. alias da="date '+%A, %d.%m.%Y, %T'"              # Wednesday, 21.04.2010, 14:22:25
  646. alias dat="date '+%A, %B %d, %Y [%T]'"           # Thursday, April 15, 2010 [16:27:42]
  647. alias df="df -h"                                 # file system disk space usage in human-readable sizes
  648. alias du="du -hc"                                # disk space usage in human-readable sizes
  649. alias du1="du --max-depth=1"                     # look no deeper than one directory level
  650. alias dus="du -s"                                # disk space usage in human-readable sizes
  651. alias duchs="du -chs * 2>/dev/null |sort -rn |head -11" # disk hog
  652. alias eg="egrep --color=auto"                    # colourized egrep
  653. alias egrep="egrep --color=auto"                 # colourized egrep
  654. alias free="free -m"                             # show sizes in MB
  655. alias hist="history | grep"                      # search cmd history
  656. alias ka="killall"                               # killall
  657. alias lam="la | less"                            # long list?
  658. alias lat="lt -A"                                # lt with -A
  659. alias lax="lx -A"                                # lx with -A
  660. alias lay="ly -A"                                # ly with -A
  661. alias less="less -iF"                            # less with ignore-case and quit-if-one-screen enabled
  662. alias llm="ll | less"                            # long list?
  663. alias lnew="ll -rt *(.) | tail"                  # list newest
  664. alias lold="ll -rt *(.) | head"                  # list oldest
  665. alias ls="ls --color=always -hF"                 # classify and human-readable
  666. alias lsb="la $HOME/.backup"                     # list content of .backup
  667. alias lscr="ll $HOME/.local/screenshots"         # list screenshots
  668. alias lsmall='ls -lSh *(.) | head'               # list smallest
  669. alias lst="ll /tmp"                              # list temporary directory
  670. alias lsuuid="ls -l /dev/disk/by-uuid/"          # list disks by uuid
  671. alias lt="la -rt"                                # sort by modification time
  672. alias lw="ls -1"                                 # windows-style list
  673. alias lx="ll -BX"                                # sort by extension
  674. alias ly="ll -rS"                                # sort by size
  675. alias make="time make"                           # time make
  676. alias makepkg="time makepkg"                     # time makepkg
  677. alias md="mkdir -pv"                             # create parents and verbose output
  678. alias mtd='tdir=`mktemp -d` && cd $tdir'         # make temp dir and cd into it
  679. alias more="less"                                # less is more
  680. alias nano="vim"                                 # .
  681. alias ns="netstat -alnp --protocol=inet | grep -v CLOSE_WAIT | cut -c-6,21-94 | tail"
  682. alias nsw="sudo watch -n 3 -d -t netstat -vantp" # watch incoming connections
  683. alias openports="netstat --all --numeric --programs --inet"
  684. alias parts="cat /proc/partitions"               # show partitions
  685. alias pas="ps -efH"                              # all processes, in hierarchy and full-format listing
  686. alias pac0="ps aux | sort -k 3,3 | tail "        # list processes by cpu usage
  687. alias pac1='ps -eo pcpu,nice,stat,time,pid,cmd --sort=-pcpu,-time | sed "/^ 0.0 /d"'
  688. alias pag="ps aux | grep -v grep | grep"         # search process
  689. alias pam="echo '%CPU %MEM   PID COMMAND' && /bin/ps hgaxo %cpu,%mem,pid,comm | sort -nrk1 | head -n 10 | sed -e 's/-bin//' | sed -e 's/-media-play//'"
  690. alias par0="ps aux | sort -k 4,4 | tail "        # list processes by memory usage
  691. alias par1='ps -eo rss,vsz,pid,cmd --sort=-rss,-vsz | awk "{ if (\$1 > 10000) print }"'
  692. alias pau="ps uxU $1"                            # list processes by user
  693. alias pk="pkill"                                 # pkill
  694. alias pm="pmount"                                # pmount
  695. alias pum="pumount"                              # pumount
  696. alias pw='echo `< /dev/urandom tr -cd "[:graph:]" | head -c8`' # create secure password
  697. alias rd="rmdir"                 # remove directory
  698. alias rsynn="rsync -r -n -t -p -o -g -v --progress --delete -l"
  699. alias trace="traceroute -I"                      # tracerout using icmp echo instead of udp datagrams
  700. alias tree="tree -C"                             # colorize tree output
  701. alias vb="v $HOME/{.bashtweaks,.bashrc}"         # visual edit bash files
  702. alias vn="v $HOME/.notes"                        # visual edit notes (also see function note() below)
  703. alias vz="v $HOME/.zshrc"                        # visual edit zsh files
  704.  
  705. ## .bin
  706. #alias archinfo="archinfo"       # shows DE/WM information
  707. alias bat="bat -b0"              # battery information
  708. #alias firefox="firefox"         # wrapper for firefox
  709. #alias mod="mod"                 # shows required kernel modules
  710. #alias pclean="pclean"           # clean pacman database
  711. #alias pfree="pfree"             # shows files that are not owned by any package
  712. #alias psizee="psizee"           # sorts all installed packages by size
  713. #alias pwcat="pwcat"             # show power setting information (needs redo)
  714. #alias pwdo="pwdo"               # execute power settings (needs redo)
  715. #alias q="q"                     # run program quietly and detached from terminal
  716. #alias read_msr="read_msr"       # used to verify undervolting controls
  717. #alias rndwp="rndwp"             # random wallpaper!
  718. #alias session="session"         # used with gxmessage to create popup for session control
  719. #alias temp="temp"               # show temperatures (needs redo)
  720.  
  721. ## colorize
  722. if which grc &>/dev/null; then
  723.   alias .cl='grc -es --colour=auto'
  724.   alias configure='.cl ./configure'
  725.   alias diff='.cl diff'
  726.   alias make='.cl make'
  727.   alias gcc='.cl gcc'
  728.   alias g++='.cl g++'
  729.   #alias as='.cl as'
  730.   #alias gas='.cl gas'
  731.   #alias ld='.cl ld'
  732.   alias netstat='.cl netstat'
  733.   alias ping='.cl ping -c 5'
  734.   alias traceroute='.cl traceroute'
  735. fi
  736.  
  737. ## user
  738. alias irc="irssi -n mikar"               # irc
  739. alias or="openbox --reconfigure"                     # reconfigure openbox
  740. alias sdr="screen -D -R $1"                          # if session is running, reattach. if necessary detach and logout remotely first. if it was not running create it and notify the user.
  741. alias sls="screen -ls"                               # lists pid.tty.host strings
  742. alias ss="screen -S $1"                              # start session specifying a name
  743. alias vo="v $HOME/.config/openbox/{rc.xml,menu.xml}" # visual edit openbox files
  744.  
  745. ## pacman
  746. alias pqg="pacman-color -Qg | sed 's/ .*//' | sort | uniq" # list groups of installed packages
  747. alias psl="pacman-color -Sl | grep -i "         # search pacman-color database for string
  748. #alias pfree="pfree"                            # create list of all files not owned by any package
  749. #alias psizea="psizea"                          # list all installed packages and sort by size
  750. #alias psizee="psizee"                          # list explicitly installed packages and sort by si
  751.  
  752. ## tupac (wrapper for yaourt and pacman with local caching)
  753. alias y="tupac"                  # tupac
  754. alias yq="tupac -Q | grep -i"    # query
  755. alias yqe="tupac -Qe"            # show explicitly installed packages
  756. alias yqi="tupac -Qi"            # show information about an installed package
  757. alias yql="tupac -Ql"            # show files installed by a package
  758. alias yqo="tupac -Qo"            # search for package that owns the file
  759. alias yqs="tupac -Qs"            # search installed packages
  760. alias yr="tupac -R"              # remove
  761. alias yrd="tupac -Rd"            # remove omitting dependencies
  762. alias yrs="tupac -Rs"            # remove including unused dependencies
  763. alias ys="tupac -S"              # download and install
  764. alias ysb="tupac -Sb"            # builds the targets from source
  765. alias ysc="tupac -Sc"            # clean those packages from cage that are no longer installed
  766. alias yscc="tupac -Scc"          # clean the whole cache directory
  767. alias ysf="tupac -Sf"            # force (re-)installation
  768. alias ysi="tupac -Si"            # show information about a non-local package
  769. alias ysl="tupac -Sl | grep -i " # list all packages in specified repository
  770. alias yss="tupac -Ss"            # query database
  771. alias ysw="tupac -Sw"            # download but don't install
  772. alias ysu="tupac -Su --aur"      # upgrade all aur packages
  773. alias ysy="tupac -Sy --aur"      # sync refresh
  774. alias ysyu="tupac -Syu --aur"    # sync refresh sys update + aur
  775. alias ysyy="tupac -Syy --aur"    # force sync refresh + aur
  776. alias ysyyu="tupac -Syyu --aur"  # force sync refresh and update + aur
  777. alias yu="tupac -U"              # install local package
  778.  
  779. # sudo user aliases
  780. alias abs="sudo abs"                            # update abs database
  781. alias chi="sudo chattr +i"                      # immunize file
  782. alias chu="sudo chattr -i"                      # unimmunize file
  783. alias clams="sudo clam -r -l $HOME/.clamlog /"  # scan whole system
  784. alias freshc="dstart clamav ; freshclam ; dstop clamav"      # update clamav database
  785. alias freshclam="sudo freshclam"        # freshclam
  786. alias hdparm="sudo hdparm"                      # hdparm
  787. alias hlt="sudo shutdown -h now"                # halt now
  788. alias hltin="sudo shutdown -h"                  # halt in n minutes
  789. alias mkinitcpio="sudo mkinitcpio"              # mkinitcpio
  790. alias ifconfig="sudo ifconfig"                  # ifconfig
  791. alias mnt="mount"                               # mount
  792. alias modprobe="sudo modprobe"                  # modprobe
  793. alias mount="sudo mount"                        # mount
  794. alias p="sudo pacman"                           # sudo pacman-color
  795. alias pin="sudo pacman-color -S"                # install
  796. alias pout="sudo pacman-color -R"               # remove
  797. alias pq="sudo pacman-color -Q | grep -i"       # query
  798. alias pqe="sudo pacman-color -Qe"               # show explicitly installed packages
  799. alias pqi="sudo pacman-color -Qi"               # show information about an installed package
  800. alias pql="sudo pacman-color -Ql"               # show files installed by a package
  801. alias pqo="sudo pacman-color -Qo"               # search for package that owns the file
  802. alias pqs="sudo pacman-color -Qs"               # search installed packages
  803. alias prd="sudo pacman-color -Rd"               # remove omit dependencies
  804. alias prs="sudo pacman-color -Rs"               # remove plus unused dependencies
  805. alias psc="sudo pacman-color -Sc"               # clean those packages from cage that are no longer installed
  806. alias pscc="sudo pacman-color -Scc"             # clean the whole cache directory
  807. alias psf="sudo pacman-color -Sf"               # force (re-)installation
  808. alias psi="sudo pacman-color -Si"               # show information about a non-local package
  809. alias pss="sudo pacman-color -Ss"               # query database
  810. alias psw="sudo pacman-color -Sw"               # download but don't install
  811. alias psu="sudo pacman-color -Su"               # sys update without refresh
  812. alias psy="sudo pacman-color -Sy"               # sync refresh
  813. alias psyu="sudo pacman-color -Syu"             # sync refresh and update
  814. alias psyy="sudo pacman-color -Syy"             # force all db to be refreshed
  815. alias psyyu="sudo pacman-color -Syyu"           # force refresh and update
  816. alias pu="sudo pacman-color -U"                 # install local pkg
  817. alias pclean="sudo pclean"                      # .bin/pclean with sudo privileges
  818. alias pmirror="sudo reflector -l 8 -r -o /etc/pacman.d/mirrorlist ; c /etc/pacman.d/mirrorlist" update mirrorlist
  819. alias popt="sudo pacman-optimize"               # defrag pacman database
  820. alias porph="sudo pacman -Rsc $(pacman -Qtdq)"  # remove orphans
  821. alias powertop="sudo powertop"                  # powertop
  822. alias rbt="sudo shutdown -r now"                # reboot now
  823. alias rbtin="sudo shutdown -r"                  # reboot in n minutes
  824. alias rmmod="sudo rmmod"                        # rmmod
  825. alias s="sudo"                                  # lazy much
  826. alias sa="sudo a"                               # cat
  827. alias s-cp="sudo cp"                            # cp -i
  828. alias scpr="sudo cpr"                           # cp -r
  829. alias showlog="sudo tail -f /var/log/everything.log"
  830. alias sk="sudo k"                               # kill -9
  831. alias smv="sudo mv"                             # mv -i
  832. alias spk="sudo pk"                             # pkill
  833. alias srm="sudo rm"                             # rm -I
  834. alias srmr="sudo rmr"                           # rm -Ir
  835. alias su="su -"                                 # change to root directory
  836. alias sudo="sudo "                              # avoid some problems with sudo
  837. alias suspend="sudo pm-suspend"                 # suspend
  838. alias sv="sudo v"                               # $VISUAL
  839. alias umnt="sudo umount"                        # umount
  840. alias updfonts="sudo fc-cache -vf"              # update font cache
  841.  
  842. ## unalias everything
  843. #unalias -a                      # uncomment to unalias everything
  844.  
  845. ### user functions
  846. ## various
  847. del() { # manage trash can
  848.   if [ -z $1 ]; then
  849.     la $HOME/.local/trash
  850.     echo "Empty Trash? (y/n)"
  851.     read var
  852.       if [ $var = y ]; then
  853.         sudo rm -rf $HOME/.local/trash/*
  854.     echo "Emptied trash."
  855.       else
  856.         echo "Doing nothing."
  857.       fi
  858.   elif [ -f $1 ]; then
  859.     echo "Delete or just move to trash? (d/t)?"
  860.       read var
  861.       if [ $var = t ]; then
  862.         mv -v $1 $HOME/.local/trash/
  863.       elif [ $var = d ]; then
  864.         rm -rI $1
  865.       else
  866.         echo 'The requested file/folder, $1, does not exist'
  867.       fi
  868.   fi
  869. }
  870. note() { # create or show notes
  871.       #if file doesn't exist, create it
  872.       [ -f $HOME/.notes ] || touch $HOME/.notes
  873.       #no arguments, print file
  874.       if [ $# = 0 ]
  875.       then
  876.               cat $HOME/.notes
  877.       #clear file
  878.       elif [ $1 = -c ]
  879.       then
  880.               > $HOME/.notes
  881.       #add all arguments to file
  882.       else
  883.               echo "$@" >> $HOME/.notes
  884.       fi
  885. }
  886. reprobe() { # remove and reinsert module
  887.   sudo modprobe -r $1
  888.   sudo modprobe $1
  889. }
  890.  
  891. ## file operations
  892. cpd() {
  893.   [ ! -d "$2" ] && mkdir -p "$2"
  894.   cp "$1" "$2"
  895. }
  896. cpg() { # copy file and go to dir
  897.   if [ -d "$2" ];then
  898.     cp -irv $1 $2 && cd $2
  899.   else
  900.     cp -irv $1 $2
  901.   fi
  902. }
  903.  
  904. files() { # show amount of files in a directory
  905.   ls -Al $1 | wc -l
  906. }
  907. findopen() { # find and open a file
  908.   local PS3="select file: "
  909.   files=( $(find "$1" -iname "$2" | sort | tr ' ' '@') )
  910.   select file in "${files[@]//@/ }"; do
  911.       ${3:-exo-open} "$file"
  912.       break
  913.   done
  914. }
  915. grab() { # change ownership to me
  916.   sudo chown -R ${USER}:${USER} ${1:-.}
  917. }
  918. lcfiles() { # lowercase all files in a directory
  919.   print -n 'Really lowercase all files? (yn) '
  920.   if read -q ; then
  921.     for i in * ; do
  922.       mv $i $i:l
  923.     done
  924.   fi
  925. }
  926. mdc() { # make directory and cd into it
  927.   mkdir -p "$1" && cd "$1"
  928. }
  929. mvd() {
  930.   [ ! -d "$2" ] && mkdir -p "$2"
  931.   mv "$1" "$2"
  932. }
  933. mvg() { # move file and go to dir
  934.   if [ -d "$2" ];then
  935.     mv -iv $1 $2 && cd $2
  936.   else
  937.     mv -iv $1 $2
  938.   fi
  939. }
  940. rmspaces() {
  941.   ls | while read -r FILE
  942.   do
  943.     mv -v "$FILE" `echo $FILE | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | tr '[A-Z]' '[a-z]' | sed 's/_-_/_/g'`
  944.   done
  945. }
  946. rme() { # remove everything except $1
  947.   rm -r ^("$1"|"$2")
  948. }
  949. space() { # create report of biggest files in folder $@
  950.   du -h "$@" | sort -nr > $HOME/.space.txt && vim $HOME/.space.txt
  951. }
  952.  
  953. ssanitize() { # sanitize but with sudo privileges
  954.   sudo chmod -R u=rwX,go=rX "$@"
  955.   sudo chown -R ${USER}:users "$@"
  956. }
  957. svs() { # vs but with sudo privileges
  958.   sudo cp -iv "$1" ${1}.backup && sudo $VISUAL "$1"
  959. }
  960. swap() { # swap two filenames
  961.       if [ $# -ne 2 ]; then
  962.               echo "swap: 2 arguments needed"; return 1
  963.       fi
  964.       if [ ! -e $1 ]; then
  965.               echo "swap: $1 does not exist"; return 1
  966.       fi
  967.       if [ ! -e $2 ]; then
  968.               echo "swap: $2 does not exist"; return 1
  969.       fi
  970.       local TMPFILE=tmp.$$ ; mv $1 $TMPFILE ; mv $2 $1 ; mv $TMPFILE $2
  971. }
  972. up() { # go up n directories
  973.       [ "${1/[^0-9]/}" == "$1" ] && {
  974.       local ups=""
  975.       for i in $(seq 1 $1)
  976.       do
  977.               ups=$ups"../"
  978.       done
  979.       cd $ups
  980.       } || echo "usage: up INTEGER"
  981. }
  982.  
  983. ## pacman
  984. psizea() { # list all packages and sort them by their (installed) size
  985.   LANG=C pacman -Qi | sed -n '/^Name[^:]*: \(.*\)/{s//\1 /;x};/^Installed[^:]*: \(.*\)/{s//\1/;H;x;s/\n//;p}' | sort -nk2
  986. }
  987. roulette() { # pacman roulette
  988.   sudo pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))
  989. }
  990.  
  991. ## pictures
  992. res() { # resize a picture to 1920 x 1200 at 90% quality
  993.   #no arguments, print usage
  994.   if [ $# = 0 ]
  995.   then
  996.     echo "Usage: res filename"
  997.     echo "Example: res P103845.JPG"
  998.   else
  999.     echo "Resizing ${i:2} to 1920 x 1200 at 90% quality with filename res-$1";convert -resize 1920x1200 -quality 90 $1 res-$1
  1000.   fi
  1001. }
  1002. resa() { # resize and replace all pictures in a directory
  1003.   #no arguments, print usage
  1004.   if [ $# = 0 ]
  1005.   then
  1006.     echo "Usage: resa width height quality"
  1007.     echo "Example: resa 1920 1200 90"
  1008.   else
  1009.     for i in $(find . -maxdepth 1 -type f \-iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.bmp");
  1010.   do
  1011.     echo "Resizing ${i:2} to $1 x $2 at $3% quality";convert ${i:2} -quality $3 -resize $1\x$2 new_${i:2}; /bin/mv new_${i:2} ${i:2}
  1012.   done
  1013.   fi
  1014. }
  1015. ress() { # resize a single picture specifying width, height, quality and filename
  1016.   #no arguments, print usage
  1017.   if [ $# = 0 ]
  1018.   then
  1019.     echo "Usage: ress width height quality filename"
  1020.     echo "Example: ress 1920 1200 90 P103845.JPG"
  1021.   else
  1022.     echo "Resizing ${i:2} to $1 x $2 at $3% quality with filename ress-$4";convert -resize $1\x$2 -quality $3 $4 ress-$4
  1023.   fi
  1024. }
  1025. rest() { # create thumbnail of pictures and move them to the directory final
  1026.     fmt="jpg"
  1027.     imgsz="100%"
  1028.     tmbsz="15%"
  1029.     id=1
  1030.     while [ $# -gt 0 ] ; do
  1031.         case "$1" in
  1032.             -f)
  1033.                 fmt=$2 ; shift 2 ;;
  1034.             -i)
  1035.                 imgsz=$2 ; shift 2 ;;
  1036.             -t)
  1037.                 tmbsz=$2 ; shift 2 ;;
  1038.             -n)
  1039.                 id=$2 ; shift 2 ;;
  1040.             -s)
  1041.                 sfx=$2 ; shift 2 ;;
  1042.             -p)
  1043.                 pfx=$2 ; shift 2 ;;
  1044.             *)
  1045.                 echo 'error: ' $1 $2
  1046.                 shift 1 ;;
  1047.         esac
  1048.     done
  1049.     mkdir final
  1050.     ls *.* | while read img ; do
  1051.        echo "$img    -> $id.$fmt"            
  1052.        convert $img -scale $imgsz final/$pfx$id$sfx.$fmt &
  1053.        convert $img -scale $tmbsz final/$pfx$id\_t$sfx.$fmt &            
  1054.        id=$((id+1))
  1055.   done
  1056. }
  1057. shot() { # create a screenshot with thumbnail in specified folder
  1058.   local PIC="${HOME}/.local/screenshots/%d.%m.%y_%H-%M-%S.jpg"
  1059.   scrot -q 90 $PIC
  1060. }
  1061. shotw() { # create a screenshot of a window
  1062.   local PIC="${HOME}/.local/screenshots/w_%d.%m.%y_%H-%M-%S.jpg"
  1063.   scrot -s -q 90 $PIC
  1064. }
  1065.  
  1066. ## information
  1067. cal() { # print a calender in terminal
  1068.   if [[ ! -f /usr/bin/cal ]] ; then
  1069.     echo "Please install cal before trying to use it!"
  1070.     return
  1071.   fi
  1072.   if [[ "$#" = "0" ]] ; then
  1073.     /usr/bin/cal | egrep -C 40 --color "\<$(date +%e| tr -d ' ')\>"
  1074.     echo "Today is `da`"      
  1075.   else
  1076.       cal $@ | egrep -C 40 --color "\<($(date +%B)|$(date +%e | tr -d ' '))\>"
  1077.     echo "Today is `da`"
  1078.   fi
  1079. }
  1080. ip() { # print my ip
  1081.   lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | awk '{ print $4 }' | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g'
  1082. }
  1083. freem() { # show free memory
  1084.   free -m | grep 'Mem:' | awk '{print $4}'
  1085. }
  1086. netinfo() { # show network information
  1087.   echo "--------------- Network Information ---------------"
  1088.   /sbin/ifconfig | awk /'inet addr/ {print $2}'
  1089.   /sbin/ifconfig | awk /'Bcast/ {print $3}'
  1090.   /sbin/ifconfig | awk /'inet addr/ {print $4}'
  1091.   /sbin/ifconfig | awk /'HWaddr/ {print $4,$5}'
  1092.   myip=`lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g' `
  1093.   echo "${myip}"
  1094.   echo "---------------------------------------------------"
  1095. }
  1096. sysinfo() { # show information about my system
  1097.   clear
  1098.   num_cpus=`cat /proc/cpuinfo | grep -c "model name"`
  1099.   machine_cpu=`cat /proc/cpuinfo | grep -m 1 "model name" | cut -d: -f2`
  1100.   machine_mhz=`cat /proc/cpuinfo | grep -m 1 "cpu MHz" | cut -d: -f2`
  1101.   machine_cpuinfo=`uname -mp`
  1102.   todays_date=`date +"%D %r"`
  1103.   machine_uptime=`uptime`
  1104.   machine_ram=`cat /proc/meminfo | grep -m 1 "MemTotal:" | cut -d: -f2 |  sed 's/^[ \t]*//'`
  1105.   machine_video=`lspci | grep -m 1 "VGA" | cut -d: -f3 |  sed 's/^[ \t]*//'`
  1106.   machine_eth_card=`lspci | grep -m 1 "Ethernet" | cut -d: -f3 |  sed 's/^[ \t]*//'`
  1107.   machine_audio_controller=`lspci | grep -m 1 "audio" | cut -d: -f3 |  sed 's/^[ \t]*//'`
  1108.   arch_daemons=`grep "DAEMONS=" /etc/rc.conf `
  1109.   last_logins=`last | head`
  1110.   eth0info=`ifconfig eth0 | grep "inet addr:" | sed 's/inet addr/Local IP/g' | sed 's/^[ \t]*//;s/[ \t]*$//'`
  1111.   echo "ARCH LINUX - Machine Information Script ver .10"
  1112.   echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  1113.   echo "DATE: $todays_date   MACHINE NAME: $HOSTNAME  "
  1114.   echo " "
  1115.   echo "Eth0: $eth0info"
  1116.   echo "ETHERNET CARD: $machine_eth_card"
  1117.   echo "CPU INFO: Qty=$num_cpus $machine_cpuinfo"
  1118.   echo "VIDEO CARD: $machine_video"
  1119.   echo "AUDIO CONTROLLER: $machine_audio_controller"
  1120.   echo "RAM INFO: $machine_ram"
  1121.   echo " "
  1122.   echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  1123.   route
  1124.   echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  1125.   echo "DISK USAGE:"
  1126.   df -h
  1127.   echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  1128.   echo "UPTIME: $machine_uptime"
  1129.   echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  1130.   echo "$arch_daemons"
  1131.   echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  1132. }
  1133. vh() { # show basic vi help
  1134.   echo "h       Move cursor left"
  1135.   echo "l       Move cursor right"  
  1136.   echo "A       Move cursor to end of line and put in insert mode"
  1137.   echo "0       Move cursor to beginning of line"
  1138.   echo "i       Put into insert mode at current position"
  1139.   echo "a       Put into insert mode after current position"
  1140.   echo "dd          Delete line"
  1141.   echo "D       Delete text after current cursor position"
  1142.   echo "p       Paste text that was deleted"
  1143.   echo "j       Move up through history commands"
  1144.   echo "k       Move down through history commands"
  1145.   echo "u       Undo"
  1146. }
  1147. weather() { # show the weather for city $1
  1148.   declare -a WEATHERARRAY
  1149.   WEATHERARRAY=( `lynx -dump "http://www.google.com/search?hl=en&lr=&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=weather+${1}&btnG=Search" | grep -A 5 -m 1 "Weather for" | grep -v "Add to "`)
  1150.   echo ${WEATHERARRAY[@]}
  1151. }
  1152.  
  1153. ## archives
  1154. xshow() { # show content of archive but don't unpack
  1155.     if [ -f "$1" ]; then
  1156.          case "$1" in
  1157.          *.tar.bz2)     tar -jtf "$1" ;;
  1158.          *.tar.gz)      tar -ztf "$1" ;;
  1159.          *.tar)         tar -tf "$1"  ;;
  1160.          *.tgz)         tar -ztf "$1" ;;
  1161.          *.zip)         unzip -l "$1" ;;
  1162.          *.rar)         rar vb "$1"   ;;
  1163.          *)             echo "'$1' Error. Please go away" ;;
  1164.          esac
  1165.          else
  1166.          echo "'$1' is not a valid archive"
  1167.     fi
  1168. }
  1169. xtar() {
  1170.   tar cvf  "${1%%/}.tar"     "${1%%/}/"
  1171. }
  1172. xtarr() { # same as xtar but remove files/folder after creation of archive
  1173.   NAME=`echo $1 | sed -e 's|/||'`
  1174.   tar -cf $NAME.tar $NAME
  1175.        gzip $NAME.tar
  1176.   rm -R $NAME
  1177. }
  1178. xtbz() { # create .tar.bz2 archive
  1179.   tar cvjf "${1%%/}.tar.bz2" "${1%%/}/"
  1180. }
  1181. xtgz() { # create .tar.gz archive with optionally $2 being the target directory
  1182.   tar cvzf "${1%%/}.tar.gz"  "${1%%/}/"
  1183. }
  1184. xtr() { # extract
  1185.    if [ -f "$1" ] ; then
  1186.        case "$1" in
  1187.            *.tar.bz2)   mkdir "$2" 2>/dev/null ; tar xjf "$1" -C "$2" ; cd "$2" ;;
  1188.            *.tar.gz)    mkdir "$2" 2>/dev/null ; tar xzf "$1" -C "$2" ; cd "$2" ;;
  1189.            *.bz2)       mkdir "$2" 2>/dev/null ; bunzip2 "$1" -C "$2" ; cd "$2" ;;
  1190.            *.rar)       mkdir "$2" 2>/dev/null ; rar x "$1" -C "$2" ; cd "$2" ;;
  1191.            *.gz)        mkdir "$2" 2>/dev/null ; gunzip "$1" -C "$2" ; cd "$2" ;;
  1192.            *.tar)       mkdir "$2" 2>/dev/null ; tar xf "$1" -C "$2" ; cd "$2" ;;
  1193.            *.tbz2)      mkdir "$2" 2>/dev/null ; tar xjf "$1" -C "$2" ; cd "$2" ;;
  1194.            *.tgz)       mkdir "$2" 2>/dev/null ; tar xzf "$1" -C "$2" ; cd "$2" ;;
  1195.            *.zip)       mkdir "$2" 2>/dev/null ; unzip "$1" -C "$2" ; cd "$2" ;;
  1196.            *.Z)         mkdir "$2" 2>/dev/null ; uncompress "$1" -C "$2" ; cd "$2" ;;
  1197.            *.7z)        mkdir "$2" 2>/dev/null ; 7z x "$1" -C "$2" ; cd "$2" ;;
  1198.            *)           echo "Error. Please go away" ;;
  1199.        esac
  1200.    else
  1201.        echo "'$1' is not a valid file"
  1202.    fi
  1203. }
Add Comment
Please, Sign In to add comment