###################################################################################################################################################### ################################### MY BASHRC FILE ################################### MY BASHRC FILE ################################### MY BASHRC FILE ###################################################################################################################################################### ################################################## # 'About' section for 'The Ultimate Bashrc File' # ################################################## function about() { cat < # # ├── ORIGINAL CONTENT # # ├── CUSTOM STARTS HERE # # │ ├── MISCELLANEOUS # # │ ├── COMMAND PROMPT & CLI # # │ ├── BASH SETTINGS # # │ ├── COMPLETIONS # # │ ├── FUNCTIONS # # │ ├── ALIASES # # │ └── MY CUSTOM STARTS HERE (put own here) # # └── BASHRC ENDS HERE # # # # Latest Changes: # # 4.2 - 13/02/14 - Added Liquid Prompt option; # # Updates; added several aliases/functions; # # now including several of my custom aliases and # # functions, contingent on having my custom # # nautilus-/nemo- scripts # # 4.0+ - 27/11/13 - Tweaks for Ubuntu Saucy / # # Linux Mint Petra # # 4.0+ - 01/10/13 - Tweaks for Ubuntu Raring / # # Linux Mint Olivia # # 4.0+ - 12/09/12 - video_record, webcam_record # # updated tv-monitor-switch-end and # # tv-monitor-switch-start; ntm; remastersys-gtk # # # # Descripton: # # For those who love using the terminal, here is # # a '.bashrc' file I created, mainly for those # # who've had issues with their own. Hopefully # # it'll benefit those of whom love aliases, # # functions, and such. Probably more than you # # need, so modify all you want. I've organized it# # best I can to make it easier for using and # # modification. This is also for those many # # who've had a difficult time finding a good # # source for their own on the net, like it was # # for me. # # Oh, and any modifications that others wish to # # share are always welcome. # # # # Installation Instructions: # # Just extract the tar file and put in your # # home directory. You may have to overwrite the # # current one, so be sure to backup whatever # # beforehand. FYI, the default text in the # # '.bashrc' is included in this version so if # # you haven't modified it at all, you should # # have nothing to worry about. # # To refresh it, just type in the terminal: # # source ~/.bashrc # # ...or just close and open your terminal window.# # # # License: # # This program is free software; you can # # redistribute it and/or modify it under the # # terms of the GNU General Public License as # # published by the Free Software Foundation; # # either version 3 of the License, or (at your # # option) any later version. # # # # This program is distributed in the hope that it# # will be useful, but WITHOUT ANY WARRANTY; # # without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR # # PURPOSE. See the GNU General Public License # # for more details. # # # # Credits: # # Found through various sources (including # # several things by me). I credit when I can. # # Commented-out stuff is what I personally do not# # need, so use at your own risk. # # Feel free to copy, share, tweak, eat, or # # whatever. Just remember to give credit, as I # # have put a lot of work into this. Enjoy. # # # ################################################## EOF } ################################################## ################################################## ################################################## ###################################################################################################################################################### #----- ORIGINAL CONTENT ------ ORIGINAL CONTENT ------ ORIGINAL CONTENT ------ ORIGINAL CONTENT ------ ORIGINAL CONTENT ------ ORIGINAL CONTENT ------ ###################################################################################################################################################### # ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples # If not running interactively, don't do anything [ -z "$PS1" ] && return # don't put duplicate lines in the history. See bash(1) for more options # ... or force ignoredups and ignorespace HISTCONTROL=ignoredups:ignorespace # append to the history file, don't overwrite it shopt -s histappend # for setting history length see HISTSIZE and HISTFILESIZE in bash(1) HISTSIZE=1000 HISTFILESIZE=2000 # check the window size after each command and, if necessary, # update the values of LINES and COLUMNS. shopt -s checkwinsize # make less more friendly for non-text input files, see lesspipe(1) [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" # set variable identifying the chroot you work in (used in the prompt below) if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then debian_chroot=$(cat /etc/debian_chroot) fi # set a fancy prompt (non-color, unless we know we "want" color) case "$TERM" in xterm-color) color_prompt=yes;; esac # uncomment for a colored prompt, if the terminal has the capability; turned # off by default to not distract the user: the focus in a terminal window # should be on the output of commands, not on the prompt #force_color_prompt=yes if [ -n "$force_color_prompt" ]; then if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then # We have color support; assume it's compliant with Ecma-48 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such # a case would tend to support setf rather than setaf.) color_prompt=yes else color_prompt= fi fi if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' fi unset color_prompt force_color_prompt # If this is an xterm set the title to user@host:dir case "$TERM" in xterm*|rxvt*) PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" ;; *) ;; esac # enable color support of ls and also add handy aliases if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" alias ls='ls --color=auto' #alias dir='dir --color=auto' #alias vdir='vdir --color=auto' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' fi # some more ls aliases alias ll='ls -alF' alias la='ls -A' alias l='ls -CF' # Add an "alert" alias for long running commands. Use like so: # sleep 10; alert alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' # Alias definitions. # You may want to put all your additions into a separate file like # ~/.bash_aliases, instead of adding them here directly. # See /usr/share/doc/bash-doc/examples in the bash-doc package. if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi # enable programmable completion features (you don't need to enable # this, if it's already enabled in /etc/bash.bashrc and /etc/profile # sources /etc/bash.bashrc). if [ -f /etc/bash_completion ] && ! shopt -oq posix; then . /etc/bash_completion fi ###################################################################################################################################################### #----- CUSTOM STARTS HERE ------ CUSTOM STARTS HERE ------ CUSTOM STARTS HERE ------ CUSTOM STARTS HERE ------ CUSTOM STARTS HERE ------ CUSTOM STARTS HERE ###################################################################################################################################################### ###################################################################################################################################################### ###### MISCELLANEOUS ###### MISCELLANEOUS ###### MISCELLANEOUS ###### MISCELLANEOUS ###### MISCELLANEOUS ###### MISCELLANEOUS ###### MISCELLANEOUS ###### ###################################################################################################################################################### if [ "$PS1" ]; then # if running interactively, then run till 'fi' at EOF: # source ~/.bashlocalrc # settings that vary per workstation OS=$(uname) # for resolving pesky os differing switches ###################################################################################################################################################### ###### COMMAND PROMPT & CLI ###### COMMAND PROMPT & CLI ###### COMMAND PROMPT & CLI ###### COMMAND PROMPT & CLI ###### COMMAND PROMPT & CLI ###### ###################################################################################################################################################### ################################################## # Prompt escapes # ################################################## # Bash allows these prompt strings to be customized by inserting a # number of backslash-escaped special characters that are # decoded as follows: # \a an ASCII bell character (07) # \d the date in "Weekday Month Date" format (e.g., "Tue May 26") # \D{format} the format is passed to strftime(3) and the result # is inserted into the prompt string an empty format # results in a locale-specific time representation. # The braces are required # \e an ASCII escape character (033) # \h the hostname up to the first `.' # \H the hostname # \j the number of jobs currently managed by the shell # \l the basename of the shell's terminal device name # \n newline # \r carriage return # \s the name of the shell, the basename of $0 (the portion following # the final slash) # \t the current time in 24-hour HH:MM:SS format # \T the current time in 12-hour HH:MM:SS format # \@ the current time in 12-hour am/pm format # \A the current time in 24-hour HH:MM format # \u the username of the current user # \v the version of bash (e.g., 2.00) # \V the release of bash, version + patch level (e.g., 2.00.0) # \w the current working directory, with $HOME abbreviated with a tilde # \W the basename of the current working directory, with $HOME # abbreviated with a tilde # \! the history number of this command # \# the command number of this command # \$ if the effective UID is 0, a #, otherwise a $ # \nnn the character corresponding to the octal number nnn # \\ a backslash # \[ begin a sequence of non-printing characters, which could be used # to embed a terminal control sequence into the prompt # \] end a sequence of non-printing characters # # The command number and the history number are usually different: # the history number of a command is its position in the history # list, which may include commands restored from the history file # (see HISTORY below), while the command number is the position in # the sequence of commands executed during the current shell session. # After the string is decoded, it is expanded via parameter # expansion, command substitution, arithmetic expansion, and quote # removal, subject to the value of the promptvars shell option (see # the description of the shopt command under SHELL BUILTIN COMMANDS # below). ################################################## # Color chart # ################################################## txtblk='\e[0;30m' # Black - Regular txtred='\e[0;31m' # Red txtgrn='\e[0;32m' # Green txtylw='\e[0;33m' # Yellow txtblu='\e[0;34m' # Blue txtpur='\e[0;35m' # Purple txtcyn='\e[0;36m' # Cyan txtwht='\e[0;37m' # White bldblk='\e[1;30m' # Black - Bold bldred='\e[1;31m' # Red bldgrn='\e[1;32m' # Green bldylw='\e[1;33m' # Yellow bldblu='\e[1;34m' # Blue bldpur='\e[1;35m' # Purple bldcyn='\e[1;36m' # Cyan bldwht='\e[1;37m' # White unkblk='\e[4;30m' # Black - Underline undred='\e[4;31m' # Red undgrn='\e[4;32m' # Green undylw='\e[4;33m' # Yellow undblu='\e[4;34m' # Blue undpur='\e[4;35m' # Purple undcyn='\e[4;36m' # Cyan undwht='\e[4;37m' # White bakblk='\e[40m' # Black - Background bakred='\e[41m' # Red badgrn='\e[42m' # Green bakylw='\e[43m' # Yellow bakblu='\e[44m' # Blue bakpur='\e[45m' # Purple bakcyn='\e[46m' # Cyan bakwht='\e[47m' # White txtrst='\e[0m' # Text Reset ################################################## # This bashrc's current prompt # ################################################## PS1='\[\033]0;\w\007\]\[\e[35;1m\]\u\[\e[0m\]\[\e[32m\]@\h\[\e[34m\]\w \[\e[33m\]\$ \[\e[0m\]' # purple, green, blue prompt w/default black & dir title ################################################## # More command prompt choices (CHOOSE ONE, either# # one of single lines below, or one of the # # fancier ones farther below - just uncomment # # one want and comment mine above) # ################################################## # PS1='\[\033[01;31m\]\u\[\033[01;36m\]@\[\033[01;32m\]\h\[\033[01;33m\]:\[\033[01;33m\]\w\n\[\033[01;31m\]\$ \[\033[00;32m\]' # red, cyan, green, yellow with green output # PS1="\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] " # green and blue prompt with pc name & default black output # PS1="\[\033[0;31m\][\u] [ \w ] \[\033[0m\] \n # " # red with default black output (2-tier) # PS1="\[\033[0;33m\][\!]\`if [[ \$? = "0" ]]; then echo "\\[\\033[32m\\]"; else echo "\\[\\033[31m\\]"; fi\`[\u.\h: \`if [[ `pwd|wc -c|tr -d " "` > 18 ]]; then echo "\\W"; else echo "\\w"; fi\`]\$\[\033[0m\] "; echo -ne "\033]0;`hostname -s`:`pwd`\007" # yellow and green with default black output # PS1="\[\033[0;33m\][\!]\`if [[ \$? = "0" ]]; then echo "\\[\\033[32m\\]"; else echo "\\[\\033[31m\\]"; fi\`[\u.\h: \`if [[ `pwd|wc -c|tr -d " "` > 18 ]]; then echo "\\W"; else echo "\\w"; fi\`]\$\[\033[0m\] "; echo -ne "\033]0;`hostname -s`:`pwd`\007" # yellow, green, w/black output w/color change upon bad command # PS1="\[\033[0;34m\][\u] \[\033[0;0m\]\w \[\033[0m\]$ " # blue username and default black output # PS1="\[\033[0;34m\][\u] \[\033[0;31m\][ \w ] \[\033[0m\] \n >> " # blue and red with default black output (2-tier) # PS1="\[\033[0;34m\][\u] \[\033[0;33m\][ \t ] \[\033[0;31m\][ \w ] \[\033[0m\] \n >> " # blue, yellow, red with default black output (2-tier) # PS1='\[\033[1;30m\][\[\033[0;37m\]${PIPESTATUS}\[\033[1;30m\]:\[\033[0;37m\]${SHLVL}\[\033[1;30m\]:\[\033[0;37m\]\j\[\033[1;30m\]][\[\033[1;34m\]\u\[\033[0;34m\]@\[\033[1;34m\]\h\[\033[1;30m\]:\[\033[0;37m\]`tty | sed s/\\\\\/dev\\\\\/\//g`\[\033[1;30m\]]\[\033[0;37m\][\[\033[1;37m\]\W\[\033[0;37m\]]\[\033[1;30m\] \$\[\033[00m\] ' # grey and blue with default black output # PS1="[\[\033[1;34m\]\u\[\033[0m\]@\h \W]\\$ " # blue username with default colors (black) # PS1="[\!] \033[1;36m[ \u@\h ]\033[1;32m\] [ \t ] [ \d ]\n\033[1;33m\[[ \w ] \033[00m\\n\[\e[30;1m\](\[\e[32;1m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files, \$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\e[30;1m\]) \[\e[0m\] $: " # black, cyan, green, yellow, default black output (2-tier) # PS1="[\[\033[32m\]\w]\[\033[0m\]\n\[\033[1;36m\]\u\[\033[1;33m\]-> \[\033[0m\]" # black, green, cyan, yellow, w/black output w/full path (2-tier) # PS1="\[\033[34m\] \u@\h `tty | sed 's/\/dev\///'` \t \d \[\033[35m\]\w/ \n\[\033[34m\] $\[\033[0m\] " # cyan with green output # PS1="\[\033[35m\]\t\[\033[m\]-\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ " # purple, cyan, black, green, yellow, default black # PS1="\[\033[35m\]\t\[\033[m\]-\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ " # purple, cyan, black, green, yellow, w/black output # PS1="\[\033[36m\] \u@\h `tty | sed 's/\/dev\///'` \t \d \[\033[32m\]\w/ \n\[\033[36m\] $\[\033[0m\] " # blue with purple output # PS1=">\[\033[s\]\[\033[1;\$((COLUMNS-4))f\]\$(date +%H:%M)\[\033[u\]" # trimmed up prompt with clock using default colors (black) # PS1='C:${PWD//\//\\\}>' # change prompt to MS-DOS one (joke) # PS1='${debian_chroot:+($debian_chroot)}\[[ \033[01;31m\]\w\[\033[00m\]] ' # basic red with default black output # PS1='\[\e[0;31m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[0;31m\]\$ \[\e[m\]\[\e[0;32m\]' # red and blue prompt with green output # PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] \[\e[1;37m\]' # green and blue prompt with light grey output # PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\]' # green and blue prompt with default black output # PS1='\e[1;31;47m\u \e[1;32;47mon \h \e[1;35;47m\d \@\e[0;0m\n\e[1;31m[dir.= \w] \# > \e[0;0m' # red, green, purple, red with default black output # PS1='\[\e[1;31m\][\[\e[0;37m\]\u\[\e[1;31m\]@\[\e[0;37m\]\h \W\[\e[1;31m\]]\$\[\e[0m\] ' # red and grey with default black output # PS1='\[\e[1;31m\][\u@\h \W]\$\[\e[0m\] ' # red color with default black output # PS1='\[\e[1;32m\]\u@\H:\[\e[m\] \[\e[1;37m\]\w\[\e[m\]\n\[\e[1;33m\]hist:\! \[\e[0;33m\] \[\e[1;31m\]jobs:\j \$\[\e[m\] ' # green, yellow, red, grey and default black output (2-tier) # PS1='\[\e[1;32m\]\u@\H:\[\e[m\] \[\e[1;37m\]\w\[\e[m\]\n\[\e[1;33m\]hist:\! \[\e[0;33m\] \[\e[1;31m\]jobs:\j \$\[\e[m\] ' # green, yellow, red, w/black output (2-tier) w/background job count # PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] ' # green color with default black output # PS1='\e[1;33;47m\u \e[1;32;47mon \h \e[1;35;47m\d \@\e[0;0m\n\e[1;34m[dir.= \w] \# > \e[0;0m' # yellow, green, purple, cyan with default black output # PS1="\[\e[1;33m\] > \[\033[0m\]" # basic yellow with default black output & nothing else # PS1='\[\e[1m\]\h:\w\$\[\e[0m\] ' # black-bold with default colors (black) # PS1="\[\e]2;\u@\H \w\a\e[30;1m\]>\[\e[0m\] " # trimmed up prompt w/black arrow & title is current dir. # PS1="\[\e[30;1m\]\w> \[\e[0m\]" # trimmed up prompt with just black arrow and default colors # PS1="\[\e[36;1m\]\u@\[\e[32;1m\]\H> \[\e[0m\]" # cyan and green prompt with default black output # PS1="\[\e[37;1m\]-{\[\e[34;1m\]\u@\h\[\e[37;1m\]}-\n\[\e[37;1m\](\[\e[34;1m\]\w: \$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files, \$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\e[37;1m\])\n--> \[\e[0m\]" # grey and cyan w/black output (2-tier) w/dir size # PS1='\[\e[41m\]\[\e[1;37m\] \u \[\e[47m\]\[\e[1;30m\] \W \[\e[0m\]\[\e[1;37m\]\[\e[42m\] # \[\033[0m\] ' # red, grey, green boxed with default black # PS1='\[\e[45m\]\[\e[1;37m\] \u@\h \[\e[47m\]\[\e[1;30m\] \W \[\e[0m\]\[\e[1;37m\]\[\e[42m\] > \[\033[0m\] ' # purple, grey, green boxed with default black # PS1='\[\e[m\n\e[0;33m\][$$:$PPID \j:\!\[\e[0;33m\]]\[\e[0;36m\] \T \d \[\e[1;34m\][\[\e[1;34m\]\u@\H\[\e[1;31m\]:\[\e[0;37m\]${SSH_TTY} \[\e[0;32m\]+${SHLVL}\[\e[1;30m\]] \[\e[1;31m\]\w\[\e[0;30m\] \n($SHLVL:\!)\$ ' # yellow, cyan, red, blue, white, green, black, red w/ default black output # PS1="\`if [ \$? = 0 ]; then echo \[\e[33m\]^_^\[\e[0m\]; else echo \[\e[31m\]O_O\[\e[0m\]; fi\`[\u@\h:\w]\\$ " # all black with happy face (yellow/red) upon successful completion # PS1="\`if [ \$? = 0 ]; then echo \[\e[33m\]^_^\[\e[0m\]; else echo \[\e[31m\]O_O\[\e[0m\]; fi\`[\u@\h:\w]\\$ " # basic prompt but with yellow smiley # PS1="\n\[\033[32;1m\]It's \t\[\033[33;1m\] Currently browsing \[\033[1;36m\]\w \[\033[33;1m\]directory\n\[\033[34;1m\]\`if [ \$? = 0 ]; then echo \[\e[37m\]Last Command Was Successfully Executed \[\e[32m\]^_^\[\e[0m\]; else echo \[\e[37m\]Smeggin Hell !!! Last Command Was Unknown \[\e[32m\]O_O\[\e[0m\]; fi\` \n\[\033[31m\]What is thy bidding, my master? \n\n\[\033[34;1m\]" # green, yellow, grey, green, red, w/cyan output (3-tier) Star Wars version # PS1="\n\[\033[35m\]\$(/bin/date)\n\[\033[32m\]\w\n\[\033[1;31m\]\u@\h: \[\033[1;34m\]\$(/usr/bin/tty | /bin/sed -e 's:/dev/::'): \[\033[1;36m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files \[\033[1;33m\]\$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\033[0m\] -> \[\033[0m\]" - purple, green, blue, cyan, yellow, with default black output (3-tier) # PS1="\n\[\033[35m\]\$(/bin/date)\n\[\033[32m\]\w\n\[\033[1;31m\]\u@\h: \[\033[1;34m\]\$(/usr/bin/tty | /bin/sed -e 's:/dev/::'): \[\033[1;36m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files \[\033[1;33m\]\$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\033[0m\] -> \[\033[0m\]" # purple, red, blue, cyan, yellow, w/white output (3-tier) # PS1="\n\[$bldgrn\][\[$txtrst\]\w\[$bldgrn\]]\[$bldwht\]\n\[$bldwht\][\[$txtrst\]\t\[$bldwht\]]\[$bldylw\]$ \[$txtrst\]" # green, black, grey, yellow with default black output (3-tier) # PS1="\n#--[\[\e[1;36m\]\u@\h\[\e[m\]]-[\[\e[1;34m\]\w\[\e[m\]]-[\$(date +%k:%M)]-->\n" # black, cyan, blue, black, w/black output (2-tier) # PS1="\n\[\e[30;1m\]\[\016\]l\[\017\](\[\e[34;1m\]\u@\h\[\e[30;1m\])-(\[\e[34;1m\]\j\[\e[30;1m\])-(\[\e[34;1m\]\@ \d\[\e[30;1m\])->\[\e[30;1m\]\n\[\016\]m\[\017\]-(\[\[\e[32;1m\]\w\[\e[30;1m\])-(\[\e[32;1m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files, \$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\e[30;1m\])--> \[\e[0m\]" # grey, cyan, green, w/black output (2-tier) w/ dir. info # PS1="\n\[\e[30;1m\]?(\[\e[34;1m\]\u@\h\[\e[30;1m\])-(\[\e[34;1m\]\j\[\e[30;1m\])-(\[\e[34;1m\]\@ \d\[\e[30;1m\])->\[\e[30;1m\]\n??(\[\e[32;1m\]\w\[\e[30;1m\])-(\[\e[32;1m\]$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files, $(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\e[30;1m\])--> \[\e[0m\]" # black, cyan, green w/black output (2-tier) # PS1="\n\[\e[32;1m\](\[\e[37;1m\]\u\[\e[32;1m\])-(\[\e[37;1m\]jobs:\j\[\e[32;1m\])-(\[\e[37;1m\]\w\[\e[32;1m\])\n(\[\[\e[37;1m\]! \!\[\e[32;1m\])-> \[\e[0m\]" # grey and green with default black output (3-tier) # PS1="\n\[\e[m\][\[\033[01;32m\]\w\[\e[m\]] [\t] \n\[\033[01;33m\]$ \[\033[00m\]" # green, black, yellow, with default black output (3-tier) # PS1="\t \u@\h\$ " # simple prompt with time (black) # PS1="\t \u@\h `tty | sed 's/\/dev\///'` \w \$ " # longer prompt with time (black) # PS1="\u@\h\$ " # simple default prompt (black) # PS1="\u@\h `tty | sed 's/\/dev\///'` \w \$ " # longer prompt with brief info (black) # PS1='[\u@\h \W]\$ ' # default colors (black) # PS1="\u@\h [\w] \$ " # simple prompt with directory (black) # PS1="\u `tty | sed 's/\/dev\///'` [\W] \$ " # prompt with brief info (black) ################################################## # Jsnx's prompt of power (disabled by a single # # "#") # ################################################## ## I used to have the prompt set up as a bunch of functions; but that ## didn't work very well with sh. Now, I have mastered the various ## levels of evaluation and quoting of the shell and can confidently ## write hideous macros! # DARK="\[\e[01;34m\]" # NORM="\[\e[01;32m\]" # FADE="\[\e[01;30m\]" # REST="\[\e[00;00m\]" # HIGH="\[\e[01;33m\]" # dir="pwd -P | awk '{ printf \"%-65.65s\", \$1 }'" # sub="sed -r 's/^/$NORM/ ; s|/|$FADE&$NORM|g ; s/:/$DARK&$NORM/g'" # t="date +%H:%M" # hist="history 1 | xargs echo '' | awk '{ printf \"%03.3d\", \$1 + 1 }'" # warn="[ $USER = root ] && echo -n '$HIGH' || echo -n '$FADE'" # bang="echo -ne '\x21'" ## this gives me a single '!' in bash and sh # prompt=" $DARK: \`$dir | $sub\` \`$warn;$bang;\`$NORM\`$hist\` \`$t | $sub\` # $DARK:\`$warn\`; $REST" # prepend='' # if [ "${TERM}" = "xterm" ] # then # my_tty=`tty | awk -F/ '{ print $3 $4}'` # xterm_title="\[\e]0;${my_tty} \u@\H\007\]" # prepend="${xterm_title}" # fi ## export PROMPT_COMMAND="export PS1=\"${prepend}${prompt}\"" # export PS1="${prepend}${prompt}" # export PS2=' ' ################################################## # Nate Mitchell's (Kasyx's) Bash Prompt (red with# # green dashes and black output) (disabled by a # # single "#") # ################################################## # function prompt() { # Black="\e[30m" # Red="\e[31m" # Green="\e[32m" # LightGreen="\e[32;1m" # Blue="\e[34m" # LightBlue="\e[34;1m" # NC="\e[0m" # No Color # PS1="\[$LightGreen\033(0\154\033(B\][\[\033(0\161\161\033(B$Green\][\[$Red\]\u@\h\[$Green\]]\[\033(0\161\033(B\][\[$Red\]\w\[$Green\]]\[\033(0\161\033(B\][\[$Red\]\!\[$Green\]]\[\033(0\161\161\033(B\]]\n\[$LightGreen\033(0\155\161\033(B$Green\][\[$Red\]\#\[$Green\]]\[\033(0\161\033(B\][\[$Red\]\$\[$Green\]]\[\033(0\161\161\033(B\][\[$NC\]" # PS2="> " # } # prompt ################################################## # Wolfman's prompt (disabled by a single "#") # ################################################## ## Fancy PWD display function ## The home directory (HOME) is replaced with a ~ ## The last pwdmaxlen characters of the PWD are displayed ## Leading partial directory names are striped off ## /home/me/stuff -> ~/stuff if USER=me ## /usr/share/big_dir_name -> ../share/big_dir_name if pwdmaxlen=20 # function bash_prompt_command() { # # How many characters of the $PWD should be kept # local pwdmaxlen=25 # # Indicate that there has been dir truncation # local trunc_symbol=".." # local dir=${PWD##*/} # pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen )) # NEW_PWD=${PWD/#$HOME/\~} # local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen )) # if [ ${pwdoffset} -gt "0" ] # then # NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen} # NEW_PWD=${trunc_symbol}/${NEW_PWD#*/} # fi # } # function bash_prompt() { # case $TERM in # xterm*|rxvt*) # local TITLEBAR='\[\033]0;\u:${NEW_PWD}\007\]' # ;; # *) # local TITLEBAR="" # ;; # esac # local NONE="\[\033[0m\]" # unsets color to term's fg color # # regular colors # local K="\[\033[0;30m\]" # black # local R="\[\033[0;31m\]" # red # local G="\[\033[0;32m\]" # green # local Y="\[\033[0;33m\]" # yellow # local B="\[\033[0;34m\]" # blue # local M="\[\033[0;35m\]" # magenta # local C="\[\033[0;36m\]" # cyan # local W="\[\033[0;37m\]" # white # # emphasized (bolded) colors # local EMK="\[\033[1;30m\]" # local EMR="\[\033[1;31m\]" # local EMG="\[\033[1;32m\]" # local EMY="\[\033[1;33m\]" # local EMB="\[\033[1;34m\]" # local EMM="\[\033[1;35m\]" # local EMC="\[\033[1;36m\]" # local EMW="\[\033[1;37m\]" # # background colors # local BGK="\[\033[40m\]" # local BGR="\[\033[41m\]" # local BGG="\[\033[42m\]" # local BGY="\[\033[43m\]" # local BGB="\[\033[44m\]" # local BGM="\[\033[45m\]" # local BGC="\[\033[46m\]" # local BGW="\[\033[47m\]" # local UC=$W # user's color # [ $UID -eq "0" ] && UC=$R # root's color ## PS1="$TITLEBAR ${EMK}[${UC}\u${EMK}@${UC}\h ${EMB}\${NEW_PWD}${EMK}]${UC}\\$ ${NONE}" # # without colors: PS1="[\u@\h \${NEW_PWD}]\\$ " # # extra backslash in front of \$ to make bash colorize the prompt # } # PROMPT_COMMAND=bash_prompt_command # bash_prompt # unset bash_prompt ################################################## # Emmanuel Rouat's shell prompt (fancy all # # black with info) # ################################################## # if [[ "${DISPLAY%%:0*}" != "" ]]; then # HILIT=${red} # remote machine: prompt will be partly red # else # HILIT=${cyan} # local machine: prompt will be partly cyan # fi ## --> Replace instances of \W with \w in prompt functions below ## + --> to get display of full path name. # function fastprompt() # { # unset PROMPT_COMMAND # case $TERM in # *term | rxvt ) # PS1="${HILIT}[\h]$NC \W > \[\033]0;\${TERM} [\u@\h] \w\007\]" ;; # linux ) # PS1="${HILIT}[\h]$NC \W > " ;; # *) # PS1="[\h] \W > " ;; # esac # } # function _powerprompt() # { # LOAD=$(uptime|sed -e "s/.*: \([^,]*\).*/\1/" -e "s/ //g") # } # # function powerprompt() # { # PROMPT_COMMAND=_powerprompt # case $TERM in # *term | rxvt ) # PS1="${HILIT}[\A - \$LOAD]$NC\n[\u@\h \#] \W > \ # \[\033]0;\${TERM} [\u@\h] \w\007\]" ;; # linux ) # PS1="${HILIT}[\A - \$LOAD]$NC\n[\u@\h \#] \W > " ;; # * ) # PS1="[\A - \$LOAD]\n[\u@\h \#] \W > " ;; # esac # } # powerprompt # This is the default prompt -- might be slow. # # If too slow, use fastprompt instead. ... ################################################## # Xterm windowdressing (cyan and black with # # grey output info prompt( (disabled by a # # single '#') # ################################################## # function elite() # { # local GRAY="\[\033[1;30m\]" # local LIGHT_GRAY="\[\033[0;37m\]" # local CYAN="\[\033[0;36m\]" # local LIGHT_CYAN="\[\033[1;36m\]" # case $TERM in # xterm*) # local TITLEBAR='\[\033]0;\u@\h:\w\007\]' # ;; # *) # local TITLEBAR="" # ;; # esac # local GRAD1=$(tty|cut -d/ -f3) # PS1="$TITLEBAR\ # $GRAY-$CYAN-$LIGHT_CYAN(\ # $CYAN\u$GRAY@$CYAN\h\ # $LIGHT_CYAN)$CYAN-$LIGHT_CYAN(\ # $CYAN\#$GRAY/$CYAN$GRAD1\ # $LIGHT_CYAN)$CYAN-$LIGHT_CYAN(\ # $CYAN\$(date +%H%M)$GRAY/$CYAN\$(date +%d-%b-%y)\ # $LIGHT_CYAN)$CYAN-$GRAY-\ # $LIGHT_GRAY\n\ # $GRAY-$CYAN-$LIGHT_CYAN(\ # $CYAN\$$GRAY:$CYAN\w\ # $LIGHT_CYAN)$CYAN-$GRAY-$LIGHT_GRAY " # PS2="$LIGHT_CYAN-$CYAN-$GRAY-$LIGHT_GRAY " # } # PROMPT_COMMAND=elite ################################################## # Another prompt = # # (PS1="\[\e]2;\u@\H \w\a\e[30;1m\]>\[\e[0m\] # # " but fixed for various systems - simple # # prompt that shows currently directory in # # title) # ################################################## # if [ "$TERM" = "linux" ] # then # # we're on the system console or maybe telnetting in # export PS1="\[\e[32;1m\]\u@\H > \[\e[0m\]" # else # # we're not on the console, assume an xterm # export PS1="\[\e]2;\u@\H \w\a\e[32;1m\]>\[\e[0m\] " # fi ################################################## # Yet another prompt (simple black prompt with # # the word 'bash$' only) # ################################################## ## Check if running in an xterm and give a more suitable prompt ## (two alternative blocks given below) ## mesg y allows talk(1) requests, here only if not an xterm ## Gives informative prompt, puts user,host,path in xterm title ## Comment or uncomment all of the following lines ('case' to 'esac') # case $TERM in # xterm*) # PS1="\[\033]0;\u@\h: \w\007\]bash\$ " # ;; # *) # PS1="\t \u@\h `tty | sed 's/\/dev\///'`\$ " # mesg y # ;; # esac ################################################## # Still another prompt (cyan and red with # # green output info prompt) (disabled by a # # single '#') # ################################################## ### Colourful prompts ### Comment or uncomment all of the following lines ('case' to 'esac') ## case $TERM in ## xterm*) ## TERM=xterm-color; export TERM ## PS1="\[\033[36m\] \u@my_computer `tty | sed 's/\/dev\///'` \t \d \[\033[35m\]\w/ \n\[\033[36m\] $\[\033[0m\] " ## ;; ## *) # PS1="`setterm -bold on` \[\033[36m\] \u@my_computer `tty | sed 's/\/dev\///'` \t \d \[\033[1;31m\]\w/ \n\[\033[36m\]! \[\033[1;32m\] `setterm -#bold off`" # # this adds a bg color; comment out the above ## PS1="\[\033[35m\] \u@my_computer `tty | sed 's/\/dev\///'` \t \d \[\033[32m\]\w/ \n\[\033[36m\] $\[\033[44;1;36m\] `setterm -bold on` " ## mesg y ## ;; ## esac ################################################## # Liquid Prompt Command # ################################################## # requires the code for 'liquid prompt', which can # be gotten using the following commands: # note: 'acpi' is for temperature # sudo apt-get install git acpi # git clone https://github.com/nojhan/liquidprompt.git ~/.liquidprompt # cp ~/.liquidprompt/liquidpromptrc-dist ~/.config/liquidpromptrc # . ~/.liquidprompt/liquidprompt ################################################## # More PROMPT_COMMANDS # ################################################## ###### Annoying PROMPT_COMMAND animation # PROMPT_COMMAND='seq $COLUMNS | xargs -IX printf "%Xs\r" @' ###### Saves terminal commands in history file in real time (for use with 'shopt -s histappend') if [ ! -f $HOME/.bash_history ];then touch $HOME/.bash_history;fi # ensure bash history file always there PROMPT_COMMAND="history -a;$PROMPT_COMMAND" # use with 'shopt -s histappend';save terminal commands in history file in real time ###### Share history between using multiple commands (press enter before get history from other bash shells) # PROMPT_COMMAND='history -a && history -n' ###### Shows date # PROMPT_COMMAND='date +%k:%m:%S' ###### Shows memory, load average, and history # PROMPT_COMMAND='history -a;echo -en "\033[m\033[38;5;2m"$(( `sed -nu "s/MemFree:[\t ]\+\([0-9]\+\) kB/\1/p" /proc/meminfo`/1024))"\033[38;5;22m/"$((`sed -nu "s/MemTotal:[\t ]\+\([0-9]\+\) kB/\1/Ip" /proc/meminfo`/1024 ))MB"\t\033[m\033[38;5;55m$(< /proc/loadavg)\033[m"' ###### Shows the return value of the last executed command (using smileys as to whether it was successful or not) # PROMPT_COMMAND='RET=$?; if [[ $RET -eq 0 ]]; then echo -ne "\033[0;32m$RET\033[0m ;)"; else echo -ne "\033[0;31m$RET\033[0m ;("; fi; echo -n " "' ################################################## ################################################## ################################################## ###################################################################################################################################################### ###### BASH SETTINGS ###### BASH SETTINGS ###### BASH SETTINGS ###### BASH SETTINGS ###### BASH SETTINGS ###### BASH SETTINGS ###### BASH SETTINGS ###### ###################################################################################################################################################### # autoload -U compinit # use to enable famous zsh tab-completion system # compinit # use to enable famous zsh tab-completion system export BLOCKSIZE=K # set blocksize size export BROWSER='firefox' # set default browser # export BROWSER='opera' # set default browser # export BROWSER=$(find_alternatives chromium-browser google-chrome opera firefox firefox-bin iceweasel konqueror w3m lynx) # uses function 'find_alternatives' export CDDIR="$HOME" # for use with the function 'cd' and the alias 'cdd' # export CDPATH=.:~:~/src:/etc # export CDPATH=.:~:~/Dropbox # if you use dropbox from the command line often # export DISPLAY=:79 # export EDITOR='gedit' # use default text editor # export EDITOR="gedit -w --resume" Typing 'fc' # open last command for editing in gedit, then execute on save export EDITOR='vi' # use default text editor # export ftp_proxy=${MY_PROXY} # export GPG_TTY='tty' # gpg-agent says it needs this # export GREP_OPTIONS='-D skip --binary-files=without-match --ignore-case' # most commonly used grep options export HISTCONTROL=ignoreboth:erasedups # for 'ignoreboth': ignore duplicates and /^\s/ # export HISTCONTROL=ignoreboth # ignore spaced commands and prevents storing of duplicate commands (ie, ignoredups & ignorespace) # export HISTCONTROL=ignoredups # don't put duplicate lines in the history. See bash(1) for more options # export HISTCONTROL=ignorespace # will make sure that bash don’t store any command beginning with the space character # export HISTFILE=/dev/null # disable history for current shell session # export HISTFILE='$HOME/.history' # set history file location # export HISTFILESIZE=10000 # increase or decrease the size of the history to '10,000' # export HISTFILESIZE=${HISTSIZE} # bash will remember 'N' commands export HISTIGNORE='&:bg:fg:ll:h' # export HISTIGNORE=' cd "`*: PROMPT_COMMAND=?*?' # define shell variable HISTIGNORE so comments appear in shell history # export HISTIGNORE='${HISTIGNORE:+$HISTIGNORE:}la:ll:lah:lat:;a:-:fg:bg:j:sync:esu:rma:rmp:fol:pfol' # export HISTIGNORE="&:ls:[bf]g:exit" # duplicate entries in bash history, as well as ls, bg, fg & exit, making for cleaner bash history # export HISTIGNORE="&:ls:ll:la:l.:pwd:exit:clear" # export HISTIGNORE='pwd:cd:ls:ls -l:' # ignore commands given export HISTSIZE=10000 # increase or decrease the size of the history to '10,000' # export HISTTIMEFORMAT='| %d/%m/%y %T | ' # make 'History' Show The Date For Each Command # export HISTTIMEFORMAT='%F %T ' # adds date and time to history export HISTTIMEFORMAT='%H:%M > ' # export HISTTIMEFORMAT='%s' # the beloved Second of Our Linux # export HISTTIMEFORMAT='%Y-%b-%d::%Hh:%Mm:%Ss ' export HISTTIMEFORMAT='%Y-%m-%d_%H:%M:%S_%a ' # makes history display in YYYY-MM-DD_HH:MM:SS_3CharWeekdaySpaceSpace format export HOSTFILE=$HOME/.hosts # put list of remote hosts in ~/.hosts ... # export http_proxy=${MY_PROXY} # proxy setting # export https_proxy=${MY_PROXY} # proxy setting # export IGNOREEOF=1 # prevent CTRL-D from immediately logging out # export INPUTRC=/etc/inputrc # it's possible that this will make bash find my delete key (and everything else)((but i don't think it did)) # export INPUTRC=$HOME/.inputrc # type in ‘whatever’ and press ‘Page Up’ key and bash automatically fetches last command that starts with whatever and completes the command for you (requires '$HOME/.inputrc' with these lines: #Page up/page down && "\e[5~": history-search-backward && "\e[6~": history-search-forward) # export LC_COLLATE="en_CA.utf8" # change sorting methods [a-Z] instead of [A-Z] export LESSCHARSET='latin1' export LESS='-i -N -w -z-4 -g -e -M -X -F -R -P%t?f%f \' # export LESSOPEN="|lesspipe.sh %s"; export LESSOPEN export LESSOPEN='|/usr/bin/lesspipe.sh %s 2>&-' # use this if lesspipe.sh exists # export LESS="-QR" # tell less not to beep and also display colours # export LESS='-R' # export LESS_TERMCAP_mb=$'\E[01;31m' # less colors for Man pages # begin blinking # export LESS_TERMCAP_md=$'\E[01;38;5;74m' # less colors for Man pages # begin bold # export LESS_TERMCAP_me=$'\E[0m' # less colors for Man pages # end mode # export LESS_TERMCAP_se=$'\E[0m' # less colors for Man pages # end standout-mode # export LESS_TERMCAP_so=$'\E[38;5;246m' # less colors for Man pages # begin standout-mode - info box # export LESS_TERMCAP_ue=$'\E[0m' # less colors for Man pages # end underline # export LESS_TERMCAP_us=$'\E[04;38;5;146m' # less colors for Man pages # begin underline # export LIBGL_DRIVERS_PATH=/usr/lib/xorg/modules/dri # gallium # export MY_PROXY='http://YOUR_USERNAME:YOUR_PASSWORD@PROXY_IP:PROXY_PORT/' # export OOO_FORCE_DESKTOP=gnome # openoffice preferences # export OPERA_KEEP_BLOCKED_PLUGIN=1 # this is the special sauce to enhance flash (on opera's) performance # export OPERAPLUGINWRAPPER_PRIORITY=0 # this is the special sauce to enhance flash (on opera's) performance export PAGER='less -e' # export PATH=$PATH:$HOME/scripts # export PILOTRATE=57600 # make pilot-xfer go faster than 9600 export TERM='xterm' export TIMEFORMAT=$'\nreal %3R\tuser %3U\tsys %3S\tpcpu %P\n' export TMOUT=600 # auto logout after n seconds of inactivity # export USER_CLIENT=deluge # export USER_DPRT=22218 # export USER_OPRT=47426 # export USER_VPRT=79 # export USER_WPRT=30818 export VIDEO_FORMAT=NTSC # for use with creating compatible DVDs ('dvdauthor -x dvdauthor.xml' will fail if this not here) # export VIDEO_FORMAT=PAL # for use with creating compatible DVDs ('dvdauthor -x dvdauthor.xml' will fail if this not here) export VISUAL='vi' # export wpsetters=feh # ${file%\.[^.]*} # to remove filename extensions in bash # fortune -a # fortunes at each new shell # mesg n # set -b # causes output from background processes to be output right away, not on wait for next primary prompt # set bell-style visible # I hate noise # set completion-ignore-case on # complete things that have been typed in the wrong case # set -o ignoreeof # can't c-d out of shell # set -o noclobber # disallow > to work on files that already exist (prevents catting over file) set -o notify # notify when jobs running in background terminate # set -o nounset # attempt to use undefined variable outputs error message and forces exit (messes up completion if enabled) # set +o nounset # otherwise some completions will fail # setopt autopushd pushdminus pushdsilent pushdtohome # setopt correct # setopt extendedglob # setopt hist_ignore_space # prepend ' ' to not be saved # setopt hist_verify # verify when using ! # setopt nocheckjobs # don't complain about background jobs on e # setopt no_clobber # don't overwrite files when redirect # setopt nohup # don't kill bg jobs when tty quits # setopt printexitvalue # print exit value from jobs # setopt share_history # set -o xtrace # useful for debuging # setterm -blength 0 # set the bell duration in milliseconds (silence the beeps) # set visible-stats on # when listing possible file completions, put / after directory names and * after programs shopt -s cdable_vars # set the bash option so that no '$' is required (disallow write access to terminal) shopt -s cdspell # this will correct minor spelling errors in a cd command shopt -s checkhash shopt -s checkwinsize # update windows size on command shopt -s cmdhist # save multi-line commands in history as single line # shopt -s dotglob # files beginning with . to be returned in the results of path-name expansion # shopt -s expand aliases # expand aliases shopt -s extglob # necessary for bash completion (programmable completion) # shopt -s globstar # enables the ** globbing operator # shopt -s histappend # bash history is only saved when close terminal, not after each command and this fixes it shopt -s histappend histreedit histverify # shopt -s histreedit # shopt -s histverify # shopt -s hostcomplete # attempt hostname expansion when @ is at the beginning of a word # shopt -s huponexit shopt -s mailwarn # keep an eye on the mail file (access time) # shopt -s nocaseglob cdspell histappend shopt -s nocaseglob # pathname expansion will be treated as case-insensitive (auto-corrects the case) shopt -s no_empty_cmd_completion # no empty completion (bash>=2.04 only) # shopt -s nullglob dotglob shopt -s sourcepath # shopt -u cmdhist # do not treat multiple line commands as a single entry # shopt -u force_fignore # expand to complete an ignored word, if no other words match. # shopt -u mailwarn # shopt -u sourcepath # stty -ixon # disable XON/XOFF flow control (^s/^q) stty start undef stty stop undef # stty stop '' # use C-s to search forward through history (do not block output) # ulimit -c unlimited # let me have core dumps ulimit -S -c 0 # (core file size) don't want any coredumps # ulimit -S -f 1024 # open files # ulimit -S -s 8192 # stack size # ulimit -S -u 256 # max user processes # umask 007 # all files created 660, dirs 770 # umask 022 # makes new files have permissions: rwxr-xr-x # umask 077 # after everything is installed, uncomment this and the mkdir alias below ((base 8) 777 & ~077 = 700 = u=rwx,g=,o=) # unset HISTFILESIZE # infinite History # unset HISTSIZE # infinite History unset MAILCHECK # don't want my shell to warn me of incoming mail # unsetopt bgnice # don't nice bg command if [ -d $HOME/Maildir/ ]; then export MAIL=$HOME/Maildir/ export MAILPATH=$HOME/Maildir/ export MAILDIR=$HOME/Maildir/ elif [ -f /var/mail/$USER ]; then export MAIL="/var/mail/$USER" fi if [ "$TERM" = "screen" ]; then export TERM=$TERMINAL fi # if [ "$OS" = "Linux" ]; then # source ~/.lscolorsrc # elif [ "$OS" = "Darwin" ]; then # export LSCOLORS='gxfxcxdxbxegedabagacad' # fi function get_xserver() { case $TERM in xterm ) XSERVER=$(who am i | awk '{print $NF}' | tr -d ')''(' ) # Ane-Pieter Wieringa suggests the following alternative: # I_AM=$(who am i) # SERVER=${I_AM#*(} # SERVER=${SERVER%*)} XSERVER=${XSERVER%%:*} ;; aterm | rxvt) # Find some code that works here. ... ;; esac } if [ -z ${DISPLAY:=""} ]; then get_xserver if [[ -z ${XSERVER} || ${XSERVER} == $(hostname) || \ ${XSERVER} == "unix" ]]; then DISPLAY=":0.0" # Display on local host. else DISPLAY=${XSERVER}:0.0 # Display on remote host. fi fi export DISPLAY # if [ -f ~/.bash_exports ]; then . ~/.bash_exports ; fi # if [ -f ~/.bash_functions ]; then . ~/.bash_functions ; fi # if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases ; fi # if [ -f ~/.bash_completion ]; then . ~/.bash_completion ; fi # if [ -f /etc/bash_completion ]; then . /etc/bash_completion ; complete -cf sudo; fi ################################################## # Alternative To The "200 Lines Kernel Patch That# # Does Wonders" - not needed if have Linux kernel# # 2.6.37 and higher # ################################################## ###### FOR DISTROS THAT USE '/cgroup/cpu' & '/etc/init.d/rc.local' (REDHAT/CENTOS?) # Run sudo gedit /etc/init.d/rc.local & add following lines above "exit 0": # mkdir -p /cgroup/cpu # mount -t cgroup cgroup /cgroup/cpu -o cpu # mkdir -m 0777 /cgroup/cpu/user # echo "/usr/local/sbin/cgroup_clean" > /cgroup/cpu/release_agent # Now, make it executable: # sudo chmod +x /etc/init.d/rc.local # To make sure that cgroups are deleted whenever the last task # leaves, run sudo gedit /usr/local/sbin/cgroup_clean and copy-paste this: # #!/bin/sh # if [ "$*" != "/user" ]; then # rmdir /cgroup/cpu/$* # fi # Now, make it executable: # sudo chmod +x /usr/local/sbin/cgroup_clean # Ensure the below ~/.bashrc section is uncommented # Restart your computer to apply the changes. # # # # BEFORE YOU UNCOMMENT THE BELOW, MAKE SURE YOU'VE DONE THE ABOVE # if [ "$PS1" ] ; then # mkdir -p -m 0700 /cgroup/cpu/user/$$ > /dev/null 2>&1 # echo $$ > /cgroup/cpu/user/$$/tasks # echo "1" > /cgroup/cpu/user/$$/notify_on_release # fi ###### FOR DISTROS THAT USE '/sys/fs/cgroup/cpu' & '/etc/init.d/rc.local' # Run sudo gedit /etc/init.d/rc.local & add following lines above "exit 0": # mkdir -p /sys/fs/cgroup/cpu # mount -t cgroup cgroup /sys/fs/cgroup/cpu -o cpu # mkdir -m 0777 /sys/fs/cgroup/cpu/user # echo "/usr/local/sbin/cgroup_clean" > /sys/fs/cgroup/cpu/release_agent # Now, make it executable: # sudo chmod +x /etc/init.d/rc.local # To make sure that cgroups are deleted whenever the last task # leaves, run sudo gedit /usr/local/sbin/cgroup_clean and copy-paste this: # #!/bin/sh # if [ "$*" != "/user" ]; then # rmdir /sys/fs/cgroup/cpu/$* # fi # Now, make it executable: # sudo chmod +x /usr/local/sbin/cgroup_clean # Ensure the below ~/.bashrc section is uncommented # Restart your computer to apply the changes. # # # # BEFORE YOU UNCOMMENT THE BELOW, MAKE SURE YOU'VE DONE THE ABOVE # if [ "$PS1" ] ; then # mkdir -p -m 0700 /sys/fs/cgroup/cpu/user/$$ > /dev/null 2>&1 # echo $$ > /sys/fs/cgroup/cpu/user/$$/tasks # echo "1" > /sys/fs/cgroup/cpu/user/$$/notify_on_release # fi ###### FOR UBUNTU (AND OTHER DISTROS THAT USE '/dev/cgroup/cpu' & '/etc/rc.local') # Run sudo gedit /etc/rc.local & add following lines above "exit 0": # mkdir -p /dev/cgroup/cpu # mount -t cgroup cgroup /dev/cgroup/cpu -o cpu # mkdir -m 0777 /dev/cgroup/cpu/user # echo "/usr/local/sbin/cgroup_clean" > /dev/cgroup/cpu/release_agent # Now, make it executable: # sudo chmod +x /etc/rc.local # To make sure that cgroups are deleted whenever the last task # leaves, run sudo gedit /usr/local/sbin/cgroup_clean and copy-paste this: # #!/bin/sh # if [ "$*" != "/user" ]; then # rmdir /dev/cgroup/cpu/$* # fi # Now, make it executable: # sudo chmod +x /usr/local/sbin/cgroup_clean # Ensure the below ~/.bashrc section is uncommented # Restart your computer to apply the changes. # # # # BEFORE YOU UNCOMMENT THE BELOW, MAKE SURE YOU'VE DONE THE ABOVE # if [ "$PS1" ] ; then # mkdir -p -m 0700 /dev/cgroup/cpu/user/$$ > /dev/null 2>&1 # echo $$ > /dev/cgroup/cpu/user/$$/tasks # echo "1" > /dev/cgroup/cpu/user/$$/notify_on_release # fi ################################################## # PATH # ################################################## if [ "$UID" -eq 0 ]; then PATH=$PATH:/usr/local:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games fi # remove duplicate path entries export PATH=$(echo $PATH | awk -F: ' { for (i = 1; i <= NF; i++) arr[$i]; } END { for (i in arr) printf "%s:" , i; printf "\n"; } ') # autocomplete ssh commands complete -W "$(echo `cat ~/.bash_history | egrep '^ssh ' | sort | uniq | sed 's/^ssh //'`;)" ssh ################################################## # 'TIME' stuff... # ################################################## ###### Time redis ping in thousands of a second # TIME=$( { time redis-cli PING; } 2>&1 ) ; echo $TIME | awk '{print $3}' | sed 's/0m//; s/\.//; s/s//; s/^0.[^[1-9]*//g;' ###### redirect bash built-in output to stdout # TIME=$( { time YOUR_COMMAND_HERE; } 2>&1 ) ; echo $TIME ################################################## # Startup programs # ################################################## # if [ "$USE_SCREEN" = "Y" ]; then # if [ "$UID" -ne 0 ]; then # if [ "$SHLVL" -eq 1 ]; then # /usr/bin/screen -d -RR # fi # fi # fi # if [ -e "/usr/games/fortune" ]; then # echo "Fortune: " # /usr/games/fortune # echo # fi # if [ -e "/usr/bin/uptime" ]; then # echo "Uptime: ` /usr/bin/uptime`" # fi # echo # ~/bin/rc_sync.sh # $HOME/bin/motd.pl ################################################## # Various options to make $HOME comfy # ################################################## # if [ ! -d "${HOME}/bin" ]; then # mkdir ${HOME}/bin # chmod 700 ${HOME}/bin # echo "${HOME}/bin was missing. I created it for you." # fi # if [ ! -d "${HOME}/Documents" ]; then # if ! [ -d "${HOME}/data" ]; then # mkdir ${HOME}/data # chmod 700 ${HOME}/data # echo "${HOME}/data was missing. I created it for you." # fi # fi # if [ ! -d "${HOME}/tmp" ]; then # mkdir ${HOME}/tmp # chmod 700 ${HOME}/tmp # echo "${HOME}/tmp was missing. I created it for you." # fi ################################################## # Automatically clean up all temporary files in # # $HOME directory # ################################################## # find "$HOME" -type f \( -name "*~" -or -name ".*~" -or -name "*.old" -or -name "*.bak" -or -name "*.OLD" -or -name "*.BAK" \)|xargs -I{} bash -c "rm -rf \"{}\"" ################################################## # Stop Flash from tracking everything you do. # ################################################## ###### Brute force way to block all LSO cookies on Linux system with non-free Flash browser plugin # for A in ~/.adobe ~/.macromedia ; do ( [ -d $A ] && rm -rf $A ; ln -s -f /dev/null $A ) ; done for A in ~/.macromedia ; do ( [ -d $A ] && rm -rf $A ; ln -s -f /dev/null $A ) ; done ################################################## # Bashrc greetings # ################################################## ###### greeting # # from Jonathan's .bashrc file (by ~71KR117) # # get current hour (24 clock format i.e. 0-23) # hour=$(date +"%H") # # if it is midnight to midafternoon will say G'morning # if [ $hour -ge 0 -a $hour -lt 12 ] # then # greet="Good Morning, $USER. Welcome back." # # if it is midafternoon to evening ( before 6 pm) will say G'noon # elif [ $hour -ge 12 -a $hour -lt 18 ] # then # greet="Good Afternoon, $USER. Welcome back." # else # it is good evening till midnight # greet="Good Evening, $USER. Welcome back." # fi # # display greeting # echo $greet ###### holiday greeting # # from Jonathan's .bashrc file (by ~71KR117) # # get current day (Month-Day Format) # day=$(date +"%B%e") # # get current year (for new years greeting) # year=$(date +"%Y") # # make sure the holiday greeting is displayed (if any) # hol=1 # # if it is New Year's Day # if [ "$day" = "January1" ] # then # holgreet="Happy New Years. Have a Happy $year." # # if it is Groundhog Day # elif [ "$day" = "February2" ] # then # holgreet="Have a Happy Groundhog Day." # # if it is Valentine's Day # elif [ "$day" = "February14" ] # then # holgreet="Have a Happy Valentine's Day." # # if it is Independance Day # elif [ "$day" = "July4" ] # then # holgreet="Have a Happy Forth of July." # # if it is my birthday # elif [ "$day" = "July19" ] # then # holgreet="Have a Happy Birthday." # # if it is Halloween # elif [ "$day" = "October31" ] # then # holgreet="Happy Halloween." # # if it is Christmas Eve # elif [ "$day" = "December24" ] # then # holgreet="Merry Christmas Eve." # # if it is Christmas # elif [ "$day" = "December25" ] # then # holgreet="Merry Christmas." # # if it is New Year's Eve # elif [ "$day" = "December31" ] # then # holgreet="Happy New Year's Eve." # else # hol=0 # fi # # display holiday greeting # if [ "$hol" = "1" ] # then # echo $holgreet # elif [ "$hol" = "0" ] # then # randomvarthatsomehowimportant=0 # fi ################################################## ################################################## ################################################## ###################################################################################################################################################### ###### COMPLETIONS ###### COMPLETIONS ###### COMPLETIONS ###### COMPLETIONS ###### COMPLETIONS ###### COMPLETIONS ###### COMPLETIONS ###### COMPLETIONS ###################################################################################################################################################### ################################################## # 'Universal' completion function # ################################################## ###### it works when commands have a so-called 'long options' mode # ie: 'ls --all' instead of 'ls -a' # Needs the '-o' option of grep # (try the commented-out version if not available). # First, remove '=' from completion word separators # (this will allow completions like 'ls --color=auto' to work correctly). COMP_WORDBREAKS=${COMP_WORDBREAKS/=/} ################################################## # To enable tab-completion with sudo # ################################################## ###### alternatively, install bash-completion, which does this too # complete -cf sudo ################################################## # Completion functions (only since Bash-2.04) # ################################################## ###### avoid tilde expansion from the bash_completion script function _expand() { [ "$cur" != "${cur%\\}" ] && cur="$cur\\"; if [[ "$cur" == \~*/* ]]; then #eval cur=$cur; :; else if [[ "$cur" == \~* ]]; then cur=${cur#\~}; COMPREPLY=($( compgen -P '~' -u $cur )); return ${#COMPREPLY[@]}; fi; fi } function _get_longopts() { # $1 --help | sed -e '/--/!d' -e 's/.*--\([^[:space:].,]*\).*/--\1/'| \ # grep ^"$2" |sort -u ; $1 --help | grep -o -e "--[^[:space:].,]*" | grep -e "$2" |sort -u } function _killall() { local cur prev COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} # get a list of processes (the first sed evaluation # takes care of swapped out processes, the second # takes care of getting the basename of the process) COMPREPLY=( $( /usr/bin/ps -u $USER -o comm | \ sed -e '1,1d' -e 's#[]\[]##g' -e 's#^.*/##'| \ awk '{if ($0 ~ /^'$cur'/) print $0}' )) return 0 } complete -F _killall killall killps function _longopts() { local cur cur=${COMP_WORDS[COMP_CWORD]} case "${cur:-*}" in -*) ;; *) return ;; esac case "$1" in \~*) eval cmd="$1" ;; *) cmd="$1" ;; esac COMPREPLY=( $(_get_longopts ${1} ${cur} ) ) } complete -o default -F _longopts configure bash complete -o default -F _longopts wget id info a2ps ls recode function _make() { local mdef makef makef_dir="." makef_inc gcmd cur prev i; COMPREPLY=(); cur=${COMP_WORDS[COMP_CWORD]}; prev=${COMP_WORDS[COMP_CWORD-1]}; case "$prev" in -*f) COMPREPLY=($(compgen -f $cur )); return 0 ;; esac; case "$cur" in -*) COMPREPLY=($(_get_longopts $1 $cur )); return 0 ;; esac; # make reads `GNUmakefile', then `makefile', then `Makefile' if [ -f ${makef_dir}/GNUmakefile ]; then makef=${makef_dir}/GNUmakefile elif [ -f ${makef_dir}/makefile ]; then makef=${makef_dir}/makefile elif [ -f ${makef_dir}/Makefile ]; then makef=${makef_dir}/Makefile else makef=${makef_dir}/*.mk # Local convention. fi # Before we scan for targets, see if a Makefile name was # specified with -f ... for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do if [[ ${COMP_WORDS[i]} == -f ]]; then # eval for tilde expansion eval makef=${COMP_WORDS[i+1]} break fi done [ ! -f $makef ] && return 0 # deal with included Makefiles makef_inc=$( grep -E '^-?include' $makef | \ sed -e "s,^.* ,"$makef_dir"/," ) for file in $makef_inc; do [ -f $file ] && makef="$makef $file" done # If we have a partial word to complete, restrict completions to # matches of that word. if [ -n "$cur" ]; then gcmd='grep "^$cur"' ; else gcmd=cat ; fi COMPREPLY=( $( awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ \ {split($1,A,/ /);for(i in A)print A[i]}' \ $makef 2>/dev/null | eval $gcmd )) } complete -F _make -X '+($*|*.[cho])' make gmake pmake\ ###### A meta-command completion function for commands like sudo(8), which need to # first complete on a command, then complete according to that command's own # completion definition - currently not quite foolproof, # but still quite useful (By Ian McDonald, modified by me). function _meta_comp() { local cur func cline cspec COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} cmdline=${COMP_WORDS[@]} if [ $COMP_CWORD = 1 ]; then COMPREPLY=( $( compgen -c $cur ) ) else cmd=${COMP_WORDS[1]} # Find command. cspec=$( complete -p ${cmd} ) # Find spec of that command. # COMP_CWORD and COMP_WORDS() are not read-only, # so we can set them before handing off to regular # completion routine: # Get current command line minus initial command, cline="${COMP_LINE#$1 }" # split current command line tokens into array, COMP_WORDS=( $cline ) # set current token number to 1 less than now. COMP_CWORD=$(( $COMP_CWORD - 1 )) # If current arg is empty, add it to COMP_WORDS array # (otherwise that information will be lost). if [ -z $cur ]; then COMP_WORDS[COMP_CWORD]="" ; fi if [ "${cspec%%-F *}" != "${cspec}" ]; then # if -F then get function: func=${cspec#*-F } func=${func%% *} eval $func $cline # Evaluate it. else func=$( echo $cspec | sed -e 's/^complete//' -e 's/[^ ]*$//' ) COMPREPLY=( $( eval compgen $func $cur ) ) fi fi } complete -o default -F _meta_comp nohup \ eval exec trace truss strace sotruss gdb complete -o default -F _meta_comp command type which man nice time function _tar() { local cur ext regex tar untar COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} # If we want an option, return the possible long options. case "$cur" in -*) COMPREPLY=( $(_get_longopts $1 $cur ) ); return 0;; esac if [ $COMP_CWORD -eq 1 ]; then COMPREPLY=( $( compgen -W 'c t x u r d A' -- $cur ) ) return 0 fi case "${COMP_WORDS[1]}" in ?(-)c*f) COMPREPLY=( $( compgen -f $cur ) ) return 0 ;; +([^Izjy])f) ext='tar' regex=$ext ;; *z*f) ext='tar.gz' regex='t\(ar\.\)\(gz\|Z\)' ;; *[Ijy]*f) ext='t?(ar.)bz?(2)' regex='t\(ar\.\)bz2\?' ;; *) COMPREPLY=( $( compgen -f $cur ) ) return 0 ;; esac if [[ "$COMP_LINE" == tar*.$ext' '* ]]; then # Complete on files in tar file. # # Get name of tar file from command line. tar=$( echo "$COMP_LINE" | \ sed -e 's|^.* \([^ ]*'$regex'\) .*$|\1|' ) # Devise how to untar and list it. untar=t${COMP_WORDS[1]//[^Izjyf]/} COMPREPLY=( $( compgen -W "$( echo $( tar $untar $tar \ 2>/dev/null ) )" -- "$cur" ) ) return 0 else # File completion on relevant files. COMPREPLY=( $( compgen -G $cur\*.$ext ) ) fi return 0 } complete -F _tar -o default tar ################################################## ################################################## ################################################## ###################################################################################################################################################### ###### FUNCTIONS ###### FUNCTIONS ###### FUNCTIONS ###### FUNCTIONS ###### FUNCTIONS ###### FUNCTIONS ###### FUNCTIONS ###### FUNCTIONS ###### FUNCTIONS ###################################################################################################################################################### ################################################## # Download all images from a 4chan thread # ################################################## function 4chanimages() { curl -s http://boards.4chan.org/wg/|sed -r 's/.*href="([^"]*).*/\1\n/g'|grep images|xargs wget } ################################################## # Add a function you've defined to .bashrc # ################################################## function addfunction() { declare -f $1 >> ~/.bashrc ; } ################################################## # OpenPGP/GPG pubkeys stuff (for Launchpad / etc.# ################################################## ###### add keys alias addkey='sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys' ###### autograb missing keys alias autokey='sudo apt-get update 2> /tmp/keymissing; for key in $(grep "NO_PUBKEY" /tmp/keymissing |sed "s/.*NO_PUBKEY //"); do echo -e "\nProcessing key: $key"; gpg --keyserver pool.sks-keyservers.net --recv $key && gpg --export --armor $key | sudo apt-key add -; done' ###### create mykeys for use on Launchpad / etc. alias createmykeys='gpg --gen-key' ###### show single repo key info using keyid found in 'sudo apt-key list' alias exportkey='sudo apt-key export' ###### exports all repo keys info into single 'repokeys.txt' document alias exportkeys='sudo apt-key exportall > repokeys.txt' ###### to export public OpenPGP keys to a file for safe keeping and potential restoration alias exportmykeys='exportmykeys_private && exportmykeys_public' ###### to export private OpenPGP keys to a file for safe keeping and potential restoration # using 'mykeys', put the appropriate GPG key after you type this function function exportmykeys_private() { gpg --list-secret-keys echo -n "Please enter the appropriate private key... Look for the line that starts something like "sec 1024D/". The part after the 1024D is the key_id. ...like this: '2942FE31'... " read MYKEYPRIV gpg -ao Private_Keys-private.key --export-secret-keys "$MYKEYPRIV" echo -n "All done." } ###### to export public OpenPGP keys to a file for safe keeping and potential restoration # using 'mykeys', put the appropriate GPG key after you type this function function exportmykeys_public() { gpg --list-keys echo -n "Please enter the appropriate public key... Look for line that starts something like "pub 1024D/". The part after the 1024D is the public key_id. ...like this: '2942FE31'... " read MYKEYPUB gpg -ao Public_Keys-public.key --export "$MYKEYPUB" echo -n "All done." } ###### to get the new key fingerprint for use in the appropriate section on Launchpad.net to start verification process alias fingerprintmykeys='gpg --fingerprint' ###### to automatically get all pubkeys (Launchpad PPA ones and others) # requires: sudo apt-get install launchpad-getkeys alias getkeys='sudo launchpad-getkeys' ###### to get a list of your public and private OpenPGP/GPG pubkeys alias mykeys='gpg --list-keys && gpg --list-secret-keys' ###### publish newly-created mykeys for use on Launchpad / etc. alias publishmykeys='gpg --keyserver hkp://keyserver.ubuntu.com --send-keys' ###### to restore your public and private OpenPGP keys # from Public_Key-public.key and Private_Keys-private.key files: function restoremykeys() { echo -n "Please enter the full path to Public keys (spaces are fine)... Example: '/home/(your username)/Public_Key-public.key'... " read MYKEYS_PUBLIC_LOCATION gpg --import "$MYKEYS_PUBLIC_LOCATION" echo -n "Please enter the full path to Private keys (spaces are fine)... Example: '/home/(your username)/Private_Keys-private.key'... " read MYKEYS_PRIVATE_LOCATION gpg --import "$MYKEYS_PRIVATE_LOCATION" echo -n "All done." } ###### to setup new public and private OpenPGP keys function setupmykeys() { # Generate new key gpg --gen-key # Publish new key to Ubuntu keyserver gpg --keyserver hkp://keyserver.ubuntu.com --send-keys # Import an OpenPGP key gpg --fingerprint # Verify new key read -sn 1 -p "Before you continue, you must enter the fingerprint in the appropriate place in your Launchpad PPA on their website... Once you have successfully inputed it, wait for your email before you press any key to continue... " gedit $HOME/file.txt read -sn 1 -p "Once you have received your email from Launchpad to verify your new key, copy and paste the email message received upon import of OpenPGP key from "-----BEGIN PGP MESSAGE-----" till "-----END PGP MESSAGE-----" to the 'file.txt' in your home folder that was just opened for you Once you have successfully copied and pasted it, save it and press any key to continue... " gpg -d $HOME/file.txt echo -n "All done." } ###### shows list of repository keys alias showkeys='sudo apt-key list' ################################################## # Text alignment # ################################################## ###### center text in console with simple pipe like function align_center() { l="$(cat -)"; s=$(echo -e "$l"| wc -L); echo "$l" | while read l;do j=$(((s-${#l})/2));echo "$(while ((--j>0)); do printf " ";done;)$l";done;} #; ls --color=none / | center ###### right-align text in console using pipe like ( command | right ) function align_right() { l="$(cat -)"; [ -n "$1" ] && s=$1 || s=$(echo -e "$l"| wc -L); echo "$l" | while read l;do j=$(((s-${#l})));echo "$(while ((j-->0)); do printf " ";done;)$l";done;} #; ls --color=none / | right 150 ################################################## # Network information and IP address stuff # ################################################## ###### get all IPs via ifconfig function allips() { ifconfig | awk '/inet / {sub(/addr:/, "", $2); print $2}' } ###### clear iptables rules safely function clearIptables() { iptables -P INPUT ACCEPT; iptables -P FORWARD ACCEPT; iptables -P OUTPUT ACCEPT; iptables -F; iptables -X; iptables -L } ###### online check function connected() { ping -c1 -w2 google.com > /dev/null 2>&1; } function connected_() { rm -f /tmp/connect; http_proxy='http://a.b.c.d:8080' wget -q -O /tmp/connect http://www.google.com; if [[ -s /tmp/connect ]]; then return 0; else return 1; fi; } ###### check if a remote port is up using dnstools.com # (i.e. from behind a firewall/proxy) function cpo() { [[ $# -lt 2 ]] && echo 'need IP and port' && return 2; [[ `wget -q "http://dnstools.com/?count=3&checkp=on&portNum=$2&target=$1&submit=Go\!" -O - |grep -ic "Connected successfully to port $2"` -gt 0 ]] && echo OPEN || echo CLOSED; } ###### find an unused unprivileged TCP port function findtcp() { (netstat -atn | awk '{printf "%s\n%s\n", $4, $4}' | grep -oE '[0-9]*$'; seq 32768 61000) | sort -n | uniq -u | head -n 1 } ###### geoip lookup (need geoip database: sudo apt-get install geoip-bin) function geoip() { geoiplookup $1 } ###### geoip information # requires 'html2text': sudo apt-get install html2text function geoiplookup() { curl -A "Mozilla/5.0" -s "http://www.geody.com/geoip.php?ip=$1" | grep "^IP.*$1" | html2text; } ###### get IP address of a given interface # Example: getip lo # Example: getip eth0 # this is the default function getip() { lynx -dump http://whatismyip.org/; } ###### display private IP function ippriv() { ifconfig eth0|grep "inet adr"|awk '{print $2}'|awk -F ':' '{print $2}' } ###### ifconfig connection check function ips() { if [ "$OS" = "Linux" ]; then for i in $( /sbin/ifconfig | grep ^e | awk '{print $1}' | sed 's/://' ); do echo -n "$i: "; /sbin/ifconfig $i | perl -nle'/dr:(\S+)/ && print $1'; done elif [ "$OS" = "Darwin" ]; then for i in $( /sbin/ifconfig | grep ^e | awk '{print $1}' | sed 's/://' ); do echo -n "$i: "; /sbin/ifconfig $i | perl -nle'/inet (\S+)/ && print $1'; done fi } ###### geolocate a given IP address function ip2loc() { wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; } function ip2locall() { # best if used through a proxy, as ip2loc's free usage only lets you search a maximum of 20 times per day # currently set on using a proxy through tor; if don't want that, just comment out the two 'export..' and 'unset...' lines export http_proxy='http://localhost:8118' export https_proxy='http://localhost:8118' echo "" echo "Country:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "Region (State, Province, Etc.):" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "City:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "Latitude:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "Longitude:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "ZIP Code:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "Time Zone:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "Net Speed:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "ISP:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "Domain:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "IDD Code:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "Area Code:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "Weather Station:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "MCC:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "MNC:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "Mobile Brand:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" unset http_proxy unset https_proxy } function ip2locate() { # best if used through a proxy, as ip2loc's free usage only lets you search a maximum of 20 times per day # currently set on using a proxy through tor; if don't want that, just comment out the two 'export..' and 'unset...' lines export http_proxy='http://localhost:8118' export https_proxy='http://localhost:8118' echo "" echo "Country:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "Region (State, Province, Etc.):" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "City:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "Latitude:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" echo "Longitude:" wget -qO - www.ip2location.com/$1 | grep "" | sed 's/<[^>]*>//g; s/^[\t]*//; s/"/"/g; s//>/g; s/&/\&/g'; echo "" unset http_proxy unset https_proxy } ###### find the IP addresses that are currently online in your network function localIps() { for i in {1..254}; do x=`ping -c1 -w1 192.168.1.$i | grep "%" | cut -d"," -f3 | cut -d"%" -f1 | tr '\n' ' ' | sed 's/ //g'` if [ "$x" == "0" ]; then echo "192.168.1.$i" fi done } ###### myip - finds your current IP if your connected to the internet function myip() { lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | awk '{ print $4 }' | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g' } ###### netinfo - shows network information for your system function netinfo() { echo "--------------- Network Information ---------------" /sbin/ifconfig | awk /'inet addr/ {print $2}' /sbin/ifconfig | awk /'Bcast/ {print $3}' /sbin/ifconfig | awk /'inet addr/ {print $4}' /sbin/ifconfig | awk /'HWaddr/ {print $4,$5}' myip=`lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g' ` echo "${myip}" echo "---------------------------------------------------" } ###### check whether or not a port on your box is open function portcheck() { for i in $@;do curl -s "deluge-torrent.org/test-port.php?port=$i" | sed '/^$/d;s/

/ /g';done; } ###### scp sending function scpsend() { scp -P PORTNUMBERHERE "$@" USERNAME@YOURWEBSITE.com:/var/www/html/pathtodirectoryonremoteserver/; } ###### show ip # copyright 2007 - 2010 Christopher Bratusek function show_ip() { case $1 in *help | "" ) echo -e "\n${ewhite}Usage:\n" echo -e "${eorange}show_ip${ewhite} |${egreen} ${eiceblue}[show ip-address for ]\ \n${eorange}show_ip${ewhite} |${egreen} external${eiceblue} [show external ip address]\n" tput sgr0 ;; *external ) wget -q -O - http://showip.spamt.net/ ;; * ) LANG=C /sbin/ifconfig $1 | grep 'inet addr:' | cut -d: -f2 | gawk '{ print $1}' ;; esac } ###### display the ttl of a hostname in a human readable form function ttl() { /usr/sbin/timetrans -count $(dig +noquestion +noadditional +noauthority $1 | grep "^$1" | awk '{print $2}') } ###### show Url information # Usage: url-info "ur" # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. # Modified by Silviu Silaghi (http://docs.opensourcesolutions.ro) to handle # more ip adresses on the domains on which this is available (eg google.com or yahoo.com) # Last updated on Sep/06/2010 function url-info() { doms=$@ if [ $# -eq 0 ]; then echo -e "No domain given\nTry $0 domain.com domain2.org anyotherdomain.net" fi for i in $doms; do _ip=$(host $i|grep 'has address'|awk {'print $4'}) if [ "$_ip" == "" ]; then echo -e "\nERROR: $i DNS error or not a valid domain\n" continue fi ip=`echo ${_ip[*]}|tr " " "|"` echo -e "\nInformation for domain: $i [ $ip ]\nQuerying individual IPs" for j in ${_ip[*]}; do echo -e "\n$j results:" whois $j |egrep -w 'OrgName:|City:|Country:|OriginAS:|NetRange:' done done } ###### cleanly list available wireless networks (using iwlist) function wscan() { iwlist wlan0 scan | sed -ne 's#^[[:space:]]*\(Quality=\|Encryption key:\|ESSID:\)#\1#p' -e 's#^[[:space:]]*\(Mode:.*\)$#\1\n#p' } ################################################## # Show all strings (ASCII & Unicode) in a file # ################################################## function allStrings() { cat "$1" | tr -d "\0" | strings ; } ################################################## # Find all videos under current directory using # # MIME a.k.a not using extension # ################################################## function allVideos() { find ./ -type f -print0 | xargs -0 file -iNf - | grep ": video/" | cut -d: -f1 ; } ################################################## # Miscellaneous Fun # ################################################## ###### anagrams function anagrams() { cat > "/tmp/anagrams.py" <<"End-of-message" #!/usr/bin/python infile = open ("/usr/share/dict/words", "r") ## "dict" is a reserved word words_in = infile.readlines() scrambled = raw_input("Enter the scrambled word: ") scrambled = scrambled.lower() scrambled_list = list(scrambled) scrambled_list.sort() for word in words_in: word_list = list(word.strip().lower()) word_list.sort() ## you don't really have to compare lengths when using lists as the ## extra compare takes about as long as finding the first difference if word_list == scrambled_list: print word, scrambled End-of-message chmod +x "/tmp/anagrams.py" "/tmp/anagrams.py" "$1" rm "/tmp/anagrams.py" } function anagram_() { function s() { sed 's/[[:space:]]*//g;s/./\n\0/g'<<<"$@"|tr A-Z a-z|sort;};cmp -s <(s $1) <(s $2)||echo -n "not ";echo anagram; } ###### random Cyanide and Happiness comics from explosm.net function cyanide() { display "$(wget -q http://explosm.net/comics/random/ -O - | grep -Po 'http://www.explosm.net/db/files/Comics/*/[^"]+(png|jpg|jpeg)')"; } ###### fake error string function error() { while true; do awk '{ print ; system("let R=$RANDOM%10; sleep $R") }' compiler.log; done } ###### stupid funny face function funny_face() { _ret=$?; if test $_ret -ne 0; then echo "0_0->ret=$_ret"; set ?=$_ret; unset _ret; else echo "^_^"; fi } ###### pretend to be busy in office to enjoy a cup of coffee function grepcolor() { cat /dev/urandom | hexdump -C | grep --color=auto "ca fe" } ###### a simple number guessing game function hilow() { biggest=1000 # maximum number possible guess=0 # guessed by player guesses=0 # number of guesses made number=$(( $$ % $biggest )) # random number, 1 .. $biggest while [ $guess -ne $number ] ; do echo -n "Guess? " ; read guess if [ "$guess" -lt $number ] ; then echo "... bigger!" elif [ "$guess" -gt $number ] ; then echo "... smaller!" fi guesses=$(( $guesses + 1 )) done echo "Right!! Guessed $number in $guesses guesses." } ###### watch the National debt clock function natdebt() { watch -n 10 "wget -q http://www.brillig.com/debt_clock -O - | grep debtiv.gif | sed -e 's/.*ALT=\"//' -e 's/\".*//' -e 's/ //g'" } function oneliners() { w3m -dump_source http://www.onelinerz.net/random-one-liners/1/ | awk ' /.*
][^>]*>/, "", $0); print $0}' } ###### random cowsay stuff function random_cow() { files=(/usr/share/cowsay/cows/*) printf "%s\n" "${files[RANDOM % ${#files}]}" } ################################################## # Temporarily add to PATH # ################################################## function apath() { if [ $# -lt 1 ] || [ $# -gt 2 ]; then echo "Temporarily add to PATH" echo "usage: apath [dir]" else PATH=$1:$PATH fi } ################################################## # Function you want after you've overwritten some# # important file using > instead of >> ^^ # ################################################## function append() { lastarg="${!#}" echo "${@:1:$(($#-1))}" >> "$lastarg" } ################################################## # Common commands piped through grep # ################################################## function aptg() # debian specific. { if [ $# -lt 1 ] || [ $# -gt 1 ]; then echo "search debian package list" echo "usage: aptg [program/keyword]" else apt-cache search $1 | sort | less fi } ###### grep by paragraph instead of by line function grepp() { [ $# -eq 1 ] && perl -00ne "print if /$1/i" || perl -00ne "print if /$1/i" < "$2";} function hgg() { if [ $# -lt 1 ] || [ $# -gt 1 ]; then echo "search bash history" echo "usage: mg [search pattern]" else history | grep -i $1 | grep -v hg fi } function lsofg() { if [ $# -lt 1 ] || [ $# -gt 1 ]; then echo "grep lsof" echo "usage: losfg [port/program/whatever]" else lsof | grep -i $1 | less fi } function psg() { if [ $# -lt 1 ] || [ $# -gt 1 ]; then echo "grep running processes" echo "usage: psg [process]" else ps aux | grep USER | grep -v grep ps aux | grep -i $1 | grep -v grep fi } ################################################## # Sudo stuff # ################################################## ###### Apt-get via sudo # An apt-get wrapper function which will run the command via sudo, but will run it normally if you're only downloading source files. # function apt-get() { [ "$1" = source ] && (command apt-get "$@";true) || sudo apt-get "$@" } # function sudo() # { # command="$@" # if [ -z "$command" ]; then # command sudo -s # else # command sudo "$@" # fi # } ###### Wrap sudo to handle aliases and functions # (enabled means all 'sudo' in this file need # to be removed) (disabled for now by adding # a single '#') # function sudo() # { # local c o t parse ## Parse sudo args # OPTIND=1 # while getopts xVhlLvkKsHPSb:p:c:a:u: t; do # if [ "$t" = x ]; then # parse=true # else # o="$o -$t" # [ "$OPTARG" ] && o="$o $OPTARG" # fi # done # shift $(( $OPTIND - 1 )) ## If no arguments are left, it's a simple call to sudo # if [ $# -ge 1 ]; then # c="$1"; # shift; # case $(type -t "$c") in # "") # echo No such command "$c" # return 127 # ;; # alias) # c="$(type "$c"|sed "s/^.* to \`//;s/.$//")" # ;; # function) # c=$(type "$c"|sed 1d)";\"$c\"" # ;; # *) # c="\"$c\"" # ;; # esac # if [ -n "$parse" ]; then ## Quote the rest once, so it gets processed by bash. ## Done this way so variables can get expanded. # while [ -n "$1" ]; do # c="$c \"$1\"" # shift # done # else ## Otherwise, quote the arguments. The echo gets an extra ## space to prevent echo from parsing arguments like -n ## Note the lovely interactions between " and ' ;-) # while [ -n "$1" ]; do # c="$c '$(echo " $1"|sed -e "s/^ //" -e "s/'/'\"'\"'/")'" # shift # done # fi ## Run the command with verbose options ## echo Executing sudo $o -- bash -x -v -c "$c" >&2 # command sudo $o bash -xvc "$c" # else ## echo sudo $o >&2 # command sudo $o # fi # } ###### Sudo for entire line (including pipes and redirects) # USAGE: $ sudor your command # This command uses a dirty hack with history, so be sure you not turned it off. # WARNING!: This command behavior differ from other commands. It more like text macro, so you shouldn't use it in subshells, non-interactive sessions, other # functions/aliases and so on. You shouldn't pipe into sudor (any string that prefixes sudor will be removed), but if you really want, use this commands: function proceed_sudo() { sudor_command="`HISTTIMEFORMAT=\"\" history 1 | sed -r -e 's/^.*?sudor//' -e 's/\"/\\\"/g'`" ; sudo sh -c "$sudor_command"; }; alias sudor="proceed_sudo # " ################################################## # To show Apt Log History # ################################################## function apt-history() { case "$1" in install) cat /var/log/dpkg.log | grep 'install ' ;; upgrade|remove) cat /var/log/dpkg.log | grep $1 ;; rollback) cat /var/log/dpkg.log | grep upgrade | \ grep "$2" -A10000000 | \ grep "$3" -B10000000 | \ awk '{print $4"="$5}' ;; *) cat /var/log/dpkg.log ;; esac } ################################################## # Undo apt-get build-dep (remove build # # dependencies) # ################################################## function aptitude-remove-dep() { sudo aptitude markauto $(apt-cache showsrc "$1" | grep Build-Depends | perl -p -e 's/(?:[\[(].+?[\])]|Build-Depends:|,|\|)//g'); } ################################################## # Arch-wiki-docs simple search # ################################################## function archwikisearch() { # old version # cd /usr/share/doc/arch-wiki/html/ # grep -i "$1" index.html | sed 's/.*HREF=.\(.*\.html\).*/\1/g' | xargs opera -newpage cd /usr/share/doc/arch-wiki/html/ for i in $(grep -li $1 *) do STRING=`grep -m1 -o 'wgTitle = "[[:print:]]\+"' $i` LEN=${#STRING} let LEN=LEN-12 STRING=${STRING:11:LEN} LOCATION="/usr/share/doc/arch-wiki/html/$i" echo -e " \E[33m$STRING \E[37m$LOCATION" done } ################################################## # Numerical conversions and numbers stuff # ################################################## ###### convert arabic to roman numerals # Copyright 2007 - 2010 Christopher Bratusek function arabic2roman() { echo $1 | sed -e 's/1...$/M&/;s/2...$/MM&/;s/3...$/MMM&/;s/4...$/MMMM&/ s/6..$/DC&/;s/7..$/DCC&/;s/8..$/DCCC&/;s/9..$/CM&/ s/1..$/C&/;s/2..$/CC&/;s/3..$/CCC&/;s/4..$/CD&/;s/5..$/D&/ s/6.$/LX&/;s/7.$/LXX&/;s/8.$/LXXX&/;s/9.$/XC&/ s/1.$/X&/;s/2.$/XX&/;s/3.$/XXX&/;s/4.$/XL&/;s/5.$/L&/ s/1$/I/;s/2$/II/;s/3$/III/;s/4$/IV/;s/5$/V/ s/6$/VI/;s/7$/VII/;s/8$/VIII/;s/9$/IX/ s/[0-9]//g' } ###### convert ascii # copyright 2007 - 2010 Christopher Bratusek function asc2all() { if [[ $1 ]]; then echo "ascii $1 = binary $(asc2bin $1)" echo "ascii $1 = octal $(asc2oct $1)" echo "ascii $1 = decimal $(asc2dec $1)" echo "ascii $1 = hexadecimal $(asc2hex $1)" echo "ascii $1 = base32 $(asc2b32 $1)" echo "ascii $1 = base64 $(asc2b64 $1)" fi } function asc2bin() { if [[ $1 ]]; then echo "obase=2 ; $(asc2dec $1)" | bc fi } function asc2b64() { if [[ $1 ]]; then echo "obase=64 ; $(asc2dec $1)" | bc fi } function asc2b32() { if [[ $1 ]]; then echo "obase=32 ; $(asc2dec $1)" | bc fi } function asc2dec() { if [[ $1 ]]; then printf '%d\n' "'$1'" fi } function asc2hex() { if [[ $1 ]]; then echo "obase=16 ; $(asc2dec $1)" | bc fi } function asc2oct() { if [[ $1 ]]; then echo "obase=8 ; $(asc2dec $1)" | bc fi } ###### Averaging columns of numbers # Computes a columns average in a file. Input parameters = column number and optional pattern. function avg() { awk "/$2/{sum += \$$1; lc += 1;} END {printf \"Average over %d lines: %f\n\", lc, sum/lc}"; } ###### convert binaries # copyright 2007 - 2010 Christopher Bratusek function bin2all() { if [[ $1 ]]; then echo "binary $1 = octal $(bin2oct $1)" echo "binary $1 = decimal $(bin2dec $1)" echo "binary $1 = hexadecimal $(bin2hex $1)" echo "binary $1 = base32 $(bin2b32 $1)" echo "binary $1 = base64 $(bin2b64 $1)" echo "binary $1 = ascii $(bin2asc $1)" fi } function bin2asc() { if [[ $1 ]]; then echo -e "\0$(printf %o $((2#$1)))" fi } function bin2b64() { if [[ $1 ]]; then echo "obase=64 ; ibase=2 ; $1" | bc fi } function bin2b32() { if [[ $1 ]]; then echo "obase=32 ; ibase=2 ; $1 " | bc fi } function bin2dec() { if [[ $1 ]]; then echo $((2#$1)) fi } function bin2hex() { if [[ $1 ]]; then echo "obase=16 ; ibase=2 ; $1" | bc fi } function bin2oct() { if [[ $1 ]]; then echo "obase=8 ; ibase=2 ; $1" | bc fi } ###### simple calculator to 4 decimals function calc() { echo "scale=4; $1" | bc } ###### temperature conversion # Copyright 2007 - 2010 Christopher Bratusek function cel2fah() { if [[ $1 ]]; then echo "scale=2; $1 * 1.8 + 32" | bc fi } function cel2kel() { if [[ $1 ]]; then echo "scale=2; $1 + 237.15" | bc fi } function fah2cel() { if [[ $1 ]]; then echo "scale=2 ; ( $1 - 32 ) / 1.8" | bc fi } function fah2kel() { if [[ $1 ]]; then echo "scale=2; ( $1 + 459.67 ) / 1.8 " | bc fi } function kel2cel() { if [[ $1 ]]; then echo "scale=2; $1 - 273.15" | bc fi } function kel2fah() { if [[ $1 ]]; then echo "scale=2; $1 * 1.8 - 459,67" | bc fi } ###### Output an ASCII character given its decimal equivalent function chr() { printf \\$(($1/64*100+$1%64/8*10+$1%8)); } ###### the notorious "hailstone" or Collatz series. function collatz() { # get the integer "seed" from the command-line to generate the integer "result" # if NUMBER is even, divide by 2, or if odd, multiply by 3 and add 1 # the theory is that every sequence eventually settles down to repeating "4,2,1..." cycles MAX_ITERATIONS=200 # For large seed numbers (>32000), try increasing MAX_ITERATIONS. h=${1:-$$} # Seed. # Use $PID as seed, #+ if not specified as command-line arg. echo echo "C($h) --- $MAX_ITERATIONS Iterations" echo for ((i=1; i<=MAX_ITERATIONS; i++)) do COLWIDTH=%7d printf $COLWIDTH $h let "remainder = h % 2" if [ "$remainder" -eq 0 ] # Even? then let "h /= 2" # Divide by 2. else let "h = h*3 + 1" # Multiply by 3 and add 1. fi COLUMNS=10 # Output 10 values per line. let "line_break = i % $COLUMNS" if [ "$line_break" -eq 0 ] then echo fi done echo } ###### temperature conversion script that lets the user enter # a temperature in any of Fahrenheit, Celsius or Kelvin and receive the # equivalent temperature in the other two units as the output. # usage: convertatemp F100 (if don't put F,C, or K, default is F) function convertatemp() { if uname | grep 'SunOS'>/dev/null ; then echo "Yep, SunOS, let\'s fix this baby" PATH="/usr/xpg4/bin:$PATH" fi if [ $# -eq 0 ] ; then cat << EOF >&2 Usage: $0 temperature[F|C|K] where the suffix: F indicates input is in Fahrenheit (default) C indicates input is in Celsius K indicates input is in Kelvin EOF fi unit="$(echo $1|sed -e 's/[-[[:digit:]]*//g' | tr '[:lower:]' '[:upper:]' )" temp="$(echo $1|sed -e 's/[^-[[:digit:]]*//g')" case ${unit:=F} in F ) # Fahrenheit to Celsius formula: Tc = (F -32 ) / 1.8 farn="$temp" cels="$(echo "scale=2;($farn - 32) / 1.8" | bc)" kelv="$(echo "scale=2;$cels + 273.15" | bc)" ;; C ) # Celsius to Fahrenheit formula: Tf = (9/5)*Tc+32 cels=$temp kelv="$(echo "scale=2;$cels + 273.15" | bc)" farn="$(echo "scale=2;((9/5) * $cels) + 32" | bc)" ;; K ) # Celsius = Kelvin + 273.15, then use Cels -> Fahr formula kelv=$temp cels="$(echo "scale=2; $kelv - 273.15" | bc)" farn="$(echo "scale=2; ((9/5) * $cels) + 32" | bc)" esac echo "Fahrenheit = $farn" echo "Celsius = $cels" echo "Kelvin = $kelv" } ###### convert hexadecimal numbers to decimals function dec() { printf "%d\n" $1; } ###### convert decimals to hexadecimal numbers function hex() { printf "0x%08x\n" $1; } ###### convert decimals # copyright 2007 - 2010 Christopher Bratusek function dec2all() { if [[ $1 ]]; then echo "decimal $1 = binary $(dec2bin $1)" echo "decimal $1 = octal $(dec2oct $1)" echo "decimal $1 = hexadecimal $(dec2hex $1)" echo "decimal $1 = base32 $(dec2b32 $1)" echo "decimal $1 = base64 $(dec2b64 $1)" echo "deciaml $1 = ascii $(dec2asc $1)" fi } function dec2asc() { if [[ $1 ]]; then echo -e "\0$(printf %o 97)" fi } function dec2bin() { if [[ $1 ]]; then echo "obase=2 ; $1" | bc fi } function dec2b64() { if [[ $1 ]]; then echo "obase=64 ; $1" | bc fi } function dec2b32() { if [[ $1 ]]; then echo "obase=32 ; $1" | bc fi } function dec2hex() { if [[ $1 ]]; then echo "obase=16 ; $1" | bc fi } function dec2oct() { if [[ $1 ]]; then echo "obase=8 ; $1" | bc fi } ###### number --- convert decimal integer to english words # total number # Usage: dec2text 1234 -> one thousand two hundred thirty-four # Author: Noah Friedman function dec2text() { prog=`echo "$0" | sed -e 's/[^\/]*\///g'` garbage=`echo "$*" | sed -e 's/[0-9,.]//g'` if test ".$garbage" != "."; then echo "$prog: Invalid character in argument." 1>&2 fi case "$*" in # This doesn't always seem to work. # *[!0-9,.]* ) echo "$prog: Invalid character in argument." 1>&2; ;; *.* ) echo "$prog: fractions not supported (yet)." 1>&2; ;; '' ) echo "Usage: $prog [decimal integer]" 1>&2; ;; esac result= eval set - "`echo ${1+\"$@\"} | sed -n -e ' s/[, ]//g s/^00*/0/g s/\(.\)\(.\)\(.\)$/\"\1 \2 \3\"/ :l /[0-9][0-9][0-9]/{ s/\([^\" ][^\" ]*\)\([^\" ]\)\([^\" ]\)\([^\" ]\)/\1\"\2 \3 \4\"/g t l } /^[0-9][0-9][0-9]/s/\([^\" ]\)\([^\" ]\)\([^\" ]\)/\"\1 \2 \3\"/ /^[0-9][0-9]/s/\([^\" ]\)\([^\" ]\)/\"\1 \2\"/ /^[0-9]/s/^\([^\" ][^\" ]*\)/\"\1\"/g;s/\"\"/\" \"/g p'`" while test $# -ne 0 ; do eval `set - $1; d3='' d2='' d1='' case $# in 1 ) d1=$1 ;; 2 ) d2=$1 d1=$2 ;; 3 ) d3=$1 d2=$2 d1=$3 ;; esac echo "d3=\"$d3\" d2=\"$d2\" d1=\"$d1\""` val1='' val2='' val3='' case "$d3" in 1 ) val3=one ;; 6 ) val3=six ;; 2 ) val3=two ;; 7 ) val3=seven ;; 3 ) val3=three ;; 8 ) val3=eight ;; 4 ) val3=four ;; 9 ) val3=nine ;; 5 ) val3=five ;; esac case "$d2" in 1 ) val2=teen ;; 6 ) val2=sixty ;; 2 ) val2=twenty ;; 7 ) val2=seventy ;; 3 ) val2=thirty ;; 8 ) val2=eighty ;; 4 ) val2=forty ;; 9 ) val2=ninety ;; 5 ) val2=fifty ;; esac case "$val2" in teen ) val2= case "$d1" in 0 ) val1=ten ;; 5 ) val1=fifteen ;; 1 ) val1=eleven ;; 6 ) val1=sixteen ;; 2 ) val1=twelve ;; 7 ) val1=seventeen ;; 3 ) val1=thirteen ;; 8 ) val1=eighteen ;; 4 ) val1=fourteen ;; 9 ) val1=nineteen ;; esac ;; 0 ) : ;; * ) test ".$val2" != '.' -a ".$d1" != '.0' \ && val2="${val2}-" case "$d1" in 0 ) val2="$val2 " ;; 5 ) val1=five ;; 1 ) val1=one ;; 6 ) val1=six ;; 2 ) val1=two ;; 7 ) val1=seven ;; 3 ) val1=three ;; 8 ) val1=eight ;; 4 ) val1=four ;; 9 ) val1=nine ;; esac ;; esac test ".$val3" != '.' && result="$result$val3 hundred " test ".$val2" != '.' && result="$result$val2" test ".$val1" != '.' && result="$result$val1 " if test ".$d1$d2$d3" != '.000' ; then case $# in 0 | 1 ) ;; 2 ) result="${result}thousand " ;; 3 ) result="${result}million " ;; 4 ) result="${result}billion " ;; 5 ) result="${result}trillion " ;; 6 ) result="${result}quadrillion " ;; 7 ) result="${result}quintillion " ;; 8 ) result="${result}sextillion " ;; 9 ) result="${result}septillion " ;; 10 ) result="${result}octillion " ;; 11 ) result="${result}nonillion " ;; 12 ) result="${result}decillion " ;; 13 ) result="${result}undecillion " ;; 14 ) result="${result}duodecillion " ;; 15 ) result="${result}tredecillion " ;; 16 ) result="${result}quattuordecillion " ;; 17 ) result="${result}quindecillion " ;; 18 ) result="${result}sexdecillion " ;; 19 ) result="${result}septendecillion " ;; 20 ) result="${result}octodecillion " ;; 21 ) result="${result}novemdecillion " ;; 22 ) result="${result}vigintillion " ;; * ) echo "Error: number too large (66 digits max)." 1>&2; ;; esac fi shift done set $result > /dev/null case "$*" in '') set zero ;; esac echo ${1+"$@"} # number ends here } # individual numbers # Usage: dec2text 1234 -> one two three four function dec2text_() { # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. n=$1 len=$(echo $n | wc -c) len=$(( $len - 1 )) for (( i=1; i<=$len; i++ )) do # get one digit at a time digit=$(echo $n | cut -c $i) # use case control structure to find digit equivalent in words case $digit in 0) echo -n "zero " ;; 1) echo -n "one " ;; 2) echo -n "two " ;; 3) echo -n "three " ;; 4) echo -n "four " ;; 5) echo -n "five " ;; 6) echo -n "six " ;; 7) echo -n "seven " ;; 8) echo -n "eight " ;; 9) echo -n "nine " ;; esac done # just print new line echo "" } function d2u() { # copyright 2007 - 2010 Christopher Bratusek if [[ -e "$1" ]]; then sed -r 's/\r$//' -i "$1" fi } function u2d() { # copyright 2007 - 2010 Christopher Bratusek if [[ -e "$1" ]]; then sed -r 's/$/\r/' -i "$1" fi } ###### factorial for integers function factorial() { echo "Enter an integer: " read n # Below we define the factorial function in bc syntax fact="define f (x) { i=x fact=1 while (i > 1) { fact=fact*i i=i-1 } return fact }" # Below we pass the function defined above, and call it with n as a parameter and pipe it to bc factorial=`echo "$fact;f($n)" | bc -l` echo "$n! = $factorial" } ###### convert hexadecimal numbers # copyright 2007 - 2010 Christopher Bratusek function hex2all() { if [[ $1 ]]; then echo "hexadecimal $1 = binary $(hex2bin $1)" echo "hexadecimal $1 = octal $(hex2oct $1)" echo "hexadecimal $1 = decimal $(hex2dec $1)" echo "hexadecimal $1 = base32 $(hex2b32 $1)" echo "hexadecimal $1 = base64 $(hex2b64 $1)" echo "hexadecimal $1 = ascii $(hex2asc $1)" fi } function hex2asc() { if [[ $1 ]]; then echo -e "\0$(printf %o $((16#$1)))" fi } function hex2bin() { if [[ $1 ]]; then echo "obase=2 ; ibase=16 ; $1" | bc fi } function hex2b64() { if [[ $1 ]]; then echo "obase=64 ; ibase=16 ; $1" | bc fi } function hex2b32() { if [[ $1 ]]; then echo "obase=32 ; ibase=16 ; $1" | bc fi } function hex2dec() { if [[ $1 ]]; then echo $((16#$1)) fi } function hex2oct() { if [[ $1 ]]; then echo "obase=8 ; ibase=16 ; $1" | bc fi } ###### length function length() { if [ $# -lt 1 ]; then echo "count # of chars in arugment" echo "usage: length [string]" else echo -n $@ | wc -c fi } ###### finding logs for numbers function math-log() { echo "Enter value: " read x echo "Natural Log: ln($x) :" echo "l($x)" | bc -l echo "Ten Base Log: log($x) :" echo "l($x)/l(10)" | bc -l } ###### magic square generator (odd-order squares only!) function msquare() { # Author: mendel cooper EVEN=2 MAXSIZE=31 # 31 rows x 31 cols. E_usage=90 # Invocation error. dimension= declare -i square function usage_message() { echo "Usage: $0 square-size" echo " ... where \"square-size\" is an ODD integer" echo " in the range 3 - 31." # Works for squares up to order 159 } function calculate() # Here's where the actual work gets done. { local row col index dimadj j k cell_val=1 dimension=$1 let "dimadj = $dimension * 3"; let "dimadj /= 2" # x 1.5, then truncate. for ((j=0; j < dimension; j++)) do for ((k=0; k < dimension; k++)) do # Calculate indices, then convert to 1-dim. array index. # Bash doesn't support multidimensional arrays. Pity. let "col = $k - $j + $dimadj"; let "col %= $dimension" let "row = $j * 2 - $k + $dimension"; let "row %= $dimension" let "index = $row*($dimension) + $col" square[$index]=cell_val; ((cell_val++)) done done } # Plain math, no visualization required. function print_square() # Output square, one row at a time. { local row col idx d1 let "d1 = $dimension - 1" # Adjust for zero-indexed array. for row in $(seq 0 $d1) do for col in $(seq 0 $d1) do let "idx = $row * $dimension + $col" printf "%3d " "${square[idx]}"; echo -n " " done # Displays up to 13-order neatly in 80-column term window. echo # Newline after each row. done } if [[ -z "$1" ]] || [[ "$1" -gt $MAXSIZE ]] then usage_message fi let "test_even = $1 % $EVEN" if [ $test_even -eq 0 ] then # Can't handle even-order squares. usage_message fi calculate $1 print_square # echo "${square[@]}" # DEBUG } ###### print multiplication tables function multitables() { for i in {1..9}; do for j in `seq 1 $i`; do echo -ne "${j}x${i}=$((j*i))\t"; done; echo; done } ###### given a number, show it with comma separated values function nicenumber() { # expects DD and TD to be instantiated. instantiates nicenum # or, if a second arg is specified, the output is echoed to stdout function nice_number() { # Note that we use the '.' as the decimal separator for parsing # the INPUT value to this script. The output value is as specified # by the user with the -d flag, if different from a '.' integer=$(echo $1 | cut -d. -f1) # left of the decimal decimal=$(echo $1 | cut -d. -f2) # right of the decimal if [ $decimal != $1 ]; then # there's a fractional part, let's include it. result="${DD:="."}$decimal" fi thousands=$integer while [ $thousands -gt 999 ]; do remainder=$(($thousands % 1000)) # three least significant digits while [ ${#remainder} -lt 3 ] ; do # force leading zeroes as needed remainder="0$remainder" done thousands=$(($thousands / 1000)) # to left of remainder, if any result="${TD:=","}${remainder}${result}" # builds right-to-left done nicenum="${thousands}${result}" if [ ! -z $2 ] ; then echo $nicenum fi } DD="." # decimal point delimiter, between integer & fractional value TD="," # thousands delimiter, separates every three digits while getopts "d:t:" opt; do case $opt in d ) DD="$OPTARG" ;; t ) TD="$OPTARG" ;; esac done shift $(($OPTIND - 1)) if [ $# -eq 0 ] ; then cat << "EOF" >&2 Usage: $(basename $0) [-d c] [-t c] numeric value -d specifies the decimal point delimiter (default '.') -t specifies the thousands delimiter (default ',') EOF fi nice_number $1 1 # second arg forces this to 'echo' output } ###### convert normal to unix function normal2unix() { echo "${@}" | awk '{print mktime($0)}'; } ###### convert unix to normal function unix2normal() { echo $1 | awk '{print strftime("%Y-%m-%d %H:%M:%S",$1)}'; } ###### list of numbers with equal width function nseq() { seq -w 0 "$1" } ###### convert octals # copyright 2007 - 2010 Christopher Bratusek function oct2all() { if [[ $1 ]]; then echo "octal $1 = binary $(oct2bin $1)" echo "octal $1 = decimal $(oct2dec $1)" echo "octal $1 = hexadecimal $(oct2hex $1)" echo "octal $1 = base32 $(oct2b32 $1)" echo "octal $1 = base64 $(oct2b64 $1)" echo "octal $1 = ascii $(oct2asc $1)" fi } function oct2asc() { if [[ $1 ]]; then echo -e "\0$(printf %o $((8#$1)))" fi } function oct2bin() { if [[ $1 ]]; then echo "obase=2 ; ibase=8 ; $1" | bc fi } function oct2b64() { if [[ $1 ]]; then echo "obase=64 ; ibase=8 ; $1" | bc fi } function oct2b32() { if [[ $1 ]]; then echo "obase=32 ; ibase=8 ; $1" | bc fi } function oct2dec() { if [[ $1 ]]; then echo $((8#$1)) fi } function oct2hex() { if [[ $1 ]]; then echo "obase=16 ; ibase=8 ; $1" | bc fi } ###### Pascal's triangle function pascal() { l=15;for((i=0;i<$l;i++));do eval "a$i=($(pv=1;v=1;for((j=0;j<$l-$i;j++));do [ $i -eq 0 -o $j -eq 0 ]&&{ v=1 && pv=1; }||v=$((pv+a$((i-1))[$((j))]));echo -n "$v ";pv=$v;done;));";o="$(eval echo "$(for((k=0;k<=$i;k++)); do eval "echo -n \"\$((a\$((i-k))[k])) \""; done)")";echo "$o";s="${#o}"; done; } | while read l; do j=$((s-${#l}/2)); echo "$(while ((i++ < j)); do echo -n " ";done;)$l";done ###### convert phone numbers to letters/potentially english words # Creator: asmoore82 function phone2text() { echo -n "Enter number: " read num # Create a list of possibilites for expansion by the shell # the "\}" is an ugly hack to get "}" into the replacment string - # this is not a clean escape sequence - the litteral "\" is left behind! num="${num//2/{a,b,c\}}" num="${num//3/{d,e,f\}}" num="${num//4/{g,h,i\}}" num="${num//5/{j,k,l\}}" num="${num//6/{m,n,o\}}" num="${num//7/{p,q,r,s\}}" num="${num//8/{t,u,v\}}" num="${num//9/{w,x,y,z\}}" # cleaup from the hack - remove all litteral \'s num="${num//\\/}" echo "" echo "Possible words are:" for word in $( eval echo "$num" ) do echo '>' "$word" done # End of File } ###### powers of numerals # copyright 2007 - 2010 Christopher Bratusek function power() { if [[ $1 ]]; then if [[ $2 ]]; then echo "$1 ^ $2" | bc else echo "$1 ^ 2" | bc fi fi } ###### generate prime numbers, without using arrays. # script contributed by Stephane Chazelas. function primes() { LIMIT=1000 # Primes, 2 ... 1000. Primes() { (( n = $1 + 1 )) # Bump to next integer. shift # Next parameter in list. # echo "_n=$n i=$i_" if (( n == LIMIT )) then echo $* return fi for i; do # "i" set to "@", previous values of $n. # echo "-n=$n i=$i-" (( i * i > n )) && break # Optimization. (( n % i )) && continue # Sift out non-primes using modulo operator. Primes $n $@ # Recursion inside loop. return done Primes $n $@ $n # Recursion outside loop. # Successively accumulate #+ positional parameters. # "$@" is the accumulating list of primes. } Primes 1 } ###### radicals of numbers # copyright 2007 - 2010 Christopher Bratusek function radical() { if [[ $1 ]]; then echo "sqrt($1)" | bc -l fi } ###### convert to roman numerals function roman-numeral() { python -c 'while True: print (lambda y,x=[],nums={ 1000:"M",900:"CM",500:"D",400:"CD",100:"C",90:"XC", 50:"L",40:"XL",10:"X",9:"IX",5:"V",4:"IV",1:"I"}: (lambda ro=(lambda : map(lambda g,r=lambda b:x.append( y[-1]/b),t=lambda v:y.append(y[-1]%v):map(eval,["r(g)","t(g)"]),sorted(nums.keys())[::-1]))():"".join( map(lambda fg: map(lambda ht: nums[ht],sorted(nums.keys())[::-1])[fg] * x[fg],range(len(x)))))())([int( raw_input("Please enter a number between 1 and 4000: "))])' } ###### round numerals to whole numbers # copyright 2007 - 2010 Christopher Bratusek function round() { if [[ $1 ]]; then if [[ $2 ]]; then echo "$(printf %.${2}f $1)" else echo "$(printf %.0f $1)" fi fi } ###### ruler that stretches across the terminal function ruler() { for s in '....^....|' '1234567890'; do w=${#s}; str=$( for (( i=1; $i<=$(( ($COLUMNS + $w) / $w )) ; i=$i+1 )); do echo -n $s; done ); str=$(echo $str | cut -c -$COLUMNS) ; echo $str; done; } ###### convert seconds to minutes, hours, days, and etc. # inputs a number of seconds, outputs a string like "2 minutes, 1 second" # $1: number of seconds function sec2all() { local millennia=$((0)) local centuries=$((0)) local years=$((0)) local days=$((0)) local hour=$((0)) local mins=$((0)) local secs=$1 local text="" # convert seconds to days, hours, etc millennia=$((secs / 31536000000)) secs=$((secs % 31536000000)) centuries=$((secs / 3153600000)) secs=$((secs % 3153600000)) years=$((secs / 31536000)) secs=$((secs % 31536000)) days=$((secs / 86400)) secs=$((secs % 86400)) hour=$((secs / 3600)) secs=$((secs % 3600)) mins=$((secs / 60)) secs=$((secs % 60)) # build full string from unit strings text="$text$(seconds-convert-part $millennia "millennia")" text="$text$(seconds-convert-part $centuries "century")" text="$text$(seconds-convert-part $years "year")" text="$text$(seconds-convert-part $days "day")" text="$text$(seconds-convert-part $hour "hour")" text="$text$(seconds-convert-part $mins "minute")" text="$text$(seconds-convert-part $secs "second")" # trim leading and trailing whitespace text=${text## } text=${text%% } # special case for zero seconds if [ "$text" == "" ]; then text="0 seconds" fi # echo output for the caller echo ${text} } # formats a time unit into a string # $1: integer count of units: 0, 6, etc # $2: unit name: "hour", "minute", etc function seconds-convert-part() { local unit=$1 local name=$2 if [ $unit -ge 2 ]; then echo " ${unit} ${name}s" elif [ $unit -ge 1 ]; then echo " ${unit} ${name}" else echo "" fi } ###### finding the square root of numbers function sqrt() { echo "sqrt ("$1")" | bc -l } ###### converts a string (words, text) to binary function string2bin() { perl -nle 'printf "%0*v8b\n"," ",$_' } ###### trigonmetry calculations with angles function trig-angle() { echo "Enter angle in degree: " read deg # Note: Pi calculation # tan(pi/4) = 1 # atan(1) = pi/4 and # pi = 4*atan(1) pi=`echo "4*a(1)" | bc -l` rad=`echo "$deg*($pi/180)" | bc -l` echo "$deg Degree = $rad Radian" echo "Sin($deg): " echo "s($rad)" | bc -l echo "Cos($deg): " echo "c($rad)" | bc -l echo "Tan($deg): " echo "s($rad)/c($rad)" | bc -l } ################################################## # Ask # ################################################## function ask() { echo -n "$@" '[y/n] ' ; read ans case "$ans" in y*|Y*) return 0 ;; *) return 1 ;; esac } ################################################## # Escape potential tarbombs # ################################################## function atb() { l=$(tar tf $1); if [ $(echo "$l" | wc -l) -eq $(echo "$l" | grep $(echo "$l" | head -n1) | wc -l) ]; then tar xf $1; else mkdir ${1%.tar.gz} && tar xf $1 -C ${1%.tar.gz}; fi ; } ################################################## # Get the headlines of an atom feed # ################################################## function atomtitles() { curl --silent $1 | xmlstarlet sel -N atom="http://www.w3.org/2005/Atom" -t -m /atom:feed/atom:entry -v atom:title -n } ################################################## # TV/DVD/Video/Audio Copying/ripping/extracting # ################################################## ############ TV ############ ###### ANALOG TV to AVI function atv2avi() { # great xvid quality is "2000" (11mb/min) echo -n "What analog/cable tv channel would you like to convert? (1-99)?: " read achan_type echo -n "Please enter how long you want to record (in this format: 02:08:17): " read time_type echo -n "Please enter a name for the AVI file you will convert: " read file_name echo -n "Please enter the quality you want your recording to be (in this format: 2000): " read qual_type mencoder -tv driver=v4l2:device=/dev/video1:input=0:norm=ntsc:chanlist=us-cable:channel=$achan_type:alsa=1:adevice=hw.1:audiorate=48000:immediatemode=0:amode=1 tv:// -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$qual_type:vhq:v4mv:keyint=250 -vf pp=de,pullup,softskip -oac mp3lame -lameopts abr:br=128:vol=3 -ffourcc xvid -o $HOME/Temp/$file_name.avi -endpos $time_type } alias atvrip='atv2avi' function atv2avi_w() { # great xvid quality is "2000" (11mb/min) (watch the recording at the same time) echo -n "What analog/cable tv channel would you like to convert? (1-99)?: " read achan_type echo -n "Please enter how long you want to record (in this format: 02:08:17): " read time_type echo -n "Please enter a name for the AVI file you will convert: " read file_name echo -n "Please enter the quality you want your recording to be (in this format: 2000): " read qual_type mencoder -tv driver=v4l2:device=/dev/video1:input=0:norm=ntsc:chanlist=us-cable:channel=$achan_type:alsa=1:adevice=hw.1:audiorate=48000:immediatemode=0:amode=1 tv:// -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$qual_type:vhq:v4mv:keyint=250 -vf pp=de,pullup,softskip -oac mp3lame -lameopts abr:br=128:vol=3 -ffourcc xvid -o $HOME/Temp/$file_name.avi -endpos $time_type & (sleep 5 && mplayer $HOME/Temp/$file_name.avi) } alias atvrip_w='atv2avi_w' ###### WATCH ANALOG TV function atv() { echo -n "What analog/cable tv channel would you like to watch? (1-99)?: " read ANALOGSTATION sh -c "mplayer -tv driver=v4l2:device=/dev/video1:input=0:norm=ntsc:chanlist=us-cable:channel="$ANALOGSTATION" tv:// & sox -r 48000 -t alsa hw:1,0 -t alsa hw:0,0" } function atv_() { sh -c "tvtime & sox -r 48000 -t alsa hw:1,0 -t alsa hw:0,0" } function ATV() { sox -s -r 32000 -c 2 -t alsa hw:1,0 -s -r 32000 -c 2 -t alsa hw:0,0 & tvtime t=`pidof sox`; kill $t; } ###### WATCH DIGITAL TV function dtv() { dtvchannels echo -n "What digital tv channel would you like to watch?: " read DIGITALSTATION mplayer dvb://"$DIGITALSTATION" } ###### DIGITAL TV to AVI function dtv2avi() { # great xvid quality is "1600" (13mb/min) dtvchannels echo -n "What digital tv channel would you like to convert?: " read dchan_type echo -n "Please enter how long you want to record (in this format: 02:08:17): " read time_type echo -n "Please enter a name for the AVI file you will convert: " read file_name echo -n "Please enter the quality you want your recording to be (in this format: 1600): " read qual_type mencoder dvb://$dchan_type -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$qual_type:vhq:v4mv:keyint=250 -vf pp=de,pullup,softskip,scale -zoom -xy 624 -oac mp3lame -lameopts abr:br=128:vol=3 -ffourcc xvid -o $HOME/Temp/$file_name.avi -endpos $time_type } alias dtvrip='dtv2avi' function dtv2avi_w() { # great xvid quality is "1600" (13mb/min) (watch the recording at the same time) dtvchannels echo -n "What digital tv channel would you like to convert?: " read dchan_type echo -n "Please enter how long you want to record (in this format: 02:08:17): " read time_type echo -n "Please enter a name for the AVI file you will convert: " read file_name echo -n "Please enter the quality you want your recording to be (in this format: 1600): " read qual_type mencoder dvb://$dchan_type -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$qual_type:vhq:v4mv:keyint=250 -vf pp=de,pullup,softskip,scale -zoom -xy 624 -oac mp3lame -lameopts abr:br=128:vol=3 -ffourcc xvid -o $HOME/Temp/$file_name.avi -endpos $time_type & (sleep 5 && mplayer $HOME/Temp/$file_name.avi) } alias dtvrip_w='dtv2avi_w' function DTV2AVI() { # best quality; big file size (100mb/min), but needs strong signal dtvchannels echo -n "What digital tv channel would you like to convert?: " read dchan_type echo -n "Please enter how long you want to record (in this format: 02:08:17): " read time_type echo -n "Please enter a name for the AVI file you will convert: " read file_name mencoder dvb://$dchan_type -ovc copy -oac copy -o $HOME/Temp/$file_name.mpg -endpos $time_type } alias DTVRIP='DTV2AVI' ###### DIGITAL TV to YouTube-compliant AVI function dtv2yt() { # ok quality (YouTube) (5mb/min) dtvchannels echo -n "What digital tv channel would you like to convert?: " read DIGITALSTATION echo -n "Please enter a name for the AVI file you will convert: " read AVINAME echo -n "Please enter how long you want to record (in this format: 02:08:17): " read ENDPOSITION mencoder dvb://"$DIGITALSTATION" -oac mp3lame -lameopts cbr=128 -ovc lavc -lavcopts vcodec=mpeg4 -ffourcc xvid -vf scale=320:-2,expand=:240:::1 -o "$AVINAME".avi -endpos "$ENDPOSITION" } ####### list of all of the local digital tv channels #function dtvchannels() { #cat < #EOF #} ###### TV (recording and watching (includes those tv functions above) function tv() { # Creator: Inameiname # Original Creator: Jose Catre-Vandis # Version: 1.0 # Last modified: 24 September 2011 # Requirements: mencoder & zenity # sudo apt-get install mencoder zenity # # THINGS YOU WILL NEED TO DO: # 1. A working dvb card and/or analog tv card # 2. If dvb, a ~/.mplayer/channels.conf # - can scan dvb channels and create this by: # - sudo scan /usr/share/dvb/atsc/us-ATSC- # - center-frequencies-8VSB > ~/.mplayer/ # - channels.conf # 3. If analog, a channel list, and tuned in! # - (all channels must have no spaces!) # - can scan analog channels and tune in by: # - tvtime-scanner # 4. Determine where your tv card is located, and # change if need be (script set on 'video1') # - tvtime-configure -d /dev/video0 # if tvtime # - otherwise, change 'video1' to 'video0' below ######################## SOFTWARE CHECK ############ Check for required software... mencoder_bin=`which mencoder | grep -c "mencoder"` ###### check for mencoder (also requires 'zenity') if [ $mencoder_bin -eq "0" ]; then zenity --error --title="Error - Missing Software" \ --text="You do not have the mencoder package installed Please install it in order to use this script. Make sure that the Multiverse repositories are enabled and then type: 'sudo apt-get install mencoder' at a terminal." exit fi ######################## CHOOSE TV TYPE ############ What type of TV TYPE do you want? ###### you can edit these entries to suit title="Which TV type do you want ?" tv_type=`zenity --width="480" --height="300" --title="$title" --list --radiolist --column="Click Here" \ --column="Channel" --column="Description" \ FALSE "DVB_RECORD" "Records dvb tv"\ FALSE "ANALOG_RECORD" "Records analog tv"\ FALSE "DVB_TV" "Watch dvb tv through mplayer"\ TRUE "ANALOG_TV" "Watch analog tv through mplayer"\ FALSE "ANALOG_TV1" "Watch analog tv through tvtime 1"\ FALSE "ANALOG_TV2" "Watch analog tv through tvtime 2"\ | sed 's/ max//g' ` echo "$tv_type chosen as the channel to record." ###### user must select a target type (Check if they cancelled) if [ ! "$tv_type" ]; then zenity --error --title="Error" --text="You must select a TV type!" exit fi ######################## TV TYPES if [ "$tv_type" = "DVB_RECORD" ]; then ############ RECORD DVB TV ###### Which DVB TV Channel? ###### ###### YOU NEED TO EDIT THIS SECTION FOR YOUR ENVIRONMENT # just change the channel names to reflect your channels.conf file # ensure there are no spaces in channel names here or in your channels.conf file # can scan dvb channels and create this by: # sudo scan /usr/share/dvb/atsc/us-ATSC-center-frequencies-8VSB > ~/.mplayer/channels.conf title="Which DVB-T Channel do you want to record ?" dchan_type=`zenity --width="380" --height="500" --title="$title" --list --radiolist --column="Click Here" \ --column="Channel" --column="Description" \ TRUE "ABC" "" \ FALSE "MYTV" "" \ FALSE "NBC" "" \ FALSE "CBS" "" \ FALSE "CBS2" "" \ FALSE "FOX" "" \ FALSE "WOSU-HD" "" \ FALSE "WOSU-D1" "" \ FALSE "WOSU-D2" "" \ FALSE "ADD" "" \ FALSE "YOUR" "" \ FALSE "OWN" "" \ FALSE "CHANNELS" "" \ FALSE "HERE" "" \ FALSE "Custom" "Input your own channel: 'NBC'"\ | sed 's/ max//g' ` echo "$dchan_type chosen as the channel to record." ###### user must select a target type (Check if they cancelled) if [ ! "$dchan_type" ]; then zenity --error --title="Error" --text="You must select a Channel!" exit fi ###### How Long Do You Want To Record? ###### ###### how long? title="How long do you want to record for ?" time_type=`zenity --width="380" --height="500" --title="$title" --list --radiolist --column="Click Here" \ --column="Record Time" --column="Description" \ TRUE "00:00:20" "20 seconds for testing" \ FALSE "00:01:00" "1 minute" \ FALSE "00:05:00" "5 minutes" \ FALSE "00:10:00" "10 minutes" \ FALSE "00:15:00" "15 minutes" \ FALSE "00:30:00" "30 minutes" \ FALSE "00:45:00" "45 minutes" \ FALSE "01:00:00" "1 hour" \ FALSE "01:15:00" "1:15 minutes" \ FALSE "01:30:00" "1:30 minutes" \ FALSE "01:45:00" "1:45 minutes" \ FALSE "02:00:00" "2 hours" \ FALSE "02:15:00" "2:15 minutes" \ FALSE "02:30:00" "2:30 minutes" \ FALSE "02:45:00" "2:45 minutes" \ FALSE "03:00:00" "3 hours" \ FALSE "03:15:00" "3:15 minutes" \ FALSE "03:30:00" "3:30 minutes" \ FALSE "03:45:00" "3:45 minutes" \ FALSE "04:00:00" "4 hours" \ FALSE "04:15:00" "4:15 minutes" \ FALSE "04:30:00" "4:30 minutes" \ FALSE "04:45:00" "4:45 minutes" \ FALSE "05:00:00" "5 hours" \ FALSE "05:15:00" "5:15 minutes" \ FALSE "05:30:00" "5:30 minutes" \ FALSE "05:45:00" "5:45 minutes" \ FALSE "06:00:00" "6 hours" \ FALSE "06:15:00" "6:15 minutes" \ FALSE "06:30:00" "6:30 minutes" \ FALSE "06:45:00" "6:45 minutes" \ FALSE "07:00:00" "7 hours" \ FALSE "07:15:00" "7:15 minutes" \ FALSE "07:30:00" "7:30 minutes" \ FALSE "07:45:00" "7:45 minutes" \ FALSE "08:00:00" "8 hours" \ FALSE "08:15:00" "8:15 minutes" \ FALSE "08:30:00" "8:30 minutes" \ FALSE "08:45:00" "8:45 minutes" \ FALSE "09:00:00" "9 hours" \ FALSE "09:15:00" "9:15 minutes" \ FALSE "09:30:00" "9:30 minutes" \ FALSE "09:45:00" "9:45 minutes" \ FALSE "10:00:00" "10 hours" \ FALSE "10:15:00" "10:15 minutes" \ FALSE "10:30:00" "10:30 minutes" \ FALSE "10:45:00" "10:45 minutes" \ FALSE "11:00:00" "11 hours" \ FALSE "11:15:00" "11:15 minutes" \ FALSE "11:30:00" "11:30 minutes" \ FALSE "11:45:00" "11:45 minutes" \ FALSE "12:00:00" "12 hours" \ FALSE "12:15:00" "12:15 minutes" \ FALSE "12:30:00" "12:30 minutes" \ FALSE "12:45:00" "12:45 minutes" \ FALSE "13:00:00" "13 hours" \ FALSE "13:15:00" "13:15 minutes" \ FALSE "13:30:00" "13:30 minutes" \ FALSE "13:45:00" "13:45 minutes" \ FALSE "14:00:00" "14 hours" \ FALSE "14:15:00" "14:15 minutes" \ FALSE "14:30:00" "14:30 minutes" \ FALSE "14:45:00" "14:45 minutes" \ FALSE "15:00:00" "15 hours" \ FALSE "15:15:00" "15:15 minutes" \ FALSE "15:30:00" "15:30 minutes" \ FALSE "15:45:00" "15:45 minutes" \ FALSE "16:00:00" "16 hours" \ FALSE "16:15:00" "16:15 minutes" \ FALSE "16:30:00" "16:30 minutes" \ FALSE "16:45:00" "16:45 minutes" \ FALSE "17:00:00" "17 hours" \ FALSE "17:15:00" "17:15 minutes" \ FALSE "17:30:00" "17:30 minutes" \ FALSE "17:45:00" "17:45 minutes" \ FALSE "18:00:00" "18 hours" \ FALSE "18:15:00" "18:15 minutes" \ FALSE "18:30:00" "18:30 minutes" \ FALSE "18:45:00" "18:45 minutes" \ FALSE "19:00:00" "19 hours" \ FALSE "19:15:00" "19:15 minutes" \ FALSE "19:30:00" "19:30 minutes" \ FALSE "19:45:00" "19:45 minutes" \ FALSE "20:00:00" "20 hours" \ FALSE "20:15:00" "20:15 minutes" \ FALSE "20:30:00" "20:30 minutes" \ FALSE "20:45:00" "20:45 minutes" \ FALSE "21:00:00" "21 hours" \ FALSE "21:15:00" "21:15 minutes" \ FALSE "21:30:00" "21:30 minutes" \ FALSE "21:45:00" "21:45 minutes" \ FALSE "22:00:00" "22 hours" \ FALSE "22:15:00" "22:15 minutes" \ FALSE "22:30:00" "22:30 minutes" \ FALSE "22:45:00" "22:45 minutes" \ FALSE "23:00:00" "23 hours" \ FALSE "23:15:00" "23:15 minutes" \ FALSE "23:30:00" "23:30 minutes" \ FALSE "23:45:00" "23:45 minutes" \ FALSE "24:00:00" "24 hours" \ | sed 's/ max//g' ` echo "$time_type chosen as the record time." ###### user must select a target type (Check if they cancelled) if [ ! "$time_type" ]; then zenity --error --title="Error" --text="You must select a Time!" exit fi ###### Choose a Filename? ###### ###### user must enter a filename title="Please enter a filename for your recording, no spaces" file_name=`zenity --width="480" --height="150" --title="$title" --entry` echo "$file_name entered as the file name." ###### user must select a target type (Check if they cancelled) if [ ! "$file_name" ]; then zenity --error --title="Error" --text="You must enter a Filename!" exit fi ###### Select the Quality of Your Recording? ###### ###### quality? title="What quality do you want to record at ?" qual_type=`zenity --width="380" --height="380" --title="$title" --list --radiolist --column="Click Here" \ --column="Record Quality" --column="Description" \ FALSE "500" "Passable Quality"\ FALSE "900" "OK Quality"\ FALSE "1100" "VHS Quality"\ FALSE "1300" "SVHS Quality"\ FALSE "1500" "VCD Quality"\ TRUE "1600" "MY Quality"\ FALSE "1800" "SVCD Quality" \ FALSE "2000" "Very Good Quality"\ FALSE "2500" "High Quality" \ FALSE "3000" "Excellent Quality"\ FALSE "MPEG-TS" "Raw dvb in ts format"\ | sed 's/ max//g' ` echo "$qual_type chosen as the encoding quality." ###### user must select a target type (Check if they cancelled) if [ ! "$qual_type" ]; then zenity --error --title="Error" --text="You must select an encoding quality!" exit fi ###### Start Time, Now or a Set Time Later? ###### ###### date-time timer # enter required time: title="Please enter a start time..." starttime=`zenity --width="480" --height="150" --title="$title" --entry --entry-text="now" --text="Enter Start Time in 00:00 format or click 'OK' for immediate start"` echo "$starttime entered as the start time." curtime=$(date --utc --date now +%s) echo "$curtime entered as the current time." righttime=$(date --utc --date $starttime +%s) echo "$righttime entered as the start time." # this bit copes with the starting time for the encode # beginning after midnight the following day if (($righttime<$curtime)); then newtime=$(($righttime+86400)) else newtime=$righttime fi waittime=$(($newtime - $curtime)) echo "$waittime entered as time to wait before encoding starts" ###### user must select a target type (Check if they cancelled) if [ ! "$newtime" ]; then zenity --error --title="Error" --text="You must enter a Start Time!" exit fi echo Channel= $dchan_type echo Filename= $file_name echo Encode length= $time_type echo Quality of encode= $qual_type sleep $waittime ###### The Actual DVB Video Encoding? ###### ###### video encoding DVB # YOU NEED TO EDIT THIS SECTION FOR YOUR ENVIRONMENT if [ "$qual_type" = "MPEG-TS" ]; then mencoder dvb://$dchan_type -ovc copy -oac copy -o $HOME/Temp/$file_name.mpg -endpos $time_type | zenity --progress --percentage=0 --title="DVB Recording Script" --text="Processing Video... $file_name" elif [ "$dchan_type" = "Custom" ]; then # custom channel custom_dchannel="Please enter custom digital channel, no spaces" dchan_type_custom=`zenity --width="480" --height="150" --title="$custom_dchannel" --entry` echo "$dchan_type_custom entered as the dvb channel." mencoder dvb://$dchan_type_custom -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$qual_type:vhq:v4mv:keyint=250 -vf pp=de,pullup,softskip,scale -zoom -xy 624 -oac mp3lame -lameopts abr:br=128:vol=3 -ffourcc xvid -o $HOME/Temp/$file_name.avi -endpos $time_type | zenity --progress --percentage=0 --title="DVB Recording Script" --text="Processing Video... $file_name" else mencoder dvb://$dchan_type -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$qual_type:vhq:v4mv:keyint=250 -vf pp=de,pullup,softskip,scale -zoom -xy 624 -oac mp3lame -lameopts abr:br=128:vol=3 -ffourcc xvid -o $HOME/Temp/$file_name.avi -endpos $time_type | zenity --progress --percentage=0 --title="DVB Recording Script" --text="Processing Video... $file_name" fi elif [ "$tv_type" = "ANALOG_RECORD" ]; then ############ RECORD ANALOG TV ###### Which Analog TV Channel? ###### ###### YOU NEED TO EDIT THIS SECTION FOR YOUR ENVIRONMENT # just change the channel names to reflect your analog channels list # you need to keep the "31-BBC1" style and format, if applicable. # this is "channelnumber-channelname" # can scan analog channels and tune in by (at least with tvtime): # tvtime-scanner title="Which Analog Channel do you want to record ?" achan_type=`zenity --width="380" --height="500" --title="$title" --list --radiolist --column="Click Here" \ --column="Channel" --column="Description" \ TRUE "Composite" "Records from Composite Input" \ FALSE "SVIDEO" "Records from S-Video Input" \ FALSE "1" ""\ FALSE "2" ""\ FALSE "3" ""\ FALSE "4" ""\ FALSE "5" ""\ FALSE "6" ""\ FALSE "7" ""\ FALSE "8" ""\ FALSE "9" ""\ FALSE "10" ""\ FALSE "11" ""\ FALSE "12" ""\ FALSE "13" ""\ FALSE "14" ""\ FALSE "15" ""\ FALSE "16" ""\ FALSE "17" ""\ FALSE "18" ""\ FALSE "19" ""\ FALSE "20" ""\ FALSE "21" ""\ FALSE "22" ""\ FALSE "23" ""\ FALSE "24" ""\ FALSE "25" ""\ FALSE "26" ""\ FALSE "27" ""\ FALSE "28" ""\ FALSE "29" ""\ FALSE "30" ""\ FALSE "31" ""\ FALSE "32" ""\ FALSE "33" ""\ FALSE "34" ""\ FALSE "35" ""\ FALSE "36" ""\ FALSE "37" ""\ FALSE "38" ""\ FALSE "39" ""\ FALSE "40" ""\ FALSE "41" ""\ FALSE "42" ""\ FALSE "43" ""\ FALSE "44" ""\ FALSE "45" ""\ FALSE "46" ""\ FALSE "47" ""\ FALSE "48" ""\ FALSE "49" ""\ FALSE "50" ""\ FALSE "51" ""\ FALSE "52" ""\ FALSE "53" ""\ FALSE "54" ""\ FALSE "55" ""\ FALSE "56" ""\ FALSE "57" ""\ FALSE "58" ""\ FALSE "59" ""\ FALSE "60" ""\ FALSE "61" ""\ FALSE "62" ""\ FALSE "63" ""\ FALSE "64" ""\ FALSE "65" ""\ FALSE "66" ""\ FALSE "67" ""\ FALSE "68" ""\ FALSE "69" ""\ FALSE "70" ""\ FALSE "71" ""\ FALSE "72" ""\ FALSE "73" ""\ FALSE "74" ""\ FALSE "75" ""\ FALSE "76" ""\ FALSE "77" ""\ FALSE "78" ""\ FALSE "79" ""\ FALSE "80" ""\ FALSE "81" ""\ FALSE "82" ""\ FALSE "83" ""\ FALSE "84" ""\ FALSE "85" ""\ FALSE "86" ""\ FALSE "87" ""\ FALSE "88" ""\ FALSE "89" ""\ FALSE "90" ""\ FALSE "91" ""\ FALSE "92" ""\ FALSE "93" ""\ FALSE "94" ""\ FALSE "95" ""\ FALSE "96" ""\ FALSE "97" ""\ FALSE "98" ""\ FALSE "99" ""\ FALSE "100" ""\ FALSE "101" ""\ FALSE "102" ""\ FALSE "103" ""\ FALSE "104" ""\ FALSE "105" ""\ FALSE "106" ""\ FALSE "107" ""\ FALSE "108" ""\ FALSE "109" ""\ FALSE "110" ""\ FALSE "111" ""\ FALSE "112" ""\ FALSE "113" ""\ FALSE "114" ""\ FALSE "115" ""\ FALSE "116" ""\ FALSE "117" ""\ FALSE "118" ""\ FALSE "119" ""\ FALSE "120" ""\ FALSE "121" ""\ FALSE "122" ""\ FALSE "123" ""\ FALSE "124" ""\ FALSE "125" ""\ FALSE "Custom" "Input your own channel: '234'"\ | sed 's/ max//g' ` echo "$achan_type chosen as the channel to record." ###### user must select a target type (Check if they cancelled) if [ ! "$achan_type" ]; then zenity --error --title="Error" --text="You must select a Channel!" exit fi ###### How Long Do You Want To Record? ###### ###### how long? title="How long do you want to record for ?" time_type=`zenity --width="380" --height="500" --title="$title" --list --radiolist --column="Click Here" \ --column="Record Time" --column="Description" \ TRUE "00:00:20" "20 seconds for testing" \ FALSE "00:01:00" "1 minute" \ FALSE "00:05:00" "5 minutes" \ FALSE "00:10:00" "10 minutes" \ FALSE "00:15:00" "15 minutes" \ FALSE "00:30:00" "30 minutes" \ FALSE "00:45:00" "45 minutes" \ FALSE "01:00:00" "1 hour" \ FALSE "01:15:00" "1:15 minutes" \ FALSE "01:30:00" "1:30 minutes" \ FALSE "01:45:00" "1:45 minutes" \ FALSE "02:00:00" "2 hours" \ FALSE "02:15:00" "2:15 minutes" \ FALSE "02:30:00" "2:30 minutes" \ FALSE "02:45:00" "2:45 minutes" \ FALSE "03:00:00" "3 hours" \ FALSE "03:15:00" "3:15 minutes" \ FALSE "03:30:00" "3:30 minutes" \ FALSE "03:45:00" "3:45 minutes" \ FALSE "04:00:00" "4 hours" \ FALSE "04:15:00" "4:15 minutes" \ FALSE "04:30:00" "4:30 minutes" \ FALSE "04:45:00" "4:45 minutes" \ FALSE "05:00:00" "5 hours" \ FALSE "05:15:00" "5:15 minutes" \ FALSE "05:30:00" "5:30 minutes" \ FALSE "05:45:00" "5:45 minutes" \ FALSE "06:00:00" "6 hours" \ FALSE "06:15:00" "6:15 minutes" \ FALSE "06:30:00" "6:30 minutes" \ FALSE "06:45:00" "6:45 minutes" \ FALSE "07:00:00" "7 hours" \ FALSE "07:15:00" "7:15 minutes" \ FALSE "07:30:00" "7:30 minutes" \ FALSE "07:45:00" "7:45 minutes" \ FALSE "08:00:00" "8 hours" \ FALSE "08:15:00" "8:15 minutes" \ FALSE "08:30:00" "8:30 minutes" \ FALSE "08:45:00" "8:45 minutes" \ FALSE "09:00:00" "9 hours" \ FALSE "09:15:00" "9:15 minutes" \ FALSE "09:30:00" "9:30 minutes" \ FALSE "09:45:00" "9:45 minutes" \ FALSE "10:00:00" "10 hours" \ FALSE "10:15:00" "10:15 minutes" \ FALSE "10:30:00" "10:30 minutes" \ FALSE "10:45:00" "10:45 minutes" \ FALSE "11:00:00" "11 hours" \ FALSE "11:15:00" "11:15 minutes" \ FALSE "11:30:00" "11:30 minutes" \ FALSE "11:45:00" "11:45 minutes" \ FALSE "12:00:00" "12 hours" \ FALSE "12:15:00" "12:15 minutes" \ FALSE "12:30:00" "12:30 minutes" \ FALSE "12:45:00" "12:45 minutes" \ FALSE "13:00:00" "13 hours" \ FALSE "13:15:00" "13:15 minutes" \ FALSE "13:30:00" "13:30 minutes" \ FALSE "13:45:00" "13:45 minutes" \ FALSE "14:00:00" "14 hours" \ FALSE "14:15:00" "14:15 minutes" \ FALSE "14:30:00" "14:30 minutes" \ FALSE "14:45:00" "14:45 minutes" \ FALSE "15:00:00" "15 hours" \ FALSE "15:15:00" "15:15 minutes" \ FALSE "15:30:00" "15:30 minutes" \ FALSE "15:45:00" "15:45 minutes" \ FALSE "16:00:00" "16 hours" \ FALSE "16:15:00" "16:15 minutes" \ FALSE "16:30:00" "16:30 minutes" \ FALSE "16:45:00" "16:45 minutes" \ FALSE "17:00:00" "17 hours" \ FALSE "17:15:00" "17:15 minutes" \ FALSE "17:30:00" "17:30 minutes" \ FALSE "17:45:00" "17:45 minutes" \ FALSE "18:00:00" "18 hours" \ FALSE "18:15:00" "18:15 minutes" \ FALSE "18:30:00" "18:30 minutes" \ FALSE "18:45:00" "18:45 minutes" \ FALSE "19:00:00" "19 hours" \ FALSE "19:15:00" "19:15 minutes" \ FALSE "19:30:00" "19:30 minutes" \ FALSE "19:45:00" "19:45 minutes" \ FALSE "20:00:00" "20 hours" \ FALSE "20:15:00" "20:15 minutes" \ FALSE "20:30:00" "20:30 minutes" \ FALSE "20:45:00" "20:45 minutes" \ FALSE "21:00:00" "21 hours" \ FALSE "21:15:00" "21:15 minutes" \ FALSE "21:30:00" "21:30 minutes" \ FALSE "21:45:00" "21:45 minutes" \ FALSE "22:00:00" "22 hours" \ FALSE "22:15:00" "22:15 minutes" \ FALSE "22:30:00" "22:30 minutes" \ FALSE "22:45:00" "22:45 minutes" \ FALSE "23:00:00" "23 hours" \ FALSE "23:15:00" "23:15 minutes" \ FALSE "23:30:00" "23:30 minutes" \ FALSE "23:45:00" "23:45 minutes" \ FALSE "24:00:00" "24 hours" \ | sed 's/ max//g' ` echo "$time_type chosen as the record time." ###### user must select a target type (Check if they cancelled) if [ ! "$time_type" ]; then zenity --error --title="Error" --text="You must select a Time!" exit fi ###### Choose a Filename? ###### ###### user must enter a filename title="Please enter a filename for your recording, no spaces" file_name=`zenity --width="480" --height="150" --title="$title" --entry` echo "$file_name entered as the file name." ###### user must select a target type (Check if they cancelled) if [ ! "$file_name" ]; then zenity --error --title="Error" --text="You must enter a Filename!" exit fi ###### Select the Quality of Your Recording? ###### ###### quality? title="What quality do you want to record at ?" qual_type=`zenity --width="380" --height="380" --title="$title" --list --radiolist --column="Click Here" \ --column="Record Quality" --column="Description" \ FALSE "500" "Passable Quality"\ FALSE "900" "OK Quality"\ FALSE "1100" "VHS Quality"\ FALSE "1300" "SVHS Quality"\ FALSE "1500" "VCD Quality"\ TRUE "1600" "MY Quality"\ FALSE "1800" "SVCD Quality" \ FALSE "2000" "Very Good Quality"\ FALSE "2500" "High Quality" \ FALSE "3000" "Excellent Quality"\ | sed 's/ max//g' ` echo "$qual_type chosen as the encoding quality." ###### user must select a target type (Check if they cancelled) if [ ! "$qual_type" ]; then zenity --error --title="Error" --text="You must select an encoding quality!" exit fi ###### Start Time, Now or a Set Time Later? ###### ###### date-time timer # enter required time: title="Please enter a start time..." starttime=`zenity --width="480" --height="150" --title="$title" --entry --entry-text="now" --text="Enter Start Time in 00:00 format or click 'OK' for immediate start"` echo "$starttime entered as the start time." curtime=$(date --utc --date now +%s) echo "$curtime entered as the current time." newtime=$(date --utc --date $starttime +%s) echo "$newtime entered as the start time." waittime=$(($newtime - $curtime)) echo "$waittime entered as time to wait before encoding starts" ###### user must select a target type (Check if they cancelled) if [ ! "$newtime" ]; then zenity --error --title="Error" --text="You must enter a Start Time!" exit fi echo Channel= $achan_type echo Filename= $file_name echo Encode length= $time_type echo Quality of encode= $qual_type sleep $waittime ###### The Actual Analog Video Encoding? ###### ###### video encoding analog # YOU NEED TO EDIT THIS SECTION FOR YOUR ENVIRONMENT # In the third script (after "else") just change the # chanlist value from us-cable to your chanlist region # AND change device (video1) to video0 or whatever if need be if [ "$achan_type" = "Composite" ]; then input_type=1 mencoder -tv driver=v4l2:device=/dev/video1:input=$input_type:norm=ntsc:alsa=1:adevice=hw.1:audiorate=48000:immediatemode=0:amode=1 tv:// -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$qual_type:vhq:v4mv:keyint=250 -vf pp=de,pullup,softskip -oac mp3lame -lameopts abr:br=128:vol=3 -ffourcc xvid -o $HOME/Temp/$file_name.avi -endpos $time_type | zenity --progress --percentage=0 --title="COMPOSITE Recording Script" --text="Processing Video... $file_name" elif [ "$achan_type" = "SVIDEO" ]; then input_type=2 mencoder -tv driver=v4l2:device=/dev/video1:input=$input_type:norm=ntsc:alsa=1:adevice=hw.1:audiorate=48000:immediatemode=0:amode=1 tv:// -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$qual_type:vhq:v4mv:keyint=250 -vf pp=de,pullup,softskip -oac mp3lame -lameopts abr:br=128:vol=3 -ffourcc xvid -o $HOME/Temp/$file_name.avi -endpos $time_type | zenity --progress --percentage=0 --title="SVIDEO Recording Script" --text="Processing Video... $file_name" elif [ "$achan_type" = "Custom" ]; then # custom channel custom_achannel="Please enter custom analog channel, no spaces" achan_type_custom=`zenity --width="480" --height="150" --title="$custom_achannel" --entry` echo "$achan_type_custom entered as the analog channel." mencoder -tv driver=v4l2:device=/dev/video1:input=0:norm=ntsc:chanlist=us-cable:channel=$achan_type_custom:alsa=1:adevice=hw.1:audiorate=48000:immediatemode=0:amode=1 tv:// -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$qual_type:vhq:v4mv:keyint=250 -vf pp=de,pullup,softskip -oac mp3lame -lameopts abr:br=128:vol=3 -ffourcc xvid -o $HOME/Temp/$file_name.avi -endpos $time_type | zenity --progress --percentage=0 --title="ANALOG TV Recording Script" --text="Processing Video... $file_name" else mencoder -tv driver=v4l2:device=/dev/video1:input=0:norm=ntsc:chanlist=us-cable:channel=$achan_type:alsa=1:adevice=hw.1:audiorate=48000:immediatemode=0:amode=1 tv:// -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$qual_type:vhq:v4mv:keyint=250 -vf pp=de,pullup,softskip -oac mp3lame -lameopts abr:br=128:vol=3 -ffourcc xvid -o $HOME/Temp/$file_name.avi -endpos $time_type | zenity --progress --percentage=0 --title="ANALOG TV Recording Script" --text="Processing Video... $file_name" fi elif [ "$tv_type" = "DVB_TV" ]; then ############ WATCH DVB TV (through MPlayer) # YOU NEED TO EDIT THIS SECTION FOR YOUR ENVIRONMENT # gives you list of your current dvb channels dchan_type=$(zenity --entry --text="What digital tv channel would you like to watch?: ATSC/NTSC local digital channel list: ADD YOUR LIST OF DIGITAL CHANNELS HERE FOR EASY USE ") mplayer dvb://$dchan_type ###### user must select a target type (Check if they cancelled) if [ ! "$dchan_type" ]; then zenity --error --title="Error" --text="You must select a Channel!" exit fi elif [ "$tv_type" = "ANALOG_TV" ]; then ############ WATCH Analog TV (through MPlayer) achan_type=$(zenity --entry --text="What analog/cable tv channel would you like to watch?: ") sh -c "mplayer -tv driver=v4l2:device=/dev/video1:input=0:norm=ntsc:chanlist=us-cable:channel=$achan_type tv:// & sox -r 48000 -t alsa hw:1,0 -t alsa hw:0,0" ###### user must select a target type (Check if they cancelled) if [ ! "$achan_type" ]; then zenity --error --title="Error" --text="You must select a Channel!" exit fi elif [ "$tv_type" = "ANALOG_TV1" ]; then ############ WATCH Analog TV (through TVtime 1) sox -s -r 32000 -c 2 -t alsa hw:1,0 -s -r 32000 -c 2 -t alsa hw:0,0 & tvtime t=`pidof sox`; kill $t; else ############ WATCH Analog TV (through TVtime 2) sh -c "tvtime & sox -r 48000 -t alsa hw:1,0 -t alsa hw:0,0" fi exit } ############ DVD ############ ###### DVD to ISO function dvd2iso() { # to get desired device df -h -x tmpfs -x usbfs echo -n "Using the information in the terminal window, please enter the appropriate DVD drive: " read DVDDEVICE echo -n "Please enter a name for the ISO file you will create: " read XVIDNAME pv "$DVDDEVICE" | dd of="$XVIDNAME".iso } alias dvdcopy='dvd2iso' ###### DVD to MPG alias dvd2mpeg='dvd2mpg' function dvd2mpg() { # to get desired device df -h -x tmpfs -x usbfs echo -n "Using the information in the terminal window, please enter the appropriate DVD drive: " read DVDDEVICE # to get desired title on dvd # requires lsdvd: sudo apt-get install lsdvd lsdvd "$DVDDEVICE" echo -n "Using the information in the terminal window, please enter the title number you will convert (usually the longest one): " read DVDTITLE echo -n "Please enter a name for the MPG/MPEG file you will convert: " read MPEGNAME mplayer dvd://"$DVDTITLE" -dumpstream -alang es -dumpfile "$MPEGNAME".mpg } ###### DVD to VOB # requires vobcopy: sudo apt-get install vobcopy # alias dvd2vob='vobcopy -i /dev/dvd -o ~/ -l' alias dvd2vob='dvd2mpg' ###### extract audio from DVD VOB files # USAGE: dvdaudio input_file.vob output_file.ac3 function dvdaudio() { echo -n "Please enter the name (full path) for the MPG/MPEG/VOB file you will extract the audio from: " read VOBNAME echo -n "Please enter a name for the audio file you will extract from the MPG/MPEG/VOB file: " read AC3NAME mplayer "$VOBNAME" -aid 128 -dumpaudio -dumpfile "$AC3NAME" } ############ Video ############ ###### Video to AVI alias dvdrip='video2avi' alias rip='video2avi' function video2avi() { # Video To Avi # Created: Inameiname # Version: 3.2 ####################### Run in the terminal on double-click tty -s; if [ $? -ne 0 ] ; then gnome-terminal -e "$0"; exit; fi ####################### If it doesn't run in the terminal on double-click, say so [ -t 0 ] && [ -t 1 ] || { zenity --warning --text="${0}: this script must be run from a terminal." ; exit 1 ;} ####################### Check whether environment variables are empty ###### see if the Nautilus environment variable is empty # if it exists, set it equal to 'INPUT_FILE' for ARCHIVE_FULLPATH in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS; do ARCHIVE_PATH=${ARCHIVE_FULLPATH%.*} if [ -f $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS ] ; then # if select iso file: if [ $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS = $ARCHIVE_PATH.iso ] ; then # to get desired title on dvd # requires lsdvd: sudo apt-get install lsdvd lsdvd $ARCHIVE_PATH.iso echo -n "Please enter the title number you will convert (usually the longest one): Press 'Enter' for default (default is '1')... " read TITLE # extra blank space echo " " # default if [[ -z $TITLE ]] ; then # If no title passed, default to 1 TITLE=1 fi INPUT_FILE="dvd://$TITLE -dvd-device $ARCHIVE_PATH.iso" fi # if select video file: if [ $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS != $ARCHIVE_PATH.iso ] ; then INPUT_FILE=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS fi fi done # if it's blank, set it equal to $1 if [ -z $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS ] ; then # If it's blank, set it equal to $1 NAUTILUS_SCRIPT_SELECTED_FILE_PATHS=$1 ###### see if the '$1' variable is empty # if it exists, set it equal to 'INPUT_FILE' for ARCHIVE_FULLPATH in $1; do ARCHIVE_PATH=${ARCHIVE_FULLPATH%.*} if [ -f $1 ] ; then # if select iso file: if [ $1 = $ARCHIVE_PATH.iso ] ; then # to get desired title on dvd # requires lsdvd: sudo apt-get install lsdvd lsdvd $ARCHIVE_PATH.iso echo -n "Please enter the title number you will convert (usually the longest one): Press 'Enter' for default (default is '1')... " read TITLE # extra blank space echo " " # default if [[ -z $TITLE ]] ; then # If no title passed, default to 1 TITLE=1 fi INPUT_FILE="dvd://$TITLE -dvd-device $ARCHIVE_PATH.iso" fi # if select video file: if [ $1 != $ARCHIVE_PATH.iso ] ; then INPUT_FILE=$1 fi fi done # if it's blank, do the following: if [ -z "$1" ] ; then ####################### Input DVD/ISO/VIDEO file menu echo -n "What do you want to convert to AVI?: (1) DVD (2) ISO file (3) Video file (such as MKV, VOB, MPEG, AVI, WMV, and etc.) Press 'Enter' for default (default is '1')... " read TYPE # extra blank space echo " " ###### Input DVD/ISO/VIDEO source default ###### if [[ -z $TYPE ]] ; then # If no media passed, default to 1 TYPE=1 fi ###### Input DVD/ISO/VIDEO source ###### ###### DVD to AVI if [[ $TYPE = 1 ]] ; then # to get desired device df -h -x tmpfs -x usbfs echo -n "Please enter the appropriate DVD drive: (1) /dev/dvd (2) /dev/sr0 (3) /dev/sr1 (4) /dev/sr2 (5) custom Press 'Enter' for default (default is '1')... " read DEVICE_NUMBER # extra blank space echo " " # default if [[ -z $DEVICE_NUMBER ]] ; then # If no device passed, default to /dev/dvd DEVICE=/dev/dvd fi # preset if [[ $DEVICE_NUMBER = 1 ]] ; then DEVICE=/dev/dvd fi if [[ $DEVICE_NUMBER = 2 ]] ; then DEVICE=/dev/sr0 fi if [[ $DEVICE_NUMBER = 3 ]] ; then DEVICE=/dev/sr1 fi if [[ $DEVICE_NUMBER = 4 ]] ; then DEVICE=/dev/sr2 fi # custom if [[ $DEVICE_NUMBER = 5 ]] ; then echo -n "Please enter the appropriate DVD drive: " echo -n "...like this: '/dev/dvd'..." read CUSTOM_DEVICE DEVICE=$CUSTOM_DEVICE fi # to get desired title on dvd # requires lsdvd: sudo apt-get install lsdvd lsdvd $DEVICE echo -n "Please enter the title number you will convert (usually the longest one): Press 'Enter' for default (default is '1')... " read TITLE # extra blank space echo " " # default if [[ -z $TITLE ]] ; then # If no title passed, default to 1 TITLE=1 fi # to decide to copy straight from the DVD or first copy to hard drive to ISO echo -n "Would you first like to copy the DVD onto your hard drive (to ISO)?: (1) Yes (Highly Recommended) (2) No Press 'Enter' for default (default is '1')... " read DVD2ISO # extra blank space echo " " # default if [[ -z $DVD2ISO ]] ; then # If no DVD2ISO passed, default to 1 dd if=$DEVICE of=NEW.iso INPUT_FILE="dvd://$TITLE -dvd-device NEW.iso" fi # preset if [[ $DVD2ISO = 1 ]] ; then dd if=$DEVICE of=NEW.iso INPUT_FILE="dvd://$TITLE -dvd-device NEW.iso" fi if [[ $DVD2ISO = 2 ]] ; then INPUT_FILE="dvd://$TITLE -dvd-device $DEVICE" fi fi ###### ISO to AVI if [[ $TYPE = 2 ]] ; then echo -n "Please enter the full path for the ISO: Example: /home/(your username)/Videos/NEW.iso... " read ISO # extra blank space echo " " # to get desired title on dvd # requires lsdvd: sudo apt-get install lsdvd lsdvd $ISO echo -n "Please enter the title number you will convert (usually the longest one): Press 'Enter' for default (default is '1')... " read TITLE # extra blank space echo " " # default if [[ -z $TITLE ]] ; then # If no title passed, default to 1 TITLE=1 fi INPUT_FILE="dvd://$TITLE -dvd-device $ISO" fi ###### Video to AVI if [[ $TYPE = 3 ]] ; then echo -n "Please enter the name for the input file (full path, with extension): It can be any type, such as MKV, VOB, MPEG, AVI, WMV, and etc... Example: /home/(your username)/Videos/NEW.avi... " read VIDEO_FILE # extra blank space echo " " INPUT_FILE=$VIDEO_FILE fi ####################### Close the variable statements fi fi ####################### Cropping (done automatically) ###### start a timer to kill mplayer echo "Cropdetect is now running... A few seconds of your video should now be playing... " ###### start a timer to kill mplayer (sleep 6 && killall mplayer)& ###### start the mplayer cropdetect on on the DVD at a random time mplayer $INPUT_FILE -ss 0:03:10 -vf cropdetect &> mplayer.tmp ###### get last crop value from mplayer output and store in variable CROP_VALUES=$(awk -F'crop=' '/\[CROP\]/{f=$2} END{print f}' ./mplayer.tmp |cut -d')' -f1) ###### print detected crop values echo -e "\n\nDetected crop values = ${CROP_VALUES}\n\n" ####################### Output desired name for file ###### file input echo -n "Please enter a name for the output file (without extension): Press 'Enter' for default (default is 'NEW')... " read OUTPUT_FILE ###### extra blank space echo " " ###### default ###### if [[ -z $OUTPUT_FILE ]] ; then # If no file passed, default to NEW OUTPUT_FILE=NEW_$(date "+%y.%m.%d_%H.%M") fi ####################### Available processor number (done automatically) CPUS=$(grep -c processor /proc/cpuinfo) echo "Using $CPUS processor(s)..." ###### extra blank space echo " " ####################### Preset/Custom type options echo -n "Select a quality level: (1) exact copy quality MPEG (DVD/ISO sources only) (2) exact copy audio-only quality AC3 (DVD/ISO sources only) (3) very high quality H.264 (2-pass) (350min:105min film w/2 1.5mhz cpus) (4) very high quality DIVX/MPEG-4 (2-pass) (270min:105min film w/2 1.5mhz cpus) (5) very high quality XVID (2-pass) (220min:105min film w/2 1.5mhz cpus) (6) very high quality H.264 (1-pass) (400min:105min film w/2 1.5mhz cpus) (7) very high quality DIVX/MPEG-4 (1-pass) (230min:105min film w/2 1.5mhz cpus) (8) very high quality XVID (1-pass) (180min:105min film w/2 1.5mhz cpus) (9) high quality H.264 (2-pass) (240min:105min film w/2 1.5mhz cpus) (10)high quality DIVX/MPEG-4 (2-pass) (190min:105min film w/2 1.5mhz cpus) (11)high quality XVID (2-pass) (135min:105min film w/2 1.5mhz cpus) (12)high quality H.264 (1-pass) (200min:105min film w/2 1.5mhz cpus) (13)high quality DIVX/MPEG-4 (1-pass) (150min:105min film w/2 1.5mhz cpus) (14)high quality XVID (1-pass) (090min:105min film w/2 1.5mhz cpus) (15)fast quality H.264 (1-pass) (155min:105min film w/2 1.5mhz cpus) (16)fast quality DIVX/MPEG-4 (1-pass) (065min:105min film w/2 1.5mhz cpus) (17)fast quality XVID (1-pass) (065min:105min film w/2 1.5mhz cpus) (18)fast quality XVID YouTube (1-pass) (025min:105min film w/2 1.5mhz cpus) (19)realtime quality DIVX/MPEG-4 (1-pass) (050min:105min film w/2 1.5mhz cpus) (20)realtime quality XVID (1-pass) (060min:105min film w/2 1.5mhz cpus) (21)low quality WMV (1-pass) (017min:105min film w/2 1.5mhz cpus) (22)custom quality Press 'Enter' for default (default is '14')... " read Q ###### extra blank space echo " " ###### default ###### if [[ -z $Q ]] ; then # If no quality passed, default to 14 Q=14 fi ####################### Frame rate ###### frame rate menu if [[ $Q != 1 && $Q != 2 ]] ; then echo -n "Select a frame rate level: (1) NTSC-VIDEO (~ 30 fps) (2) NTSC-FILM (~ 24 fps) (3) PAL (~ 25 fps) (4) Streaming (~ 15 fps) (5) custom Press 'Enter' for default (default is '2')... " read FRAME_RATE_NUMBER ###### extra blank space echo " " ###### default if [[ -z $FRAME_RATE_NUMBER ]] ; then # If no frame rate passed, default to 2 FRAME_RATE="-ofps 24000/1001" fi ###### preset if [[ $FRAME_RATE_NUMBER = 1 ]] ; then FRAME_RATE="-ofps 30000/1001" fi if [[ $FRAME_RATE_NUMBER = 2 ]] ; then FRAME_RATE="-ofps 24000/1001" fi if [[ $FRAME_RATE_NUMBER = 3 ]] ; then FRAME_RATE="-ofps 25000/1001" fi if [[ $FRAME_RATE_NUMBER = 4 ]] ; then FRAME_RATE="-ofps 15000/1001" fi ###### custom if [[ $FRAME_RATE_NUMBER = 5 ]] ; then echo -n "Please enter a frame rate: " echo -n "...like this: '-ofps 15000/1001'..." read CUSTOM_FRAME_RATE FRAME_RATE=$CUSTOM_FRAME_RATE fi fi ####################### Divx ffourcc menu ###### DivX ffourcc menu if [[ $Q != 1 && $Q != 2 && $Q != 3 && $Q != 5 && $Q != 6 && $Q != 8 && $Q != 9 && Q != 11 && $Q != 12 && $Q != 14 && $Q != 15 && $Q != 17 && $Q != 18 && $Q != 20 && $Q != 21 && $Q != 22 ]] ; then echo -n "Select the desired Divx or generic MPEG4 quality: (1) FFMPEG MPEG-4 (2) DivX MPEG-4 Version 4 (3) DivX MPEG-4 Version 5 Press 'Enter' for default (default is '3')... " read DIVX_NUMBER ###### extra blank space echo " " ###### default if [[ -z $DIVX_NUMBER ]] ; then # If no file passed, default to 3 DIVX="-ffourcc DX50" fi ###### preset if [[ $DIVX_NUMBER = 1 ]] ; then DIVX= fi if [[ $DIVX_NUMBER = 2 ]] ; then DIVX="-ffourcc DIVX" fi if [[ $DIVX_NUMBER = 3 ]] ; then DIVX="-ffourcc DX50" fi fi ####################### Conversion is starting ###### conversion is starting message if [[ $Q != 22 ]] ; then read -sn 1 -p "Your conversion is about to begin, press any key to continue..." fi ###### extra blank space echo " " ####################### Conversions ###### preset ###### ###### exact copy quality (DVD/ISO sources only) if [[ $Q = 1 ]] ; then # If 1 passed, use MPEG exact copy quality mplayer $INPUT_FILE -dumpstream -dumpfile $OUTPUT_FILE.mpg fi if [[ $Q = 2 ]] ; then # If 2 passed, use MPEG exact copy audio-only quality mplayer $INPUT_FILE -dumpaudio -dumpfile $OUTPUT_FILE.ac3 fi ###### very high quality if [[ $Q = 3 ]] ; then # very high H.264 quality (2-pass) # actual two-pass conversion mencoder $INPUT_FILE -nosound -ovc x264 -x264encopts pass=1:subq=1:partitions=all:8x8dct:me=umh:frameref=1:bframes=3:b_pyramid=normal:weight_b:threads=auto:bitrate=2000 -vf pp=de,pullup,softskip,harddup,crop=${CROP_VALUES} $FRAME_RATE -o '/dev/null' mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=192:vol=3 -ovc x264 -x264encopts pass=2:subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid=normal:weight_b:threads=auto:bitrate=2000 -vf pp=de,pullup,softskip,harddup,crop=${CROP_VALUES} $FRAME_RATE -o $OUTPUT_FILE.avi fi if [[ $Q = 4 ]] ; then # very high MPEG4 quality (2-pass) # actual two-pass conversion mencoder $INPUT_FILE -nosound -ovc lavc $DIVX -lavcopts vpass=1:vcodec=mpeg4:mbd=2:trell:v4mv:last_pred=2:dia=-1:vmax_b_frames=2:vb_strategy=1:cmp=3:subcmp=3:precmp=0:vqcomp=0.6:turbo:vhq:threads=$CPUS:vbitrate=2000 -vf pp=de,pullup,softskip,crop=${CROP_VALUES} $FRAME_RATE -o '/dev/null' mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=192:vol=3 -ovc lavc $DIVX -lavcopts vpass=2:vcodec=mpeg4:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:predia=2:dia=2:vmax_b_frames=2:vb_strategy=1:precmp=2:cmp=2:subcmp=2:preme=2:qns=2:vhq:threads=$CPUS:vbitrate=2000 -vf pp=de,pullup,softskip,crop=${CROP_VALUES} $FRAME_RATE -o $OUTPUT_FILE.avi fi if [[ $Q = 5 ]] ; then # very high XVID quality (2-pass) # actual two-pass conversion mencoder $INPUT_FILE -nosound -ovc xvid -xvidencopts pass=1:chroma_opt:vhq=1:bvhq=1:quant_type=mpeg:threads=$CPUS:bitrate=2000 -vf pp=de,pullup,softskip,crop=${CROP_VALUES} $FRAME_RATE -o '/dev/null' mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=192:vol=3 -ovc xvid -xvidencopts pass=2:chroma_opt:vhq=4:bvhq=1:quant_type=mpeg:threads=$CPUS:bitrate=2000 -vf pp=de,pullup,softskip,crop=${CROP_VALUES} $FRAME_RATE -o $OUTPUT_FILE.avi fi if [[ $Q = 6 ]] ; then # very high H.264 quality (1-pass) # actual one-pass conversion mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=192:vol=3 -ovc x264 -x264encopts subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid=normal:weight_b:threads=auto:bitrate=2000 -vf pp=de,pullup,softskip,crop=${CROP_VALUES} $FRAME_RATE -o $OUTPUT_FILE.avi fi if [[ $Q = 7 ]] ; then # very high MPEG4 quality (1-pass) # actual one-pass conversion mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=192:vol=3 -ovc lavc $DIVX -lavcopts vcodec=mpeg4:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:predia=2:dia=2:vmax_b_frames=2:vb_strategy=1:precmp=2:cmp=2:subcmp=2:preme=2:qns=2:vhq:threads=$CPUS:vbitrate=2000 -vf pp=de,pullup,softskip,crop=${CROP_VALUES} $FRAME_RATE -o $OUTPUT_FILE.avi fi if [[ $Q = 8 ]] ; then # very high XVID quality (1-pass) # actual one-pass conversion mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=192:vol=3 -ovc xvid -xvidencopts chroma_opt:vhq=4:bvhq=1:quant_type=mpeg:threads=$CPUS:bitrate=2000 -vf pp=de,pullup,softskip,crop=${CROP_VALUES} $FRAME_RATE -o $OUTPUT_FILE.avi fi ###### high quality if [[ $Q = 9 ]] ; then # high H.264 quality (2-pass) # actual two-pass conversion mencoder $INPUT_FILE -nosound -ovc x264 -x264encopts pass=1:subq=1:partitions=all:8x8dct:me=umh:frameref=1:bframes=3:b_pyramid=normal:weight_b:threads=auto:bitrate=-700000 -vf pp=de,pullup,softskip,harddup,crop=${CROP_VALUES},scale -zoom -xy 624 $FRAME_RATE -o '/dev/null' mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=128:vol=3 -ovc x264 -x264encopts pass=2:subq=5:8x8dct:frameref=2:bframes=3:b_pyramid=normal:weight_b:threads=auto:bitrate=1200 -vf pp=de,pullup,softskip,harddup,crop=${CROP_VALUES},scale -zoom -xy 624 $FRAME_RATE -o $OUTPUT_FILE.avi fi if [[ $Q = 10 ]] ; then # high MPEG4 quality (2-pass) # actual two-pass conversion mencoder $INPUT_FILE -nosound -ovc lavc $DIVX -lavcopts vpass=1:vcodec=mpeg4:mbd=2:trell:v4mv:last_pred=2:dia=-1:vmax_b_frames=2:vb_strategy=1:cmp=3:subcmp=3:precmp=0:vqcomp=0.6:turbo:vhq:threads=$CPUS:vbitrate=1100 -vf pp=de,pullup,softskip,crop=${CROP_VALUES},scale -zoom -xy 624 $FRAME_RATE -o '/dev/null' mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=128:vol=3 -ovc lavc $DIVX -lavcopts vpass=2:vcodec=mpeg4:mbd=2:trell:v4mv:last_pred=2:dia=-1:vmax_b_frames=2:vb_strategy=1:cmp=3:subcmp=3:precmp=0:vqcomp=0.6:turbo:vhq:threads=$CPUS:vbitrate=1100 -vf pp=de,pullup,softskip,crop=${CROP_VALUES},scale -zoom -xy 624 $FRAME_RATE -o $OUTPUT_FILE.avi fi if [[ $Q = 11 ]] ; then # high XVID quality (2-pass) # actual two-pass conversion mencoder $INPUT_FILE -nosound -ovc xvid -xvidencopts pass=1:vhq=1:bvhq=1:chroma_opt:quant_type=mpeg:threads=$CPUS:bitrate=-700000 -vf pp=de,pullup,softskip,crop=${CROP_VALUES},scale -zoom -xy 624 $FRAME_RATE -o '/dev/null' mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=128:vol=3 -ovc xvid -xvidencopts pass=2:vhq=2:bvhq=1:chroma_opt:quant_type=mpeg:threads=$CPUS:bitrate=-700000 -vf pp=de,pullup,softskip,crop=${CROP_VALUES},scale -zoom -xy 624 $FRAME_RATE -o $OUTPUT_FILE.avi fi if [[ $Q = 12 ]] ; then # high H.264 quality (1-pass) # actual one-pass conversion mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=128:vol=3 -ovc x264 -x264encopts subq=5:8x8dct:frameref=2:bframes=3:b_pyramid=normal:weight_b:threads=auto:bitrate=-700000 -vf pp=de,pullup,softskip,crop=${CROP_VALUES},scale -zoom -xy 624 $FRAME_RATE -o $OUTPUT_FILE.avi fi if [[ $Q = 13 ]] ; then # high MPEG4 quality (1-pass) # actual one-pass conversion mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=128:vol=3 -ovc lavc $DIVX -lavcopts vcodec=mpeg4:mbd=2:trell:v4mv:last_pred=2:dia=-1:vmax_b_frames=2:vb_strategy=1:cmp=3:subcmp=3:precmp=0:vqcomp=0.6:turbo:vhq:threads=$CPUS:vbitrate=1100 -vf pp=de,pullup,softskip,crop=${CROP_VALUES},scale -zoom -xy 624 $FRAME_RATE -o $OUTPUT_FILE.avi fi if [[ $Q = 14 ]] ; then # high XVID quality (1-pass) # actual one-pass conversion mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=128:vol=3 -ovc xvid -xvidencopts vhq=2:bvhq=1:chroma_opt:quant_type=mpeg:threads=$CPUS:bitrate=-700000 -vf pp=de,pullup,softskip,crop=${CROP_VALUES},scale -zoom -xy 624 $FRAME_RATE -o $OUTPUT_FILE.avi fi ###### fast quality if [[ $Q = 15 ]] ; then # fast H.264 quality (1-pass) # actual one-pass conversion mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=128:vol=3 -ovc x264 -x264encopts subq=4:8x8dct:bframes=2:b_pyramid=normal:weight_b:threads=auto:bitrate=-700000 -vf pp=de,pullup,softskip,crop=${CROP_VALUES},scale -zoom -xy 624 $FRAME_RATE -o $OUTPUT_FILE.avi fi if [[ $Q = 16 ]] ; then # fast MPEG4 quality (1-pass) # actual one-pass conversion mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=128:vol=3 -ovc lavc $DIVX -lavcopts vcodec=mpeg4:mbd=2:trell:v4mv:turbo:vhq:threads=$CPUS:vbitrate=1100 -vf pp=de,pullup,softskip,crop=${CROP_VALUES},scale -zoom -xy 624 $FRAME_RATE -o $OUTPUT_FILE.avi fi if [[ $Q = 17 ]] ; then # fast XVID quality (1-pass) # actual one-pass conversion mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=128:vol=3 -ovc xvid -xvidencopts turbo:vhq=0:threads=$CPUS:bitrate=-700000 -vf pp=de,pullup,softskip,crop=${CROP_VALUES},scale -zoom -xy 624 $FRAME_RATE -o $OUTPUT_FILE.avi fi ###### YouTube quality if [[ $Q = 18 ]] ; then # YouTube MPEG4 quality (1-pass) mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=128:vol=3 -ovc lavc $DIVX -lavcopts vcodec=mpeg4:threads=$CPUS -ffourcc xvid -vf scale=320:-2,expand=:240:::1 $FRAME_RATE -o $OUTPUT_FILE.avi fi ###### realtime quality if [[ $Q = 19 ]] ; then # realtime MPEG4 quality (1-pass) # actual one-pass conversion mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=128:vol=3 -ovc lavc $DIVX -lavcopts vcodec=mpeg4:mbd=2:turbo:vhq:threads=$CPUS:vbitrate=1100 -vf pp=de,pullup,softskip,crop=${CROP_VALUES},scale -zoom -xy 624 $FRAME_RATE -o $OUTPUT_FILE.avi fi if [[ $Q = 20 ]] ; then # realtime XVID quality (1-pass) # actual one-pass conversion mencoder $INPUT_FILE -oac mp3lame -lameopts abr:br=128:vol=3 -ovc xvid -xvidencopts turbo:nochroma_me:notrellis:max_bframes=0:vhq=0:threads=$CPUS:bitrate=-700000 -vf pp=de,pullup,softskip,crop=${CROP_VALUES},scale -zoom -xy 624 $FRAME_RATE -o $OUTPUT_FILE.avi fi ###### low quality if [[ $Q = 21 ]] ; then # low WMV quality (1-pass) # actual one-pass conversion mencoder $INPUT_FILE -oac mp3lame -lameopts cbr:br=16:vol=3 -ovc lavc -lavcopts vcodec=wmv2:vbitrate=100 -vf scale -zoom -xy 240 $FRAME_RATE -o $OUTPUT_FILE.wmv fi ####################### Custom quality if [[ $Q = 22 ]] ; then # If 22 passed, use custom quality (1-pass and 2-pass) ####################### Custom type options echo -n "What type of AVI do you want to create with custom settings?: (1) H.264 (2-Pass) (2) H.264 (1-Pass) (3) DIVX/MPEG-4 (2-Pass) (4) DIVX/MPEG-4 (1-Pass) (5) XVID (2-Pass) (6) XVID (1-Pass) Press 'Enter' for default (default is '6')... " read MPEG4_TYPE ###### extra blank space echo " " ###### default ###### if [[ -z $MPEG4_TYPE ]] ; then # If no media passed, default to 6 MPEG4_TYPE=6 fi ####################### Custom Divx ffourcc menu ###### DivX ffourcc menu if [[ $MPEG4_TYPE != 1 && $MPEG4_TYPE != 2 && $MPEG4_TYPE != 5 && $MPEG4_TYPE != 6 ]] ; then echo -n "Select the desired Divx or generic MPEG4 quality: (1) FFMPEG MPEG-4 (2) DivX MPEG-4 Version 4 (3) DivX MPEG-4 Version 5 Press 'Enter' for default (default is '3')... " read CUSTOM_DIVX_NUMBER ###### extra blank space echo " " ###### default if [[ -z $CUSTOM_DIVX_NUMBER ]] ; then # If no file passed, default to 3 CUSTOM_DIVX="-ffourcc DX50" fi ###### preset if [[ $CUSTOM_DIVX_NUMBER = 1 ]] ; then CUSTOM_DIVX= fi if [[ $CUSTOM_DIVX_NUMBER = 2 ]] ; then CUSTOM_DIVX="-ffourcc DIVX" fi if [[ $CUSTOM_DIVX_NUMBER = 3 ]] ; then CUSTOM_DIVX="-ffourcc DX50" fi fi ####################### Custom scaling echo -n "Choose a resolution: (1) original resolution(cropped, but no scaling) (2) 624 x 352 scaling (fullscreen/widescreen) (3) 624 x ??? scaling (fullscreen/widescreen) (auto-height) (4) 800 x 600 scaling (fullscreen) (5) 800 x ??? scaling (fullscreen) (auto-height) (6) 600 x 400 scaling (widescreen) (7) 600 x ??? scaling (widescreen) (auto-height) (8) 640 x 480 scaling (fullscreen) (9) 640 x ??? scaling (fullscreen) (auto-height) (10) 704 x 294 scaling (widescreen) (2.35:1) (11) 704 x ??? scaling (widescreen) (2.35:1) (auto-height) (12) 768 x 432 scaling (widescreen) (16:9) (13) 768 x ??? scaling (widescreen) (16:9) (auto-height) (14) custom Press 'Enter' for default (default is '3')... " read SCALING_NUMBER ###### extra blank space echo " " ###### default if [[ -z $SCALING_NUMBER ]] ; then # If no file passed, default to 3 SCALING="scale -zoom -xy 624" fi ###### preset if [[ $SCALING_NUMBER = 1 ]] ; then SCALING="scale=${CROP_VALUES}" fi if [[ $SCALING_NUMBER = 2 ]] ; then SCALING="scale=624:352" fi if [[ $SCALING_NUMBER = 3 ]] ; then SCALING="scale -zoom -xy 624" fi if [[ $SCALING_NUMBER = 4 ]] ; then SCALING="scale=800:600" fi if [[ $SCALING_NUMBER = 5 ]] ; then SCALING="scale -zoom -xy 800" fi if [[ $SCALING_NUMBER = 6 ]] ; then SCALING="scale=600:400" fi if [[ $SCALING_NUMBER = 7 ]] ; then SCALING="scale -zoom -xy 600" fi if [[ $SCALING_NUMBER = 8 ]] ; then SCALING="scale=640:480" fi if [[ $SCALING_NUMBER = 9 ]] ; then SCALING="scale -zoom -xy 640" fi if [[ $SCALING_NUMBER = 10 ]] ; then SCALING="scale=704:294" fi if [[ $SCALING_NUMBER = 11 ]] ; then SCALING="sscale -zoom -xy 704" fi if [[ $SCALING_NUMBER = 12 ]] ; then SCALING="scale=768:432" fi if [[ $SCALING_NUMBER = 13 ]] ; then SCALING="scale -zoom -xy 768" fi ###### custom if [[ $SCALING_NUMBER = 14 ]] ; then echo -n "Please enter a custom scale: " echo -n "...like this: 'scale=800:600' or 'scale -zoom -xy 624'..." read CUSTOM_SCALING SCALING=$CUSTOM_SCALING fi ####################### Custom total/video bitrate level echo -n "Select a total/video bitrate level: (1) -350000 (= max file size of ~ 350MB) (H.264/XVID only) (2) -700000 (= max file size of ~ 700MB) (H.264/XVID only) (3) -1000000 (= max file size of ~ 1GB) (H.264/XVID only) (4) 400 kbps (5) 600 kbps (6) 800 kbps (7) 1000 kbps (8) 1100 kbps (9) 1150 kbps (10) 1200 kbps (11) 1250 kbps (12) 1500 kbps (13) 2000 kbps (14) 3000 kbps (15) 4000 kbps (16) 5000 kbps (17) custom Press 'Enter' for default (default is '2')... " read BITRATE_NUMBER ###### extra blank space echo " " ###### default if [[ -z $BITRATE_NUMBER ]] ; then # If no file passed, default to 2 BITRATE=-700000 fi ###### preset if [[ $BITRATE_NUMBER = 1 ]] ; then BITRATE=-350000 fi if [[ $BITRATE_NUMBER = 2 ]] ; then BITRATE=-700000 fi if [[ $BITRATE_NUMBER = 3 ]] ; then BITRATE=-1000000 fi if [[ $BITRATE_NUMBER = 4 ]] ; then BITRATE=400 fi if [[ $BITRATE_NUMBER = 5 ]] ; then BITRATE=600 fi if [[ $BITRATE_NUMBER = 6 ]] ; then BITRATE=800 fi if [[ $BITRATE_NUMBER = 7 ]] ; then BITRATE=1000 fi if [[ $BITRATE_NUMBER = 8 ]] ; then BITRATE=1100 fi if [[ $BITRATE_NUMBER = 9 ]] ; then BITRATE=1150 fi if [[ $BITRATE_NUMBER = 10 ]] ; then BITRATE=1200 fi if [[ $BITRATE_NUMBER = 11 ]] ; then BITRATE=1250 fi if [[ $BITRATE_NUMBER = 12 ]] ; then BITRATE=1500 fi if [[ $BITRATE_NUMBER = 13 ]] ; then BITRATE=2000 fi if [[ $BITRATE_NUMBER = 14 ]] ; then BITRATE=3000 fi if [[ $BITRATE_NUMBER = 15 ]] ; then BITRATE=4000 fi if [[ $BITRATE_NUMBER = 16 ]] ; then BITRATE=5000 fi ###### custom if [[ $BITRATE_NUMBER = 17 ]] ; then echo -n "Please enter a custom total/video bitrate: " echo -n "...like this: '1175'..." read CUSTOM_BITRATE BITRATE=$CUSTOM_BITRATE fi ####################### Custom audio track echo -n "Select an audio track: (1) -aid 0 (good when getting no audio with others) (ex.: Custom DVD rips) (2) -aid 127 (3) -aid 128 (often main language non-director's commentary audio track) (4) -aid 129 (often second track, such as director's commentary) (5) -aid 130 (6) -aid 131 (7) -aid 132 (8) -aid 160 (9) custom Press 'Enter' for default (default is 'null', which is DVD default)... " read AUDIO_TRACK_NUMBER ###### extra blank space echo " " ###### default if [[ -z $AUDIO_TRACK_NUMBER ]] ; then # If no file passed, default to null AUDIO_TRACK= fi ###### preset if [[ $AUDIO_TRACK_NUMBER = 1 ]] ; then AUDIO_TRACK="-aid 0" fi if [[ $AUDIO_TRACK_NUMBER = 2 ]] ; then AUDIO_TRACK="-aid 127" fi if [[ $AUDIO_TRACK_NUMBER = 3 ]] ; then AUDIO_TRACK="-aid 128" fi if [[ $AUDIO_TRACK_NUMBER = 4 ]] ; then AUDIO_TRACK="-aid 129" fi if [[ $AUDIO_TRACK_NUMBER = 5 ]] ; then AUDIO_TRACK="-aid 130" fi if [[ $AUDIO_TRACK_NUMBER = 6 ]] ; then AUDIO_TRACK="-aid 131" fi if [[ $AUDIO_TRACK_NUMBER = 7 ]] ; then AUDIO_TRACK="-aid 132" fi if [[ $AUDIO_TRACK_NUMBER = 8 ]] ; then AUDIO_TRACK="-aid 160" fi ###### custom if [[ $AUDIO_TRACK_NUMBER = 9 ]] ; then echo -n "Please enter a custom audio track: " echo -n "...like this: '-aid 128'..." read CUSTOM_AUDIO_TRACK AUDIO_TRACK=$CUSTOM_AUDIO_TRACK fi ####################### Custom audio track language echo -n "Select an audio track language: (1) Chinese - zh (2) Dansk (Danish) - da (3) Deutsch - de (4) English - en (5) Español - es (6) Français - fr (7) Greek - el (8) Italiano (Italian) - it (9) Japanese - ja (10) Korean - ko (11) Nederlands - nl (12) Polish - pl (13) Portugues - pt (14) Russian - ru Or input your own (like this: 'en')... Press 'Enter' for default (default is 'null', which is DVD default)... " read AUDIO_LANGUAGE_NUMBER ###### extra blank space echo " " ###### default if [[ -z $AUDIO_LANGUAGE_NUMBER ]] ; then # If no file passed, default to null AUDIO_LANGUAGE= fi ###### preset if [[ $AUDIO_LANGUAGE_NUMBER = 1 ]] ; then AUDIO_LANGUAGE="-alang zh" fi if [[ $AUDIO_LANGUAGE_NUMBER = 2 ]] ; then AUDIO_LANGUAGE="-alang da" fi if [[ $AUDIO_LANGUAGE_NUMBER = 3 ]] ; then AUDIO_LANGUAGE="-alang de" fi if [[ $AUDIO_LANGUAGE_NUMBER = 4 ]] ; then AUDIO_LANGUAGE="-alang en" fi if [[ $AUDIO_LANGUAGE_NUMBER = 5 ]] ; then AUDIO_LANGUAGE="-alang es" fi if [[ $AUDIO_LANGUAGE_NUMBER = 6 ]] ; then AUDIO_LANGUAGE="-alang fr" fi if [[ $AUDIO_LANGUAGE_NUMBER = 7 ]] ; then AUDIO_LANGUAGE="-alang el" fi if [[ $AUDIO_LANGUAGE_NUMBER = 8 ]] ; then AUDIO_LANGUAGE="-alang it" fi if [[ $AUDIO_LANGUAGE_NUMBER = 9 ]] ; then AUDIO_LANGUAGE="-alang ja" fi if [[ $AUDIO_LANGUAGE_NUMBER = 10 ]] ; then AUDIO_LANGUAGE="-alang ko" fi if [[ $AUDIO_LANGUAGE_NUMBER = 11 ]] ; then AUDIO_LANGUAGE="-alang nl" fi if [[ $AUDIO_LANGUAGE_NUMBER = 12 ]] ; then AUDIO_LANGUAGE="-alang pl" fi if [[ $AUDIO_LANGUAGE_NUMBER = 13 ]] ; then AUDIO_LANGUAGE="-alang pt" fi if [[ $AUDIO_LANGUAGE_NUMBER = 14 ]] ; then AUDIO_LANGUAGE="-alang ru" fi ####################### Custom audio bitrate level echo -n "Select an audio bitrate level: (1) 48 kbps (2) 64 kbps (3) 128 kbps (4) 160 kbps (5) 192 kbps (6) 224 kbps (7) 256 kbps (8) 320 kbps (9) custom Press 'Enter' for default (default is '3')... " read AUDIO_BITRATE_NUMBER ###### extra blank space echo " " ###### default if [[ -z $AUDIO_BITRATE_NUMBER ]] ; then # If no file passed, default to 3 AUDIO_BITRATE=128 fi ###### preset if [[ $AUDIO_BITRATE_NUMBER = 1 ]] ; then AUDIO_BITRATE=48 fi if [[ $AUDIO_BITRATE_NUMBER = 2 ]] ; then AUDIO_BITRATE=96 fi if [[ $AUDIO_BITRATE_NUMBER = 3 ]] ; then AUDIO_BITRATE=128 fi if [[ $AUDIO_BITRATE_NUMBER = 4 ]] ; then AUDIO_BITRATE=160 fi if [[ $AUDIO_BITRATE_NUMBER = 5 ]] ; then AUDIO_BITRATE=192 fi if [[ $AUDIO_BITRATE_NUMBER = 6 ]] ; then AUDIO_BITRATE=224 fi if [[ $AUDIO_BITRATE_NUMBER = 7 ]] ; then AUDIO_BITRATE=256 fi if [[ $AUDIO_BITRATE_NUMBER = 8 ]] ; then AUDIO_BITRATE=320 fi ###### custom if [[ $AUDIO_BITRATE_NUMBER = 9 ]] ; then echo -n "Please enter a custom audio bitrate level: " echo -n "...like this: '100'..." read CUSTOM_AUDIO_BITRATE AUDIO_BITRATE=$CUSTOM_AUDIO_BITRATE fi ####################### Custom audio bitrate type echo -n "Select an audio bitrate type: (1) Average Bitrate (2) Constant Bitrate (3) Variable Bitrate Press 'Enter' for default (default is '1')... " read AUDIO_BITRATE_TYPE_NUMBER ###### extra blank space echo " " ###### default if [[ -z $AUDIO_BITRATE_TYPE_NUMBER ]] ; then # If no file passed, default to abr AUDIO_BITRATE_TYPE=abr fi ###### preset if [[ $AUDIO_BITRATE_TYPE_NUMBER = 1 ]] ; then AUDIO_BITRATE_TYPE=abr fi if [[ $AUDIO_BITRATE_TYPE_NUMBER = 2 ]] ; then AUDIO_BITRATE_TYPE=cbr fi if [[ $AUDIO_BITRATE_TYPE_NUMBER = 3 ]] ; then AUDIO_BITRATE_TYPE=vbr fi ####################### Custom audio volume level echo -n "Select an audio volume increase level (1-10): Press 'Enter' for default (default is '3')... " read AUDIO_VOLUME_LEVEL ###### extra blank space echo " " ###### default if [[ -z $AUDIO_VOLUME_LEVEL ]] ; then # If no file passed, default to 3 AUDIO_VOLUME_LEVEL=3 fi ####################### Subtitles? echo -n "Do you want subtitles?: (1) No (2) Yes (DVD/ISO only) Press 'Enter' for default (default is '1', for no subtitles)... " read SUBTITLE_NUMBER ###### extra blank space echo " " ###### default if [[ -z $SUBTITLE_NUMBER ]] ; then # If no file passed, default to null SUBTITLE_TRACK= SUBTITLE_LANGUAGE= SUBTITLE_TYPE= fi ###### preset if [[ $SUBTITLE_NUMBER = 1 ]] ; then SUBTITLE_TRACK= SUBTITLE_LANGUAGE= SUBTITLE_TYPE= fi if [[ $SUBTITLE_NUMBER = 2 ]] ; then ####################### Custom subtitle track echo -n "Select a subtitle track: (1) -sid 0 (2) -sid 1 (3) -sid 2 (4) -sid 3 (5) -sid 4 (6) -sid 5 (7) -sid 6 (8) -sid 7 (9) custom Press 'Enter' for default (default is 'null')... " read SUBTITLE_TRACK_NUMBER ###### extra blank space echo " " ###### default if [[ -z $SUBTITLE_TRACK_NUMBER ]] ; then # If no file passed, default to null SUBTITLE_TRACK= fi ###### preset if [[ $SUBTITLE_TRACK_NUMBER = 1 ]] ; then SUBTITLE_TRACK="-sid 0" fi if [[ $SUBTITLE_TRACK_NUMBER = 2 ]] ; then SUBTITLE_TRACK="-sid 1" fi if [[ $SUBTITLE_TRACK_NUMBER = 3 ]] ; then SUBTITLE_TRACK="-sid 2" fi if [[ $SUBTITLE_TRACK_NUMBER = 4 ]] ; then SUBTITLE_TRACK="-sid 3" fi if [[ $SUBTITLE_TRACK_NUMBER = 5 ]] ; then SUBTITLE_TRACK="-sid 4" fi if [[ $SUBTITLE_TRACK_NUMBER = 6 ]] ; then SUBTITLE_TRACK="-sid 5" fi if [[ $SUBTITLE_TRACK_NUMBER = 7 ]] ; then SUBTITLE_TRACK="-sid 6" fi if [[ $SUBTITLE_TRACK_NUMBER = 8 ]] ; then SUBTITLE_TRACK="-sid 7" fi ###### custom if [[ $SUBTITLE_TRACK_NUMBER = 9 ]] ; then echo -n "Please enter a custom subtitles track: " echo -n "...like this: '-sid 10'..." read CUSTOM_SUBTITLE_TRACK SUBTITLE_TRACK=$CUSTOM_SUBTITLE_TRACK fi ####################### Custom subtitles track language echo -n "Select a subtitles track language: (1) Chinese - zh (2) Dansk (Danish) - da (3) Deutsch - de (4) English - en (5) Español - es (6) Français - fr (7) Greek - el (8) Italiano (Italian) - it (9) Japanese - ja (10) Korean - ko (11) Nederlands - nl (12) Polish - pl (13) Portugues - pt (14) Russian - ru Or input your own (like this: 'en')... Press 'Enter' for default (default is 'null')... " read SUBTITLE_LANGUAGE_NUMBER ###### extra blank space echo " " ###### default if [[ -z $SUBTITLE_LANGUAGE_NUMBER ]] ; then # If no file passed, default to null SUBTITLE_LANGUAGE= fi ###### preset if [[ $SUBTITLE_LANGUAGE_NUMBER = 1 ]] ; then SUBTITLE_LANGUAGE="-slang zh" fi if [[ $SUBTITLE_LANGUAGE_NUMBER = 2 ]] ; then SUBTITLE_LANGUAGE="-slang da" fi if [[ $SUBTITLE_LANGUAGE_NUMBER = 3 ]] ; then SUBTITLE_LANGUAGE="-slang de" fi if [[ $SUBTITLE_LANGUAGE_NUMBER = 4 ]] ; then SUBTITLE_LANGUAGE="-slang en" fi if [[ $SUBTITLE_LANGUAGE_NUMBER = 5 ]] ; then SUBTITLE_LANGUAGE="-slang es" fi if [[ $SUBTITLE_LANGUAGE_NUMBER = 6 ]] ; then SUBTITLE_LANGUAGE="-slang fr" fi if [[ $SUBTITLE_LANGUAGE_NUMBER = 7 ]] ; then SUBTITLE_LANGUAGE="-slang el" fi if [[ $SUBTITLE_LANGUAGE_NUMBER = 8 ]] ; then SUBTITLE_LANGUAGE="-slang it" fi if [[ $SUBTITLE_LANGUAGE_NUMBER = 9 ]] ; then SUBTITLE_LANGUAGE="-slang ja" fi if [[ $SUBTITLE_LANGUAGE_NUMBER = 10 ]] ; then SUBTITLE_LANGUAGE="-slang ko" fi if [[ $SUBTITLE_LANGUAGE_NUMBER = 11 ]] ; then SUBTITLE_LANGUAGE="-slang nl" fi if [[ $SUBTITLE_LANGUAGE_NUMBER = 12 ]] ; then SUBTITLE_LANGUAGE="-slang pl" fi if [[ $SUBTITLE_LANGUAGE_NUMBER = 13 ]] ; then SUBTITLE_LANGUAGE="-slang pt" fi if [[ $SUBTITLE_LANGUAGE_NUMBER = 14 ]] ; then SUBTITLE_LANGUAGE="-slang ru" fi ####################### Subtitle Kind? echo -n "What kind of subtitles do you prefer?: (1) Embed onto the video (2) Embed into a separate file Press 'Enter' for default (default is '1')... " read SUBTITLE_TYPE_NUMBER ###### extra blank space echo " " ###### default if [[ -z $SUBTITLE_TYPE_NUMBER ]] ; then # If no file passed, default to null SUBTITLE_TYPE= fi ###### preset if [[ $SUBTITLE_TYPE_NUMBER = 1 ]] ; then SUBTITLE_TYPE= fi if [[ $SUBTITLE_TYPE_NUMBER = 2 ]] ; then SUBTITLE_TYPE="-vobsubout ${OUTPUT_FILE}" fi ###### closes the preset of 'yes' for subtitles fi ####################### Custom conversion is starting ###### extra blank space echo " " ###### custom conversion is starting message read -sn 1 -p "Your custom conversion is about to begin, press any key to continue..." ####################### Custom conversions (very high quality settings) ###### custom preset ###### ###### H.264 if [[ $MPEG4_TYPE = 1 ]] ; then # actual two-pass conversion mencoder $INPUT_FILE $AUDIO_TRACK $AUDIO_LANGUAGE $SUBTITLE_TRACK $SUBTITLE_LANGUAGE $SUBTITLE_TYPE -nosound -ovc x264 -x264encopts pass=1:subq=1:partitions=all:8x8dct:me=umh:frameref=1:bframes=3:b_pyramid=normal:weight_b:threads=auto:bitrate=$BITRATE -vf pp=de,pullup,softskip,harddup,crop=${CROP_VALUES},$SCALING $FRAME_RATE -o '/dev/null' mencoder $INPUT_FILE $AUDIO_TRACK $AUDIO_LANGUAGE $SUBTITLE_TRACK $SUBTITLE_LANGUAGE $SUBTITLE_TYPE -oac mp3lame -lameopts $AUDIO_BITRATE_TYPE:br=$AUDIO_BITRATE:vol=$AUDIO_VOLUME_LEVEL -ovc x264 -x264encopts pass=2:subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid=normal:weight_b:threads=auto:bitrate=$BITRATE -vf pp=de,pullup,softskip,harddup,crop=${CROP_VALUES},$SCALING $FRAME_RATE -o $OUTPUT_FILE.avi fi if [[ $MPEG4_TYPE = 2 ]] ; then # actual one-pass conversion mencoder $INPUT_FILE $AUDIO_TRACK $AUDIO_LANGUAGE $SUBTITLE_TRACK $SUBTITLE_LANGUAGE $SUBTITLE_TYPE -oac mp3lame -lameopts $AUDIO_BITRATE_TYPE:br=$AUDIO_BITRATE:vol=$AUDIO_VOLUME_LEVEL -ovc x264 -x264encopts subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=3:b_pyramid=normal:weight_b:threads=auto:bitrate=$BITRATE -vf pp=de,pullup,softskip,crop=${CROP_VALUES},$SCALING $FRAME_RATE -o $OUTPUT_FILE.avi fi ###### MPEG4 if [[ $MPEG4_TYPE = 3 ]] ; then # actual two-pass conversion mencoder $INPUT_FILE $AUDIO_TRACK $AUDIO_LANGUAGE $SUBTITLE_TRACK $SUBTITLE_LANGUAGE $SUBTITLE_TYPE -nosound -ovc lavc $CUSTOM_DIVX -lavcopts vpass=1:vcodec=mpeg4:mbd=2:trell:v4mv:last_pred=2:dia=-1:vmax_b_frames=2:vb_strategy=1:cmp=3:subcmp=3:precmp=0:vqcomp=0.6:turbo:threads=$CPUS:vbitrate=$BITRATE -vf pp=de,pullup,softskip,crop=${CROP_VALUES},$SCALING $FRAME_RATE -o '/dev/null' mencoder $INPUT_FILE $AUDIO_TRACK $AUDIO_LANGUAGE $SUBTITLE_TRACK $SUBTITLE_LANGUAGE $SUBTITLE_TYPE -oac mp3lame -lameopts $AUDIO_BITRATE_TYPE:br=$AUDIO_BITRATE:vol=$AUDIO_VOLUME_LEVEL -ovc lavc $CUSTOM_DIVX -lavcopts vpass=2:vcodec=mpeg4:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:predia=2:dia=2:vmax_b_frames=2:vb_strategy=1:precmp=2:cmp=2:subcmp=2:preme=2:qns=2:threads=$CPUS:vbitrate=$BITRATE -vf pp=de,pullup,softskip,crop=${CROP_VALUES},$SCALING $FRAME_RATE -o $OUTPUT_FILE.avi fi if [[ $MPEG4_TYPE = 4 ]] ; then # actual one-pass conversion mencoder $INPUT_FILE $AUDIO_TRACK $AUDIO_LANGUAGE $SUBTITLE_TRACK $SUBTITLE_LANGUAGE $SUBTITLE_TYPE -oac mp3lame -lameopts $AUDIO_BITRATE_TYPE:br=$AUDIO_BITRATE:vol=$AUDIO_VOLUME_LEVEL -ovc lavc $CUSTOM_DIVX -lavcopts vcodec=mpeg4:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:predia=2:dia=2:vmax_b_frames=2:vb_strategy=1:precmp=2:cmp=2:subcmp=2:preme=2:qns=2:threads=$CPUS:vbitrate=$BITRATE -vf pp=de,pullup,softskip,crop=${CROP_VALUES},$SCALING $FRAME_RATE -o $OUTPUT_FILE.avi fi ###### XVID if [[ $MPEG4_TYPE = 5 ]] ; then # actual two-pass conversion mencoder $INPUT_FILE $AUDIO_TRACK $AUDIO_LANGUAGE $SUBTITLE_TRACK $SUBTITLE_LANGUAGE $SUBTITLE_TYPE -nosound -ovc xvid -xvidencopts pass=1:chroma_opt:vhq=1:bvhq=1:quant_type=mpeg:threads=$CPUS:bitrate=$BITRATE -vf pp=de,pullup,softskip,crop=${CROP_VALUES},$SCALING $FRAME_RATE -o '/dev/null' mencoder $INPUT_FILE $AUDIO_TRACK $AUDIO_LANGUAGE $SUBTITLE_TRACK $SUBTITLE_LANGUAGE $SUBTITLE_TYPE -oac mp3lame -lameopts $AUDIO_BITRATE_TYPE:br=$AUDIO_BITRATE:vol=$AUDIO_VOLUME_LEVEL -ovc xvid -xvidencopts pass=2:chroma_opt:vhq=4:bvhq=1:quant_type=mpeg:threads=$CPUS:bitrate=$BITRATE -vf pp=de,pullup,softskip,crop=${CROP_VALUES},$SCALING $FRAME_RATE -o $OUTPUT_FILE.avi fi if [[ $MPEG4_TYPE = 6 ]] ; then # actual one-pass conversion mencoder $INPUT_FILE $AUDIO_TRACK $AUDIO_LANGUAGE $SUBTITLE_TRACK $SUBTITLE_LANGUAGE $SUBTITLE_TYPE -oac mp3lame -lameopts $AUDIO_BITRATE_TYPE:br=$AUDIO_BITRATE:vol=$AUDIO_VOLUME_LEVEL -ovc xvid -xvidencopts chroma_opt:vhq=4:bvhq=1:quant_type=mpeg:threads=$CPUS:bitrate=$BITRATE -vf pp=de,pullup,softskip,crop=${CROP_VALUES},$SCALING $FRAME_RATE -o $OUTPUT_FILE.avi fi ####################### Close the custom quality option #17 fi ####################### Cleanup if [ -f mplayer.tmp ];then rm mplayer.tmp fi if [ -f divx2pass.log ];then rm divx2pass.log fi ####################### Conversion finished notifications ###### extra blank spaces echo " " ###### notifications notify-send -t 7000 -i /usr/share/icons/gnome/32x32/status/info.png "Conversion Finished" ; espeak "Conversion Finished" # extra blank spaces echo " " read -sn 1 -p "Your conversion has finished, press any key to continue and close this terminal session..." } function video2dvd() { # video2dvd - Make a DVD ISO from a video file # Burn ISO after script runs # # Author - Inameiname # # Version: 1.0 # # Usage - video2dvd $1 # Run this script either from the terminal or by right clicking the video file and selecting the script # Ensure 'export VIDEO_FORMAT=NTSC' is in '~/.bashrc' or '~/.bash.profile' OR that its below ########## # See if the Nautilus environment variable is empty if [ -z $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS ]; then # If it's blank, set it equal to $1 NAUTILUS_SCRIPT_SELECTED_FILE_PATHS=$1 fi # Loop through the list (from either Nautilus or the command line) for ARCHIVE_FULLPATH in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS; do NEWDIRNAME=${ARCHIVE_FULLPATH%.*} FILENAME=${ARCHIVE_FULLPATH##*/} NAME=${ARCHIVE_FULLPATH##*/.*} ###### open and run all of the following in a terminal window tty -s; if [ $? -ne 0 ]; then gnome-terminal -e "$0"; exit; fi ###### be sure there is a "VIDEO_FORMAT=" specified export VIDEO_FORMAT=NTSC ###### cd to the video file's folder mkdir "$NEWDIRNAME" cd "$NEWDIRNAME" cd .. rmdir "$NEWDIRNAME" ###### check to see if the file is an mpg/vob file; if not, convert it and rename the mpeg file to "dvd_movie.mpg" echo 'Is this video file not already a DVD-compliant MPEG file (MPEG/mpeg/MPG/mpg/VOB/vob), 1 for true 0 for false? ' read MEDIA_TYPE if [ "$MEDIA_TYPE" -eq 1 ] ; then ###### convert the video file to '.mpg' ffmpeg -i "$ARCHIVE_FULLPATH" -target ntsc-dvd -acodec mp2 -ab 224 -sameq "$NEWDIRNAME".mpg notify-send -t 5000 -i /usr/share/icons/gnome/32x32/status/info.png "Conversion to an MPEG File Finished" ###### rename the '.mpg' file to "dvd_movie.mpg" mv -fv "$NEWDIRNAME".mpg "dvd_movie.mpg" else ###### rename the mpg/mpeg/vob file to "dvd_movie.mpg" mv -fv "$ARCHIVE_FULLPATH" "dvd_movie.mpg" fi ###### create a "dvdauthor.xml" file - (save in the same directory as movie file) cat > "dvdauthor.xml" <<"End-of-message" End-of-message ###### the actual mpg/mpeg/vob conversion to dvd-compliant folders dvdauthor -x dvdauthor.xml ###### rename the mpg/mpeg/vob file from "dvd_movie.mpg" back to the original if [ "$MEDIA_TYPE" -eq 1 ] ; then ###### rename the '.mpg' file to "dvd_movie.mpg" mv -fv "dvd_movie.mpg" "$NEWDIRNAME".mpg else ###### rename the mpg/mpeg/vob file to "dvd_movie.mpg" mv -fv "dvd_movie.mpg" "$ARCHIVE_FULLPATH" fi ###### rename the 'DVD' file to same name as the original mv -fv "DVD" "$NEWDIRNAME" ###### remove the "dvdauthor.xml" file created and used from this script rm -fv -R dvdauthor.xml ###### convert the dvd-compliant folders to an ISO echo 'Would you like to create an ISO from the DVD-complaint folders now, 1 for true 0 for false? ' read boole if [ $boole -eq 1 ]; then cd "$NEWDIRNAME" mkisofs -v -dvd-video -o "$NEWDIRNAME.iso" . cd .. notify-send -t 2000 -i /usr/share/icons/gnome/32x32/status/info.png "ISO created" else notify-send -t 2000 -i /usr/share/icons/gnome/32x32/status/info.png "no ISO created" fi ###### option to burn the ISO echo 'Would you like to burn this disc now, 1 for true 0 for false? ' read boole1 if [ $boole1 -eq 1 ]; then # to get desired device df -h -x tmpfs -x usbfs echo -n "Please enter the appropriate DVD drive: (1) /dev/dvd (2) /dev/sr0 (3) /dev/sr1 (4) /dev/sr2 (5) custom Press 'Enter' for default (default is '1')... " read DEVICE_NUMBER # extra blank space echo " " # default if [[ -z $DEVICE_NUMBER ]] ; then # If no device passed, default to /dev/dvd DEVICE=/dev/dvd fi # preset if [[ $DEVICE_NUMBER = 1 ]] ; then DEVICE=/dev/dvd fi if [[ $DEVICE_NUMBER = 2 ]] ; then DEVICE=/dev/sr0 fi if [[ $DEVICE_NUMBER = 3 ]] ; then DEVICE=/dev/sr1 fi if [[ $DEVICE_NUMBER = 4 ]] ; then DEVICE=/dev/sr2 fi # custom if [[ $DEVICE_NUMBER = 5 ]] ; then echo -n "Please enter the appropriate DVD drive: " echo -n "...like this: '/dev/dvd'..." read CUSTOM_DEVICE DEVICE=$CUSTOM_DEVICE fi growisofs -dvd-compat -speed=1 -Z "$DEVICE"="$NEWDIRNAME" notify-send -t 2000 -i /usr/share/icons/gnome/32x32/status/info.png "DVD burned" else notify-send -t 2000 -i /usr/share/icons/gnome/32x32/status/info.png "no DVD burned" fi ###### notify-send notification showing when the job has finished notify-send -t 5000 -i /usr/share/icons/gnome/32x32/status/info.png "All Conversions Finished" done } ############ Audio ############ ###### rip audio from video # ("$1" for output file & "$2" for input file) function audioextract() { mplayer -ao pcm -vo null -vc dummy -dumpaudio -dumpfile "$1" "$2" } function flac2mp3() # Author: Josh Bailey # Email: jbsnake usalug.org # call this like: # flac2mp3 /path/to/source/file.flac /path/to/destination # needs: getFileName function; flac encoder/decoder; lame { local old_file="${1}" local new_dir="${2}" local short_filename=`getFileName "${old_file}"` local new_file="${short_filename:0:${#short_filename}-5}.mp3" flac -d -o - "${old_file}" | lame -b 320 -h - > "${new_dir}/${new_file}" } function flac2ogg() # Author: Josh Bailey # Email: jbsnake usalug.org # call this like: # flac2ogg /path/to/source/file.flac /path/to/destination # needs: getFileName function; flac encoder/decoder; oggenc { local old_file="${1}" local new_dir="${2}" local short_filename=`getFileName "${old_file}"` local new_file="${short_filename:0:${#short_filename}-5}.ogg" ###### get artist and album before release ######### # flac -d -o - "${old_file}" | oggenc -a "$artist" -l "$album" -t "${title}" - -o "${new_dir}/${new_file}" #################################################### local title="${short_filename:0:${#short_filename}-4}" flac -d -o - "${old_file}" | oggenc -t "${title}" - -o "${new_dir}/${new_file}" } alias flvaudio='ffmpeg -i "$1" -f mp3 -vn -acodec copy output.mp3' # extract sound from flv & make mp3 ###### fix MP3 tags encoding (to UTF-8) # batch fixes all MP3s in one directory function mp3_tagging() { find . -iname "*.mp3" -execdir mid3iconv -e {} \; } function ogg2mp3() # Author: Josh Bailey # Email: jbsnake usalug.org # call this like: # ogg2mp3 /path/to/source/file.flac /path/to/destination # needs: getFileName function; oggdec; lame { local old_file="${1}" local new_dir="${2}" local short_filename=`getFileName "${old_file}"` local new_file="${short_filename:0:${#short_filename}-4}.mp3" local info_string=`get_ogg_info "$old_file"` local cartist=`cut -d| -f1 ${info_string}` local ctitle=`cut -d| -f2 ${info_string}` local calbum=`cut -d| -f3 ${info_string}` local cgenre=`cut -d| -f4 ${info_string}` local cdate=`cut -d| -f5 ${info_string}` local ctracknumber=`cut -d| -f6 ${info_string}` oggdec "${old_file}" -o - | lame -b 320 --tt "$ctitle" --ta "$cartist" --tl "$calbum" --ty $cdate --tn $ctracknumber --tg "$cgenre" -h - > "${new_dir}/${new_file}" sleep .5 } function ogg_info() # Author: Josh Bailey # Email: jbsnake usalug.org # call this like: # ogg_info_string=`get_ogg_info "/path/to/file.ogg"` # ofcourse the string would have to be parsed # it is pipe | delimited # in order artist, title, album, genre, date, and track number # inStr function needed; vorbiscomment (comes with oggenc) { local turn="" local index=0 local item="" local cartist="" local ctitle="" local calbum="" local cgenre="" local cdate="" local ctracknumber="" vorbiscomment -l "$1" > info.lst for turn in artist title album genre date tracknumber do tmp_comment=`grep -i "$turn" info.lst` item=`inStr "=" "$tmp_comment"` comment=${tmp_comment:${item}+1} ((index++)) case $index in 1) cartist="$comment"; ;; 2) ctitle="$comment"; ;; 3) calbum="$comment"; ;; 4) cgenre="$comment"; ;; 5) cdate="$comment"; ;; 6) ctracknumber="$comment"; ;; esac done info="${cartist}|${ctitle}|${calbum}|${cgenre}|${cdate}|${ctracknumber}" echo "${info}" rm -f info.lst } alias wma2mp3='for f in *.wma; do ffmpeg -i "$f" -ab 128k "${f%.wma}.mp3" -ab 128K; done' # convert wma to mp3@128k alias wma2ogg='for f in *.wma; do ffmpeg -i "$f" -ab 128k "${f%.wma}.ogg" -ab 128K; done' # convert wma to ogg@128 alias wma2wav='for i in *.wma; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader:file="${i%.wma}.wav" "$i" ; done' # convert wma to wav ###### record audio and use sox to eliminate silence # outputs an ogg file that only contains the audio signal exceeding -45dB # useful for recording radio scanner function audiorecord-45dB() { rec -r 44100 -p | sox -p "audio_name-$(date '+%Y-%m-%d').ogg" silence -l 1 00:00:00.5 -45d -1 00:00:00.5 -45d } ################################################## # Download AUR package using best guess at # # filename # ################################################## function aurget() { local DIR=$HOME/Packages cd $DIR && wget http://aur.archlinux.org/packages/${1}/${1}.tar.gz ls -l } ################################################## # ~/ functions # ################################################## function backupsfolder() { if [ -d $HOME/backups_html ]; then chown -R $USER:www-data $HOME/backups_html chmod 755 $HOME/backups_html find $HOME/backups_html/ -type d -exec chmod 775 {} \; find $HOME/backups_html/ -type f -exec chmod 664 {} \; chmod 755 $HOME fi } function private() { find $HOME -type d -exec chmod 700 {} \; find $HOME -type f -exec chmod 600 {} \; find $HOME/bin -type f -exec chmod +x {} \; find $HOME/.dropbox-dist/dropbox* -type f -exec chmod +x {} \; } function publicfolder() { if [ -d $HOME/public_html ]; then chown -R $USER:www-data $HOME/public_html chmod 755 $HOME/public_html find $HOME/public_html/ -type d -exec chmod 775 {} \; find $HOME/public_html/ -type f -exec chmod 664 {} \; chmod 755 $HOME fi } function setperms() { echo "setting proper permissions in ~/" private public } function wwwrc() { alias mv="mv" mv -f ~/.[a-z]*.html ~/public_html/ chmod 644 ~/public_html/.[a-z]*.html chown $USER:www-data ~/public_html/.[a-z]*.html alias mv="mv -i" } ################################################## # Backup .bash* files # ################################################## function backup_bashfiles() { ARCHIVE="$HOME/bash_dotfiles_$(date +%Y%m%d_%H%M%S).tar.gz"; cd ~ tar -czvf $ARCHIVE .bash_profile .bashrc .bash_functions .bash_aliases .bash_prompt echo "All backed up in $ARCHIVE"; } ################################################## # Creates a backup of the file passed as # # parameter with the date and time # ################################################## function bak() { cp $1 $1_`date +%H:%M:%S_%d-%m-%Y` } ################################################## # Good bash tips for everyone # ################################################## function bashtips() { # copyright 2007 - 2010 Christopher Bratusek cat <> $HOME/.bookmarks . $HOME/.bookmarks elif [[ $1 == "" ]]; then echo "need name for the bookmark." else echo "bookmark go-$1 already exists." fi } function unmark() { # copyright 2007 - 2010 Christopher Bratusek if [[ $(alias | grep -w go-$1= ) != "" ]]; then sed -e "/go-$1/d" -i $HOME/.bookmarks xunalias go-$1 fi } ###### copies/moves files to a bookmarked dir # cto file1.jpg file2.jpg file3.jpg pics function cto() { eval lastarg=\${$#} targetdir=`getBookmark $lastarg` echo "Copying files to $targetdir" if [ -n "$targetdir" ]; then for dir in "$@"; do if [ "$dir" != $lastarg ]; then cp -iv "$dir" "$targetdir" fi done fi } # mto vid1.avi vid2.avi videos function mto() { eval lastarg=\${$#} targetdir=`getBookmark $lastarg` echo "Moving files to $targetdir" if [ -n "$targetdir" ]; then for dir in "$@"; do if [ "$dir" != $lastarg ]; then mv -iv "$dir" "$targetdir" fi done fi } ###### Directory Bookmarks for BASH (c) 2009, Ira Chayut, Version 090927 # DirB and its implementation in this file are the product of, and # copyrighted by Ira Chayut. You are granted a non-exclusive, royalty-free # license to use, reproduce, modify and create derivative works from DirB; # providing that credit is given to DirB as a source material. # The lastest version is available from: http://www.dirb.info/bashDirB. Ira can # be reached at ira@dirb.info. # By default DirB will have the shell echo the current working directory out # to the title bars of Xterm windows. To disable this behavior, comment # out the next line. # PS1="\[\033]0;\w\007\]\t \!> " # If the repository of bookmarks does not exist, create it if [ ! -e ~/.DirB ] then mkdir ~/.DirB fi ###### "d" - Display (or Dereference) a saved bookmark # to use: cd "$(d xxx)" function d() { # if the bookmark exists, then extract its directory path and print it if [ -e ~/.DirB/"$1" ] then sed -e 's/\$CD //' -e 's/\\//g' ~/.DirB/"$1" # if the bookmark does not exists, complain and exit with a failing code else echo bash: DirB: ~/.DirB/"$1" does not exist >&2 false fi } ###### "g" - Go to bookmark function g() { # if no arguments, then just go to the home directory if [ -z "$1" ] then cd else # if $1 is in ~/.DirB and does not begin with ".", then go to it if [ -f ~/.DirB/"$1" -a ${1:0:1} != "." ] then # update the bookmark's timestamp and then execute it touch ~/.DirB/"$1" ; CD=cd source ~/.DirB/"$1" ; # else just do a "cd" to the argument, usually a directory path of "-" else cd "$1" fi fi } ###### "p" - Push a bookmark function p() { # Note, the author's preference is to list the directory stack in a single # column. Thus, the standard behavior of "pushd" and "popd" have been # replaced by discarding the normal output of these commands and using a # "dirs -p" after each one. # if no argument given, then just pushd and print out the directory stack if [ -z "$1" ] then pushd > /dev/null && dirs -p # if $1 is a dash, then just do a "popd" and print out the directory stack elif [ "$1" == "-" ] then popd > /dev/null dirs -p else # if $1 is in ~/.DirB and does not begin with ".", then go to it # and then print out the directory stack if [ -f ~/.DirB/"$1" -a "${1:0:1}" != "." ] then touch ~/.DirB/$1 ; CD=pushd source ~/.DirB/$1 > /dev/null && dirs -p ; # else just do a "pushd" and print out the directory stack else pushd "$1" > /dev/null && dirs -p fi fi } ###### "r" - Remove a saved bookmark function r() { # if the bookmark file exists, remove it if [ -e ~/.DirB/"$1" ] then rm ~/.DirB/"$1" # if the bookmark file does not exist, complain and exit with a failing code else echo bash: DirB: ~/.DirB/"$1" does not exist >&2 false fi } ###### "s" - Save bookmark function s() { if [ -n "$2" ] then # build the bookmark file with the contents "$CD directory_path" ( echo '$CD ' \"$2\" > ~/.DirB/"$1" ;) > /dev/null 2>&1 else # build the bookmark file with the contents "$CD directory_path" ( echo -n '$CD ' > ~/.DirB/"$1" ; pwd | sed "s/ /\\\\ /g" >> ~/.DirB/"$1" ; ) > /dev/null 2>&1 fi # if the bookmark could not be created, print an error message and # exit with a failing return code if [ $? != 0 ] then echo bash: DirB: ~/.DirB/"$1" could not be created >&2 false fi } ###### "sl" - Saved bookmark Listing function sl() { # if the "-l" argument is given, then do a long listing, passing any # remaining arguments to "ls", printing in reverse time order. Pass the # output to "less" to page the output if longer than a screen in length. if [ "$1" == "-l" ] then shift ( cd ~/.DirB ; ls -lt $* | sed -e 's/ */ /g' -e '/^total/d' \ -e 's/^\(... \)\([0-9] \)/\1 \2/' | cut -d ' ' -s -f6- | sed -e '/ [0-9] /s// &/' | less -FX ; ) # else print the short form of the bookmarks in reverse time order else ( cd ~/.DirB ; ls -xt $* ; ) fi } ###### simple bookmark system function getBookmark() { case "$1" in video|vids|vid) echo "~/Videos" ;; # video, vids and vid are shortcuts to use with the functions below, the bookmarked directory is "~/videos" images|img|pics|pictures) echo "~/Pictures";; *) echo "" ;; esac } ###### list contents of a bookmarked dir without # going there: list vids function list() { dir=`getBookmark $1` echo $dir if [ -n "$dir" ]; then ls "$dir" fi } ###### same as "list" but with details: llist vids function llist() { dir=`getBookmark $1` echo $dir if [ -n "$dir" ]; then ll "$dir" fi } ################################################## # Create box of '#' characters around given # # string # ################################################## function box() { t="$1xxxx";c=${2:-#}; echo ${t//?/$c}; echo "$c $1 $c"; echo ${t//?/$c}; } ################################################## # Download all videos in your Boxee queue # ################################################## # Gets all videos in your boxee queue with a URL associated with them and attempts to download each using get_flash_videos function boxeedl() { for i in $(curl -u http://app.boxee.tv/api/get_queue | xml2 | grep /boxeefeed/message/object/url | cut -d "=" -f 2,3); do get_flash_videos $i; done } ################################################## # Randomness # ################################################## ###### This script models Brownian motion: # random wanderings of tiny particles in fluid, as they are buffeted # by random currents and collisions (colloquially known as "Drunkard's Walk") # Author: Mendel Cooper function brownian() { PASSES=500 # Number of particle interactions / marbles. ROWS=10 # Number of "collisions" (or horiz. peg rows). RANGE=3 # 0 - 2 output range from $RANDOM. POS=0 # Left/right position. RANDOM=$$ # Seeds the random number generator from PID of script. declare -a Slots # Array holding cumulative results of passes. NUMSLOTS=21 # Number of slots at bottom of board. function Initialize_Slots() { # Zero out all elements of the array. for i in $( seq $NUMSLOTS ) do Slots[$i]=0 done echo # Blank line at beginning of run. } function Show_Slots() { echo -n " " for i in $( seq $NUMSLOTS ) # Pretty-print array elements. do printf "%3d" ${Slots[$i]} # Allot three spaces per result. done echo # Row of slots: echo " |__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|__|" echo " ^^" echo # Note that if the count within any particular slot exceeds 99, #+ it messes up the display. # Running only(!) 500 passes usually avoids this. } function Move() { # Move one unit right / left, or stay put. Move=$RANDOM # How random is $RANDOM? Well, let's see ... let "Move %= RANGE" # Normalize into range of 0 - 2. case "$Move" in 0 ) ;; # Do nothing, i.e., stay in place. 1 ) ((POS--));; # Left. 2 ) ((POS++));; # Right. * ) echo -n "Error ";; # Anomaly! (Should never occur.) esac } function Play() { # Single pass (inner loop). i=0 while [ "$i" -lt "$ROWS" ] # One event per row. do Move ((i++)); done SHIFT=11 # Why 11, and not 10? let "POS += $SHIFT" # Shift "zero position" to center. (( Slots[$POS]++ )) # DEBUG: echo $POS } function Run() { # Outer loop. p=0 while [ "$p" -lt "$PASSES" ] do Play (( p++ )) POS=0 # Reset to zero. Why? done } # main() Initialize_Slots Run Show_Slots } ###### flip a single coin 1000 times and show results function coin-flip() { SEED=$"(head -1 /dev/urandom | od -N 1 | awk '{ print $2 }')" RANDOM=$SEED SIDES=2 # A coin has 2 sides. MAXTHROWS=1000 # Increase this if you have nothing better to do with your time. throw=0 # Throw count. heads=0 # Must initialize counts to zero, tails=0 # since an uninitialized variable is null, not zero. function print_result() { echo echo "heads = $heads" echo "tails = $tails" echo } function update_count() { case "$1" in 0) let "heads += 1";; # Since coin has no "zero", this corresponds to 1. 1) let "tails += 1";; # And this to 2, etc. esac } echo while [ "$throw" -lt "$MAXTHROWS" ] do let "coin1 = RANDOM % $SIDES" update_count $coin1 let "throw += 1" done print_result echo "Out of a total of "$MAXTHROWS" tosses." echo "Change \"MAXTHROWS=1000\" if you want a different number of tosses." } ###### roll a single die of "$1" sides, just once # default number of sides is 6 # written by Dallas Vogels function one-die() { function roll_die() { # capture parameter declare -i DIE_SIDES=$1 # check for die sides if [ ! $DIE_SIDES -gt 0 ]; then # default to 6 DIE_SIDES=6 fi # echo to screen echo $[ ( $RANDOM % $DIE_SIDES ) + 1 ] } # roll_die 10 # returns 1 to 10 as per 10 sides # roll_die 2 # returns 1 or 2 as per 2 sides roll_die "$1" } ###### select random card from a deck function pick-card() { # This is an example of choosing random elements of an array. # Pick a card, any card. Suites="Clubs Diamonds Hearts Spades" Denominations="2 3 4 5 6 7 8 9 10 Jack Queen King Ace" # Note variables spread over multiple lines. suite=($Suites) # Read into array variable. denomination=($Denominations) num_suites=${#suite[*]} # Count how many elements. num_denominations=${#denomination[*]} echo -n "${denomination[$((RANDOM%num_denominations))]} of " echo ${suite[$((RANDOM%num_suites))]} # $bozo sh pick-cards.sh # Jack of Clubs # Thank you, "jipe," for pointing out this use of $RANDOM. } ###### random number (out of whatever you input) # example: random 10 = 4 # copyright 2007 - 2010 Christopher Bratusek function random() { if [[ $1 == -l ]]; then echo $(cat /dev/urandom | tr -cd '[:digit:]' | head -c ${2-5}) elif [[ $1 == -r ]]; then echo $((RANDOM%${2})) else echo $((RANDOM%${1})) fi } ###### create random blank files function randomblanks() { for (( i = 0 ; i < $1; i++ )); do touch $RANDOM; done } ###### random file # copyright 2007 - 2010 Christopher Bratusek function randomfile() { case $1 in *first) sed -n '1p' $HOME/.randomhistory ;; *last) sed -n '$p' $HOME/.randomhistory ;; *n) sed -n "${2}p" $HOME/.randomhistory ;; *l) wc -l $HOME/.randomhistory | gawk '{print $1}' ;; *c) rm $HOME/.randomhistory ;; *help ) echo -e "\n${ewhite}Usage:\n" echo -e "${eorange}randomfile${ewhite} | ${egreen}--first ${eiceblue}[get the first file in the history]\ \n${eorange}randomfile${ewhite} | ${egreen}--last ${eiceblue}[get the last file in the history]\ \n${eorange}randomfile${ewhite} | ${egreen}--n ${eiceblue}[get the NUMBERth file in the history]\ \n${eorange}randomfile${ewhite} | ${egreen}--l ${eiceblue}[get the number of files in history]\ \n${eorange}randomfile${ewhite} | ${egreen}--c ${eiceblue}[clear the history]\n" | column -t tput sgr0 ;; *) if [[ ! "$FILES" ]]; then files=(*) else files=("$FILES") fi n=${#files[@]} RANDOMFILE="${files[RANDOM % n]}" echo "$RANDOMFILE" >> $HOME/.randomhistory if [[ ! "$@" ]]; then echo "$RANDOMFILE" else "$@" "$RANDOMFILE" fi ;; esac } ###### pulls a random line from text file function randomline() { # AUTHOR: David Ivan Stark (clyphox), clyphox@gmail.com if [ "$1" ];then #checking if we were passed a filename/variable FileName="$1" #just an easier variable to work with if [ ! -f "$FileName" ];then #check if it is a file echo "Err: $FileName is not a file" fi #Count how many lines in the file LineCount="$(wc -l "$FileName" | cut -f 1 -d ' ')" #Dont continue if we have less than 1 line if [ "$LineCount" -gt "1" ];then #Test past.. selecting random line TargetLine=$[ ( $RANDOM % $LineCount ) + 1 ] Output="$(sed -n "${TargetLine}p" "$FileName")" echo "$Output" else echo need a file with more than 1 line... cmon... fi else #seems we didnt get any input echo "Please specify a text file" fi } ###### Generates neverending list of random numbers function randomnumbers() { while : do echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM echo $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM done } ###### Random wallpaper (add whatever wallpaper directory(s) you wish after 'BACKGROUND_DIRS') # function randomwp() # # for GNOME2 # { # cat > "/tmp/randomwp.py" <<"End-of-message" # #!/usr/bin/env python # BACKGROUND_DIRS = ['/usr/share/backgrounds', '~/Pictures/Backgrounds'] # EXTENSIONS = ['jpeg', 'jpg', 'bmp', 'png', 'svg'] # import os, glob, random, itertools, gconf # files = list(itertools.chain(*[[os.path.join(dirpath, name) # for name in filenames] # for dirpath, dirnames, filenames in # itertools.chain(*[os.walk(os.path.expanduser(d)) # for d in BACKGROUND_DIRS])])) # gconf.client_get_default().set_string( # '/desktop/gnome/background/picture_filename', # random.choice(files)) # End-of-message # chmod +x "/tmp/randomwp.py" # "/tmp/randomwp.py" # /bin/rm "/tmp/randomwp.py" # } function randomwp() # for GNOME3 { ################################################## # Random-Gnome3-Wallpaper.sh # # Creator: Inameiname # # Major Contributor: hwttdz # # (did most of work :P) # # Version: 1.1 # # Last modified: 18 October 2011 # # License: GPLv3+ # # Descripton: # # Script to randomly set desktop/gdm background # # from files in a directory(s) in GNOME3 # # Requires: sudo-apt get install randomize-lines # ################################################## ###### just add/remove as many directories as wish find "/usr/share/backgrounds" "$HOME/Pictures/Backgrounds" -type f \( -name "*.bmp" -or -name "*.BMP" -or -name "*.jpeg" -or -name "*.JPEG" -or -name "*.jpg" -or -name "*.JPG" -or -name "*.png" -or -name "*.PNG" -or -name "*.svg" -or -name "*.SVG" \)|rl|head -n 1|xargs -I{} bash -c "gsettings set org.gnome.desktop.background picture-uri \"file://{}\"" } function randomwp_() { ################################################## # Random-Gnome3-Wallpaper-2.sh # # Creator: Inameiname # # Version: 1.0 # # Last modified: 18 October 2011 # # License: GPLv3+ # # Descripton: # # Script to randomly set desktop/gdm background # # from files in a directory(s) in GNOME3 # ################################################## ###### Directories Containing Pictures (to add more folders here, just "/path/to/your/folder") arr[0]="/usr/share/backgrounds" arr[1]="$HOME/Pictures/Backgrounds" # arr[2]= # arr[3]= # arr[4]= # arr[5]= # arr[6]= # arr[7]= # arr[8]= # arr[9]= # arr[10]= ###### How many picture folders are there? (currently = 2) rand=$[ $RANDOM % 2 ] ###### Command to select a random folder DIR=`echo ${arr[$rand]}` ###### Command to select a random file from directory # The *.* should select only files (ideally, pictures, if that's all that's inside) PIC=$(ls $DIR/*.* | shuf -n1) ###### Command to set background Image gsettings set org.gnome.desktop.background picture-uri "file://$PIC" } function randomwpt() # automatic wallpaper switcher for GNOME2 # Usage: randomwpt "bash directory_name" "timeout_in_seconds" # for GNOME2 only { if [ $# -ne 2 ];then echo -n "Usage: $0 directory_name timeout_in_seconds Leave the directory name blank for Current Directory For you lazy pal, I assume timeout as 5 sec and Directory as current Do you want to accept this settings? (Y/n): "; read response if [[ "$response" =~ ^[^yY] ]];then exit 0 fi fi function set_wallpaper() { gconftool-2 -s /desktop/gnome/background/picture_options "centered" -t string; gconftool-2 -s /desktop/gnome/background/picture_filename "$1" -t string; } TIMEOUT=${2-5}; WALL_DIR=${1-`pwd`}; echo "Timeout value is: $TIMEOUT"; echo "Directory is: $WALL_DIR"; echo if [ ! -d "$WALL_DIR" ];then echo "The Directory Specified is invalid.."; exit 1; fi filelst="$(find "$WALL_DIR" -type f -name '*.jpg' -o -name '*.png')"; if [ -z "$filelst" ];then echo "No Suitable files found in this location: $WALL_DIR"; exit 1; fi while true;do filename=`echo "$filelst" | shuf -n 1` set_wallpaper "$filename"; sleep $TIMEOUT; done } ###### rename a file with a random name # The function will rename files but maintain their extensions. # BUG: If a file doesn't have an extension it will end up with a dot at the end of the name. # The parameter '8' for pwgen controls the length of filenames - eight random characters. function rf() { for i in "$@"; do mv "$i" "$(pwgen 8 1).${i##*.}"; done } ###### roll a single die 1000 times and show results function roll-die() { SEED=$"(head -1 /dev/urandom | od -N 1 | awk '{ print $2 }')" RANDOM=$SEED PIPS=6 # A die has 6 pips. MAXTHROWS=1000 # Increase this if you have nothing better to do with your time. throw=0 # Throw count. ones=0 # Must initialize counts to zero, twos=0 #+ since an uninitialized variable is null, not zero. threes=0 fours=0 fives=0 sixes=0 function print_result() { echo echo "ones = $ones" echo "twos = $twos" echo "threes = $threes" echo "fours = $fours" echo "fives = $fives" echo "sixes = $sixes" echo } function update_count() { case "$1" in 0) let "ones += 1";; # Since die has no "zero", this corresponds to 1. 1) let "twos += 1";; # And this to 2, etc. 2) let "threes += 1";; 3) let "fours += 1";; 4) let "fives += 1";; 5) let "sixes += 1";; esac } echo while [ "$throw" -lt "$MAXTHROWS" ] do let "die1 = RANDOM % $PIPS" update_count $die1 let "throw += 1" done print_result echo "Out of a total of "$MAXTHROWS" rolls." echo "Change \"MAXTHROWS=1000\" if you want a different number of rolls." } ################################################## # Backup a file with a date-time stamp # ################################################## # Usage "bu filename.txt" function bu() { cp $1 ${1}-`date +%Y%m%d%H%M`.backup ; } function buf() { cp -v $1 ${1/${1%%.*}/$f-$(date +"%Y%m%d_%H%M%S")}; } ################################################## # Extract a file and cd into the new folder # ################################################## function build() { extract "$1" && cd } ################################################## # Needs fixing # ################################################## function build_() { args=($@) args[0]= reset tcc -o $1 ${1}.c ${args[@]} if [ $? -eq 0 ]; then ./$1; fi } ################################################## # Buffer in order to avoir mistakes with # # redirections that empty your files # ################################################## function buffer() { tty -s && return; tmp=$(mktemp); cat > "${tmp}"; if [ -n "$1" ] && ( ( [ -f "$1" ] && [ -w "$1" ] ) || ( ! [ -a "$1" ] && [ -w "$(dirname "$1")" ] ) ); then mv -f "${tmp}" "$1"; else echo "Can't write in \"$1\""; rm -f "${tmp}"; fi } ################################################## # Generate a case-insensitive pattern # ################################################## function casepat() { perl -pe 's/([a-zA-Z])/sprintf("[%s%s]",uc($1),$1)/ge' ; } ################################################## # Concatenate PDF files # ################################################## ###### e.g. cat_pdfs -o combined.pdf file1.pdf file2.pdf file3.pdf function cat_pdfs() { python '/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py' "$@" ; } ################################################## # Copy & paste files and folders from the # # command line # ################################################## ###### Usage: "ccopy FILE/FOLDER#1 FILE/FOLDER#2 FILE/FOLDER#3 FILE/FOLDER#4 ..." # Note: You must 'cd' into the folder first ("whatever" works, while "~/myfolder/whatever" doesn't) function ccopy() { for i in $*; do cp -a $i /tmp/ccopy.$i; done } alias cpaste="ls -d /tmp/ccopy* | sed 's|[^\.]*.\.||' | xargs -I % mv /tmp/ccopy.% ./%" ################################################## # Power cd (add some of useful features to 'cd') # ################################################## ###### Move efficiently between directories. # This command adds a couple of extra features to cd, without affecting normal use. # CDPATH use is also unaffected. It introduces and environment variable CDDIR which is used as an alternate home directory. # `export CDDIR="$HOME/work"` and `alias cdd="CDDIR=$(pwd)"` must also be uncommented/enabled for this to work function cd() { if [ -n "$1" ]; then [ -f "$1" ] && set -- "${1%/*}"; else [ -n "$CDDIR" ] && set -- "$CDDIR"; fi; command cd "$@"; } alias cdd="CDDIR=$(pwd)" ################################################## # Print working directory after a cd. # ################################################## # function cd() { # if [[ $@ == '-' ]]; then # builtin cd "$@" > /dev/null # We'll handle pwd. # else # builtin cd "$@" # fi # echo -e " \033[1;30m"`pwd`"\033[0m" # } ################################################## # Change directory and list files # ################################################## function cds() { # only change directory if a directory is specified [ -n "${1}" ] && cd $1 lls } ################################################## # Grep, grep, grep # ################################################## ###### randomize GNU grep's colors 31-36 excluding black and white. function cgrep() { GREP_COLOR="1;3$((RANDOM%6+1))" grep --color=always "$@" ; } ###### to grep through files found by find, e.g. grepf pattern '*.c' # note that 'grep -r pattern dir_name' is an alternative if want all files function grepfind() { find . -type f -name "$2" -print0 | xargs -0 grep "$1" ; } ###### to grep through the /usr/include directory function grepincl() { (cd /usr/include; find . -type f -name '*.h' -print0 | xargs -0 grep "$1" ) ; } ###### hgrep, hgrepl (I use these so much I miss them not being on my other machines and should copy them over) function hgrepl() { history | sed s/.*\ \ // | grep $@ } function hgrep() { history | sed s/.*\ \ // | grep $@ | tail -n 30 } function hhgrep() { history | egrep "$@" | egrep -v "hgrep $@" } ################################################## # Analyze your bash usage # ################################################## function check_() { cut -f1 -d" " .bash_history | sort | uniq -c | sort -nr | head -n 30 } ################################################## # Checksum # ################################################## function checksum() # copyright 2007 - 2010 Christopher Bratusek { action=$1 shift if [[ ( $action == "-c" || $action == "--check" ) && $1 == *.* ]]; then type="${1/*./}" else type=$1 shift fi case $type in md5 ) checktool=md5sum ;; sha1 | sha ) checktool=sha1sum ;; sha224 ) checktool=sha224sum ;; sha256 ) checktool=sha256sum ;; sha384 ) checktool=sha384sum ;; sha512 ) checktool=sha512sum ;; esac case $action in -g | --generate ) for file in "${@}"; do $checktool "${file}" > "${file}".$type done ;; -c | --check ) for file in "${@}"; do if [[ "${file}" == *.$type ]]; then $checktool --check "${file}" else $checktool --check "${file}".$type fi done ;; -h | --help ) ;; esac } ###### MD5 checksum function md5() { echo -n $@ | md5sum } ###### Encode a string in md5 hash of 32 characters # You can short the length with the second parameter. # @param string $1 string (required) # @param integer $2 length (option, default: 32) # @return string # @example: md5 "Hello World" 8 function md5_() { local length=${2:-32} local string=$( echo "$1" | md5sum | awk '{ print $1 }' ) echo ${string:0:${length}} } ################################################## # Mount/unmount CIFS shares; pseudo- # # replacement for smbmount # ################################################## ###### $1 = remote share name in form of //server/share # $2 = local mount point function cifsmount() { sudo mount -t cifs -o username=${USER},uid=${UID},gid=${GROUPS} $1 $2; } function cifsumount() { sudo umount $1; } ################################################## # Commandlinefu.com and Shell-fu.org stuff # ################################################## ###### Search commandlinefu.com from the command line # using the API # Usage: cmdfu hello world function cmdfu() { curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ | openssl base64)/plaintext" --silent | sed "s/\(^#.*\)/\x1b[32m\1\x1b[0m/g" | less -R ; } # function cmdfu() { curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ | openssl base64)/plaintext"; } ###### automatically downloads all commands from http://www.commandlinefu.com into a single text file alias cmdfu_dl='mkdir /tmp/commandlinefu && cd /tmp/commandlinefu && curl -O http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/[0-2400:25] && ls -1 | sort -n | while read mork ; do cat $mork >> commandlinefu.txt ; ls -ald $mork; done && mv commandlinefu.txt $HOME && rm -rf /tmp/commandlinefu' ###### find a CommandlineFu users average command rating function cmdfu_rating() { wget -qO- www.commandlinefu.com/commands/by/PhillipNordwall | awk -F\> '/class="num-votes"/{S+=$2; I++}END{print S/I}' } function cmdfu_rating_() { curl -s www.commandlinefu.com/commands/by/PhillipNordwall | awk -F\> '/class="num-votes"/{S+=$2; I++}END{print S/I}' } ##### key binding to search commandlinefu.com function ds_() { echo -n "search : "; read ST; EST=`php -r "echo rawurlencode('$ST');"`; B64=`echo -n $ST| openssl enc -base64`; curl -s "http://www.commandlinefu.com/commands/matching/$EST/$B64/plaintext" | less -p "$ST"; } ; bind '"\C-k"':"\"ds\C-m\"" ###### command examples from shell-fu function examples() { lynx -width=$COLUMNS -nonumbers -dump "http://www.shell-fu.org/lister.php?tag=$1" | \ sed -n '/^[a-zA-Z]/,$p' | egrep -v '^http|^javas|View Comm|HIDE|] \+|to Share|^ +\*|^ +[HV][a-z]* l|^ .*efu.*ep.*!$' | \ sed -e '/^ *__*/N;s/\n$//g' | less -r; } ###### fuman, an alternative to the 'man' command that shows commandlinefu.com examples function fuman() { lynx -width=$COLUMNS -nonumbers -dump "http://www.commandlinefu.com/commands/using/$1" |sed '/Add to favourites/,/This is sample output/!d' |sed 's/ *Add to favourites/----/' |less -r; } ###### Random Commandlinefu command function fur() { curl -sL 'http://www.commandlinefu.com/commands/random/plaintext' | grep -v "^# commandlinefu" ; } ###### Prepare a commandlinefu command function goclf() { type "$1" | sed '1d' | tr -d "\n" | tr -s '[:space:]'; echo } ################################################## # What package does that command come from? # ################################################## function cmdpkg() { PACKAGE=$(dpkg -S $(which $1) | cut -d':' -f1); echo "[${PACKAGE}]"; dpkg -s "${PACKAGE}" ;} ################################################## # Sets custom Catalog Number ID3 tag for all # # MP3 files in current directory # ################################################## ###### $1 = catalog number function cn() { for i in *.mp3; do id3v2 --TXXX "Catalog Number":"$1" "$i"; done; } ################################################## # Quick reference color charts & color stuff # ################################################## ###### shows a gui color chart function color-picker() { # for GNOME2 only # sudo apt-get install python-gtkmozembed xulrunner-2.0 # also requires: "~/.gnome2/nemo-scripts/.colorchart/view.html" echo "When you are finished, press "Control C" to continue..." cat > "/tmp/color-picker.py" <<"End-of-message" #!/usr/bin/python import os import pygtk pygtk.require('2.0') import gtk import gtkmozembed homedir = os.path.expanduser('~') try: from win32com.shell import shellcon, shell homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0) except ImportError: homedir = os.path.expanduser("~/.gnome2/nemo-scripts/.colorchart/view.html") class ColorChart: def __init__(self): self.moz = gtkmozembed.MozEmbed() box = gtk.VBox(False,0) win = gtk.Window() win.add(box) hbox = gtk.HBox(False,0) box.pack_start(hbox,False,False) hbox.show() box.pack_start(self.moz,True,True,0) self.moz.show() self.moz.load_url(homedir) self.moz.set_size_request(650,550) title=self.moz.get_title() win.set_title("RGB/HEX Color Picker") win.show_all() if __name__ == "__main__": ColorChart() gtk.main() End-of-message chmod +x "/tmp/color-picker-.py" /usr/bin/python "/tmp/color-picker.py" /bin/rm "/tmp/color-picker.py" } ###### shows a gui color chart # function color-picker() # { # # for GNOME3 only # # sudo apt-get install python-webkit # # also requires: "~/.gnome2/nemo-scripts/.colorchart/view.html" # echo "When you are finished, press "Control C" to continue..." # cat > "/tmp/color-picker.py" <<"End-of-message" # #!/usr/bin/python # import os # import pygtk # pygtk.require('2.0') # import gtk # import webkit # homedir = os.path.expanduser('~') # try: # from win32com.shell import shellcon, shell # homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0) # except ImportError: # homedir = os.path.expanduser("~/.gnome2/nemo-scripts/.colorchart/view.html") # class ColorChart: # def __init__(self): # self.moz = webkit.WebView() # box = gtk.VBox(False,0) # win = gtk.Window() # win.add(box) # hbox = gtk.HBox(False,0) # box.pack_start(hbox,False,False) # hbox.show() # box.pack_start(self.moz,True,True,0) # self.moz.show() # self.moz.open(homedir) # self.moz.set_size_request(650,550) # title=self.moz.get_title() # win.set_title("RGB/HEX Color Picker") # win.show_all() # if __name__ == "__main__": # ColorChart() # gtk.main() # End-of-message # chmod +x "/tmp/color-picker-.py" # /usr/bin/python "/tmp/color-picker.py" # /bin/rm "/tmp/color-picker.py" # } ###### takes a name of a color and some text and then echoes out the text in the named color # Usage: colorize_text "color" "whatever text" function colorize-text() { b='[0;30m' # Implement command-line options while getopts "nr" opt do case $opt in n ) o='-n' ;; r ) b='' ;; esac done shift $(($OPTIND - 1)) # Set variables col=$1 shift text="$*" # Set a to console color code case $col in 'black' ) a='[0;30m' ;; 'blue' ) a='[0;34m' ;; 'green' ) a='[0;32m' ;; 'cyan' ) a='[0;36m' ;; 'red' ) a='[0;31m' ;; 'purple' ) a='[0;35m' ;; 'brown' ) a='[0;33m' ;; 'ltgray' ) a='[0;37m' ;; 'white' ) a='[1;30m' ;; 'ltblue' ) a='[1;34m' ;; 'ltgreen') a='[1;32m' ;; 'ltcyan' ) a='[1;36m' ;; 'ltred' ) a='[1;31m' ;; 'pink' ) a='[1;35m' ;; 'yellow' ) a='[1;33m' ;; 'gray' ) a='[1;37m' ;; esac # Display text in designated color, no newline echo -en "\033$a$text" # If 'b' switch not on, restore color to black if [ -n $b ] then echo -en "\033$b" fi # If 'n' switch on, do not display final newline # otherwise output newline echo $o } ###### shows the colors in a kewl way...partially stolen from HH function colors() { # Display ANSI colours. esc="\033[" echo -e "\t 40\t 41\t 42\t 43\t 44 45\t46\t 47" for fore in 30 31 32 33 34 35 36 37; do line1="$fore " line2=" " for back in 40 41 42 43 44 45 46 47; do line1="${line1}${esc}${back};${fore}m Normal ${esc}0m" line2="${line2}${esc}${back};${fore};1m Bold ${esc}0m" done echo -e "$line1\n$line2" done echo "" echo "# Example:" echo "#" echo "# Type a Blinkin TJEENARE in Swedens colours (Yellow on Blue)" echo "#" echo "# ESC" echo "# | CD" echo "# | | CD2" echo "# | | | FG" echo "# | | | | BG + m" echo "# | | | | | END-CD" echo "# | | | | | |" echo "# echo -e '\033[1;5;33;44mTJEENARE\033[0m'" echo "#" echo "# Sedika Signing off for now ;->" } ###### displays all 256 possible background colors, using ANSI escape sequences. # author: Chetankumar Phulpagare # used in ABS Guide with permission. function colors2() { T1=8 T2=6 T3=36 offset=0 for num1 in {0..7} do { for num2 in {0,1} do { shownum=`echo "$offset + $T1 * ${num2} + $num1" | bc` echo -en "\E[0;48;5;${shownum}m color ${shownum} \E[0m" } done echo } done offset=16 for num1 in {0..5} do { for num2 in {0..5} do { for num3 in {0..5} do { shownum=`echo "$offset + $T2 * ${num3} \ + $num2 + $T3 * ${num1}" | bc` echo -en "\E[0;48;5;${shownum}m color ${shownum} \E[0m" } done echo } done } done offset=232 for num1 in {0..23} do { shownum=`expr $offset + $num1` echo -en "\E[0;48;5;${shownum}m ${shownum}\E[0m" } done echo } ###### print all 256 colors for testing TERM or for a quick reference # show numerical values for each of the 256 colors in bash function colors2nums() { for code in {0..255}; do echo -e "\e[38;05;${code}m $code: Test"; done } ###### replaces a color in PDF document (useful for removing dark background for printing) # usage: remove_color input.pdf output.pdf function uncolorpdf() { convert -density 300 "$1" -fill "rgb(255,255,255)" -opaque "rgb(0,0,0)" "$2" } ################################################## # View daily comics (set on Viewnior as image # # viewer...can use 'eog' or whatever instead) # ################################################## function comics() { # xkcd XKCD_FILE="/tmp/xkcd" wget -q $(curl -s http://xkcd.com/ | sed -n 's/

Image URL.*: \(.*\)<\/h3>/\1/p') -O $XKCD_FILE # Geek and Poke GAP_FILE="/tmp/geekandpoke" wget -q $(lynx --dump 'http://geekandpoke.typepad.com/' | grep '\/.a\/' | grep '\-pi' | head -n 1 | awk '{print $2}') -O $GAP_FILE viewnior $XKCD_FILE viewnior $GAP_FILE } ################################################## # Install and run when a command is not found # ################################################## # function command_not_found_handle() { apt-get install $( apt-file search "$1" | grep bin | grep -w "$1" | head -n1 | cut -d ':' -f 1 ) && $* ; } ################################################## # Run command/program using a timer # ################################################## ###### Run a command until a specified time # Example: command-timer 04:00 function command-timer() { echo "notify-send TimeToQuit" | at "$@" ; } ###### Run a program on a timer # Example: program-timer 20 viewnior arg1 function program-timer() { perl -e 'alarm shift; exec @ARGV' "$@" & exit; } ################################################## # Computer the speed of two commands # ################################################## function comp() { # compare the speed of two commands (loop $1 times) if [[ $# -ne 3 ]] ; then return 1 ; fi echo -n 1 time for ((i=0;i<$1;i++)) ; do $2 ; done >/dev/null 2>&1 echo -n 2 time for ((i=0;i<$1;i++)) ; do $3 ; done >/dev/null 2>&1 } ################################################## # Remove text from file1 which is in file2 and # # store it in an other file # ################################################## ###### handy if you have file where file1 was the original # and you want to remove the original data from your file2 # usage: grep -Fvf nameofinputfile1 nameofinputfile2 > nameofoutputfile function comparenclean() { grep -Fvf $1 $2 > $3 ; } ###### save lines unique to file2 # if both file1 and file2 are already sorted: comm -13 nameofinputfile1 nameofinputfile2 > nameofoutputfile function comparenclean_() { comm -13 <(sort $1) <(sort $2) > $3 ; } ################################################## # Compress stuff # ################################################## function compress_() { # Credit goes to: Daenyth FILE=$1 shift case $FILE in *.tar.bz2) tar cjf $FILE $* ;; *.tar.gz) tar czf $FILE $* ;; *.tgz) tar czf $FILE $* ;; *.zip) zip $FILE $* ;; *.rar) rar $FILE $* ;; *) echo "Filetype not recognized" ;; esac } ################################################## # Sets the compression level for file-roller # ################################################## function compression_level() { echo -n "Please enter the number for the compression level desired: (1) very_fast (2) fast (3) normal (4) maximum Press 'Enter' for default (default is '3')... " read COMPRESSION_LEVEL_NUMBER # extra blank space echo " " # default if [[ -z $COMPRESSION_LEVEL_NUMBER ]] ; then # If no COMPRESSION_LEVEL passed, default to '3' COMPRESSION_LEVEL=normal fi # preset if [[ $COMPRESSION_LEVEL_NUMBER = 1 ]] ; then COMPRESSION_LEVEL=very_fast fi if [[ $COMPRESSION_LEVEL_NUMBER = 2 ]] ; then COMPRESSION_LEVEL=fast fi if [[ $COMPRESSION_LEVEL_NUMBER = 3 ]] ; then COMPRESSION_LEVEL=normal fi if [[ $COMPRESSION_LEVEL_NUMBER = 4 ]] ; then COMPRESSION_LEVEL=maximum fi gconftool-2 --set /apps/file-roller/general/compression_level --type string "$COMPRESSION_LEVEL" } ################################################## # Convert to avi # ################################################## function conv2avi() { # copyright 2007 - 2010 Christopher Bratusek if [[ $(which mencoder-mt) != "" ]]; then mencoder-mt "$1" -lavdopts threads=8 \ -ovc xvid -xvidencopts fixed_quant=4 -of avi \ -oac mp3lame -lameopts vbr=3 \ -o "$1".avi else mencoder "$1" -lavdopts \ -ovc xvid -xvidencopts fixed_quant=4 -of avi \ -oac mp3lame -lameopts vbr=3 \ -o "$1".avi fi } ################################################## # Get name of app that created a corefile # ################################################## function corename() { for file ; do echo -n $file : ; gdb --core=$file --batch | head -1 done } ################################################## # Count opening and closing braces in a string # ################################################## function countbraces() { COUNT_OPENING=$(echo $1 | grep -o "(" | wc -l); COUNT_CLOSING=$(echo $1 | grep -o ")" | wc -l); echo Opening: $COUNT_OPENING; echo Closing: $COUNT_CLOSING; } ################################################## # Count files in current directory # ################################################## function count_files() # copyright 2007 - 2010 Christopher Bratusek { case $1 in *+h) echo $(($(ls --color=no -1 -la . | grep -v ^l | wc -l)-1)) ;; *-h) echo $(($(ls --color=no -1 -l . | grep -v ^l | wc -l)-1)) ;; *+d) echo $(($(ls --color=no -1 -la . | grep -v ^- | wc -l)-1)) ;; *-d) echo $(($(ls --color=no -1 -l . | grep -v ^- | wc -l)-1)) ;; *+f) echo $(($(ls --color=no -1 -la . | grep -v ^d | wc -l)-1)) ;; *-f) echo $(($(ls --color=no -1 -l . | grep -v ^d | wc -l)-1)) ;; *) echo -e "\n${ewhite}Usage:" echo -e "\n${eorange}count_files${ewhite} | ${egreen}+h ${eiceblue}[count files and folders - include hidden ones] \ \n${eorange}count_files${ewhite} | ${egreen}-h ${eiceblue}[count files and folders - exclude hidden ones] \ \n${eorange}count_files${ewhite} | ${egreen}+d ${eiceblue}[count folders - include hidden ones] \ \n${eorange}count_files${ewhite} | ${egreen}-d ${eiceblue}[count folders - exclude hidden ones] \ \n${eorange}count_files${ewhite} | ${egreen}+f ${eiceblue}[count files - include hidden ones] \ \n${eorange}count_files${ewhite} | ${egreen}-f ${eiceblue}[count files - exclude hidden ones]\n" tput sgr0 ;; esac } ################################################## # Count files by extension # ################################################## function count_files_by_ext() { find . -type f | sed -n 's/..*\.//p' | sort -f | uniq -ic ; } ################################################## # Count processes that are running # ################################################## function count_processes() # copyright 2007 - 2010 Christopher Bratusek { case $1 in *help ) echo -e "\n${ewhite}Usage:" echo -e "\n${eorange}count_processes${ewhite} | ${egreen}! no options !\n" tput sgr0 ;; * ) procs=$(ps ax | wc -l | awk '{print $1}') if [[ $procs -lt 10 ]]; then echo "000$procs" elif [[ $procs -lt 100 ]]; then echo "00$procs" elif [[ $procs -lt 1000 ]]; then echo "0$procs" fi ;; esac } ################################################## # Copies currently played song in Audacious to # # selected directory # ################################################## function cp_mp3_to() { PID=`pidof audacious2`; FILEPATH=`lsof -p $PID| grep mp3| sed s/[^\/]*//`; cp "$FILEPATH" "$1"; } ################################################## # Cp with progress bar (using pv) # ################################################## function cp_p() { if [ `echo "$2" | grep ".*\/$"` ] then pv "$1" > "$2""$1" else pv "$1" > "$2"/"$1" fi } ################################################## # Create User List # ################################################## function create_user_list() # Author: Josh Bailey # Email: jbsnake usalug.org # further tweaked by: jsz # usage: create_user_list { local users u while IFS=: read -r u _; do users+=("$u") done printf '%s\n' "${users[@]:1}" } ################################################## # Print a cron formatted time for 2 minutes in # # the future (for crontab testing) # ################################################## function crontest() { date '-d +2 minutes' +'%M %k %d %m *'; } ################################################## # Encryption / decryption # ################################################## ###### do twice to decrypt # copyright 2007 - 2010 Christopher Bratusek function crypt() { if [[ -e "$1" ]]; then tr a-zA-Z n-za-mN-ZA-M < "$1" > "$1".crypt rm -f "$1" mv "$1".crypt "$1" fi } ###### basic encrypt / decrypt # example: "encry filename" or "decry filename" function encry() { gpg -ac --no-options "$1" } function decry() { gpg --no-options "$1" } ###### More advanced encryption / decryption # example: "encrypt filename" or "decrypt filename" function encrypt() { # Author: Martin Langasek case $LANG in cs* ) err_title="Chyba" err_files="Neoznačen soubor" encrypt="Šifrovat" decrypt="Dešifrovat" file_msg="soubor:" pass_msg="Vložte heslo";; * ) err_title="Error" err_files="No file selected" encrypt="Encrypt" decrypt="Decrypt" file_msg="file:" pass_msg="Enter passphrase";; esac if [ "$1" != "" ] then i=1 file=`echo "$1" | sed ''$i'!d'` while [ "$file" != "" ] do ext=`echo "$file" | grep [.]gpg$ 2>&1` if [ "$ext" != "" ] then pass_decrypt=`zenity --entry --entry-text "$pass_decrypt" --hide-text --title "$pass_msg" --text "$decrypt $file_msg ${file##*/}" "" 2>&1` if [ "$pass_decrypt" != "" ] then output=${file%.*} echo "$pass_decrypt" | gpg -o "$output" --batch --passphrase-fd 0 -d "$file" fi else pass_encrypt=`zenity --entry --hide-text --entry-text "$pass_encrypt" --title "$pass_msg" --text "$encrypt $file_msg ${file##*/}" "" 2>&1` if [ "$pass_encrypt" != "" ] then echo "$pass_encrypt" | gpg --batch --passphrase-fd 0 --cipher-algo aes256 -c "$file" fi fi i=$(($i+1)) file=`echo "$1" | sed ''$i'!d'` done else zenity --error --title "$err_title" --text "$err_files" fi } alias decrypt='encrypt' ###### rot13 ("rotate alphabet 13 places" Caesar-cypher encryption) function rot13() { if [ $# -lt 1 ] || [ $# -gt 1 ]; then echo "Seriously? You don't know what rot13 does?" else echo $@ | tr A-Za-z N-ZA-Mn-za-m fi } ###### rot47 ("rotate ASCII characters from '!" to '~' 47 places" Caesar-cypher encryption) function rot47() { if [ $# -lt 1 ] || [ $# -gt 1 ]; then echo "Seriously? You don't know what rot47 does?" else echo $@ | tr '!-~' 'P-~!-O' fi } ################################################## # Google stuff # ################################################## ###### convert currencies # usage: currency_convert 1 usd eur # for currency shorthand: http://www.xe.com/currency/ function currency_convert() { wget -qO- "http://www.google.com/finance/converter?a=$1&from=$2&to=$3&hl=es" | sed '/res/!d;s/<[^>]*>//g'; } function currency_convert_() { curl "http://www.xe.com/wap/2co/convert.cgi?Amount=$1&From=$2&To=$3" -A "Mozilla" -s | sed -n "s/.*>\(.*\) $3<.*/\1/p"; } function currency_convert_help() { cat < /tmp/define if [ ! -s /tmp/define ]; then echo "Sorry, google doesn't know this one..." rm -f /tmp/define return 1 else cat /tmp/define | grep -v Search echo "" fi rm -f /tmp/define return 0 } ###### detect language of a string function detectlanguage() { curl -s "http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=$@" | sed 's/{"responseData": {"language":"\([^"]*\)".*/\1\n/'; } ###### find a location's coordinates # usage: findlocation "Las Vegas, Nevada" = coordinates: [ -115.1728160, 36.1146460, 0 ] function findlocation() { place=`echo $1 | sed 's/ /%20/g'` ; curl -s "http://maps.google.com/maps/geo?output=json&oe=utf-8&q=$place" | grep -e "address" -e "coordinates" | sed -e 's/^ *//' -e 's/"//g' -e 's/address/Full Address/';} ###### your GeoIP location on Google Maps function geoipme() { curl -s http://geoiplookup.wikimedia.org/|awk -F, '{print $3,$4}'|awk -F'"' '{print "http://maps.google.com/maps?q="$4 "," $8}' } ###### Google search (example: google dog) function google() { firefox "http://www.google.com/search?&num=100&q=${@}" & } ###### Google chart function google_chart() { wget -O chart.png 'http://chart.googleapis.com/chart?chs=250x100&chd=t:60,40&cht=p3&chl=Hello|World' } ###### Google search (example: google dog) function google-fonts() { # Google-Fonts.sh # Version: 0.1 # Last modified: 04 November 2011 # License: GPLv3+ # Creator: Inameiname # # Credit also goes to Michalis Georgiou # for his original # google-font script and to Andrew # http://www.webupd8.org for # his further modification of it. # # Descripton: # For those who want an extremely easy method to # download and install the entire Google font # repository. ###### Installation of Mercurial Needed for Downloading of Fonts ###### sudo apt-get install mercurial ###### Setting of Default Directories ###### _hgroot="https://googlefontdirectory.googlecode.com/hg/" _hgrepo="googlefontdirectory" _hgoutdir="google-fonts" ###### Google Font Choice Decision ###### echo " " echo -n "What do you want to do with the fonts from Google once they are downloaded?: (1) Download Only (and keep all fonts in a single folder) (2) Download Only (and keep all fonts in separate folders (pure hg copy)) (3) Download and Install Press 'Enter' for default (default is '1')... " read GOOGLE_FONT_CHOICE ###### Actual Downloading of the Google Fonts ###### if [ ! -d $HOME/$_hgrepo ] ; then echo " " echo "Connecting to Mercurial server...." if [ -d $HOME/$_hgrepo ] ; then cd $HOME/$_hgrepo hg pull -u || return 1 echo "The local files have been updated." cd .. else hg clone $_hgroot $HOME/$_hgrepo || return 1 fi echo "Mercurial checkout done or server timeout" echo " " else echo "The directory $HOME/$_hgrepo already exists." echo "" echo "No need to redownload all of the Google fonts." fi ###### Google Font Choice Selection ###### ###### default if [[ -z $GOOGLE_FONT_CHOICE ]] ; then # If no file passed, default to 1 mkdir -p $HOME/$_hgoutdir/ find $HOME/$_hgrepo/ -name "*.ttf"|xargs -I{} bash -c "cp -rf \"{}\" $HOME/$_hgoutdir/" rm -rf $HOME/$_hgrepo/ fi ###### preset if [[ $GOOGLE_FONT_CHOICE = 1 ]] ; then mkdir -p $HOME/$_hgoutdir/ find $HOME/$_hgrepo/ -name "*.ttf"|xargs -I{} bash -c "cp -rf \"{}\" $HOME/$_hgoutdir/" rm -rf $HOME/$_hgrepo/ fi if [[ $GOOGLE_FONT_CHOICE = 2 ]] ; then mv $HOME/$_hgrepo/ $HOME/$_hgoutdir/ fi if [[ $GOOGLE_FONT_CHOICE = 3 ]] ; then sudo mkdir -p /usr/share/fonts/truetype/google-fonts/ find $HOME/$_hgrepo/ -name "*.ttf" -exec sudo install -m644 {} /usr/share/fonts/truetype/google-fonts/ \; || return 1 fc-cache -f > /dev/null rm -rf $HOME/$_hgrepo/ fi ###### Wrap Up ###### echo " " echo "done." echo " " read -sn 1 -p "You have finished downloading/installing all the Google Fonts currently available. Press any key to finish... " } ###### get Google PageRank function pagerank() { curl pagerank.bz/$1 } ###### Google text-to-speech in mp3/wav format function say() { mplayer -user-agent Mozilla "http://translate.google.com/translate_tts?tl=en&q=$(echo $* | sed 's#\ #\+#g')" > /dev/null 2>&1 ; } function say_() { # Saironiq's bash script # Usage: say_ en lol # says "lol" in english ; somecommand | say_ fr - # read text to say from a pipe # requires madplay: sudo apt-get install madplay lang=$1 shift if [ "$1" = "-" ] then read text echo $text else text=$* fi len=`expr length "$text"` if [ -z "$text" ] ; then echo "Please specify string to translate (up to 100 characters incl.)." exit 4 elif [ "$len" -gt "100" ] ; then echo "Can't translate more than 100 characters at once! (entered $len)" exit 2 fi wget -qU Mozilla -O - "http://translate.google.com/translate_tts?tl=$lang&q=$text" | madplay -Q -o wave:- - | aplay -q - } ###### translate a word using Google # usage: translate # example: translate "hello" es = hola (will auto-detect source language) # for a list of language codes: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes function translate() { wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=%7C${2:-en}" | sed 's/.*{"translatedText":"\([^"]*\)".*/\1\n/'; } function translate_help() { cat <&/dev/null &) } ################################################## # Shows what processes need to be restarted after# # system upgrade # ################################################## function deadlib() { lsof | grep 'DEL.*lib' | cut -f 1 -d ' ' | sort -u; } ################################################## # Show dead links # ################################################## function deadlink() { # copyright 2007 - 2010 Christopher Bratusek find -L -type l } ################################################## # Stuff for easy debian package extracting, # # making, remaking, and uploading # ################################################## ###### deb extraction- extracts a deb file & organizes for easy # deb manipulation and repacking using "debremaker" function debextract() { read -sn 1 -p "Press any key to continue... " # Set IFS so that it won't consider spaces as entry separators. Without this, spaces in file/folder names can make the loop go wacky. IFS=$'\n' NEWDIRNAME=${1%.*} FILENAME=${1##*/} NAME=${1##*/.*} mkdir "$NEWDIRNAME" cp -fv -R "$1" "$NEWDIRNAME" cd "$NEWDIRNAME" ar vx "$FILENAME" rm -fv -R "$FILENAME" for FILE in *.tar.gz; do tar xvpf $FILE; done for FILE in *.tar.lzma; do tar xvpf $FILE; done rm -fv -R "control.tar.gz" rm -fv -R "data.tar.gz" rm -fv -R "data.tar.lzma" rm -fv -R "debian-binary" mkdir "DEBIAN" mv -fv "changelog" "DEBIAN" mv -fv "config" "DEBIAN" mv -fv "conffiles" "DEBIAN" mv -fv "control" "DEBIAN" mv -fv "copyright" "DEBIAN" mv -fv "postinst" "DEBIAN" mv -fv "preinst" "DEBIAN" mv -fv "prerm" "DEBIAN" mv -fv "postrm" "DEBIAN" mv -fv "rules" "DEBIAN" mv -fv "shlibs" "DEBIAN" mv -fv "templates" "DEBIAN" mv -fv "triggers" "DEBIAN" mv -fv ".svn" "DEBIAN" rm -fv -R "md5sums" echo "Finished Successfully" } ###### creates an authentic and correct debian file / uploads to a Launchpad PPA for debian file creation # function debmaker() # { # function searchnreplace_() # { # # Store old text and new text in variables # old=$1; # new=$2; # # Shift positional parameters to places to left (get rid of old and # # new from command line) # shift; # shift; # # Store list of files as a variable # files=$@; # a=''; # for a in $files # do # temp=$(echo "/tmp/$LOGNAME-$a"); # # echo "$temp"; # echo -n "."; # sed -e "s/$old/$new/g" $a > $temp; # mv $temp $a; # done # echo; # echo -e "Searched $# files for '$old' and replaced with '$new'"; # } # sudo apt-get install devscripts dh-make dput # echo -n "Please enter the full path to Public keys (spaces are fine)... # # Example: '/home/(your username)/Public_Key-public.key'... # # " # read MYKEYS_PUBLIC_LOCATION # gpg --import "$MYKEYS_PUBLIC_LOCATION" # echo -n "Please enter the full path to Private keys (spaces are fine)... # # Example: '/home/(your username)/Private_Keys-private.key'... # # " # read MYKEYS_PRIVATE_LOCATION # gpg --import "$MYKEYS_PRIVATE_LOCATION" # echo -n "All done." # echo -n "Please enter the name of the package: # " # read PACKAGE_NAME # echo -n "Please enter your name as it is on Launchpad: # " # read YOUR_NAME # echo -n "Please enter your email address as it is on Launchpad: # " # read YOUR_EMAILADDRESS # dh_make -n -s -e $YOUR_EMAILADDRESS # cd debian # searchnreplace_ ""$USER" <"$YOUR_EMAILADDRESS">" ""YOUR_PPA_USERNAME" <"$YOUR_EMAILADDRESS">" * # searchnreplace_ "unstable; urgency=low" "saucy; urgency=low" * # echo '#!/usr/bin/make -f' >> $PACKAGE_NAME.install # echo '' # echo '# add more lines like below when necessary' >> $PACKAGE_NAME.install # echo '/ /' >> $PACKAGE_NAME.install # sudo chmod +x $PACKAGE_NAME.install # gedit control changelog $PACKAGE_NAME.install # cd .. # read -sn 1 -p "If you are ready to build the package, press any key to continue... # " # echo -n "What do you want to compile the original source to?: # # (1) a debian binary for personal use / check to see if the building works # (2) a new source for potential Launchpad PPA upload # (3) a debian binary for checking AND a new source for potential Launchpad PPA upload # # Press 'Enter' for default (default is '3')... # # " # read OPTION_NUMBER # # extra blank space # echo " # " # # default # if [[ -z $OPTION_NUMBER ]] ; then # # If no device passed, default to "3" # debuild -b # read -sn 1 -p "Built deb is done; if it looks good, and you feel its good enough to make the source for a PPA upload, press any key to continue... # " # debuild -S # cd .. # mkdir Debian-Package # mv -fv *_all.* Debian-Package # mv -fv *_amd64.* Debian-Package # mv -fv *_i386.* Debian-Package # read -sn 1 -p "If you are ready to upload the built package to Launchpad, press any key to continue... # " # echo -n "Please enter the name of your Launchpad PPA that you would like to upload the package to: # # ...like this...('ppa:myppa/oneiric')... # " # read PPA_NAME # dput $PPA_NAME *.changes # fi # # preset # if [[ $OPTION_NUMBER = 1 ]] ; then # debuild -b # fi # if [[ $OPTION_NUMBER = 2 ]] ; then # debuild -S # cd .. # read -sn 1 -p "If you are ready to upload the built package to Launchpad, press any key to continue... # " # echo -n "Please enter the name of your Launchpad PPA that you would like to upload the package to: # # ...like this...('ppa:myppa/oneiric')... # " # read PPA_NAME # dput $PPA_NAME *.changes # fi # if [[ $OPTION_NUMBER = 3 ]] ; then # debuild -b # read -sn 1 -p "Built deb is done; if it looks good, and you feel its good enough to make the source for a PPA upload, press any key to continue... # " # debuild -S # cd .. # mkdir Debian-Package # mv -fv *_all.* Debian-Package # mv -fv *_amd64.* Debian-Package # mv -fv *_i386.* Debian-Package # read -sn 1 -p "If you are ready to upload the built package to Launchpad, press any key to continue... # " # echo -n "Please enter the name of your Launchpad PPA that you would like to upload the package to: # # ...like this...('ppa:myppa/oneiric')... # " # read PPA_NAME # dput $PPA_NAME *.changes # fi # } ###### deb remaking- easily remakes a debian file after "debextract" (not authentically or correct according to Launchpad standards) function debremaker() { read -sn 1 -p "Make sure you have this function directed to the original debian file (previously extracted from and made into a folder with \"debextract\"; otherwise, it will fail (Note: This will take a minute): Press any key to continue... " # Set IFS so that it won't consider spaces as entry separators. Without this, spaces in file/folder names can make the loop go wacky. IFS=$'\n' NEWDIRNAME=${1%.*} FILENAME=${1##*/} NAME=${1##*/.*} cd "$NEWDIRNAME" rm -fv -R "$1" find . -type f ! -regex '.*\.hg.*' ! -regex '.*?debian-binary.*' ! -regex '.*?DEBIAN.*' -printf '%P ' | xargs md5sum > DEBIAN/md5sums cd .. dpkg-deb -b "$NEWDIRNAME" rm -rf "$NEWDIRNAME" echo "Finished Successfully" } ################################################## # Download a web page and show info on what # # took time # ################################################## function debug_http() { /usr/bin/curl $@ -o /dev/null -w "dns: %{time_namelookup} connect: %{time_connect} pretransfer: %{time_pretransfer} starttransfer: %{time_starttransfer} total: %{time_total}\n" ; } ################################################## # Defragmentation of selected files/folder # # (use at your own risk) & fragmentation-checking# ################################################## function defrag() { cd "$1" read -sn 1 -p "Warning! Pressing enter will defrag the current directory. Close this now if you are in the wrong directory and/or you forgot to type the name of the directory you wish to defrag after \"defrag\": Press any key to continue... " read -sn 1 -p "I'm serious. It's now or never...: Press any key to continue... " cat > "/tmp/defrag.sh" <<"End-of-message" #!/bin/bash # defrag v0.08 by Con Kolivas /dev/null function abort() { echo -e "\nAborting" rm -f tmpfile dirlist exit 1 } function fail() { echo -e "\nFailed" abort } declare -i filesize=0 declare -i numfiles=0 # The maximum size of a file we can easily cache in ram declare -i maxsize=$((`awk '/MemTotal/ {print $2}' /proc/meminfo`*1024)) (( maxsize-= `awk '/Mapped/ {print $2}' /proc/meminfo` )) (( maxsize/= 2)) if [[ -a tmpfile || -a dirlist ]] ; then echo dirlist or tmpfile exists exit 1 fi # Sort in the following order: # 1) Depth of directory # 2) Size of directory descending # 3) Filesize descending # I made this crap up. It's completely unvalidated. echo "Creating list of files..." # stupid script to find max directory depth find -xdev -type d -printf "%d\n" | sort -n | uniq > dirlist # sort directories in descending size order cat dirlist | while read d; do find -xdev -type d -mindepth $d -maxdepth $d -printf "\"%p\"\n" | \ xargs du -bS --max-depth=0 | \ sort -k 1,1nr -k 2 |\ cut -f2 >> tmpfile if (( $? )) ; then fail fi done rm -f dirlist # sort files in descending size order cat tmpfile | while read d; do find "$d" -xdev -type f -maxdepth 1 -printf "%s\t%p\n" | \ sort -k 1,1nr | \ cut -f2 >> dirlist if (( $? )) ; then fail fi done rm -f tmpfile numfiles=`wc -l dirlist | awk '{print $1}'` echo -e "$numfiles files will be reordered\n" # copy to temp file, check the file hasn't changed and then overwrite original cat dirlist | while read i; do (( --numfiles )) if [[ ! -f $i ]]; then continue fi # We could be this paranoid but it would slow it down 1000 times # if [[ `lsof -f -- "$i"` ]]; then # echo -e "\n File $i open! Skipping" # continue # fi filesize=`find "$i" -printf "%s"` # read the file first to cache it in ram if possible if (( filesize < maxsize )) then echo -e "\r $numfiles files left \c" cat "$i" > /dev/null else echo -e "\r $numfiles files left - Reordering large file sized $filesize ... \c" fi datestamp=`find "$i" -printf "%s"` cp -a -f "$i" tmpfile if (( $? )) ; then fail fi # check the file hasn't been altered since we copied it if [[ `find "$i" -printf "%s"` != $datestamp ]] ; then continue fi mv -f tmpfile "$i" if (( $? )) ; then fail fi done echo -e "\nSucceeded" rm -f dirlist End-of-message chmod +x "/tmp/defrag.sh" sudo "/tmp/defrag.sh" "$1" read -sn 1 -p "When you are finished, press any key to continue... " rm "/tmp/defrag.sh" } ###### if run this in your $HOME directory, you will have to change permissions back function defrag2() { cd "$1" read -sn 1 -p "Warning! Pressing enter will defrag the current directory. Close this now if you are in the wrong directory and/or you forgot to type the name of the directory you wish to defrag after \"defrag\": Press any key to continue... " read -sn 1 -p "I'm serious. It's now or never...: Press any key to continue... " cat > "/tmp/defrag2.sh" <<"End-of-message" #!/bin/bash # Creator: private_lock # Recursively descend in a folder-structure and recreate every folder on ascending, to ensure it is # sorted (check with 'ls -lU'). This will defrag the FAT32 file-system but not touch the files. # count some statistics directories=0 invalid=0 unreadable=0 # the latest modification date of a file within the given directory function getMaxDate { # read the output of ls (one file per line, sorted for descending modification time) ls -1t "$1" | while read line; do # "return value" is piped through standard out echo "-d $(stat -c %y "$1"/"$line")" # stop after first line return done } # expect a single directory as argument function rewrite { # get canonical path local canonical="$(readlink -f "$1")" if [[ ! -d "$1" || -h "$1" ]]; then echo "Skipping symbolic link \"$1\" -> \"$canonical\"!" let invalid+=1 return fi if [[ ! -d "$1" || -h "$1" ]]; then echo \"$canonical\" is not a valid directory! let invalid+=1 return fi cd "$canonical" if [[ $? != 0 ]]; then echo Cannot change to directory \"$canonical\"! Skipping ... let unreadable+=1 return fi echo $canonical let directories+=1 local isEmpty=true # recursive descend for d in *; do if [[ -d "$d" ]]; then rewrite "$d" fi let isEmpty=false done # ascend to parent of canonical (But don't ascend blindly) cd "$canonical"/.. if [[ $isEmpty == true ]]; then # no need to recreate an empty directory, as it's zero entries are always sorted return fi # check for an empty temporary directory-name local tempdir="$canonical".bak if [[ -e "$tempdir" ]]; then # echo $tempdir exits local counter=1 while [[ -e "$tempdir$counter" ]]; do # echo ${tempdir}${counter} exits let counter+=1 done tempdir="${tempdir}${counter}" fi # TODO check file-system boundaries (don't move across) # rename the current directory mv "$canonical" "$tempdir" # create a new directory mkdir "$canonical" # move all the content from the old to the new directory # The whole script is build around the side-effect of mv to sort the entries. mv "$tempdir"/* "$canonical" # check, that the old directory is really empty if [[ "$(ls -A "$tempdir")" ]]; then echo ERROR: "$tempdir" is not empty! exit -2 fi # restore permissions chmod --reference="$tempdir" "$canonical" # delete the old directory rmdir "$tempdir" # update the timestamp of the new directory # start off with today local maxDate=$(date) # evaluate the latest modification time of a file within this directory # empty directories would be set to now touch "$(getMaxDate "$canonical")" "$canonical" } # check commandline for help option for a in "$@"; do if [[ ${a} = "-?" || ${a} = "-h" || ${a} = "--help" ]]; then echo -e "\nUsage: folderSort [-?|-h|--help] [directories]\n" exit -1 fi done # start processing the directories if [[ "$#" -eq 0 ]]; then # no commandline argument was given -> work on the current directory rewrite . else for a in "$@"; do rewrite ${a} done fi echo Processed a total of $directories directories! if [[ $invalid > 0 ]]; then echo Found $invalid invalid directories! fi if [[ $unreadable > 0 ]]; then echo Found $unreadable directories, that could not be changed into! fi exit $(($invalid + $unreadable)) End-of-message chmod +x "/tmp/defrag2.sh" sudo "/tmp/defrag2.sh" "$1" read -sn 1 -p "When you are finished, press any key to continue... " rm "/tmp/defrag2.sh" } ###### fragmentation check (basic check, which will generate a percentage of fragmentation) function fragcheck() { cd "$1" read -sn 1 -p "Warning! Pressing enter will do a search for fragmentation in the current directory. Close this now if you are in the wrong directory and/or you forgot to type the name of the directory you wish to do a fragcheck after \"fragcheck\": Press any key to continue... " cat > "/tmp/fragcheck.pl" <<"End-of-message" #!/usr/bin/perl -w # Original creator: _droop_ # Updated by: as # Updated again by: user11 # this script search for frag on a fs use strict; # number of files my $files = 0; # number of fragment my $fragments = 0; # number of fragmented files my $fragfiles = 0; my $verbose; if ($ARGV[0] eq '-v') { shift @ARGV; $verbose++; } open (REPORT, "find " . $ARGV[0] . " -xdev -type f -print0 | xargs -0 filefrag |"); while (defined (my $res = )) { if ($res =~ m/.*:\s+(\d+) extents? found$/) { my $fragment = $1; $fragments += $fragment; if ($fragment > 1) { $fragfiles++; } $files++; } else { print ("Failed to parse: $res\n"); } } close (REPORT); if ($verbose) { print "Total files: $files\n"; print "Fragmented files: $fragfiles\n"; print "Fragments: $fragments\n"; } sub round($$) { my $v = shift; # value my $p = shift; # rouding divisor (1 for '123', 10 for '123.4', 100 for '123.45') return int($v * $p) / $p; } print ( $fragfiles / $files * 100 . "% non contiguous files, " . $fragments / $files . " average fragments.\n"); End-of-message chmod +x "/tmp/fragcheck.pl" sudo "/tmp/fragcheck.pl" "$1" read -sn 1 -p "When you are finished, press any key to continue... " rm "/tmp/fragcheck.pl" } ###### will generate a percentage for fragmentation and several other things: takes longer than first one function fragcheck2() { cd "$1" read -sn 1 -p "Warning! Pressing enter will do a search for fragmentation in the current directory. Close this now if you are in the wrong directory and/or you forgot to type the name of the directory you wish to do a fragcheck after \"fragcheck\": Press any key to continue... " cat > "/tmp/fragcheck2.pl" <<"End-of-message" #! /usr/bin/perl -w # Original creator: _droop_ # Updated by: as # Updated again by: c07 use strict; @ARGV >= 1 && @ARGV <= 2 or die "usage: $0 []"; $/= "\0"; my ($files, $blocks, $fragments, $frag, $fragblocks, $multi, $empty)= (0) x 7; my $dir= shift; my $blocksize= (shift || 4) + 0; print qq|scanning "$dir", using block size $blocksize KB ...\n|; open my $find, "-|", "find", $dir, qw"-xdev -type f -print0"; while ( my $file= <$find> ) { { open my $fh, "-|", "filefrag", $file; $_= <$fh> } /:\s+(\d+) extents? found/ or (print qq|"$_"?\n|), next; my $n= $1 + 0; { open my $fh, "-|", "ls", "-sk", $file; $_= <$fh> } /^(\d+)\s/ or (print qq|"$_" (ls)?\n|), next; my $s= $1 / $blocksize; ++$files; $s or ++$empty, next; $blocks += $s; $fragments += $n; ++$frag, $fragblocks += $s if $n > 1; ++$multi if $s > 1; } my $single= $files - $multi - $empty; my $nonfrag= $files - $frag - $empty; if ( ! $files ) { print "no files\n" } else { printf "$files files, $frag (%.3f %%) fragmented\n", 100 * $frag / $files; if ( ! $multi ) { print "no multi-block files\n" } else { printf "$multi multi-block files, %.3f %% fragmented\n", 100 * $frag / $multi; } print "$blocks blocks, $fragments fragments, $empty empty files\n"; if ( $fragments ) { printf "average %.3f fragments per file, %.3f blocks per fragment,\n", $fragments / $files, $blocks / $fragments; if ( $multi ) { printf "%.3f fragments per multi-block file, %.3f blocks each,\n", ($fragments - $single) / $multi, ($blocks - $single) / ($fragments - $single); if ( $frag ) { printf "%.3f fragments per fragmented file, %.3f blocks each\n", ($fragments - $nonfrag) / $frag, $fragblocks / ($fragments - $nonfrag); } } } } End-of-message chmod +x "/tmp/fragcheck2.pl" sudo "/tmp/fragcheck2.pl" "$1" read -sn 1 -p "When you are finished, press any key to continue... " rm "/tmp/fragcheck2.pl" } ################################################## # Delete function # ################################################## function del() { mv "$@" "/${HOME}/.local/share/Trash/files/" } function delete() { DIR=$1 shift for i in $*; do if [ -f $DIR/$i ]; then rm $DIR/$i fi done } ################################################## # Lookup a word with dict.org # ################################################## ###### define "whatever" function dic() { curl dict://dict.org/d:"$@" ; } ###### find matches of $1, with optional strat $2 and optional db $3 function ref() { if [[ -z $3 ]]; then curl dict://dict.org/m:${1}:english:${2}; else curl dict://dict.org/m:${1}:${3}:${2}; fi } ###### look in Webster function webster() { curl dict://dict.org/d:${1}:web1913; } ###### look in WordNet function wordnet() { curl dict://dict.org/d:${1}:wn; } ################################################## # Shell function to exit script with error in # # exit status and print optional message to # # stderr # ################################################## function die() { result=$1;shift;[ -n "$*" ]&&printf "%s\n" "$*" >&2;exit $result;} ################################################## # Diffs two xml files by formatting them first # # using xmllint and then invoking diff # ################################################## ###### usage: diffxml XMLFile1 XMLFile2 function diffxml() { diff -wb <(xmllint --format "$1") <(xmllint --format "$2"); } ################################################## # Dirsize - finds directory sizes and lists # # them for the current directory # ################################################## function dirsize() { du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \ egrep '^ *[0-9.]*[MG]' | sort -n > /tmp/list egrep '^ *[0-9.]*M' /tmp/list egrep '^ *[0-9.]*G' /tmp/list rm /tmp/list } ################################################## # Display off (Turns the display off) # ################################################## ###### turns the display off and will stay off until any key/cursor is touched function display-off() { cat > "/tmp/display-off.py" <<"End-of-message" #!/usr/bin/python import time import subprocess from Xlib import X from Xlib.display import Display display = Display(':0') root = display.screen().root root.grab_pointer(True, X.ButtonPressMask | X.ButtonReleaseMask | X.PointerMotionMask, X.GrabModeAsync, X.GrabModeAsync, 0, 0, X.CurrentTime) root.grab_keyboard(True, X.GrabModeAsync, X.GrabModeAsync, X.CurrentTime) subprocess.call('xset dpms force off'.split()) p = subprocess.Popen('gnome-screensaver-command -i'.split()) time.sleep(1) while True: print display.next_event() p.terminate() break End-of-message chmod +x "/tmp/display-off.py" "/tmp/display-off.py" /bin/rm "/tmp/display-off.py" } ###### turns the display off and will stay off until this command is run again or cancelled, even after key/cursor is touched function display-offed() { LF=/tmp/screen-lock; if [ -f $LF ]; then /bin/rm $LF; else touch $LF; sleep .5; while [ -f $LF ]; do xset dpms force off; sleep 2; done; fi ; } ###### turns the display off and will stay off until any key/cursor is touched # Display off with login (Turns the display off) function display-oft() { cat > "/tmp/display-oft.py" <<"End-of-message" #!/usr/bin/python import time import subprocess from Xlib import X from Xlib.display import Display display = Display(':0') root = display.screen().root root.grab_pointer(True, X.ButtonPressMask | X.ButtonReleaseMask | X.PointerMotionMask, X.GrabModeAsync, X.GrabModeAsync, 0, 0, X.CurrentTime) root.grab_keyboard(True, X.GrabModeAsync, X.GrabModeAsync, X.CurrentTime) subprocess.call('xset dpms force off'.split()) p = subprocess.Popen('gnome-screensaver-command -i'.split()) time.sleep(1) while True: print display.next_event() p.terminate() subprocess.Popen('gnome-screensaver-command -l'.split()) break End-of-message chmod +x "/tmp/display-oft.py" "/tmp/display-oft.py" /bin/rm "/tmp/display-oft.py" } ################################################## # Change to specified pkg's documentation dir and# # display the files # ################################################## ###### Usage: doc function doc() { pushd "/usr/share/doc/$1" && ls } ################################################## # Lists unique IPs currently connected to # # logged-in system & how many concurrent # # connections each IP has # ################################################## function doscheck() { "netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n" } ################################################## # Symlinks all hidden files in a directory to the# # same names without the dot # ################################################## function dot_ln() { for file in `/bin/ls -a | /bin/egrep "^\.[^./]"` ; do if [[ "$1" == "-f" ]] ; then /bin/ln -svif $file ${file:1} else /bin/ln -svi $file ${file:1} fi done } ################################################## # Site down for everyone or just me? # ################################################## function downforme() { RED='\e[1;31m' GREEN='\e[1;32m' YELLOW='\e[1;33m' NC='\e[0m' if [ $# = 0 ] then echo -e "${YELLOW}usage:${NC} downforme website_url" else JUSTYOUARRAY=(`lynx -dump http://downforeveryoneorjustme.com/$1 | grep -o "It's just you"`) if [ ${#JUSTYOUARRAY} != 0 ] then echo -e "${RED}It's just you. \n${NC}$1 is up." else echo -e "${GREEN}It's not just you! \n${NC}$1 looks down from here." fi fi } ################################################## # Size of directories in MB # ################################################## function ds() { echo "size of directories in MB" if [ $# -lt 1 ] || [ $# -gt 2 ]; then echo "you did not specify a directy, using pwd" DIR=$(pwd) find $DIR -maxdepth 1 -type d -exec du -sm \{\} \; | sort -nr else find $1 -maxdepth 1 -type d -exec du -sm \{\} \; | sort -nr fi } ################################################## # Size of items in directory # ################################################## function dubigf() { du -sh * | awk '/[[:space:]]*[[:digit:]]+,*[[:digit:]]*G/' | sort -nr du -sh * | awk '/[[:space:]]*[[:digit:]]+,*[[:digit:]]*M/' | sort -nr } ################################################## # Find duplicate/non-duplicate lines in series of# # files or in stdin # ################################################## ###### find duplicate lines function dups() { sort "$@" | uniq -d; } ###### find duplicate lines, keep just 1 of them, and output to txt file function dupscleaner() { sort "$@" | uniq -d > dupscleaned.txt; } ###### find duplicate lines, remove all non-duplicate lines and output to txt file function dupsonly() { sort "$@" | uniq -D > dupsonly.txt; } ###### find non-duplicate lines function nondups() { sort "$@" | uniq -u; } ###### find duplicate lines, remove all of them, keeping just non-duplicate lines and output to txt file function nondupsonly() { sort "$@" | uniq -u > nondupsonly.txt; } ################################################## # View portage changelog for specified package # ################################################## ###### $1 = package name function echange() { PACKAGE="$(eix -e --only-names $1)" if [ "$PACKAGE" != "" ]; then view /usr/portage/$PACKAGE/ChangeLog fi } ################################################## # Directory operations: editd, flipd, popd, # # printd, pushd, rotd, swapd # ################################################## ###### Edit directory stack function editd() { export EDITDNO=$((${EDITDNO:=0} + 1)) typeset FiLe=/tmp/`basename -- $0`$$.${EDITDNO} printd >${FiLe} ${EDITOR} ${FiLe} DS=`while read ea; do echo -n "$ea:"; done <${FiLe}` rm -f ${FiLe} } ###### flip back-and-forth between current dir and top of stack (like "cd -") function flipd() { if [ "$DS" ] then cd "${DS%%:*}" export DS="$OLDPWD:${DS#*:}" else echo "$0: empty directory stack" >&2 fi } ###### pop top dir off stack and cd to it function popd() { if [ "$DS" ] then cd "${DS%%:*}" export DS="${DS#*:}" else echo "$0: empty directory stack" >&2 fi } ###### Print directory stack function printd() { ( IFS=:; for each in $DS; do echo $each; done; ) } ###### Change to new dir, pushing current onto stack function pushd() { export DS="$PWD:$DS" if [ -n "$1" ]; then cd "$1"; else cd; fi || export DS="${DS#*:}" } ###### rotate thru directory stack (from bottom to top) function rotd() { if [ "$DS" ] then typeset DSr="${DS%:*:}" [ "${DSr}" = "${DS}" ] || export DS="${DS##${DSr}:}$DSr:" flipd else echo "$0: directory stack is empty" >&2 fi } ###### swap top two dir stack entries function swapd() { typeset DSr="${DS#*:}" if [ "$DSr" ] then export DS="${DSr%%:*}:${DS%%:*}:${DSr#*:}" else echo "$0: less than two on directory stack" >&2 fi } if [ ! -f ${HOME}/.lastdir ];then cat > ${HOME}/.lastdir fi alias lastd="cd $(cat ~/.lastdir)" # change to last dir at 'bye' ###### save current dir for lastd on exit if not $HOME alias saved='[ ${PWD} != ${HOME} ] && pwd >~/.lastdir; [ -n "${DS}" ] && echo "${DS}" >~/.dirstak' ###### get dir stack back on login [ -s ${HOME}/.dirstak ] && export DS=`cat ${HOME}/.dirstak` ################################################## # Download ed2k file # ################################################## function ed2k() { wget -q -O - "$1" | grep "ed2k://" | sed -e 's/^.*=//g;s/..$//g' } ################################################## # Edit your history file # ################################################## function eh() { history -a ; vi ~/.bash_history ; history -r ; } ################################################## # Elements database # ################################################## function ele() { dict -d elements $@ } ################################################## # Show empty files in the directed directory # ################################################## function empty() { # copyright 2007 - 2010 Christopher Bratusek find "$1" -empty } ################################################## # Surround lines with quotes (useful in pipes) # # - from mervTormel # ################################################## function enquote() { /usr/bin/sed 's/^/"/;s/$/"/' ; } ################################################## # Determining the meaning of error codes # ################################################## function err() { grep --recursive --color=auto --recursive -- "$@" /usr/include/*/errno.h if [ "${?}" != 0 ]; then echo "Not found." fi } ################################################## # View latest installable portage ebuild for # # specified package # ################################################## ###### $1 = package name function eview() { FILE=$(equery which $1) if [ -f "$FILE" ]; then view $FILE fi } ################################################## # Exchange stuff from two places # ################################################## function exchange() # copyright 2007 - 2010 Christopher Bratusek { typeset temp SAVE=$IFS IFS='' eval $(echo "temp=\"\$$1\"") eval $(echo "$1=\"\$$2\"") eval $(echo "$2=\"$temp\"") IFS=$SAVE } ################################################## # URLs ... # ################################################## ###### expand shortened URLs function expandurl() { curl -sIL $1 2>&1 | awk '/^Location/ {print $2}' | tail -n1; } ###### short URLs with is.gd function isgd() { /usr/bin/wget -qO - "http://is.gd/create.php?format=simple&url=$1" ;} ###### resolve short URLs function resolve() { curl -Is $1 | sed -n 's/^Location: //p'; } ################################################## # Extract - extract most common compression # # types # ################################################## function extract() { local e=0 i c for i; do if [[ -f $i && -r $i ]]; then c='' case $i in *.t@(gz|lz|xz|b@(2|z?(2))|a@(z|r?(.@(Z|bz?(2)|gz|lzma|xz))))) c='bsdtar xvf' ;; *.7z) c='7z x' ;; *.Z) c='uncompress' ;; *.bz2) c='bunzip2' ;; *.exe) c='cabextract' ;; *.gz) c='gunzip' ;; *.rar) c='unrar x' ;; *.xz) c='unxz' ;; *.zip) c='unzip' ;; *) echo "$0: cannot extract \`$i': Unrecognized file extension" >&2; e=1 ;; esac [[ $c ]] && command $c "$i" else echo "$0: cannot extract \`$i': File is unreadable" >&2; e=2 fi done return $e } ################################################## # CIA world fact book # ################################################## function fact() { dict -d world02 $@ } ################################################## # Passwording # ################################################## ###### fake name and pass function fakepass() { local l=8 [ -n "$1" ] && l=$1 dd if=/dev/urandom count=1 2> /dev/null | uuencode -m - | head -n 2 | tail -n 1 | cut -c $l } alias fakename='nc koeln.ccc.de 23 | cut -d \ -f 4,5' ###### password file function pw() { if [ "$OS" = "Linux" ]; then gpg $HOME/priv.asc vi -n $HOME/priv gpg -ea $HOME/priv wipe -f $HOME/priv elif [ "$OS" = "Darwin" ]; then gpg $HOME/Documents/priv.asc vi -n $HOME/Documents/priv gpg -ea $HOME/Documents/priv srm -f $HOME/Documents/priv fi } ###### generate a random password # $1 = number of characters; defaults to 32 # $2 = include special characters; 1 = yes, 0 = no; defaults to 1 # copyright 2007 - 2010 Christopher Bratusek function randompw() { if [[ $2 == "!" ]]; then echo $(cat /dev/urandom | tr -cd '[:graph:]' | head -c ${1:-32}) else echo $(cat /dev/urandom | tr -cd '[:alnum:]' | head -c ${1:-32}) fi } ###### generate a random left-hand password alias randompwl='&- | \ sed "s/$1/${SMSO}\0${RMSO}/gI" | more } ###### searches through the text of all the files in your current directory # http://seanp2k.com/?p=13 # Good for debugging a PHP script you didn't write and can't trackdown where MySQL connect string actually is # function grip() { # grep -ir "$1″ "$PWD" # } ###### ... who is the newest file in a directory function newest() { find ${1:-\.} -type f |xargs ls -lrt ; } ################################################## # Festival - text-to-speech # ################################################## ###### requires festival: sudo apt-get install festival # Usage: fest "text" function fest() { echo $1 | festival --tts } ################################################## # Find in file and ( AND relation ) # ################################################## # Will search PWD for text files that contain $1 AND $2 AND $3 etc... # Actually it does the same as grep word1|grep word2|grep word3 etc, but in a more elegant way. function ffa() { (($# < 2)) && { echo "usage: ffa pat1 pat2 [...]" >&2; return 1; };awk "/$1/$(printf "&&/%s/" "${@:2}")"'{ print FILENAME ":" $0 }' *; } ################################################## # Alternative for basename using grep to extract # # file name # ################################################## ###### eg: fileName /path/to/file.ext function fileName() { echo "$1" | grep -o "[^/]*$"; } ################################################## # Extract extention of a file # ################################################## function filext() { echo ${1##*.}; } ################################################## # Pick the first program found from a list of # # alternatives # ################################################## ###### used to set environmental variables from list of alternatives depending on what's installed (uses bash setting 'export BROWSER' above) # it returns the first program found in the list # Usage: export BROWSER=$(find_alternatives chromium-browser google-chrome opera firefox firefox-bin iceweasel konqueror w3m lynx) function find_alternatives() { for i;do which "$i" >/dev/null && { echo "$i"; return 0;};done;return 1; } ################################################## # Find out the pid of a specified process # ################################################## ###### note that the command name can be specified via a regex # E.g. findPid '/d$/' finds pids of all processes with names ending in 'd' # Without the 'sudo' it will only find processes of the current user function findPid() { sudo /usr/sbin/lsof -t -c "$@" ; } ################################################## # Search for a word in the Unix word list # ################################################## function findword() { /usr/bin/grep ^"$@"$ /usr/share/dict/words ; } ################################################## # Recursively fix dir/file permissions on a # # given directory # ################################################## function fix() { if [ -d $1 ]; then find $1 -type d -exec chmod 755 {} \; find $1 -type f -exec chmod 644 {} \; else echo "$1 is not a directory." fi } ################################################## # Edit files in place to ensure Unix line- # # endings # ################################################## function fixlines() { /usr/bin/perl -pi~ -e 's/\r\n?/\n/g' "$@" ; } ################################################## # Fix eclipse mistakes with tabs # ################################################## ###### Sources files should never use TABs for indenting because they may looks different in different editors # For example there popular Eclipse IDE use a the non default tab size 4 function fix-tabs() { expand -t 4 "$1" > "$1.expanded"; mv -f "$1.expanded" "$1"; } ################################################## # Inserts a flag with the specified content # ################################################## ###### Usage: flag "comment" # If no comment, inserts the date. function flag() { if [ "$1" == "" ]; then echo -e "\e[0;31m[====== " `date +"%A %e %B %Y"`, `date +"%H"`h`date +"%M"` " ======]\e[0m" else echo -e "\e[0;31m[====== " $@ " ======]\e[0m" fi } ################################################## # Inserts a flag and executes the command # ################################################## ###### Example: flagcommand ls function flagcommand() { if [ "$1" == "" ]; then return else flag $@ $@ fi } ################################################## # Flight status # ################################################## ###### track flights from the command line (requires html2text: sudo apt-get install html2text) function flight_status() { if [[ $# -eq 3 ]];then offset=$3; else offset=0; fi; curl "http://mobile.flightview.com/TrackByRoute.aspx?view=detail&al="$1"&fn="$2"&dpdat=$(date +%Y%m%d -d ${offset}day)" 2>/dev/null |html2text |grep ":"; } ################################################## # Autofocus window after executing some command` # ################################################## ###### example: focus make all # from: http://noisy-coder.blogspot.com/2010/10/autofocus-window.html function focus() { winID=`xprop -root |awk '/_NET_ACTIVE_WINDOW/ {print $5; exit;}'`; $@; wmctrl -i -a $winID; } ################################################## # Weather and stuff # ################################################## ###### 10-day forcast # USAGE: forecast 50315 function forecast() { _ZIP=$1 if [ $# = 1 ];then printf "$_ZIP\n" | egrep '^[0-9][0-9][0-9][0-9][0-9]$' >>/dev/null if [ $? = 0 ];then printf "Your 10 Day Weather Forecast as follows:\n"; lynx -dump "http://www.weather.com/weather/print/$_ZIP" | sed -n '/%$/s/\[.*\]//p'; printf "\n" elif [ $? = 1 ];then printf "Bad ZIP code!\n" fi elif [ $# != 1 ];then printf "You need to supply a ZIP code!\n" fi } ###### get sunrise and sunset times function suntimes() { l=12765843;curl -s http://weather.yahooapis.com/forecastrss?w=$l|grep astronomy| awk -F\" '{print $2 "\n" $4;}' } ###### weather-util # requires "weather-util" and "weather-util-data" # sudo apt-get install weather-util weather-util-data # usage = weather 'zip'/'location'/'code' # weather search without extended forecast alias weather='weather-util' # weather search with extended forecast alias weatherf='weather-util --forecast' ###### weather by US zip code - Can be called two # ways # weather 50315 # weather "Des # Moines" function weather_() { declare -a WEATHERARRAY WEATHERARRAY=( `lynx -dump http://google.com/search?q=weather+$1 | grep -A 5 '^ *Weather for' | grep -v 'Add to'`) echo ${WEATHERARRAY[@]} } ###### weather search with function "forecast" function zipweather() { search=$1 weather-util $search forecast $search } ################################################## # Easily run a program in the background without # # losing output # ################################################## function fork() { tf=$(tempfile -d /tmp -p $1.);echo -n "$tf "; $@ &>$tf& } ################################################## # Get FreeMusicCharts of the current month # ################################################## function freemusiccharts() { wget -O - "http://www.darkerradio.com/news/free-music-charts-$(date "+%B-%Y")/" 2> /dev/null | grep -o "http://[^ \"']*\.mp3" |grep "freemusiccharts.songs" | sort | uniq | xargs -n1 wget -c } ################################################## # Find all bash functions in a file # ################################################## ###### finds all functions defined in any shell script secified, including .bashrc function functions() { read -p "File name> "; sort -d $REPLY | grep "() {" | sed -e 's/() {//g' | less; } ################################################## # ISO-maker from disc # ################################################## function geniso() { # copyright 2007 - 2010 Christopher Bratusek if [[ $CD_WRITER ]]; then dd $DD_OPTS if=$CD_WRITER of="$1" else dd $DD_OPTS if=/dev/dvdrw of="$1" fi } ################################################## # Extract a particular column of space- # # separated output # ################################################## ###### e.g.: lsof | getcolumn 0 | sort | uniq function getcolumn() { perl -ne '@cols = split; print "$cols['$1']\n"' ; } ################################################## # Get duration of an audio file in seconds. # ################################################## function get_duration() { durline=$(sox "$1" -n stat 2>&1|grep "Length (seconds):");echo ${durline#*\: }; } ################################################## # Get/verify info on stuff (useful in other # # functions) # ################################################## ###### Author: Josh Bailey # Email: jbsnake usalug.org function getExtension() # Author: Josh Bailey # Email: jbsnake usalug.org # further tweaked by: jsz # usage: getExtension { echo "${1##*.}"; } function getFileName() # Author: Josh Bailey # Email: jbsnake usalug.org # further tweaked by: jsz # usage: getFileName { local filename=${1##*/} echo "${filename%.*}" } function getPath() # Author: Josh Bailey # Email: jbsnake usalug.org # further tweaked by: jsz # usage: getPath { echo "${1%/*}"; } function inStr() # Author: Josh Bailey # Email: jbsnake usalug.org # further tweaked by: jsz # usage: inStr { local i for ((i = 0; i < ${#2}; i++)); do if [[ ${2:i:1} = $1 ]]; then echo "$i" fi done } function notADot() # Author: Josh Bailey # Email: jbsnake usalug.org { if [[ ${1} != '.' ]] then return 0 else return 1 fi } function notAForwardSlash() { if [[ ${1} != '/' ]] then return 0 else return 1 fi } ################################################## # Download the latest kernel # ################################################## function get_kernel() { # copyright 2007 - 2010 Christopher Bratusek if [[ $1 == "-s" ]]; then wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-${2}.tar.bz2 elif [[ $1 == "-t" ]]; then wget http://www.kernel.org/pub/linux/kernel/v2.6/testing/linux-${2}.tar.bz2 elif [[ $1 == "-sg" ]]; then git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-${2}.y.git elif [[ $1 == "-tg" ]]; then git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git elif [[ $1 == "-z" ]]; then wget http://downloads.zen-kernel.org/${2}/${2}-zen${3}.patch.lzma fi } ################################################## # Git stuff # ################################################## ###### copyright 2007 - 2010 Christopher Bratusek function git_action() { if [[ -d .git ]]; then if [[ -f .git/dotest/rebasing ]]; then ACTION="rebase" elif [[ -f .git/dotest/applying ]]; then ACTION="apply" elif [[ -f .git/dotest-merge/interactive ]]; then ACTION="rebase -i" elif [[ -d .git/dotest-merge ]]; then ACTION="rebase -m" elif [[ -f .git/MERGE_HEAD ]]; then ACTION="merge" elif [[ -f .git/index.lock ]]; then ACTION="locked" elif [[ -f .git/BISECT_LOG ]]; then ACTION="bisect" else ACTION="nothing" fi echo $ACTION else echo -- fi } function git_branch() { if [[ -d .git ]]; then BRANCH=$(git symbolic-ref HEAD 2>/dev/null) echo ${BRANCH#refs/heads/} else echo -- fi } function git_bzip() { git archive master | bzip2 -9 >"$PWD".tar.bz2 } function git_e() { if [[ "$SVN_USER_ENLIGTENMENT" && $1 == "-m" ]]; then svn co svn+ssh://"$SVN_USER_ENLIGTENMENT"@svn.enlightenment.org/var/svn/$2 else svn co http://svn.enlightenment.org/svn/$2 fi } function git_export() { if [[ "$1" != "" ]]; then git checkout-index --prefix="$1"/ -a fi } function git_gnome() { if [[ $GIT_USER_GNOME ]]; then if [[ $1 == "-m" ]]; then git clone git+ssh://$GIT_USER_GNOME@git.gnome.org/git/$2 elif [[ $1 == "-mb" ]]; then git clone -b $3 git+ssh://$GIT_USER_GNOME@git.gnome.org/git/$2 fi fi if [[ $1 == "-b" ]]; then git clone -b $3 git://git.gnome.org/$2 else git clone git://git.gnome.org/$1 fi } function git_kde() { if [[ "$SVN_USER_KDE" ]]; then if [[ $1 == "-m" ]]; then svn co --user-name="$SVN_USER_KDE" svn+ssh://svn.kde.org/home/kde/trunk/KDE/$2 elif [[ $1 == "-mb" ]]; then svn co --user-name="$SVN_USER_KDE" svn+ssh://svn.kde.org/home/kde/branches/KDE/$2 fi fi if [[ $1 == "-b" ]]; then svn co svn://svn.kde.org/home/kde/branches/KDE/$2 else svn co svn://svn.kde.org/home/kde/trunk/KDE/$2 fi } function git_revision() { if [[ -d .git ]]; then REVISION=$(git rev-parse HEAD 2>/dev/null) REVISION=${REVISION/HEAD/} echo ${REVISION:0:6} else echo -- fi } function git_xfce() { if [[ $GIT_USER_XFCE ]]; then if [[ $1 == "-m" ]]; then git clone ssh://$GIT_USER_XFCE@git.xfce.org/git/$2 elif [[ $1 == "-mb" ]]; then git clone -b $3 ssh://$GIT_USER_XFCE@git.xfce.org/git/$2 fi fi if [[ $1 == "-b" ]]; then git clone -b $3 git://git.xfce.org/$2 else git clone git://git.xfce.org/$1 fi } function git_xz() { git archive master | xz -9 > "$PWD".tar.xz } function gup() { git fetch && git rebase origin/$(git branch | grep '^\*' | cut -d\ -f2) } ###### edit the svn log at the given revision function svnlogedit() { svn propedit svn:log --revprop -r$1 --editor-cmd gedit } ###### svn recursive directory/file adder # this will recursively add files/directories in SVN function svnradd() { for i in $1/*;do if [ -e "$i" ];then if [ -d "$i" ];then svn add $i;svnradd $i;else svn add $i;fi; fi;done } ###### bash function for convenient 'find' in subversion working directories function svn_find() { local a=$1; shift; find $a -not \( -name .svn -prune \) $*; } ###### display the revision number of the current repository function svn_rev() { svn info $@ | awk '/^Revision:/ {print $2}' } ###### do a svn update and show the log messages since the last update function svn_uplog() { local old_revision=`svn_rev $@` local first_update=$((${old_revision} + 1)) svn up -q $@ if [ $(svn_rev $@) -gt ${old_revision} ] then svn log -v -rHEAD:${first_update} $@ else echo "No Changes." fi } ################################################## # Speed up builds and scripts, remove duplicate # # entries in $PATH. Users scripts are often bad: # # PATH=/apath:$PATH type of thing cause duplicate# ################################################## function glu() { (local IFS="$1"; shift && echo "$*") } function repath() { ( _E=`echo "${PATH//:/$'\n'}" | awk '!x[$0]++'`; glu ":" $_E ) ; } PATH=`repath` export PATH ################################################## # Pipe stdout to image and mail # ################################################## function gotxt2imgmail() { if [ $# != 1 ]; then echo 'gotxt2imgmail < email >'; return; fi; e="$1"; f=$RANDOM.png; convert label:@- $f; echo "" | mailx -s $f -a $f $e ; } ################################################## # Twitter, Twitter, Twitter # ################################################## ###### view someone's twitter stream from terminal function grabtweets() { curl -s "twitter.com/$1" | sed -ne '/entry-content/{s/<[^>]*>//g;s/^[ \t]*//;p}'; } ###### update twitter via curl as function function tweet() { curl -u "$1" -d status="$2" "http://twitter.com/statuses/update.xml"; } ################################################## # Hide/Unhide file(s)/folder(s) in Nautilus # ################################################## ###### Hide-Unhide-In-Nautilus.sh # Usage: hideme filename (hideme whatever.txt) function hideme() { # Creator: Inameiname # Date: 21 June 2011 # Version: 1.0 # # # This is a simple nautilus script to automatically add file(s)/folder(s) # to a ".hidden" file so Nautilus will hide them, just like ".*" files # Instructions: # - decide what file(s)/folder(s) you want to hide inside a particular folder, # - highlight them, and right click and select the script # - it will automatically add the filenames to a created ".hidden" file inside the directory # - if ".hidden" isn't there, it will add it # - if you decide to unhide things, simply highlight and select the script again, # - and it will automatically remove the filenames from the ".hidden" file # - if ".hidden" contains no filenames, it will remove it # # # Optionals: # - Add the option to change the owner and group for whatever is selected to hide/unhide # - Add the option to add the permissions for whatever is selected to hide/unhide # - Add the option to make executable whatever is selected to hide/unhide # # # Remember this only works inside the current directory/opened folder and files/folders inside that folder. # Just comment out or uncomment whatever desired. # Currently, only the ability to hide/unhide stuff is uncommented, # but you can always just comment it out, and uncomment one of the "Make Executable" commands, # and/or one of the "Change the owner and/or group of each file" commands, # and/or one of the "Add permissions" commands, or mix and match whatever you want. # # # For the changes to take effect to the file(s)/folder(s) you hid/unhid, you may have to refresh the folder, or even Nautilus # Set IFS so that it won't consider spaces as entry separators. # Without this, spaces in file/folder names can make the loop go wacky. IFS=$'\n' # See if the Nautilus environment variable is empty if [ -z $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS ]; then # If it's blank, set it equal to $1 NAUTILUS_SCRIPT_SELECTED_FILE_PATHS=$1 fi # Loop through the list (from either Nautilus or the command line) for ARCHIVE_FULLPATH in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS; do NEWDIRNAME=${ARCHIVE_FULLPATH%.*} FILENAME=${ARCHIVE_FULLPATH##*/} NAME=${ARCHIVE_FULLPATH##*/.*} # Hide/Unhide file(s)/folder(s) using ".hidden" file within the current folder # Copies all selected files/folders filenames to ".hidden" echo $FILENAME >> .hidden # Sorts and Checks ".hidden" for any duplicates sort .hidden | uniq -u > .hidden_temp rm .hidden mv .hidden_temp .hidden # Checks ".hidden" to see if there is anything there; if not, it removes it for file in .hidden do if [ `wc -l < $file` -eq 0 ]; then # file is empty rm $file fi done # Change the owner and/or group of each FILE to OWNER and/or GROUP, if desired # chown -R $USER:$USER $ARCHIVE_FULLPATH # set owner:group to current user # gnome-terminal -x sudo chown -R root:root $ARCHIVE_FULLPATH # set owner:group to root # gnome-terminal -x sudo chown -R $USER:$USER $ARCHIVE_FULLPATH # set owner:group to current user # Add permissions, if desired # chmod 444 $ARCHIVE_FULLPATH # read-only permissions for all # chmod 600 $ARCHIVE_FULLPATH # read/write for you, no permissions for rest # chmod 644 $ARCHIVE_FULLPATH # read/write for you, read-only permissions for rest (default) # sudo chmod 444 $ARCHIVE_FULLPATH # read-only permissions for all # sudo chmod 600 $ARCHIVE_FULLPATH # read/write for you, no permissions for rest # sudo chmod 644 $ARCHIVE_FULLPATH # read/write for you, read-only permissions for rest (default) # Make executable, if desired # chmod +x $ARCHIVE_FULLPATH # gnome-terminal -x sudo chmod +x $ARCHIVE_FULLPATH done # Add a notification when finished, if desired echo -n '' echo -n 'Job Finished ' } alias unhideme='hideme' ################################################## # Cool History Summerizer # ################################################## function historyawk() { history|awk '{a[$2]++}END{for(i in a){printf"%5d\t%s\n",a[i],i}}'|sort -nr|head; } ################################################## # Progress visuals # ################################################## ###### display animated hourglass in the shell to indicate ongoing processing function hourglass() { s=$(($SECONDS +${1:-10}));(tput civis;while [[ $SECONDS -lt $s ]];do for f in '|' ' ' '\-' /;do echo -n $f&&sleep .2s&&tput cub1;done;done);tput cnorm; } ###### pretty progressbar function progressbar() # copyright 2007 - 2010 Christopher Bratusek { SP_COLOUR="\e[37;44m" SP_WIDTH=5.5 SP_DELAY=0.2 SP_STRING=${2:-"'|/=\'"} while [ -d /proc/$1 ] do printf "$SP_COLOUR\e7 %${SP_WIDTH}s \e8\e[01;37m" "$SP_STRING" sleep ${SP_DELAY:-.2} SP_STRING=${SP_STRING#"${SP_STRING%?}"}${SP_STRING%?} done tput sgr0 } ###### please wait... # copyright 2007 - 2010 Christopher Bratusek function spanner() { PROC=$1;COUNT=0 echo -n "Please wait " while [ -d /proc/$PROC ];do while [ "$COUNT" -lt 10 ];do echo -ne '\x08 ' ; sleep 0.1 ((COUNT++)) done until [ "$COUNT" -eq 0 ];do echo -ne '\x08\x08 ' ; sleep 0.1 ((COUNT -= 1)) done done } function spin() { # copyright 2007 - 2010 Christopher Bratusek echo -n "|/ |" while [ -d /proc/$1 ] do # moving right echo -ne "\b\b\b\b\b\b\b- |" sleep .05 echo -ne "\b\b\b\b\b\b\b\\ |" sleep .05 echo -ne "\b\b\b\b\b\b\b| |" sleep .05 echo -ne "\b\b\b\b\b\b\b / |" sleep .05 echo -ne "\b\b\b\b\b\b- |" sleep .05 echo -ne "\b\b\b\b\b\b\\ |" sleep .05 echo -ne "\b\b\b\b\b\b| |" sleep .05 echo -ne "\b\b\b\b\b\b / |" sleep .05 echo -ne "\b\b\b\b\b- |" sleep .05 echo -ne "\b\b\b\b\b\\ |" sleep .05 echo -ne "\b\b\b\b\b| |" sleep .05 echo -ne "\b\b\b\b\b / |" sleep .05 echo -ne "\b\b\b\b- |" sleep .05 echo -ne "\b\b\b\b\\ |" sleep .05 echo -ne "\b\b\b\b| |" sleep .05 echo -ne "\b\b\b\b / |" sleep .05 echo -ne "\b\b\b- |" sleep .05 echo -ne "\b\b\b\\ |" sleep .05 echo -ne "\b\b\b| |" sleep .05 echo -ne "\b\b\b /|" sleep .05 echo -ne "\b\b-|" sleep .05 echo -ne "\b\b\\|" sleep .05 echo -ne "\b\b||" sleep .05 echo -ne "\b\b/|" sleep .05 # moving left echo -ne "\b\b||" sleep .05 echo -ne "\b\b\\|" sleep .05 echo -ne "\b\b-|" sleep .05 echo -ne "\b\b\b/ |" sleep .05 echo -ne "\b\b\b| |" sleep .05 echo -ne "\b\b\b\\ |" sleep .05 echo -ne "\b\b\b- |" sleep .05 echo -ne "\b\b\b\b/ |" sleep .05 echo -ne "\b\b\b\b| |" sleep .05 echo -ne "\b\b\b\b\\ |" sleep .05 echo -ne "\b\b\b\b- |" sleep .05 echo -ne "\b\b\b\b\b/ |" sleep .05 echo -ne "\b\b\b\b\b| |" sleep .05 echo -ne "\b\b\b\b\b\\ |" sleep .05 echo -ne "\b\b\b\b\b- |" sleep .05 echo -ne "\b\b\b\b\b\b/ |" sleep .05 echo -ne "\b\b\b\b\b\b| |" sleep .05 echo -ne "\b\b\b\b\b\b\\ |" sleep .05 echo -ne "\b\b\b\b\b\b- |" sleep .05 echo -ne "\b\b\b\b\b\b\b/ |" sleep .05 done echo -e "\b\b\b\b\b\b\b\b\b|=======| done!" } function spinner() # copyright 2007 - 2010 Christopher Bratusek { PROC=$1 while [ -d /proc/$PROC ];do echo -ne '\e[01;32m/\x08' ; sleep 0.05 echo -ne '\e[01;32m-\x08' ; sleep 0.05 echo -ne '\e[01;32m\\\x08' ; sleep 0.05 echo -ne '\e[01;32m|\x08' ; sleep 0.05 done } ###### Display a progress process # To start the spinner2 function, you have to send the function # into the background. To stop the spinner2 function, you have # to define the argument "stop". # EXAMPLE: # echo -n "Starting some daemon "; spinner2 & # if sleep 10; then # spinner2 "stop"; echo -e "\t[ OK ]" # else # spinner2 "stop"; echo -e "\t[ FAILED ]" # fi function spinner2() { local action=${1:-"start"} declare -a sign=( "-" "/" "|" "\\\\" ) # define singnal file... [ "$action" = "start" ] && echo 1 > /tmp/signal [ "$action" = "stop" ] && echo 0 > /tmp/signal while [ "$( cat /tmp/signal 2>/dev/null )" == "1" ] ; do for (( i=0; i<${#sign[@]}; i++ )); do echo -en "${sign[$i]}\b" # with this command you can use millisecond as sleep time - perl rules ;-) perl -e 'select( undef, undef, undef, 0.1 );' done done # clear the last ${sign[$i]} sign at finish... [ "$action" = "stop" ] && echo -ne " \b" } function working() # copyright 2007 - 2010 Christopher Bratusek { while [ -d /proc/$1 ] do echo -ne "w \b\b\b\b\b\b\b";sleep .08; echo -ne "wo \b\b\b\b\b\b\b";sleep .08; echo -ne "wor \b\b\b\b\b\b\b";sleep .08; echo -ne "work \b\b\b\b\b\b\b";sleep .08; echo -ne "worki \b\b\b\b\b\b\b";sleep .08; echo -ne "workin \b\b\b\b\b\b\b";sleep .08; echo -ne "working\b\b\b\b\b\b\b";sleep .08; echo -ne " orking\b\b\b\b\b\b\b";sleep .08; echo -ne " rking\b\b\b\b\b\b\b";sleep .08; echo -ne " king\b\b\b\b\b\b\b";sleep .08; echo -ne " ing\b\b\b\b\b\b\b";sleep .08; echo -ne " ng\b\b\b\b\b\b\b";sleep .08; echo -ne " g\b\b\b\b\b\b\b";sleep .08; done } ################################################## # Get just the HTTP headers from a web page # # (and its redirects) # ################################################## function http_headers() { /usr/bin/curl -I -L $@ ; } ################################################## # Convert number of bytes to human readable # # filesize # ################################################## function human_filesize() { awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } ' ; } ################################################## # :h gets you to the vim help menu or directly # # to :help wordname # ################################################## function :h() { vim --cmd ":silent help $@" --cmd "only"; } ################################################## # Show computer information of all sorts # # (requires 'gawk': sudo apt-get install gawk) # ################################################## ###### machine details function ii() { echo -e "\n${RED}You are logged onto:$NC " ; hostname echo -e "\n${RED}Additionnal information:$NC " ; uname -a echo -e "\n${RED}Users logged on:$NC " ; w -h echo -e "\n${RED}Current date:$NC " ; date echo -e "\n${RED}Machine stat:$NC " ; uptime echo -e "\n${RED}Disk space:$NC " ; df -h echo -e "\n${RED}Memory stats (in MB):$NC " ; if [ "$OS" = "Linux" ]; then free -m elif [ "$OS" = "Darwin" ]; then vm_stat fi echo -e "\n${RED}IPs:$NC " ; ips } ###### paste hardware list (hwls) in html format into # pastehtml.com directly from console and return URI function listhw() { curl -s -S --data-urlencode "txt=$(sudo lshw -html)" "http://pastehtml.com/upload/create?input_type=html&result=address";echo; } ###### full memcache client in under 255 chars (uses dd, sed and nc) # usage: mem memcache-command [arguments] function mem() { { case $1 in st*|[gid]*) printf "%s " "$@";; *) dd if=$3 2>&1|sed '$!d;/^0/d;s/ .*//;s/^/'"$1"' '"$2"' 1 0 /; r '"$3"'' 2>/dev/null;;esac;printf "\r\nquit\r\n";}|nc -n 127.0.0.1 11211; } ###### notify on Battery power # works on laptops, desktop having communication b/w UPS & CPU function NotifyOnBATTERY() { while :; do on_ac_power||notify-send "Running on BATTERY"; sleep 1m; done ; } ###### colored status of running services function services() { printf "$(service --status-all 2>&1|sed -e 's/\[ + \]/\\E\[42m\[ + \]\\E\[0m/g' -e 's/\[ - \]/\\E\[41m\[ - \]\\E\[0m/g' -e 's/\[ ? \]/\\E\[43m\[ ? \]\\E\[0m/g')\n"; } function show_battery_load() # copyright 2007 - 2010 Christopher Bratusek { case $1 in *acpi ) check_opt acpi show_battery_load::acpi if [[ $? != "1" ]]; then load=$(acpi -b | sed -e "s/.* \([1-9][0-9]*\)%.*/\1/") out="$(acpi -b)" state="$(echo "${out}" | awk '{print $3}')" case ${state} in charging,) statesign="^" ;; discharging,) statesign="v" ;; charged,) statesign="°" ;; esac battery="${statesign}${load}" echo $battery fi ;; *apm ) check_opt apm show_battery_load::apm if [[ $? != "1" ]]; then result="$(apm)" case ${result} in *'AC on'*) state="^" ;; *'AC off'*) state="v" ;; esac load="${temp##* }" battery="${state}${load}" echo $battery fi ;; * ) echo -e "\n${ewhite}Usage:\n" echo -e "${eorange}show_battery_load${ewhite} |${egreen} --acpi${eiceblue} [show batteryload using acpi]\ \n${eorange}show_battery_load${ewhite} |${egreen} --apm${eiceblue} [show batteryload using apm]" | column -t echo "" tput sgr0 ;; esac } function show_cpu_load() # copyright 2007 - 2010 Christopher Bratusek { case $1 in *help ) echo -e "\n${ewhite}Usage:\n" echo -e "${eorange}show_cpu_load${ewhite} |${egreen} ! no options !\n" tput sgr0 ;; * ) NICE_IGNORE=20 t="0" while read cpu ni; do if [[ $ni == *-* || $ni -le $NICE_IGNORE ]]; then t="$t + $cpu" fi if [[ ${cpu%%.*} -eq 0 ]]; then break fi done < <(ps -Ao "%cpu= ni="| sort -r) cpu=$(echo "$t" | bc) if [[ ! "${cpu#.}x" = "${cpu}x" ]]; then cpu="0${cpu}" fi cpu=${cpu%%.*} if [[ $cpu -gt 100 ]]; then cpu=100 fi if [[ $cpu -lt 16 ]]; then color=${eiceblue} elif [[ $cpu -lt 26 ]]; then color=${eturqoise} elif [[ $cpu -lt 41 ]]; then color=${esmoothgreen} elif [[ $cpu -lt 61 ]]; then color=${egreen} elif [[ $cpu -lt 81 ]]; then color=${eyellow} else color=${ered} fi if [[ $cpu -lt 10 ]]; then prepend=00 elif [[ $cpu -lt 100 ]]; then prepend=0 fi if [[ $enabcol == true ]]; then echo -e "$color$prepend$cpu" else echo $prepend$cpu fi ;; esac } function show_mem() { # copyright 2007 - 2010 Christopher Bratusek case $1 in *used ) used=$(free -m | grep 'buffers/cache' | awk '{print $3}') if [[ $used -lt 1000 ]]; then echo 0$used elif [[ $used -lt 100 ]]; then echo 00$used else echo $used fi ;; *free ) free=$(free -m | grep 'buffers/cache' | awk '{print $4}') if [[ $free -lt 1000 ]]; then echo 0$free elif [[ $free -lt 100 ]]; then echo 00$ree else echo $free fi ;; *used-percent ) free | { read read m t u f s b c; f=$[$f + $b + $c] f=$[100-100*$f/$t] if [ $f -gt 100 ]; then f=100 fi echo ${f}% } ;; *free-percent ) free | { read read m t u f s b c; f=$[$f + $b + $c] f=$[100-100*$f/$t] if [ $f -gt 100 ]; then f=100 fi echo $((100-${f}))% } ;; * ) echo -e "\n${ewhite}Usage:\n" echo -e "\n${eorange}show_mem ${ewhite}|${egreen} --used ${eiceblue}[display used memory in mb]\ \n${eorange}show_mem ${ewhite}|${egreen} --free ${eiceblue}[display free memory in mb]\ \n${eorange}show_mem ${ewhite}|${egreen} --percent-used ${eiceblue}[display used memory in %]\ \n${eorange}show_mem ${ewhite}|${egreen} --percent-free ${eiceblue}[display free memory in %]" | column -t echo "" tput sgr0 ;; esac } function show_size() # copyright 2007 - 2010 Christopher Bratusek { case $1 in *help ) echo -e "\n${ewhite}Usage:\n" echo -e "${eorange}show_size ${ewhite}|${egreen} ! no options !\n" tput sgr0 ;; * ) let TotalBytes=0 for Bytes in $(ls -lA -1 | grep "^-" | awk '{ print $5 }'); do let TotalBytes=$TotalBytes+$Bytes done if [ $TotalBytes -lt 1024 ]; then TotalSize=$(echo -e "scale=1 \n$TotalBytes \nquit" | bc) suffix="B" elif [ $TotalBytes -lt 1048576 ]; then TotalSize=$(echo -e "scale=1 \n$TotalBytes/1024 \nquit" | bc) suffix="KB" elif [ $TotalBytes -lt 1073741824 ]; then TotalSize=$(echo -e "scale=1 \n$TotalBytes/1048576 \nquit" | bc) suffix="MB" else TotalSize=$(echo -e "scale=1 \n$TotalBytes/1073741824 \nquit" | bc) suffix="GB" fi echo "${TotalSize} ${suffix}" ;; esac } function show_space() # copyright 2007 - 2010 Christopher Bratusek { case $1 in *used-percent ) echo $(df | grep -w $2 | gawk '{print $5}') ;; *free-percent ) echo $((100-$(df | grep -w $2 | gawk '{print $5}' | sed -e 's/\%//g')))% ;; *used ) echo $(df -h | grep -w $2 | gawk '{print $3}')B ;; *free ) echo $(df -h | grep -w $2 | gawk '{print $4}')B ;; *total ) echo $(df -h | grep -w $2 | gawk '{print $2}')B ;; * ) echo -e "\n${ewhite}Usage:\n" echo -e "${eorange}show_space ${ewhite}|${egreen} --used ${eiceblue}[display used space in mb/gb]\ \n${eorange}show_space ${ewhite}|${egreen} --free ${eiceblue}[display free space in mb/gb]\ \n${eorange}show_space ${ewhite}|${egreen} --percent-used ${eiceblue}[display used space in %]\ \n${eorange}show_space ${ewhite}|${egreen} --percent-free ${eiceblue}[display free space in %]" | column -t echo "" tput sgr0 ;; esac } function show_system_load() { # copyright 2007 - 2010 Christopher Bratusek case $1 in 1 ) load=$(uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\)/\1/" -e "s/ //g") ;; 10 ) load=$(uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\)/\2/" -e "s/ //g") ;; 15 ) load=$(uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\)/\3/" -e "s/ //g") ;; *help | "") echo -e "\n${ewhite}Usage:\n" echo -e "${eorange}show_system_load${ewhite} | ${egreen}1 ${eiceblue}[load average for 1 minute]\ \n${eorange}show_system_load${ewhite} | ${egreen}10 ${eiceblue}[load average for 10 minutes]\ \n${eorange}show_system_load${ewhite} | ${egreen}15 ${eiceblue}[load average for 15 minutes]\n" | column -t tput sgr0 ;; esac if [[ $load != "" ]]; then tmp=$(echo $load*100 | bc) load100=${tmp%.*} if [[ $enabcol == true ]]; then if [[ ${load100} -lt 35 ]]; then loadcolor=${eblue} elif [[ ${load100} -ge 35 ]] && [[ ${load100} -lt 120 ]]; then loadcolor=${eiceblue} elif [[ ${load100} -ge 120 ]] && [[ ${load100} -lt 200 ]]; then loadcolor=${egreen} elif [[ ${load100} -ge 200 ]] && [[ ${load100} -lt 300 ]]; then loadcolor=${eyellow} else loadcolor=${ered} fi fi echo -e $loadcolor$load fi } function show_tty() # copyright 2007 - 2010 Christopher Bratusek { case $1 in *help ) echo -e "\n${ewhite}Usage:\n" echo -e "${eorange}show_tty${ewhite}|${egreen} ! no options !\n" tput sgr0 ;; * ) TTY=$(tty) echo ${TTY:5} | sed -e 's/\//\:/g' ;; esac } function show_uptime() { # copyright 2007 - 2010 Christopher Bratusek case $1 in *help ) echo -e "\n${ewhite}Usage:\n" echo -e "${eorange}show_uptime${ewhite} |${egreen} ! no options !\n" tput sgr0 ;; * ) uptime=$( 86400 )); then (( daysused=timeused/86400, hoursused=timeused/3600-daysused*24, minutesused=timeused/60-hoursused*60-daysused*60*24, secondsused=timeused-minutesused*60-hoursused*3600-daysused*3600*24 )) if (( hoursused < 10 )); then hoursused=0${hoursused} fi if (( minutesused < 10 )); then minutesused=0${minutesused} fi if (( secondsused < 10 )); then secondsused=0${secondsused} fi output="${daysused}d ${hoursused}h:${minutesused}m:${secondsused}s" elif (( timeused < 10 )); then output="0d 00h:00m:0$(timeused)s" elif (( timeused < 60 )); then output="0d 00h:00m:${timeused}s" elif (( timeused < 3600 )); then (( minutesused=timeused/60, secondsused=timeused-minutesused*60 )) if (( minutesused < 10 )); then minutesused=0${minutesused} fi if (( secondsused < 10 )); then secondsused=0${secondsused} fi output="0d 00h:${minutesused}m:${secondsused}s" elif (( timeused < 86400 )); then (( hoursused=timeused/3600, minutesused=timeused/60-hoursused*60, secondsused=timeused-minutesused*60-hoursused*3600 )) if (( hoursused < 10 )); then hoursused=0${hoursused} fi if (( minutesused < 10 )); then minutesused=0${minutesused} fi if (( secondsused < 10 )); then secondsused=0${secondsused} fi output="0d ${hoursused}h:${minutesused}m:${secondsused}s" fi echo "$output" ;; esac } ###### STAT Function showing ALL info, stat options, and descriptions function statt() { C=c;stat --h|sed '/Th/,/NO/!d;/%/!d'|while read l;do p=${l/% */};[ $p == %Z ]&&C=fc&&echo ^FS:^;echo "`stat -$C $p \"$1\"` ^$p^${l#%* }";done|column -ts^; } function system_infos() # copyright 2007 - 2010 Christopher Bratusek { case $1 in *cpu) echo -e "${ewhite}CPU:\n" echo -e "${eorange}Model:${eiceblue} $(grep "model name" /proc/cpuinfo | sed -e 's/.*: //g')" echo -e "${eorange}MHz :${eiceblue} $(grep "cpu MHz" /proc/cpuinfo | sed -e 's/.*: //g')\n" ;; *kernel) echo -e "${ewhite}Kernel:\n" echo -e "${eorange}Release:${eiceblue} $(uname -r)" echo -e "${eorange}Version:${eiceblue} $(uname -v)" echo -e "${eorange}Machine:${eiceblue} $(uname -m)\n" ;; *mem | *ram) echo -e "${ewhite}RAM:\n" echo -e "${eorange}Total:${eiceblue} $(((`showmem --free`) + (`showmem --used`))) MB" echo -e "${eorange}Free :${eiceblue} $(showmem --free) MB" echo -e "${eorange}Used :${eiceblue} $(showmem --used) MB\n" ;; *partitions) echo -e "${ewhite}Partitions:${eorange}\n" echo -e "major minor blocks device-node ${eiceblue}\ \n$(cat /proc/partitions | sed -e '1,2d')" | column -t echo "" ;; *pci) check_opt lspci systeminfos::pci if [[ $? != "1" ]]; then echo -e "${ewhite}PCI Devices:\n${eiceblue}" lspci -vkmm echo "" fi ;; *usb) check_opt lsusb systeminfos::usb if [[ $? != "1" ]]; then echo -e "${ewhite}USB Devices:\n${eiceblue}" lsusb -v echo "" fi ;; *mounts) echo -e "${ewhite}Mounts:\n${eorange}\ \ndevice-node on mount-point type filesystem options\n" ${eiceblue} "\n\n$(mount)" | column -t echo "" ;; *bios) check_opt dmidecode systeminfos::bios if [[ $? != "1" && $EUID == 0 ]]; then echo -e "${ewhite}SMBIOS/DMI Infos:${eiceblue}\n" dmidecode -q fi ;; *all) system_infos_cpu system_infos_kernel system_infos_memory system_infos_partitions # system_infos_pci # system_infos_usb system_infos_mounts # system_infos_bios ;; *) echo -e "\n${ewhite}Usage:\n" echo -e "${eorange}system_infos ${ewhite}|${egreen} --cpu\t\t${eiceblue}[Display CPU Model and Freq]\ \n${eorange}system_infos ${ewhite}|${egreen} --kernel\t${eiceblue} [Display Kernel Version, Release and Machine]\ \n${eorange}system_infos ${ewhite}|${egreen} --memory\t${eiceblue} [Display Total, Free and Used RAM]\ \n${eorange}system_infos ${ewhite}|${egreen} --partitions\t${eiceblue}[Display Major, Minor, Blocks and Node for all Paritions]\ \n${eorange}system_infos ${ewhite}|${egreen} --pci\t\t${eiceblue}[Display Infos about all PCI Devices (and their kernel-module)]\ \n${eorange}system_infos ${ewhite}|${egreen} --usb\t\t${eiceblue}[Display Infos about all USB Devices (and their kernel-module)]\ \n${eorange}system_infos ${ewhite}|${egreen} --bios\t${eiceblue} [Display SMBIOS DMI Infos]\ \n${eorange}system_infos ${ewhite}|${egreen} --mounts\t${eiceblue} [Display all mounted devices]\n" tput sgr0 ;; esac } ###### shows various info on running activities # copyright 2007 - 2010 Christopher Bratusek function treeps() { ps f -u $USER -o command,pid,%cpu,%mem,time,etime,tty | \ awk 'NR <= 1 {print;next} !/awk/ && $0~var' var=${1:-".*"} } ###### uptime in minutes function uptime_min() { awk '{print $0/60;}' /proc/uptime } ###### info about current open windows # copyright 2007 - 2010 Christopher Bratusek function wininfo() { xprop | grep -w "WM_NAME\|WM_CLASS\|WM_WINDOW_ROLE\|_NET_WM_STATE" } ################################################## # Resizing an image # ################################################## # USAGE: image_resize "percentage of image resize" "input image" "output image" function image_resize() { convert -sample "$1"%x"$1"% "$2" "$3" } ################################################## # Search IMDB.COM # ################################################## function imdb() { firefox "http://www.imdb.com/find?s=all&q="${@}"&x=0&y=0" & } ################################################## # Using PIPEs, Execute a command, convert output # # to .png file, upload file to imgur.com, then # # returning the address of the .png. # ################################################## function imgur() { convert label:@- png:-|curl -F "image=@-" -F "key=1913b4ac473c692372d108209958fd15" http://api.imgur.com/2/upload.xml|grep -E -o "(.)*" | grep -E -o "http://i.imgur.com/[^<]*" ; } ################################################## # INC # ################################################## function inc() { let OPS=$OPS+1 echo "* pcur $OPS" } ################################################## # Displays metadata for specified media file # ################################################## ###### $1 = media file name function info() { EXT=`echo "${1##*.}" | sed 's/\(.*\)/\L\1/'` if [ "$EXT" == "mp3" ]; then id3v2 -l "$1" echo mp3gain -s c "$1" elif [ "$EXT" == "flac" ]; then metaflac --list --block-type=STREAMINFO,VORBIS_COMMENT "$1" else echo "ERROR: Not a supported file type." fi } ################################################## # Sample introduction # ################################################## function intro() { less < with signal $sig ? " then kill $sig $pid fi done } ###### example: pskill firefox-bin # copyright 2007 - 2010 Christopher Bratusek function psgrep() { if [[ $1 == "-u" ]]; then ps aux | grep -v grep | grep $2 | awk '{ print $2 " : " $11}' | tee .temp CMDS=$(cat .temp) elif [[ $1 != "" ]]; then ps aux | grep -v grep | grep "$1" | awk '{ print $11 " : " $2 " : " $1 }' | tee .temp CMDS=$(cat .temp) fi if [[ $CMDS == "" ]]; then echo "no matching process" fi rm -f .temp } function pskill() { if [[ $1 ]]; then psgrep $1 shift if [[ $CMDS != "" ]]; then echo -e "\nenter process number to kill:\n" read ID if [[ ! $ID == 0 || ! $ID == "" ]]; then kill $@ $ID fi fi fi } ################################################## # Kindle connection/disconnection # ################################################## ###### be sure to press on unattached Kindle beforehand: "[SHIFT][SHIFT][N]", to start /test/bin/usbnetwork # and then connect via usb the Kindle function kindle_connect() { modprobe usbnet modprobe cdc_ether sudo ifconfig usb0 192.168.2.1 ssh root@192.168.2.2 } ###### be sure to press on unattached Kindle afterwards: "[SHIFT][SHIFT][N]", to end /test/bin/usbnetwork function kindle_disconnect() { sudo ifconfig usb0 down } ################################################## # Led set and reset # ################################################## function kitt() { # copyright 2007 - 2010 Christopher Bratusek setleds -L -num; setleds -L -caps; setleds -L -scroll; while :; do setleds -L +num; sleep 0.2; setleds -L -num; setleds -L +caps; sleep 0.2; setleds -L -caps; setleds -L +scroll; sleep 0.2; setleds -L -scroll; setleds -L +caps; sleep 0.2; setleds -L -caps; done resetleds } function resetleds() # copyright 2007 - 2010 Christopher Bratusek { setleds -L < /dev/tty1 } ################################################## # Concatenate stuff # ################################################## function kitty() { # copyright 2007 - 2010 Christopher Bratusek cat -n "$@" } ################################################## # Advanced ls functions # ################################################## function la() { # copyright 2007 - 2010 Christopher Bratusek ls -A --group-directories-first "$@" } function lg() { # copyright 2007 - 2010 Christopher Bratusek if [[ "$@" == "" ]]; then $@="*" fi ls -l --group-directories-first "$@" | gawk '{print $9, "belongs to Group ->", $4}' | column -t } function ll() { # copyright 2007 - 2010 Christopher Bratusek ls -l --group-directories-first "$@" } ###### Counts files, subdirectories and directory size and displays details # about files depending on the available space function lls() { # count files echo -n "<`find . -maxdepth 1 -mindepth 1 -type f | wc -l | tr -d '[:space:]'` files>" # count sub-directories echo -n " <`find . -maxdepth 1 -mindepth 1 -type d | wc -l | tr -d '[:space:]'` dirs/>" # count links echo -n " <`find . -maxdepth 1 -mindepth 1 -type l | wc -l | tr -d '[:space:]'` links@>" # total disk space used by this directory and all subdirectories echo " <~`du -sh . 2> /dev/null | cut -f1`>" ROWS=`stty size | cut -d' ' -f1` FILES=`find . -maxdepth 1 -mindepth 1 | wc -l | tr -d '[:space:]'` # if the terminal has enough lines, do a long listing if [ `expr "${ROWS}" - 6` -lt "${FILES}" ]; then ls else ls -hlAF --full-time fi } function lo() { # copyright 2007 - 2010 Christopher Bratusek if [[ "$@" == "" ]]; then $@="*" fi ls -l --group-directories-first "$@" | gawk '{print $9, "belongs to User ->", $3}' | sed -e '1d' | column -t } function l1() { # copyright 2007 - 2010 Christopher Bratusek ls -1 --group-directories-first "$@" } function lm() { # copyright 2007 - 2010 Christopher Bratusek if [[ ! "$@" == "" ]]; then for file in "$@"; do stat -c "%A %a %n" "$file" | gawk '{print "Permissions of:", $3, "->", $1, "("$2")"}' done | column -t fi } ###### inspired by http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x279.html # but I made it a single awk instead of an awk, forloop and a bc # asumes we have awk available. but really, who doesnt have awk? # let's get the size of the files in this dir function lsbytes() { echo -n $(ls -l | awk '/^-/{total += $5} END{printf "%.2f", total/1048576}') } function lscd() { # copyright 2007 - 2010 Christopher Bratusek builtin cd "${@}" &>/dev/null . $BSNG_RC_DIR/dirinfo/display dirinfo_display echo -e "${epink}content:" ls $LSCD_OPTS echo "$PWD" > $HOME/.lastpwd } ###### display long list of files with the given extension # example: lsext txt function lsext() { find . -type f -iname '*.'${1}'' -exec ls -l {} \; ; } ###### another way to call for a list of files/folders function lsr() { /bin/ls -l "$@"/..namedfork/rsrc ; } ###### sorted, recursive long file listing function lsr_() { find "${@:-.}" -print0 |sort -z |xargs -0 ls $LS_OPTIONS -dla; } ################################################## # Show the single most recently modified file in # # a directory # ################################################## function lastfile() { find ${1:-.} -maxdepth 1 -type f -printf "%T+ %p\n" | sort -n | tail -n1 | sed 's/[^[:space:]]\+ //'; } ################################################## # Uppercase, lowercase, & cleanup strings & names# ################################################## ###### lowercase all files in the current directory function lcfiles() { print -n 'Really lowercase all files? (y/n) ' if read -q ; then for i in * ; do mv $i $i:l done fi } ###### Convert the first letter into lowercase letters function lcfirst() { if [ -n "$1" ]; then perl -e 'print lcfirst('$1')' else cat - | perl -ne 'print lcfirst($_)' fi } ###### usage: lower [STRING]... function lower() { echo ${@,,}; } ###### usage: echo hELLO wORLD | lower # convert stdin to lower case function lower_() { tr [A-Z] [a-z]; } ###### move filenames to lowercase function lowercase() { for file ; do filename=${file##*/} case "$filename" in */*) dirname==${file%/*} ;; *) dirname=.;; esac nf=$(echo $filename | tr A-Z a-z) newname="${dirname}/${nf}" if [ "$nf" != "$filename" ]; then mv "$file" "$newname" echo "lowercase: $file --> $newname" else echo "lowercase: $file not changed." fi done } ###### Remove whitespace at the beginning of a string # @param string $1 string (optional, can also handle STDIN) # @return string # @example: echo " That is a sentinece " | trim function ltrim() { if [ -n "$1" ]; then echo $1 | sed 's/^[[:space:]]*//g' else cat - | sed 's/^[[:space:]]*//g' fi } ###### Space removal and lowercases folders in current dir. function rmspaces() { ls | while read -r FILE do mv -v "$FILE" `echo $FILE | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | tr '[A-Z]' '[a-z]' | sed 's/_-_/_/g'` done } ###### Remove whitespace at the end of a string # @param string $1 string (optional, can also handle STDIN) # @return string # @example: echo "That is a sentinece " | rtrim function rtrim() { if [ -n "$1" ]; then echo $1 | sed 's/[[:space:]]*$//g' else cat - | sed 's/[[:space:]]*$//g' fi } ###### Cut a string after X chars and append three points # string strim( string string [, int length ] ) function strim() { local string="$1" local length=${2:-30} [ "${#string}" -gt ${length} ] && string="${string:0:${length}}..." echo $string } ###### Convert all alphabetic characters to lowercase # @param string $1|STDIN string # @return string function strtolower() { if [ -n "$1" ]; then echo $1 | tr '[:upper:]' '[:lower:]' else cat - | tr '[:upper:]' '[:lower:]' fi } ###### Convert all alphabetic characters converted to uppercase # @param string $1|STDIN string # @return string function strtoupper() { if [ -n "$1" ]; then echo $1 | tr '[:lower:]' '[:upper:]' else cat - | tr '[:lower:]' '[:upper:]' fi } ###### Remove whitespace at the beginning and end of a string # @param string $1 string (optional, can also handle STDIN) # @return string # @example: echo " That is a sentinece " | trim function trim() { if [ -n "$1" ]; then echo $1 | sed 's/^[[:space:]]*//g' | sed 's/[[:space:]]*$//g' else cat - | sed 's/^[[:space:]]*//g' | sed 's/[[:space:]]*$//g' fi } ###### Convert the first letter into uppercase letters function ucfirst() { if [ -n "$1" ]; then perl -e 'print ucfirst('$1')' else cat - | perl -ne 'print ucfirst($_)' fi } ###### Converts first letter of each word within a string into an uppercase, all other to lowercase # string ucwords( string string ) function ucwords() { local string="$*" for word in $string; do # Get the first character with cut and convert them into uppercase. local first="$( echo $word | cut -c1 | tr '[:lower:]' '[:upper:]' )" # Convert the rest of the word into lowercase and append them to the first character. word="$first$( echo $word | cut -c2-${#word} | tr '[:upper:]' '[:lower:]' )" # Put together the sentence. local phrase="$phrase $word" done echo "$phrase" } ###### usage: upper [STRING]... function upper() { echo ${@^^}; } ###### usage: echo hELLO wORLD | upper # convert stdin to upper case function upper_() { tr [a-z] [A-Z]; } ################################################## # Corporate ldapsearch for users # ################################################## function ldapfind() { ldapsearch -x -h ldap.foo.bar.com -b dc=bar,dc=com uid=$1 } ################################################## # Organize a text file # ################################################## ###### sort lines in a text file function linesort() { sort -u "$1" > "$1".new } ###### remove duplicate lines in a file (without resorting) function removeduplines() { awk '!x[$0]++' "$1" > "$1".new } ################################################## # Livehttpheaders (firefox addon) replacement # ################################################## ###### usage: liveh [-i interface] [output-file] && firefox & function liveh() { tcpdump -lnnAs512 ${1-} tcp |sed ' s/.*GET /GET /;s/.*Host: /Host: /;s/.*POST /POST /;/[GPH][EOo][TSs]/!d;w '"${2-liveh.txt}"' ' >/dev/null ; } ################################################## # Search for music in the specified location # ################################################## function locatemusic() { slocate -i "${1}" | grep "$HOME/Music/"; } ################################################## # Use a logger # ################################################## function log() { echo "$1" 1>&2 logger -ist "$(basename -- "$0")" "$1" } ################################################## # List your MACs address # ################################################## function lsmac() { ifconfig -a | awk '/HWaddr/ {print $5}' ; } ################################################## # MPD music stuff # ################################################## ###### Add music files in MPD function madd() { # while [ $# -gt 0 ]; do # case "$1" in # a) # args[i++]=artist;; # b) # args[i++]=album;; # t) # args[i++]=title;; # *) # args[i++]=$1;; # esac; shift; # done # mpc search "${args[@]}" | mpc search "$@" | mpc add } ###### Clear, add and play: MPD function mcap() { mpc clear # while [ $# -gt 0 ]; do # case "$1" in # a) # args[i++]=artist;; # b) # args[i++]=album;; # t) # args[i++]=title;; # *) # args[i++]=$1;; # esac; shift; done # mpc search "${args[@]}" | mpc search "$@" | mpc add mpc play } ################################################## # Email yourself a quick message # ################################################## function mailme() { echo "$@" | mail -s "$1" $SERVERMAIL } ###### Usage: mailme message : mailme "process X completed" function mailme_() { mailx -s "$@" $USER <<< "$@"; } ################################################## # .. And function # ################################################## function man_() { for i ; do xtitle The $(basename $1|tr -d .[:digit:]) manual command man -F -a "$i" done } ################################################## # Extended man command # ################################################## ###### requires: sudo apt-get install w3m function man_ext() { /usr/bin/man $* || w3m -dump http://google.com/search?q="$*"\&btnI | less } ################################################## # Manpage to ... document # ################################################## ###### example: man2pdf wipe = wipe.pdf # copyright 2007 - 2010 Christopher Bratusek function man2pdf() { case $1 in *help | "" ) echo -e "\nUsage:" echo -e "\nman2pdf | [generate a pdf from ]\n" tput sgr0 ;; * ) check_opt ps2pdf man2pdf if [[ $? != "1" && $1 ]]; then man -t $1 | ps2pdf - >$1.pdf else echo "No manpage given." fi ;; esac } ###### example: man2text wipe = wipe.txt function man2text() { man "$1" | col -b > ~/man_"$1".txt } ################################################## # What is the use of this switch? # ################################################## function manswitch() { man $1 | less -p "^ +$2"; } ################################################## # Map a command over a list of files - map-files # # /lib *.so ls -la # ################################################## function map-files() { find $1 -name $2 -exec ${@:3} {} \ ; } ################################################## # Meta-Backup - backup your software selection # # and repositories in a deb meta package # ################################################## function meta-backup() { ## Written by Arjan van Lent aka socialdefect ## VERSION: 2.1 ## Modified by Inameiname DIALOG1="Did you enable extra repositories or PPAs on this system?. If you have no idea what this is just enter no" DIALOG2="Your backup has been created succesfully" DIALOG3="Something went wrong. Type bash -x meta-backup in a terminal to debug" DIALOG4="Would you like to use the backup for a distribution upgrade?" DIALOG5="Enter the codename of the distribution you'd like to upgrade to. eg. sid or maverick" DIALOG6="Where woud you like to save your backup files? Enter full path. eg /home/username/backups" mkdir -p /tmp/meta-backup/my-meta-backup/DEBIAN ## creating build directories dialog --title "Meta-backup" --yesno "$DIALOG1" 8 40 ## repository dialog ## question add repo's dialog --title "Meta-backup" --infobox "..." 8 40 if [ $? = 0 ] ; then mkdir -p /tmp/meta-backup/my-repo-backup/etc/apt/sources.list.d mkdir /tmp/meta-backup/my-repo-backup/DEBIAN cp -R /etc/apt/sources.list.d/* /tmp/meta-backup/my-repo-backup/etc/apt/sources.list.d/ cp -R /etc/apt/sources.list /tmp/meta-backup/my-repo-backup/etc/apt/ fi ## create the control file for the repo-backup echo 'Section: misc Priority: optional Package: my-repo-backup Version: 2.1 Maintainer: meta-backup Depends: Architecture: all Description: Repository/PPA backup created by meta-backup. Repository/PPA backup created by meta-backup. This package can be used to install all repositories and PPAs that are installed on the computer where the backup is made.' >> /tmp/meta-backup/my-repo-backup/DEBIAN/control ## create the preinst file for the repo-backup echo '#!/bin/sh set -e # Backup repo config mv /etc/apt/sources.list /etc/apt/sources.list.old mv /etc/apt/sources.list.d /etc/apt/sources.list.d.old' >> /tmp/meta-backup/my-repo-backup/DEBIAN/preinst chmod +x /tmp/meta-backup/my-repo-backup/DEBIAN/preinst ## create the postinst file for the repo-backup echo '#!/bin/sh set -e # Pubkeys (to generate this large key, which is all of them in one: sudo apt-key exportall > /tmp/repokeys.key) if [ -f /tmp/repokeys.key ];then rm /tmp/repokeys.key fi sudo cat > "/tmp/repokeys.key" <<"End-of-message"' >> /tmp/meta-backup/my-repo-backup/DEBIAN/postinst ## get the repository keys apt-key exportall >> /tmp/meta-backup/my-repo-backup/DEBIAN/postinst echo 'End-of-message if which sudo apt-key >> /dev/null; then if sudo apt-key add "/tmp/repokeys.key"; then echo "OK - repokeys key was installed" else echo "ERROR: there was a problem installing the repokeys-key" fi fi sudo rm -fv "/tmp/repokeys.key"' >> /tmp/meta-backup/my-repo-backup/DEBIAN/postinst chmod +x /tmp/meta-backup/my-repo-backup/DEBIAN/postinst ## create the postrm file for the repo-backup echo '#!/bin/sh set -e # Restore repo config mv /etc/apt/sources.list.old /etc/apt/sources.list mv /etc/apt/sources.list.d.old /etc/apt/sources.list.d' >> /tmp/meta-backup/my-repo-backup/DEBIAN/postrm chmod +x /tmp/meta-backup/my-repo-backup/DEBIAN/postrm dialog --title "Meta-backup" --yesno "$DIALOG4" 8 40 ## Distupgrade feature dialog --title "Meta-backup" --infobox "..." 8 40 if [ $? = 0 ] ; then dialog --title "Meta-backup" --inputbox "$DIALOG5" 8 40 2> /tmp/meta-backup/upgrade UPGRADE=`cat /tmp/meta-backup/upgrade` dialog --title "Meta-backup" --infobox "..." 8 40 fi if [ $UPGRADE = 0 ] ; then MYDIST=`lsb_release -cs` sed 's/$MYDIST/$UPGRADE/' /tmp/meta-backup/myrepo-backup/etc/apt/sources.list sed 's/$MYDIST/$UPGRADE/' /tmp/meta-backup/myrepo-backup/etc/apt/sources.list.d/* fi ## end dist upgrade feature DEPS=`aptitude search -F %p ~i --disable-columns | sed 's/$/,/' | tr '\n\r' ' ' | sed 's/, $//'` ## get list of inst. packages to fill DEPS variable ## create the control file for the meta-backup echo "Section: misc Priority: optional Package: my-meta-backup Version: 2.1 Maintainer: meta-backup Depends: $DEPS Architecture: all Description: Personal system backup created by meta-backup Personal system backup created by meta-backup. This package can be used to install all applications that are installed on the computer where the backup is made. Can be used on all systems using the same base system version as used on the backup machine." >> /tmp/meta-backup/my-meta-backup/DEBIAN/control cd /tmp/meta-backup && dpkg --build my-meta-backup ## build and save the package(s) if [ $? = 0 ] ; then cd /tmp/meta-backup && dpkg --build my-repo-backup fi ls /tmp/meta-backup/my-meta-backup.deb ## finish backup if [ $? = 0 ] ; then ERROR=no else ERROR=yes fi ls /tmp/meta-backup/my-repo-backup.deb if [ $? = 0 ] ; then ERROR=no else ERROR=yes fi dialog --title "Meta-backup" --inputbox "$DIALOG6" 8 40 2> /tmp/meta-backup/save ## move the debs to selected location SAVE=`cat /tmp/meta-backup/save` dialog --title "Meta-backup" --infobox "..." 8 40 ls $SAVE if [ $? = 0 ] ; then mv /tmp/meta-backup/*.deb $SAVE chmod 777 $SAVE/my-*-backup.deb else mkdir -p $SAVE mv /tmp/meta-backup/*.deb $SAVE chmod -R 777 $SAVE fi if [ $ERROR = no ] ; then ## Display exit message dialog --title "Meta-backup" --infobox "$DIALOG2" 8 40 else dialog --title "Meta-backup" --infobox "$DIALOG3" 8 40 fi rm -rf /tmp/meta-backup ## cleaning up } ################################################## # Automatically inputs aliases here in # # '.bashrc' # ################################################## ###### Usage: mkalias "" # Example: mkalias rm "rm -i" function mkalias() { if [[ $1 && $2 ]] then echo -e "alias $1=\"$2\"" >> ~/.bashrc alias $1=$2 fi } ################################################## # Makes directory then moves into it # ################################################## function mkcdr() { mkdir -p -v $1 cd $1 } function mkdircd() { mkdir -p "$@" && eval cd "\"\$$#\""; } ################################################## # Creates an archive from directory # ################################################## function mktar() { tar cvf "${1%%/}.tar" "${1%%/}/"; } function mktbz() { tar cvjf "${1%%/}.tar.bz2" "${1%%/}/"; } function mktgz() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; } ################################################## # Reminder / to do list # ################################################## function mnote() { echo -e "- $* \n" >> ~/todo echo -e "- $* \n" >> ~/todo.perm ~/motd.pl } ################################################## # Morse code encoding and decoding # ################################################## ###### this is a short Morse code decoder written as a shellscript using sed # the Morse coded text should be written with spaces between the letters # only good to convert from Morse code to text # by scvalex function morse2text() { echo $1\ | tr . 0 | sed -e {s/0----\ /1/g} -e {s/00---\ /2/g} -e {s/000--\ /3/g} -e {s/000-\ /4/g} -e {s/00000\ /5/g} -e {s/-0000\ /6/g} -e {s/--000\ /7/g} -e {s/---00\ /8/g} -e {s/----0\ /9/g} -e {s/-----\ /0/g} \ | sed -e {s/-0-0\ /c/g} -e {s/-000\ /b/g} -e {s/00-0\ /f/g} -e {s/0000\ /h/g} -e {s/0---\ /j/g} -e {s/0-00\ /l/g} -e {s/0--0\ /p/g} -e {s/--0-\ /q/g} -e {s/000-\ /v/g} -e {s/-00-\ /x/g} -e {s/-0--\ /y/g} -e {s/--00\ /z/g} \ | sed -e {s/0--\ /w/g} -e {s/-00\ /d/g} -e {s/--0\ /g/g} -e {s/-0-\ /k/g} -e {s/---\ /o/g} -e {s/0-0\ /r/g} -e {s/000\ /s/g} -e {s/00-\ /u/g} \ | sed -e {s/0-\ /a/g} -e {s/00\ /i/g} -e {s/--\ /m/g} -e {s/-0\ /n/g} \ | sed -e {s/0\ /e/g} -e {s/-\ /t/g} } function text2morse() { cat > "/tmp/text2morse.py" <<"End-of-message" #!/usr/bin/python # short mark, dot or 'dit' (.) = . # longer mark, dash or 'dah' (-) = - # intra-character gap (between the dots and dashes within a character) = no space # short gap (between letters) = single space # medium gap (between words) = double space import sys __author__="Aanand Natarajan" # morse code dictionary codes = {'1':".----",'2':"..---",'3':"...--",'4':"....-",'5':".....",'6':"-....",'7':"--...",'8':"---..", '9':"----.",'0':"-----",'A':".-",'B':"-...",'C':"-.-.",'D':"-..",'E':".",'F':"..-.",'G':"--.", 'H':"....",'I':"..",'J':".---",'K':"-.-",'L':".-..",'M':"--",'N':"-.",'O':"---",'P':".--.", 'Q':"--.-",'R':".-.",'S':"...",'T':"-",'U':"..-",'V':"...-",'W':".--",'X':"-..-",'Y':"-.--", 'Z':"--..", # punctuations ',':"--..--",'.':".-.-.-",'?':"..--..",';':"-.-.-",':':"---...",'/':"-..-.", '-':"-....-","'":".----.",'(':"-.--.",')':"-.--.-",'!':"-.-.--",'&':".-...", '=':"-...-",'+':".-.-.",'_':"..--.-",'"':".-..-.",'$':"...-..-",'@':".--.-.", # space ' ':"|"} binary = {'.':'.','-':'-',',':' ','|':' '} def encode(value): """ encodes the value into morse code """ morse_value="" value.replace('*', 'X') value.replace('^', 'XX') for c in value: try : morse_value += codes[c.upper()]+',' except : print "Unintended character " + c + " omitted" return _get_binary(morse_value) def decode(morse_code_value): """ decodes the morse bytes """ decoded_value = _decode_binary(morse_code_value) ascii_value="" for v in decoded_value.split(","): ascii_value += _get_key(v) return ascii_value def _get_binary(value): binary_value = "" for c in value: binary_value += binary[c] return binary_value def _get_key(value): """ returns the key for the given value """ for k,v in codes.items(): if v == value: return k return '' def _decode_binary(binary): dah_replaced = binary.replace('-', '-') dit_replaced = dah_replaced.replace('.', '.') comma_replaced = dit_replaced.replace(' ', ',') zero_replaced = comma_replaced.replace('', '|,') return zero_replaced def _do_decode(value): print "Decoded : "+decode(value) def _do_encode(value): print "Encoded : "+encode(value) if __name__ == "__main__": if len(sys.argv) > 2: if sys.argv[1] == 'd' : print "decoding" _do_decode(sys.argv[2]) else: print "encoding" _do_encode(sys.argv[2]) elif len(sys.argv) > 1: print "encoding" _do_encode(sys.argv[1]) else: print "Usage : "+sys.argv[0]+" [d (decode) |e (encode)] [input string]" End-of-message chmod +x "/tmp/text2morse.py" "/tmp/text2morse.py" "$1" rm "/tmp/text2morse.py" } ################################################## # Computes most frequent used words of text file # ################################################## ###### usage: most_frequent "file.txt" function most_frequent() { cat "$1" | tr -cs "[:alnum:]" "\n"| tr "[:lower:]" "[:upper:]" | awk '{h[$1]++}END{for (i in h){print h[i]" "i}}'|sort -nr | cat -n | head -n 30 } ################################################## # Mount Fat # ################################################## function mount_fat() { local _DEF_PATH="/media/tmp1" if [ -n "$2" ];then sudo mount -t vfat -o rw,users,flush,umask=0000 "$1" "$2" else sudo mount -t vfat -o rw,users,flush,umask=0000 "$1" $_DEF_PATH fi } ################################################## # Flash Video Cache Finder/Saver # ################################################## ###### flash video cache finder # Creator: marcaemus # Version: 1.1 # Last Modified: 31 October 2011 # Find cached video while watching and without needing downloader extensions # Type moz at a prompt to find the vid. # Tested with Firefox (Icecat), Chromium, Midori, Uzbl, Konqueror, and Arora function moz() { # Make sure we have lsof if [ -x /usr/sbin/lsof ]; then LSOF=/usr/sbin/lsof elif [ -x /usr/bin/lsof ]; then LSOF=/usr/bin/lsof elif [ -x /usr/local/bin/lsof ]; then LSOF=/usr/local/bin/lsof else echo "lsof was not found... exiting" return 1 fi # Find a process ID and go there PROCDIR=$( $LSOF -X | grep Flash | tail -n1 | awk '{ print $2 }' ) # Not found? exit gracefully if [ "$PROCDIR" == "" ]; then echo "No running instance found" return 1 fi cd /proc/$PROCDIR/fd # Stat through the file descriptors looking for video MQ=$( for i in *; do stat $i | head -n1 | grep "tmp/Flash" | awk '{ print $2 }'; done ) # Another exit point if [ "$MQ" == "" ]; then echo "No video found" return 1 fi #Finally, print them all out for i in $MQ; do j=${i#?} echo "Video at "${j%?} done } ###### flash video cache saver # Creator: marcaemus # Version: 0.2 # Last Modified: 01 November 2011 # Find cached flash video and copy to user's home directory # Usage: mozz [filename] (where filename is the name you want to save as) function mozz() { # Check for given filename if [ $# -ne 1 ]; then echo "Usage: mozz [filename]" exit 65 fi # Make sure we have lsof if [ -x /usr/sbin/lsof ]; then LSOF=/usr/sbin/lsof elif [ -x /usr/bin/lsof ]; then LSOF=/usr/bin/lsof elif [ -x /usr/local/bin/lsof ]; then LSOF=/usr/local/bin/lsof else echo "lsof was not found... exiting" exit 1 fi # Look for flvs in user's home - if not, create one if [ ! -d $HOME/flvs ]; then echo -e "\033[0;31mCreating " $HOME"/flvs" mkdir -v $HOME"/flvs" fi # Find a process ID and go there PROCDIR=$( $LSOF -X | grep Flash | tail -n1 | awk '{ print $2 }' ) # Not found? exit gracefully if [ "$PROCDIR" == "" ]; then echo "No running instance found" exit 1 fi # To warn us if nothing happens flvflag=0 # Stat through FDs and copy the first for i in /proc/$PROCDIR/fd/*; do j=$( stat $i | head -n1 | grep "tmp/Flash") if [ ${#j} -gt 0 ]; then k=$( echo $j | awk '{ print $2 }' ) l=${k#?} m=$( cp -v ${l%?} $HOME"/flvs/"$1".flv" ) echo -e "\033[0;32m$m" echo -e "\033[0;34mCurrent filesize: \033[0;35m"$( stat --format=%s $HOME"/flvs/"$1".flv" ) flvflag=1 break fi done # Echo the warning if [ $flvflag -eq 0 ]; then echo "Warning: no video was copied" fi } ################################################## # Messagebox maker # ################################################## function msg() # Author: Josh Bailey # Email: jbsnake usalug.org # call this like: # msg "Title of Message Box" # or # msg "Title of Message Box" $height $width { # function for making a messagebox # if it has less than two arguments if [[ $# < 2 ]] then # use auto-size for the messagebox dialog --msgbox "$1" 0 0 else # use specified height and width dialog --msgbox "$1" $2 $3 fi clear } ################################################## # Youtube stuff # ################################################## ###### stream YouTube videos directly to your media player function mtube() { video_id=$(curl -s $1 | sed -n "/watch_fullscreen/s;.*\(video_id.\+\)&title.*;\1;p"); mplayer -fs $(echo "http://youtube.com/get_video.php?$video_id"); } alias mtube_='mplayer -fs $(echo "http://youtube.com/get_video.php?$(curl -s "$1" | sed -n "/watch_fullscreen/s;.*\(video_id.\+\)&title.*;\1;p")")' ###### mps-youtube # requires "python-pip" and mps-youtube # sudo apt-get install python-pip # sudo pip install mps-youtube # sudo pip install mps-youtube --upgrade alias youtube='mpsyt' ###### Youtube-dl # requires "youtube-dl" # sudo apt-get install youtube-dl alias yt='youtube-dl -t' ###### YouTube convert and download all user's videos to MP3s on the fly function yt2mp3() { for j in `seq 1 301`;do i=`curl -s gdata.youtube.com/feeds/api/users/$1/uploads\?start-index=$j\&max-results=1|grep -o "watch[^&]*"`;ffmpeg -i `wget youtube.com/$i -qO-|grep -o 'url_map"[^,]*'|sed -n '1{s_.*|__;s_\\\__g;p}'` -vn -ab 128k "`youtube-dl -e ${i#*=}`.mp3";done;} function yt2mp3-chanrip() { for count in 1 51 101 151 201 251 301; do for i in $(curl -s http://gdata.youtube.com/feeds/api/users/"$1"/uploads\?start-index="$count"\&max-results=50 | grep -Eo "watch\?v=[^[:space:]\"\'\\]{11}" | uniq); do ffmpeg -i $(wget http://youtube.com/"$i" -qO- | sed -n "/fmt_url_map/{s/[\'\"\|]/\n/g;p}" | sed -n '/^fmt_url_map/,/videoplayback/p' | sed -e :a -e '$q;N;5,$D;ba' | tr -d '\n' | sed -e 's/\(.*\),\(.\)\{1,3\}/\1/') -vn -ab 128k "$(youtube-dl -e http://youtube.com/"$i").mp3"; done; done; unset count i; } ###### convert to ogg function yt2ogg() { # copyright 2007 - 2010 Christopher Bratusek ffmpeg -i "$1" -vn "$1".ogg } ###### play YouTube's first match directly function ytplay() { args="$*";mplayer -fs $(youtube-dl -g "http://www.youtube.com$(lynx --source "http://www.youtube.com/results?search_query=${args// /+}&aq=f"|grep -m1 ' /dev/null ; grep \/release\/ foobar | head -2 | tail -1 | sed -e 's/^
.*>\(.*\)<\/a><\/div>/\1/' ; rm foobar } ################################################## # Query Wikipedia via console over DNS # ################################################## function mwiki() { blah=`echo $@ | sed -e 's/ /_/g'`; dig +short txt $blah.wp.dg.cx; } # function mwiki() { dig +short txt `echo $*|sed 's| *|_|g'`.wp.dg.cx; } function mwiki_() { local IFS=_; dig +short txt "${*^}".wp.dg.cx; } ################################################## # User friendly ps # ################################################## function my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,bsdtime,command ; } function pp() { my_ps f | awk '!/awk/ && $0~var' var=${1:-".*"} ; } function psaux() { [ $# == 1 ] && ps aux | grep $1 } ################################################## # 'Readlink' equivalent using shell commands, and# # following all links # ################################################## ###### this is equivalent to the GNU ' readlink' tool, # but it supports following all links, even in different directories # myreadlink() { [ ! -h "$1" ] && echo "$1" || (local link="$(expr "$(command ls -ld -- "$1")" : '.*-> \(.*\)$')"; cd $(dirname $1); myreadlink "$link"; } ################################################## # Editor startup, should be transparent for # # different versions # ################################################## # function ned() # { if [[ -n `which neditc` ]] ; then # neditc $@ # elif [[ -n `which nedit` ]] ; then # nedit $@ >&/dev/null & # else # echo NEdit does not appear to be on this computer. # fi # } ################################################## # For newbies with Linux # ################################################## function newbies() { read -sn 1 -p "1/10. Welcome to Ubuntu. Relax. Take a breath. Just because it's not Windows doesn't mean it will be difficult to figure out. Especially with me at the wheel. ;) " read -sn 1 -p "2/10. Ubuntu is an operating system, just like Windows (ie. XP, Vista, 7). It is a Linux distro, meaning it uses the Linux kernel, which is essentially the brains of the operating system. Ubuntu is highly customizable, and I have tweaked it to look similar to Windows, but it can look, feel, and run any way you'd like. Unlike Windows, Ubuntu is free, as well as nearly all of it's applications. Less than 1% of the world uses Linux; about half of that use Ubuntu (#1 ranked Linux distro)). And due to this, and the fact that it's structure is different than Windows, it is pretty much virus-free. Also, no Windows viruses can ever harm a Linux/Ubuntu computer. So download away. " read -sn 1 -p "3/10. Your computer's username is 'Me'. Your computer's password is 'password'. The password can easily be changed. " read -sn 1 -p "4/10. To change the password, you must change both the User and the Default Keyring passwords. First, change the user password, by going to Menu (bottom left button) -> System -> Preferences -> About Me and click 'Change Password...'. Second, change the Default Keyring password by going to Menu (bottom left button) -> Accessories -> Passwords and Encryption Keys and find 'Passwords: default', click it with the right mouse button, and select 'Change Password'. " read -sn 1 -p "5/10. Ubuntu updates and upgrades are currently set up to install important security updates as well as to pop up a box prompting you to click install when anything else requires an upgrade. Very easy. Just need password. One thing about updates on Ubuntu is it updates everything, both the operating system and the installed applications through the repositories (official and unofficial servers that house a large number of various applications and games). " read -sn 1 -p "6/10. Your home folder (similar to a 'My Documents' folder in Windows) is 'me', and can be opened either by going to Menu (bottom left button) -> Places -> Home Folder, OR double-clicking the left mouse button on 'me's Home' on the Desktop. The 'Temp' folder inside is what is set for all downloads and is my ideal for using as the working folder for whatever you want. In the 'Pictures' folder, there is a 'Backgrounds' folder that includes all of your desktop backgrounds and is where you can add or remove backgrounds. " read -sn 1 -p "7/10. There are some application subsitutes to mention: [OpenOffice -> Microsoft Office], [(Totem) Movie Player -> Windows Media Player], [Evolution Mail -> Microsoft Outlook or Outlook Express], [Nautilus File Manager -> Windows Explorer]. " read -sn 1 -p "8/10. If you'd like to add/remove software, Ubuntu has a very easy way to do so. Just go to the Ubuntu Software Center, by going to Menu (bottom left button) -> Ubuntu Software Center. It lists all the software found in the repositories. " read -sn 1 -p "9/10. If you wish to open this extremely helpful text again, it's as easy as: single-clicking the right mouse button anywhere on the Desktop (or in Nautilus File Manager) -> Scripts -> My_Scripts -> For-Newbies -> For-Newbies.sh. " read -sn 1 -p "10/10. To get rid of this damn script at startup because you are sick of seeing it every time you log into your computer, go to Menu (bottom left button) -> Other -> Startup Applications and uncheck 'For Newbies'. " } ################################################## # Download all data from Google Ngram Viewer # ################################################## function ngramviewerdl() { wget -qO - http://ngrams.googlelabs.com/datasets | grep -E href='(.+\.zip)' | sed -r "s/.*href='(.+\.zip)'.*/\1/" | uniq | while read line; do `wget $line`; done } ################################################## # Run command detached from terminal and without # # output # ################################################## ###### Usage: nh function nh() { nohup "$@" &>/dev/null & } ################################################## # Stupid simple note taker # ################################################## function note() { # if file doesn't exist, create it [ -f $HOME/.notes ] || touch $HOME/.notes # no arguments, print file if [ $# = 0 ] then cat $HOME/.notes # clear file elif [ $1 = -c ] then > $HOME/.notes # add all arguments to file else echo "$@" >> $HOME/.notes fi } ################################################## # Open a new terminal tab in the same directory # # as the current # ################################################## ###### SOURCE => http://pastie.caboo.se/188640 # AND => http://justinfrench.com/index.php?id=231 function nth() { osascript -e " Tell application \"Terminal\" activate tell application \"System Events\" to tell process \"Terminal\" to keystroke \"t\" using command down do script with command \"cd '$(pwd)'; clear\" in selected tab of the front window end tell" } ################################################## # Remove apps with style: nuke it from orbit # ################################################## ###### You can't stand programs x, y, and z. Remove all trace of their existence by adding this function to your config. It will remove the cruft, the settings, #and such and such. This function doesn't even give a damn about you trying to remove programs that don't exist: it'll just for loop to the next one on #your hit list. function nuke() { if [ $(whoami) != "root" ] ; then for x in $@; do sudo apt-get autoremove --purge $x; done; else for x in $@; do apt-get autoremove --purge $x; done; fi } ################################################## # Echo the lines of a file preceded by line # # number # ################################################## function numberLines() { perl -pe 's/^/$. /' "$@" ; } ################################################## # How many pages will my text files print on? # ################################################## function numpages() { echo $(($(wc -l $* | sed -n 's/ total$//p')/60)); } ################################################## # Open a GUI app from CLI # ################################################## function open() { $1 >/dev/null 2>&1 & } ################################################## # Display file contents either with less or cat # # based on number of lines # ################################################## function out() { tmp=$(mktemp); awk '{print $0}' > $tmp; if [ $(wc -l $tmp | awk '{print $1}') -gt $(tput lines) ]; then less $tmp; else cat $tmp; fi; rm -fr $tmp; } ################################################## # Convert a single-page PDF to a hi-res PNG, at # # 300dpi # ################################################## ###### If you skip this part: -density 300x300, you'll get a very lo-res image function pdf2png() { convert -density 300x300 $1 $2 } ################################################## # ThePirateBay.org torrent search # ################################################## function piratebay() { lynx -dump http://thepiratebay.org/search/$@|awk '/TPB.torrent$/ {print $2}' } ################################################## # Optimize PNG files # ################################################## function pngoptim() { NAME_="pngoptim" HTML_="optimize png files" PURPOSE_="reduce the size of a PNG file if possible" SYNOPSIS_="$NAME_ [-hl] [file...]" REQUIRES_="standard GNU commands, pngcrush" VERSION_="1.0" DATE_="2004-06-29; last update: 2004-12-30" AUTHOR_="Dawid Michalczyk " URL_="www.comp.eonworks.com" CATEGORY_="gfx" PLATFORM_="Linux" SHELL_="bash" DISTRIBUTE_="yes" # This program is distributed under the terms of the GNU General Public License usage() { echo >&2 "$NAME_ $VERSION_ - $PURPOSE_ Usage: $SYNOPSIS_ Requires: $REQUIRES_ Options: -h, usage and options (this help) -l, see this script" exit 1 } # tmp file set up tmp_1=/tmp/tmp.${RANDOM}$$ # signal trapping and tmp file removal trap 'rm -f $tmp_1 >/dev/null 2>&1' 0 trap "exit 1" 1 2 3 15 # var init old_total=0 new_total=0 # arg handling and main execution case "$1" in -h) usage ;; -l) more $0; exit 1 ;; *.*) # main execution # check if required command is in $PATH variable which pngcrush &> /dev/null [[ $? != 0 ]] && { echo >&2 required \"pngcrush\" command is not in your PATH; exit 1; } for a in "$@";do if [ -f $a ] && [[ ${a##*.} == [pP][nN][gG] ]]; then old_size=$(ls -l $a | { read b c d e f g; echo $f ;} ) echo -n "${NAME_}: $a $old_size -> " pngcrush -q $a $tmp_1 rm -f -- $a mv -- $tmp_1 $a new_size=$(ls -l $a | { read b c d e f g; echo $f ;} ) echo $new_size bytes (( old_total += old_size )) (( new_total += new_size )) else echo ${NAME_}: file $a either does not exist or is not a png file fi done ;; *) echo ${NAME_}: skipping $1 ; continue ;; esac percentage=$(echo "scale = 2; ($new_total*100)/$old_total" | bc) reduction=$(echo $(( old_total - new_total )) \ | sed '{ s/$/@/; : loop; s/\(...\)@/@.\1/; t loop; s/@//; s/^\.//; }') echo "${NAME_}: total size reduction: $reduction bytes (total size reduced to ${percentage}%)" } ################################################## # Display text of ODF document in terminal # ################################################## ###### $1 = ODF file function o3() { unzip -p "$1" content.xml | o3totxt | utf8tolatin1; } ################################################## # Random data overwriting # ################################################## function overwriter() { # The author of this script, Elias Amaral, # claims no copyright over it. # http://iamstealingideas.wordpress.com/2010/05/20/writing-random-data-to-a-hard-drive-again msg() { printf "\n - $1\n\n" $2 } mbs=4 # 4mb blocksize=$(($mbs * 1024 * 1024)) dev=$1 if [[ -z $dev ]]; then msg "usage: $0 "; exit elif [[ ! -b $dev ]]; then msg "$dev: not a block device"; exit elif [[ ! -w $dev ]]; then msg "$dev: no write permission"; exit elif grep -q $dev /etc/mtab; then msg "$dev: mounted filesystem on device, omgomg!"; exit fi cat < step.new mv step.new step msg 'Writing at offset %s' $(($mbs * $i))M openssl rand \ -rand /dev/urandom \ $blocksize | \ dd of=$dev \ bs=$blocksize \ seek=$i do let i++ done msg Finished. } alias overwriter_='sudo dd if=/dev/zero bs=1M | openssl bf-cbc -pass pass:`cat /dev/urandom | tr -dc [:graph:] | head -c56` | sudo dd of=$dev bs=1M' ################################################## # Ownership Changes { own file user } # ################################################## function own() { chown -R "$2":"$2" ${1:-.}; } ################################################## # Hold/Unhold packages # ################################################## function packagehold() { echo -n "Please enter the package you wish to put a hold on: " read progID echo "$progID hold" |sudo dpkg --set-selections } function packageunhold() { echo -n "Please enter the package you wish to remove the hold on: " read progID echo "$progID install" |sudo dpkg --set-selections } ################################################## # Download all installed deb packages from # # official repos currently on system # ################################################## function packagelistdl() { sudo dpkg --get-selections | awk '{ print $1};' | while read package; do apt-cache show "$package"| wget -c 'http://ae.archive.ubuntu.com/ubuntu/'`sed -ne '/^Filename/s/^Filename: //p'`; done } ################################################## # Pacman Search # ################################################## function pacsearch() { echo -e "$(pacman -Ss $@ | sed \ -e 's#core/.*#\\033[1;31m&\\033[0;37m#g' \ -e 's#extra/.*#\\033[0;32m&\\033[0;37m#g' \ -e 's#community/.*#\\033[1;35m&\\033[0;37m#g' \ -e 's#^.*/.* [0-9].*#\\033[0;36m&\\033[0;37m#g' )" } ################################################## # Paste command output to www.pastehtml.com in # # txt format # ################################################## function paste() { curl -s -S --data-urlencode "txt=$($*)" "http://pastehtml.com/upload/create?input_type=txt&result=address";echo; } ################################################## # Removes duplicate paths # ################################################## ###### NOTE: symlinks aren't dereferenced (e.g., using `readlink`) as they may # exist for compatibility reasons function pathremove() { local IFS=':' local newpath local i for i in ${!2}; do if [ "$i" != "$1" ]; then newpath=${newpath:+$newpath:}$i fi done export $2="$newpath" } ################################################## # Print character classes # ################################################## function pcharc() { perl -e 'for (0..255) {$_ = chr($_); print if /['$1']/}' | cat -v; echo; } ################################################## # Quick plot of numbers on stdin (can also pass # # plot paramaters) # ################################################## # requires gnuplot: sudo apt-get install gnuplot # example: seq 1000 | sed 's/.*/s(&)/' | bc -l | plot linecolor 2 function plot() { { echo 'plot "-"' "$@"; cat; } | gnuplot -persist; } ################################################## # Scans a port, returns what's on it. # ################################################## function port() { lsof -i :"$1" } ################################################## # Portscan in one line # ################################################## function portscan() { $HOST=127.0.0.1;for((port=1;port<=65535;++port));do echo -en "$port ";if echo -en "open $HOST $port\nlogout\quit" | telnet 2>/dev/null | grep 'Connected to' > /dev/null;then echo -en "\n\nport $port/tcp is open\n\n";fi;done } ################################################## # Use Perl like grep # ################################################## function prep() { perl -nle 'print if '"$1"';' $2 ; } ################################################## # Find the printer driver (ppd) type being used # ################################################## function printdriver() { lpoptions -d $1 | grep -oe "printer-make-and-model='.*'" | cut -f2 -d "=" | sed -r s/\'//g } ################################################## # Print a row of characters across the terminal # ################################################## ###### Default character is "=", default color is white function println() { echo -n -e "\e[038;05;${2:-255}m";printf "%$(tput cols)s"|sed "s/ /${1:-=}/g" } ################################################## # Pronounce an English word # ################################################## ###### usage: pronounce "word1" "word2" "word3" "..." function pronounce() { for a in $@; do wget -qO- $(wget -qO- "http://www.m-w.com/dictionary/$a" | grep 'return au' | sed -r "s|.*return au\('([^']*)', '([^'])[^']*'\).*|http://cougar.eb.com/soundc11/\2/\1|") | aplay -q; done } ###### usage: pronounce_ "word1" "word2" "word3" "..." # requires 'mpg123' - sudo apt-get install mp321, but better dictionary function pronounce_() { wget -qO- $(wget -qO- "http://dictionary.reference.com/browse/$@" | grep 'soundUrl' | head -n 1 | sed 's|.*soundUrl=\([^&]*\)&.*|\1|' | sed 's/%3A/:/g;s/%2F/\//g') | mpg123 -; } ################################################## # Pull a single file out of a .tar.gz # ################################################## function pullout() { if [ $# -ne 2 ]; then echo "need proper arguments:" echo "pullout [file] [archive.tar.gz]" return 1 fi case $2 in *.tar.gz|*.tgz) gunzip < $2 | tar -xf - $1 ;; *) echo $2 is not a valid archive return 1 ;; esac return 0 } ################################################## # Create QR codes from a URL # ################################################## function qrurl() { curl -sS "http://chart.apis.google.com/chart?chs=200x200&cht=qr&chld=H|0&chl=$1" -o - | display -filter point -resize 600x600 png:-; } ################################################## # Email yourself a short note # ################################################## function quickemail() { echo "$*" | mail -s "$*" email@email.com; } ################################################## # Suppress output of loud commands you don't want# # to hear from # ################################################## function quietly() { "$@" |&:; } function Quietly() { "$@" > /dev/null 2>&1; } function quietly_() { $* 2> /dev/null > /dev/null; } ################################################## # Turning on and off Internet radio # ################################################## function radio() { if [ "$(pidof mpg123)" ] ; then killall mpg123; else mpg123 -q -@ http://173.236.29.51:8200 & fi } ################################################## # Scroll file one line at a time (w/only UNIX # # base tools) # ################################################## ###### usage: rd < file ; or ... | rd function rd_() { IFS='';$@;for i in `sed 's.\\\.\\\134.g;s.%.\\\045.g'`;do printf "$i$IFS";sleep 1;done ; } ################################################## # TTS # ################################################## function readfile() { curl -sGA Mozilla -d "language=en&format=audio/mp3&options=MaxQuality&appid=To6RoRW0R9Pt9emvqxsqEImBiS_ElZ19Dxpu9j6WURkg*&text=`python3 -c 'from urllib.parse import quote_plus; from sys import stdin; print(quote_plus(stdin.read()))' <${1:?file name is empty}`" 'http://api.microsofttranslator.com/V2/Http.svc/Speak' | mpg321 -q -; } ################################################## # Copy Relinux backups to '~/Backups' folder # # (only after Relinux has backed-up stuff) # ################################################## function relinux-copy() # requires: relinux (not yet available in PPA/repo) { notify-send -t 3000 -i /usr/share/icons/gnome/32x32/status/info.png "Relinux ISO Copy Started" DISTRIB_ID=`cat /etc/lsb-release | grep DISTRIB_ID | cut -d '=' -f 2` DISTRIB_CODENAME=`lsb_release -cs | sed "s/^./\u&/"` if [ ! -d "$HOME/Backups" ]; then mkdir "$HOME/Backups" fi if [ ! -d "$HOME/Backups/$DISTRIB_ID $DISTRIB_CODENAME Backup `date +-%e-%m-%Y`" ]; then mkdir "$HOME/Backups/$DISTRIB_ID $DISTRIB_CODENAME Backup `date +-%e-%m-%Y`" cd "$HOME/Backups/$DISTRIB_ID $DISTRIB_CODENAME Backup `date +-%e-%m-%Y`" echo 'Password: password' >> Password.txt cp /home/relinux/custom.iso "$HOME/Backups/$DISTRIB_ID $DISTRIB_CODENAME Backup `date +-%e-%m-%Y`" cd .. cd .. notify-send -t 3000 -i /usr/share/icons/gnome/32x32/status/info.png "Relinux ISO Copy Finished" else mkdir "$HOME/Backups/$DISTRIB_ID $DISTRIB_CODENAME Backup `date +-%e-%m-%Y_%H%M`" cd "$HOME/Backups/$DISTRIB_ID $DISTRIB_CODENAME Backup `date +-%e-%m-%Y_%H%M`" echo 'Password: password' >> Password.txt cp /home/relinux/custom.iso "$HOME/Backups/$DISTRIB_ID $DISTRIB_CODENAME Backup `date +-%e-%m-%Y_%H%M`" cd .. cd .. notify-send -t 3000 -i /usr/share/icons/gnome/32x32/status/info.png "Relinux ISO Copy Finished" fi ; } ################################################## # Copy Remastersys backups to '~/Backups' folder # # (only after Remastersys has backed-up stuff) # ################################################## function remastersys-copy() # requires: sudo apt-get install remastersys { notify-send -t 3000 -i /usr/share/icons/gnome/32x32/status/info.png "Remastersys ISO Copy Started" DISTRIB_ID=`cat /etc/lsb-release | grep DISTRIB_ID | cut -d '=' -f 2` DISTRIB_CODENAME=`lsb_release -cs | sed "s/^./\u&/"` if [ ! -d "$HOME/Backups" ]; then mkdir "$HOME/Backups" fi if [ ! -d "$HOME/Backups/$DISTRIB_ID $DISTRIB_CODENAME Backup `date +-%e-%m-%Y`" ]; then mkdir "$HOME/Backups/$DISTRIB_ID $DISTRIB_CODENAME Backup `date +-%e-%m-%Y`" cd "$HOME/Backups/$DISTRIB_ID $DISTRIB_CODENAME Backup `date +-%e-%m-%Y`" echo 'Password: password' >> Password.txt cp /home/remastersys/remastersys/custom-backup.iso "$HOME/Backups/$DISTRIB_ID $DISTRIB_CODENAME Backup `date +-%e-%m-%Y`" cd .. cd .. notify-send -t 3000 -i /usr/share/icons/gnome/32x32/status/info.png "Remastersys ISO Copy Finished" else mkdir "$HOME/Backups/$DISTRIB_ID $DISTRIB_CODENAME Backup `date +-%e-%m-%Y_%H%M`" cd "$HOME/Backups/$DISTRIB_ID $DISTRIB_CODENAME Backup `date +-%e-%m-%Y_%H%M`" echo 'Password: password' >> Password.txt cp /home/remastersys/remastersys/custom-backup.iso "$HOME/Backups/$DISTRIB_ID $DISTRIB_CODENAME Backup `date +-%e-%m-%Y_%H%M`" cd .. cd .. notify-send -t 3000 -i /usr/share/icons/gnome/32x32/status/info.png "Remastersys ISO Copy Finished" fi ; } ################################################## # Reminder for whatever whenever # ################################################## function remindme() { sleep $1 && zenity --info --text "$2" & } ################################################## # Remount a device # ################################################## function remount() { # copyright 2007 - 2010 Christopher Bratusek DEVICE=$1 shift mount -oremount,$@ $DEVICE } ################################################## # Repeats a command every x seconds # ################################################## ###### Usage: repeat PERIOD COMMAND function repeat() { local period period=$1; shift; while (true); do eval "$@"; sleep $period; done } ################################################## # Add repo # ################################################## function repoadd() { # copyright 2007 - 2010 Christopher Bratusek reprepro -Vb "$REPO_HOME" include "$REPO_DIST" *.changes cd "$REPO_HOME"/dists/"$REPO_DIST" gpg -abs -o Release.gpg Release } ################################################## # Repository update check # ################################################## function repository-update-check() { cat > "/tmp/repository-update-check.sh" <<"End-of-message" #!/bin/bash # created by unknown # updated and tweaked by Inameiname (11 October 2011) #Dependency check DEPENDENCIES="zenity curl" for dep in $DEPENDENCIES do which $dep &> /dev/null if [ $? -ne '0' ] then echo "[ERR]: $dep Not Found in your path." exit fi done #Cleans last usage OLD_FILES="repositories" for old in $OLD_FILES do if [ -f /tmp/$old ]; then rm -fv -R /tmp/$old fi done #Lists release, repos myrelease=$(grep 'DISTRIB_CODENAME' /etc/lsb-release | sed 's/DISTRIB_CODENAME=//' | head -1) #myrelease="saucy" repo_clean=$(ls /etc/apt/sources.list.d/ | grep -v .save) repo_list=$(cd /etc/apt/sources.list.d && cat $repo_clean /etc/apt/sources.list | grep deb\ http.* | sed -e 's/.*help\.ubuntu\.com.*//' -e 's/^#.*//' -e 's/deb\ //' -e 's/deb-src\ //' -e '/^$/d' | sort -u | awk '{print $1"|"$2}' | sed -e 's/\/|/|/' -e 's/-[a-z]*$//' | uniq && cd) #repo_list=$(cat dummy.sources.list | grep deb\ http.* | sed -e 's/.*help\.ubuntu\.com.*//' -e 's/^#.*//' -e 's/deb\ //' -e 's/deb-src\ //' -e '/^$/d' | sort -u | awk '{print $1"|"$2}' | sed -e 's/\/|/|/' -e 's/-[a-z]*$//' | uniq && cd) count_repos=$(echo $repo_list | wc -w) check_progress=$count_repos release_14="trusty" release_13="saucy" release_12="raring" release_11="quantal" release_10="precise" release_9="oneiric" release_8="natty" release_7="maverick" release_6="lucid" release_5="karmic" release_4="jaunty" release_3="intrepid" release_2="hardy" release_1="gutsy" #Checks { for repo_0 in $repo_list do repo="$(echo $repo_0 | sed 's/|.*//')" rir="$(echo $repo_0 | sed 's/.*|//')" rir_list=$(curl --silent $repo/dists/ | grep -oi href\=\"[^\/].*/\" | sed -e 's/href\=\"//i' -e 's/\/\"//' -e 's/-.*//' -e 's/\ NAME.*//i' | sort -u | uniq) if [ '$rir_list' = '' ] then rir_list=$(curl --silent $repo/ | grep -oi href\=\"[^\/].*\" | sed -e 's/href\=\"//i' -e 's/\/\"//' -e 's/-.*//' -e 's/\ NAME.*//i' -e 's/\/index\.html\"//' -e 's/.*".*//' -e 's/http.*//' | sort -u | uniq) fi #(I guess one will find something more elegant here) if [ $(echo "$rir_list" | grep -o $myrelease) ] then echo "$myrelease " >> /tmp/repositories fi if [ '$rir_list' = '' ] then echo "$myrelease " >> /tmp/repositories fi if [ $(echo "$rir_list" | grep -oi $release_14) ] then r14="yes" else r14="no" fi if [ $(echo "$rir_list" | grep -oi $release_13) ] then r13="yes" else r13="no" fi if [ $(echo "$rir_list" | grep -oi $release_12) ] then r12="yes" else r12="no" fi if [ $(echo "$rir_list" | grep -oi $release_11) ] then r11="yes" else r11="no" fi if [ $(echo "$rir_list" | grep -oi $release_10) ] then r10="yes" else r10="no" fi if [ $(echo "$rir_list" | grep -oi $release_9) ] then r9="yes" else r9="no" fi if [ $(echo "$rir_list" | grep -oi $release_8) ] then r8="yes" else r8="no" fi if [ $(echo "$rir_list" | grep -oi $release_7) ] then r7="yes" else r7="no" fi if [ $(echo "$rir_list" | grep -oi $release_6) ] then r6="yes" else r6="no" fi if [ $(echo "$rir_list" | grep -oi $release_5) ] then r5="yes" else r5="no" fi if [ $(echo "$rir_list" | grep -oi $release_4) ] then r4="yes" else r4="no" fi if [ $(echo "$rir_list" | grep -oi $release_3) ] then r3="yes" else r3="no" fi if [ $(echo "$rir_list" | grep -oi $release_2) ] then r2="yes" else r2="no" fi if [ $(echo "$rir_list" | grep -oi $release_1) ] then r1="yes" else r1="no" fi #results if [ "$rir" = "$release_14" ] then results="$repo [$r14] $r13 $r12 $r11 $r10 $r9 $r8 $r7 $r6 $r5 $r4 $r3 $r2 $r1" elif [ "$rir" = "$release_13" ] then results="$repo $r14 [$r13] $r12 $r11 $r10 $r9 $r8 $r7 $r6 $r5 $r4 $r3 $r2 $r1" elif [ "$rir" = "$release_12" ] then results="$repo $r14 $r13 [$r12] $r11 $r10 $r9 $r8 $r7 $r6 $r5 $r4 $r3 $r2 $r1" elif [ "$rir" = "$release_11" ] then results="$repo $r14 $r13 $r12 [$r11] $r10 $r9 $r8 $r7 $r6 $r5 $r4 $r3 $r2 $r1" elif [ "$rir" = "$release_10" ] then results="$repo $r14 $r13 $r12 $r11 [$r10] $r9 $r8 $r7 $r6 $r5 $r4 $r3 $r2 $r1" elif [ "$rir" = "$release_9" ] then results="$repo $r14 $r13 $r12 $r11 $r10 [$r9] $r8 $r7 $r6 $r5 $r4 $r3 $r2 $r1" elif [ "$rir" = "$release_8" ] then results="$repo $r14 $r13 $r12 $r11 $r10 $r9 [$r8] $r7 $r6 $r5 $r4 $r3 $r2 $r1" elif [ "$rir" = "$release_7" ] then results="$repo $r14 $r13 $r12 $r11 $r10 $r9 $r8 [$r7] $r6 $r5 $r4 $r3 $r2 $r1" elif [ "$rir" = "$release_6" ] then results="$repo $r14 $r13 $r12 $r11 $r10 $r9 $r8 $r7 [$r6] $r5 $r4 $r3 $r2 $r1" elif [ "$rir" = "$release_5" ] then results="$repo $r14 $r13 $r12 $r11 $r10 $r9 $r8 $r7 $r6 [$r5] $r4 $r3 $r2 $r1" elif [ "$rir" = "$release_4" ] then results="$repo $r14 $r13 $r12 $r11 $r10 $r9 $r8 $r7 $r6 $r5 [$r4] $r3 $r2 $r1" elif [ "$rir" = "$release_3" ] then results="$repo $r14 $r13 $r12 $r11 $r10 $r9 $r8 $r7 $r6 $r5 $r4 [$r3] $r2 $r1" elif [ "$rir" = "$release_2" ] then results="$repo $r14 $r13 $r12 $r11 $r10 $r9 $r8 $r7 $r6 $r5 $r4 $r3 [$r2] $r1" elif [ "$rir" = "$release_1" ] then results="$repo $r14 $r13 $r12 $r11 $r10 $r9 $r8 $r7 $r6 $r5 $r4 $r3 $r2 [$r1]" else echo "$myrelease " >> /tmp/repositories results="$repo [yes] [yes] [yes] [yes] [yes] [yes] [yes] [yes] [yes] [yes] [yes] [yes] [yes] [yes]" fi #finds status and stores results if [ $(echo "$results" | grep -o "\[no\]" | uniq) ] then status="Error" fi if [ $(echo "$results" | grep -o "\[yes\]" | uniq) ] then status="Ok" fi # if [ $(echo "$results" | grep -o "\[yes\]" | uniq) ] && [ "$rir" \< "$myrelease" ] && [ -n $(echo "$results" | grep -o "\[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]" | uniq) ] && [ echo "rir_list" | $(awk '{print $14 $13 $12 $11 $10 $9 $8 $7 $6 $5 $4 $3 $2 $1}' | grep $myrelease) ] # then # status="Upgradeable" # fi # if [ $(echo "$results" | grep -o "\[yes\]" | uniq) ] && [ "$rir" \> "$myrelease" ] && [ -n $(echo "$results" | grep -o "\[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]\ \[yes\]" | uniq) ] && [ echo "rir_list" | $(awk '{print $14 $13 $12 $11 $10 $9 $8 $7 $6 $5 $4 $3 $2 $1}' | grep $myrelease) ] # then # status="Downgradeable" # fi #TODO should be $status $repo $r14 $r13 $r12 $r11 $r10 $r9 $r8 $r7 $r6 $r5 $r4 $r3 $r2 $r1 echo "$status $results" >> /tmp/repositories #Zenity progressbar percent=$((100-$check_progress*100/$count_repos)) check_progress=$(($check_progress-1)) echo $percent done } | zenity --progress --percentage=0 --title="Repositories" --text="Scanning repositories..." --auto-close #Displays nicely if [ "$(cat /tmp/repositories | grep -c $myrelease)" = "$count_repos" ] then zeni_text="All the repositories you use support the $myrelease release." elif [ "$(cat /tmp/repositories | grep -c $myrelease)" = "1" ] then zeni_text="Only $(cat /tmp/repositories | grep -c $myrelease) of your $count_repos activated repositories supports the $myrelease release." else zeni_text="$(($count_repos - $(cat /tmp/repositories | grep -c $myrelease))) of your $count_repos activated repositories don't support the $myrelease release." fi if [ "$((100+$count_repos*25))" -gt "600" ] then window_height="600" else window_height="$((100+$count_repos*22))" fi zenity --title "Repositories" --text "$zeni_text" --width 800 --height $window_height --list --column "Status" --column "Repository" --column "$release_14" --column "$release_13" --column "$release_12" --column "$release_11" --column "$release_10" --column "$release_9" --column "$release_8" --column "$release_7" --column "$release_6" --column "$release_5" --column "$release_4" --column "$release_3" --column "$release_2" --column "$release_1" $(cat /tmp/repositories | sed s/$myrelease//) End-of-message chmod +x "/tmp/repository-update-check.sh" "/tmp/repository-update-check.sh" rm -fv -R "/tmp/repositories" rm -fv -R "/tmp/repository-update-check.sh" } ################################################## # Set permissions to "standard" values (644/755),# # recursive # ################################################## ###### Usage: resetp function resetp() { chmod -R u=rwX,go=rX "$@" } ################################################## # X DISPLAY functions # ################################################## function reset_display() { if [ "$SHLVL" -eq 1 ]; then echo $DISPLAY > $HOME/.display else if [ -e $HOME/.display ]; then export DISPLAY=$(cat $HOME/.display) fi fi } function set_xtitle() { if [ $TERM == "xterm" ]; then echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007" fi } # if [ "$UID" -ne 0 ]; then # reset_display # fi ################################################## # Resize images # ################################################## function resizeimg() { NAME_="resizeimg" HTML_="batch resize image" PURPOSE_="resize bitmap image" PURPOSE_="resize bitmap image" SYNOPSIS_="$NAME_ [-hlv] -w [file...]" REQUIRES_="standard GNU commands, ImageMagick" VERSION_="1.2" DATE_="2001-04-22; last update: 2004-10-02" AUTHOR_="Dawid Michalczyk " URL_="www.comp.eonworks.com" CATEGORY_="gfx" PLATFORM_="Linux" SHELL_="bash" DISTRIBUTE_="yes" # This program is distributed under the terms of the GNU General Public License usage () { echo >&2 "$NAME_ $VERSION_ - $PURPOSE_ Usage: $SYNOPSIS_ Requires: $REQUIRES_ Options: -w , an integer referring to width in pixels; aspect ratio will be preserved -v, verbose -h, usage and options (this help) -l, see this script" exit 1 } gfx_resizeImage() { # arg check [[ $1 == *[!0-9]* ]] && { echo >&2 $1 must be an integer; exit 1; } [ ! -f $2 ] && { echo >&2 file $2 not found; continue ;} # scaling down to value in width mogrify -geometry $1 $2 } # args check [ $# -eq 0 ] && { echo >&2 missing argument, type $NAME_ -h for help; exit 1; } # var init verbose= width= # option and arg handling while getopts vhlw: options; do case $options in v) verbose=on ;; w) width=$OPTARG ;; h) usage ;; l) more $0; exit 1 ;; \?) echo invalid argument, type $NAME_ -h for help; exit 1 ;; esac done shift $(( $OPTIND - 1 )) # check if required command is in $PATH variable which mogrify &> /dev/null [[ $? != 0 ]] && { echo >&2 the required ImageMagick \"mogrify\" command \ is not in your PATH variable; exit 1; } for a in "$@";do gfx_resizeImage $width $a [[ $verbose ]] && echo ${NAME_}: $a done } ################################################## # Daemon management # ################################################## # function restart() { sudo /etc/rc.d/$1 restart; } # function start() { sudo /etc/rc.d/$1 start; } # function stop() { sudo /etc/rc.d/$1 stop; } ################################################## # Restart the windows, only once # ################################################## function restowin() { sudo grub-set-default 3 && sudo reboot; } ################################################## # Use binary notation to chmod a file # ################################################## function right() { bc <<< "obase=8;ibase=2;$1"; }; # touch foo; chmod $(right 111111011) foo; ls -l foo ################################################## # Rip a file with handbrake and good options # ################################################## # function rip() { # handbrake -i /dev/dvd -o ${HOME}/${1}.mp4 -L -U -F -f mp4 -e x264 -b 4000 -B 192 # } ################################################## # Log rm commands # ################################################## function rm() { workingdir=$( pwdx $$ | awk '{print $2}' ) /bin/rm $* echo "rm $* issued at $(date) by the user $(who am i| awk '{print $1} ') in the directory ${workingdir}" >> /tmp/rm.out ; } ################################################## # Using associative array to remove all files and# # directories under PWD except # ################################################## function rmall_but() { declare -A keep;for arg;do keep[$arg]=1;done;for file in *;do [[ ${keep[$file]} ]] || rm -rf "$file";done; } ################################################## # Remove an inode via inode number # ################################################## function rminode() { find . -inum $1 -exec rm -i {} \; } ################################################## # Roll - archive wrapper # ################################################## ###### usage: roll ./foo ./bar function roll() { FILE=$1 case $FILE in *.tar.bz2) shift && tar cjf $FILE $* ;; *.tar.gz) shift && tar czf $FILE $* ;; *.tgz) shift && tar czf $FILE $* ;; *.zip) shift && zip $FILE $* ;; *.rar) shift && rar $FILE $* ;; esac } ################################################## # Removing all extended attributes from a # # directory tree # ################################################## function rr() { for i in $(ls -Rl@ | grep '^ ' | awk '{print $1}' | sort -u); \ do echo Removing $i ... >&2; \ find . | xargs xattr -d $i 2>/dev/null ; done } ################################################## # RTFM function # ################################################## function rtfm() { help $@ || man $@ || $BROWSER "http://www.google.com/search?q=$@"; } ################################################## # Make a backup before editing a file # ################################################## function safeedit() { cp $1 ${1}.backup && vim $1 } ################################################## # Sanitize - set file/directory owner and # # permissions to normal values (644/755) # ################################################## ###### usage: sanitize function sanitize() { chmod -R u=rwX,go=rX "$@" chown -R ${USER}:users "$@" } ################################################## # Save a specified directory # ################################################## function save() { /usr/bin/sed "/$@/d" ~/.dirs > ~/.dirs1; \mv ~/.dirs1 ~/.dirs; echo "$@"=\"`pwd`\" >> ~/.dirs; source ~/.dirs ; } ################################################## # Save a file to ~/Temp # ################################################## function saveit() { cp $1 ${HOME}/Temp/${1}.saved } ################################################## # Screencasting with mplayer webcam window # ################################################## function screencastw() { mplayer -cache 128 -tv driver=v4l2:width=176:height=177 -vo xv tv:// -noborder -geometry "95%:93%" -ontop | ffmpeg -y -f alsa -ac 2 -i pulse -f x11grab -r 30 -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -i :0.0 -acodec pcm_s16le output.wav -an -vcodec libx264 -vpre lossless_ultrafast -threads 0 output.mp4 } ################################################## # Search package database # ################################################## ###### search Gentoo package database (portage) using eix # $1 = search term (package name) # function sd() { eix -FsSc "$1"; } # Search all available w/ desc.; show summary # function se() { eix -F "^$1\$"; } # Search exact available; show details # function si() { eix -FIc "$1"; } # Search installed; show summary # function sp() { eix -Fc "$1"; } # Search all available; show summary ###### search Arch package database using pacman # $1 = search term (package name # function sp() { # echo -e "$(pacman -Ss "$@" | sed \ # -e 's#^core/.*#\\033[1;31m&\\033[0;37m#g' \ # -e 's#^extra/.*#\\033[0;32m&\\033[0;37m#g' \ # -e 's#^community/.*#\\033[1;35m&\\033[0;37m#g' \ # -e 's#^.*/.* [0-9].*#\\033[0;36m&\\033[0;37m#g' ) \ # \033[0m" # } ###### search Debian (or Ubuntu) package database (apt) using dpkg # $1 = search term (package name) function sp() { apt-cache search "$1" | grep -i "$1"; } # search all available ################################################## # Sed /pat/!d without using sed (no RE; limited # # to shell patterns aka globbing) # ################################################## # usage: se pattern # use in place of sed /pat/!d where RE are overkill function se_() { while read a;do [ "$a" != "${a#*$@*}" ]&&echo $a;done ; } ################################################## # Search and replace words/phrases from text file# ################################################## ###### usage: searchnreplace "whatever oldtext" "whatever newtext" "file(s) to act on" function searchnreplace() { # Store old text and new text in variables old=$1; new=$2; # Shift positional parameters to places to left (get rid of old and # new from command line) shift; shift; # Store list of files as a variable files=$@; a=''; for a in $files do temp=$(echo "/tmp/$LOGNAME-$a"); # echo "$temp"; echo -n "."; sed -e "s/$old/$new/g" $a > $temp; mv $temp $a; done echo; echo -e "Searched $# files for '$old' and replaced with '$new'"; } ################################################## # Sed edit-in-place using -a option instead of # # -i option (no tmp file created) # ################################################## function sedi() { case $# in [01])echo usage: sedi cmds file;;2)sed -an ''"$1"';H;$!d;g;w '"$2"'' $2;;esac; } ################################################## # Auto send an attachment from CLI # ################################################## function send() { echo "File auto-sent from linux." | mutt -s "See Attached File" -a $1 $2 } ################################################## # Manage services # ################################################## function service() { if [ $# -lt 2 ]; then echo "Missing service name or command" return 1 fi sudo /etc/init.d/$1 $2 && return 0 } ###### service() { /etc/rc.d/$1 $2; } function service_() { if [ -n "$2" ] then /etc/rc.d/$1 $2 else echo "All daemons" ls --ignore=functions* /etc/rc.d/ echo "Running daemons" ls /var/run/daemons fi } ################################################## # Create a new script, automatically populating # # the shebang line, editing the script, and # # making it executable. # ################################################## function shebang() { if i=$(which $1); then printf '#!%s\n\n' $i > $2 && vim + $2 && chmod 755 $2; else echo "'which' could not find $1, is it in your \$PATH?"; fi; } ################################################## # Pseudo namespaces in bash # ################################################## ## copyright: 2009, Poor Yorick ## author url: http://www.pooryorick.com ## license: http://www.ynform.org/w/Pub/OpenSourceSharewareLicense ## to "import" functions and assign them to pseudo namespaces using prefixes ## caveat: works well for functions, but there is still only one global namespace -- no script-level namespace like Python's # function shimport() { # local magic part prefix script script2 t tvar var vartype # magic=__shimport__ # script=' # { @1 ; } >&2 # @script2 # ' # script="${script//@1/$(< /dev/stdin)}" # script=$(printf '%s\n%s' "$script" "declare -p $magic") # prefix="$1" # shift # script2='' # while test ${#@} -gt 0; do # var=${1%%=*} # vartype=${1#*=} # case "$vartype" in # f*) # t=-f # ;; # v*) # t=-p # ;; # *) # echo "$vartype" is an invalid type specifier for "$var"! # return 1 # ;; # esac # read -d '' part <<-'EOF' # @magic=$(declare @t @var) # @magic=${@magic/@var/@prefix@var} # printf '%s\\n' "$@magic" # EOF # for tvar in magic t var prefix; do # part=${part//@$tvar/${!tvar}} # done # script2="$(printf '%s\n%s\n' "$script2" "$part")" # shift # done # printf '%s\n' "$(bash -c "${script//@script2/$script2}")" # } # shimport_test1=$(cat <<-'EOG' # eval "$(shimport mod1_ var1=v var2=v func1=f <<-'EOF' # echo welcome to the inner script! # var1=( one two "forty three" ) # var2=val2 # function func1() { # echo welcome to func1! # } # EOF # )" # mod1_func1 # printf 'mod1_var1: %s\n' "${mod1_var1[@]}" # EOG # ) # eval "$shimport_test1" # }}} ################################################## # Shot - takes a screenshot of your current # # window # ################################################## function shot() { import -frame -strip -quality 75 "$HOME/$(date +%s).png" } ################################################## # Create an easy to pronounce shortened URL from # # CLI # ################################################## function shout() { curl -s "http://shoutkey.com/new?url=$1" | sed -n 's/\/\&/p' | sed 's/<[^>]*>//g;/& /dev/null return 0 } ################################################## # Ssh functions # ################################################## function slak() { if [ $# -lt 2 ]; then echo "add public key to securelink server" echo "usage: skak [accountname] [sl port]" else cat /Volumes/Library/ssh/id_rsa-$1.pub | ssh -q lila@localhost -p $2 "if [ ! -d ~/.ssh/ ] ; then mkdir ~/.ssh ; fi ; chmod 700 ~/.ssh/ ; cat - >> ~/.ssh/authorized_keys ; chmod 600 ~/.ssh/authorized_keys" fi } function slssh() { if [ $# -lt 1 ]; then echo "connect to securelink ssh session" echo "usage slssh [port#]" echo "ssh -p \$1 localhost" else ssh -p $1 localhost fi } function slpg() { if [ $# -lt 1 ]; then echo "create securelink ssh tunnel for postgres" echo "usage: slpg [port#]" echo "ssh -N localhost -L 2345/localhost/5432 -p \$1" else ssh -N localhost -L 2345/localhost/5432 -p $1 fi } function sshmysql() { # bind MySQL hostport to forward remote MySQL connection to localhost ssh -L 13306:127.0.0.1:3306 -N $* & } function sshpg() { if [ $# -lt 1 ]; then echo "create ssh tunnel for postgres" echo "usage: sshpg username@server" echo "ssh -N \$1 -L 2345/localhost/5432" else ssh -N $1 -L 2345/localhost/5432 fi } function sshpg2() { if [ $# -lt 1 ]; then echo "create ssh tunnel for postgres" echo "usage: sshpg username@server" echo "ssh -N \$1 -L \$2/localhost/5432" else ssh -N $1 -L $2/localhost/5432 fi } ################################################## # Function that outputs dots every second until # # command completes # ################################################## function sleeper() { while `ps -p $1 &>/dev/null`; do echo -n "${2:-.}"; sleep ${3:-1}; done; }; export -f sleeper ################################################## # Slow down CPU and IO for process and its # # offsprings # ################################################## ###### requires gawk: sudo apt-get install gawk function slow2() { ionice -c3 renice -n 20 $(pstree `pidof $1` -p -a -u -A|gawk 'BEGIN{FS=","}{print $2}'|cut -f1 -d " ") ; } ################################################## # Sort a list of comma-separated list of numbers # ################################################## function sort_csn() { echo "${1}" | sed -e "s/,/\n/g"| sort -nu | awk '{printf("%s,",$0)} END {printf("\n")}' | sed -e "s/,$//"; } ################################################## # Get function's source # ################################################## function source_print() { set | sed -n "/^$1/,/^}$/p"; } ################################################## # Spellchecking # ################################################## ###### I-Spell @ work: ENGLISH # requires ispell: sudo apt-get install ispell function spell() { local CHATTO if [ $# -ne 1 ]; then echo -e "\033[1;32mUSAGE: \033[33mis word_to_check\033[0m" else CHATTO=$( echo $* | awk '{print $1}' ) shift echo -e "----------------------------------------------------->\n" echo $CHATTO | ispell -a -m -B |grep -v "@" echo -e "----------------------------------------------------->" fi } ###### Google spell checker function spellcheck() { typeset y=$@;curl -sd "$y" https://www.google.com/tbproxy/spell|sed -n '/s="[0-9]"/{s/<[^>]*>/ /g;s/\t/ /g;s/ *\(.*\)/Suggestions: \1\n/g;p}'|tee >(grep -Eq '.*'||echo -e "OK");} ###### spell checks either a Web page URL or a file # requires ispell: sudo apt-get install ispell function webspell() { okaywords="$HOME/.okaywords" tempout="/tmp/webspell.$$" trap "/bin/rm -f $tempout" 0 if [ $# -eq 0 ] ; then echo "Usage: webspell file|URL" >&2; fi for filename do if [ ! -f "$filename" -a "$(echo $filename|cut -c1-7)" != "http://" ] ; then continue; # picked up directory in '*' listing fi lynx -dump $filename | tr ' ' '\n' | sort -u | \ grep -vE "(^[^a-z]|')" | \ # adjust the following line to produce just a list of misspelled words ispell -a | awk '/^\&/ { print $2 }' | \ sort -u > $tempout if [ -r $okaywords ] ; then # if you have an okaywords file, screen okay words out grep -vif $okaywords < $tempout > ${tempout}.2 mv ${tempout}.2 $tempout fi if [ -s $tempout ] ; then echo "Probable spelling errors: ${filename}" echo '-------' ; cat $tempout ; echo '=========' cat $tempout | paste - - - - | sed 's/^/ /' fi done } ################################################## # Cut a part of a video # ################################################## # ("$1" for original file, "$2" for new file, "$3" is start time, & "$4" is length of video desired) function splitvideo() { ffmpeg -vcodec copy -acodec copy -i "$1" -ss "$3" -t "$4" "$2" } ################################################## # Posts a file to sprunge.us and copies the # # related url to the clipboard # ################################################## function sprunge() { curl -s -F "sprunge=@$1" http://sprunge.us | xclip -selection clipboard && xclip -selection clipboard -o; } ################################################## # Stock prices - can be called two ways: # # stock novl (this shows stock pricing): # # stock "novell" (this way shows stock symbol # # for novell) # ################################################## function stock() { stockname=`lynx -dump http://finance.yahoo.com/q?s=${1} | grep -i ":${1})" | sed -e 's/Delayed.*$//'` stockadvise="${stockname} - delayed quote." declare -a STOCKINFO STOCKINFO=(` lynx -dump http://finance.yahoo.com/q?s=${1} | egrep -i "Last Trade:|Change:|52wk Range:"`) stockdata=`echo ${STOCKINFO[@]}` if [[ ${#stockname} != 0 ]] ;then echo "${stockadvise}" echo "${stockdata}" else stockname2=${1} lookupsymbol=`lynx -dump -nolist http://finance.yahoo.com/lookup?s="${1}" | grep -A 1 -m 1 "Portfolio" | grep -v "Portfolio" | sed 's/\(.*\)Add/\1 /'` if [[ ${#lookupsymbol} != 0 ]] ;then echo "${lookupsymbol}" else echo "Sorry $USER, I can not find ${1}." fi fi } ###### command line way to get the stock quote via Yahoo function stock_() { curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=csco&f=l1' } ################################################## # Stopwatch and Countdown Timer # ################################################## function stopwatch() { # copyright 2007 - 2010 Christopher Bratusek BEGIN=$(date +%s) while true; do NOW=$(date +%s) DIFF=$(($NOW - $BEGIN)) MINS=$(($DIFF / 60)) SECS=$(($DIFF % 60)) echo -ne "Time elapsed: $MINS:`printf %02d $SECS`\r" sleep .1 done } ###### stopwatch with log function stop_watch() { START=$( date +%s ); while true; do CURRENT=$( date +%s ) ; echo $(( CURRENT-START )) ; sleep 1 ; echo -n ^[[A ; done } ###### countdown clock function countdown() { case "$1" in -s) shift;; *) set $(($1 * 60));; esac; local S=" "; for i in $(seq "$1" -1 1); do echo -ne "$S\r $i\r"; sleep 1; done; echo -e "$S\rBOOM!"; } ###### countdown clock alias countdown2='MIN=1 && for i in $(seq $(($MIN*60)) -1 1); do echo -n "$i, "; sleep 1; done; echo -e "\n\nBOOOM! Time to start."' ################################################## # Transcodes and streams a video over http on # # port 6789 (vlc required) # ################################################## # function stream() { cvlc $1 --extraintf rc --sout # 'transcode{vcodec=h264,vb=256,fps=12,scale=1,deinterlace,acodec=mp3,threads=3,ab=64,channels=2}:duplicate{dst=std{access=http,mux=ts,dst=0.0.0.0:6789}}'; # } ################################################## # Print the corresponding error message # ################################################## function strerror() { python -c "import os; print os.strerror($1)"; } ################################################## # Function to split a string into an array # ################################################## function string2array() { read -a ARR <<<'world domination now!'; echo ${ARR[2]}; } ################################################## # Count total number of subdirectories in current# # directory starting with specific name. # ################################################## function subdir_find() { find . -type d -name "*TestDir*" | wc -l } ################################################## # Check tcp-wrapping support # ################################################## ###### returns TRUE if the application supports tcp-wrapping or FALSE if not by reading the shared libraries used by this application. function supportsWrap() { ldd `which ${1}` | grep "libwrap" &>/dev/null && return 0 || return 1; } ################################################## # Swap 2 filenames around # ################################################## ###### from Uzi's bashrc function swap() { local TMPFILE=tmp.$$ [ $# -ne 2 ] && echo "swap: 2 arguments needed" && return 1 [ ! -e $1 ] && echo "swap: $1 does not exist" && return 1 [ ! -e $2 ] && echo "swap: $2 does not exist" && return 1 mv "$1" $TMPFILE mv "$2" "$1" mv $TMPFILE "$2" } function swap2() { if [ -f "$1" -a -f "$2" ]; then mv "$1" "$1.$$" && mv "$2" "$1" && mv "$1.$$" "$2" && echo "Success"; else echo "Fail"; fi; } ################################################## # Switch two files (comes in handy) # ################################################## function switchfile() { mv $1 ${1}.tmp && $2 $1 && mv ${1}.tmp $2 } ################################################## # Creates a dated tarball # ################################################## function tarball() { name=$1 shift tar zcvf $name-`date +%Y%m%d`.tar.gz "$@" } ################################################## # Monitor progress of data through a pipeline # ################################################## function tarcp() { if (( $# >= 2 )); then echo "copy ${@[1, -2]} => ${@[-1]}" # http://www.ivarch.com/programs/pv.shtml if which pv ; then tar -c -f - ${@[1, -2]} | pv -t -b -r | tar -x -f - -C ${@[-1]} else tar -c -v -f - ${@[1, -2]} | tar -x -f - -C ${@[-1]} fi else "error, not enough parameters." return 1 fi } ################################################## # TODO: fix so -s can be sent to cp # ################################################## function tcp() { if [ "$1" = "-s" -o "$1" = "--set-target" ]; then COPY_TARGET="$(realpath $2)"; elif [ "$1" = "-h" -o "$1" = "--help" ]; then echo "usage: tcp [-s|--set-target ] | "; else cp --target-directory "$COPY_TARGET" "$@"; fi } ################################################## # Keeping your $HOME directory organized # ################################################## ## having one temp dir for dls etc can quickly become mess, so try this tip to organise by date # export TD="$HOME/temp/`date +'%Y-%m-%d'`" # function td() { # td=$TD # if [ ! -z "$1" ]; then # td="$HOME/temp/`date -d "$1 days" +'%Y-%m-%d'`"; # fi # mkdir -p $td; cd $td # unset td # } ################################################## # Make the following commands run in # # background automatically: # ################################################## ###### wrapper around xemacs/gnuserv ... function te() { if [ "$(gnuclient -batch -eval t 2>&-)" == "t" ]; then gnuclient -q "$@"; else ( xemacs "$@" &); fi } ################################################## # Set terminal title # ################################################## function terminal_title { echo -en "\033]2;$@\007" } ################################################## # Set/Unset a proxy for the terminal using tor # ################################################## ###### For a HTTP proxy in a single terminal window, simply run the following command in a terminal: # export http_proxy='http://YOUR_USERNAME:YOUR_PASSWORD@PROXY_IP:PROXY_PORT/' # For a secure connection (HTTPS), use: # export https_proxy='http://YOUR_USERNAME:YOUR_PASSWORD@PROXY_IP:PROXY_PORT/' # Obviously, replace everything with your username, password, proxy ip and port. # If the proxy does not require an username and password, skip that part function termproxy() { export http_proxy='http://localhost:8118' export https_proxy='http://localhost:8118' } ###### To close the HTTP proxy in the terminal, either close the terminal, or enter this: function termproxyX() { unset http_proxy unset https_proxy } ################################################## # Terrorist threat level text # ################################################## function terrorist-level() { echo "Terrorist threat level: $(curl -s 'http://www.dhs.gov/dhspublic/getAdvisoryCondition' | awk -F\" 'NR==2{ print $2 }')" } ################################################## # Display theme info # ################################################## function themeinfo() { if [ `pgrep emerald` ]; then echo " Emerald: `cat $HOME/.emerald/theme/theme.ini | grep description | awk -F= '{print $2}'`" else echo " Metacity: `gconftool-2 -g /apps/metacity/general/theme`" fi echo " GTK: `gconftool-2 -g /desktop/gnome/interface/gtk_theme`" echo " Icons: `gconftool-2 -g /desktop/gnome/interface/icon_theme`" echo " Cursor: `gconftool-2 -g /desktop/gnome/peripherals/mouse/cursor_theme`" echo " Font: `gconftool-2 -g /desktop/gnome/interface/font_name`" echo " Wallpaper: `gconftool-2 -g /desktop/gnome/background/picture_filename | xargs basename | cut -d. -f 1`" echo } ################################################## # Thesaurus # ################################################## ###### requires dict: sudo apt-get install dict function ths() { dict -d moby-thes $@ } ################################################## # A function to find the fastest free DNS server # ################################################## ###### requires: sudo apt-get install moreutils function timeDNS() { { for x in "${local_DNS}" "208.67.222.222" "208.67.220.220" "198.153.192.1" "198.153.194.1" "156.154.70.1" "156.154.71.1" "8.8.8.8" "8.8.4.4"; do ({ echo -n "$x "; dig @"$x" "$*"|grep Query ; }|sponge &) done ; } | sort -n -k5 ; } ################################################## # Timer function # ################################################## ###### Elapsed time. Usage: # t=$(timer) # ... # do something # printf 'Elapsed time: %s\n' $(timer $t) # ===> Elapsed time: 0:01:12 # If called with no arguments a new timer is returned. # If called with arguments the first is used as a timer # value and the elapsed time is returned in the form HH:MM:SS. function timer() { if [[ $# -eq 0 ]]; then echo $(date '+%s') else local stime=$1 etime=$(date '+%s') if [[ -z "$stime" ]]; then stime=$etime; fi dt=$((etime - stime)) ds=$((dt % 60)) dm=$(((dt / 60) % 60)) dh=$((dt / 3600)) printf '%d:%02d:%02d' $dh $dm $ds fi } ################################################## # Return a title-cased version of the # # string[str.title() in python] # ################################################## function title() { sed 's/\<\w*/\u&/g' <<<$@; } # function title() { string=( $@ ); echo ${string[@]^} ; } ################################################## # To examine lots of files and potentially move # # them to a common directory # ################################################## ###### ex: tmv -s /mnt/disk/5k # ex: make a playlist # ex: tmv eye-of-the-tiger.mp3 # <-> mv eye-of-the-tiger.mp3 /mnt/disk/5k function tmv() { if [ "$1" = "-s" -o "$1" = "--set-target" ]; then MOVE_TARGET="$(realpath $2)"; elif [ "$1" = "-h" -o "$1" = "--help" ]; then echo "usage: tmv [-s|--set-target ] | "; else mv --target-directory "$MOVE_TARGET" "$@"; fi } ################################################## # Top-ten commands # ################################################## function top10() { # copyright 2007 - 2010 Christopher Bratusek history | awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}' | sort -rn | head } ################################################## # Switch tor on and off (requires privoxy) # ################################################## function torswitch() { # copyright 2007 - 2010 Christopher Bratusek if [[ $EUID == 0 ]]; then case $1 in *on ) if [[ $(grep forward-socks4a /etc/privoxy/config) == "" ]]; then echo "forward-socks4a / 127.0.0.1:9050 ." >> /etc/privoxy/config else sed -e 's/\# forward-socks4a/forward-socks4a/g' -i /etc/privoxy/config /etc/init.d/tor restart /etc/init.d/privoxy restart fi ;; *off ) sed -e 's/forward-socks4a/\# forward-socks4a/g' -i /etc/privoxy/config /etc/init.d/tor restart /etc/init.d/privoxy restart ;; esac fi } ################################################## # Get the total length of all video / audio in # # the current dir in H:m:s # ################################################## alias total_audio_length="mplayer -endpos 0.1 -vo null -ao null -identify *.avi 2>&1 |grep ID_LENGTH |cut -d = -f 2|awk '{SUM += $1} END { printf "%d:%d:%d\n",SUM/3600,SUM%3600/60,SUM%60}'" alias total_video_length='total_audio_length' ################################################## # Touchpad stuff # ################################################## ###### to get information on touchpad alias touchpad_id='xinput list | grep -i touchpad' ###### to disable touchpad # using 'touchpad_id', set the number for your touchpad (default is 12) function touchpad_off() { touchpad=12 xinput set-prop $touchpad "Device Enabled" 0 } ###### to enable touchpad # using 'touchpad_id', set the number for your touchpad (default is 12) function touchpad_on() { touchpad=12 xinput set-prop $touchpad "Device Enabled" 1 } ################################################## # Transmission with blocklists # ################################################## function transmissionbl() { # Creator: Inameiname # Version: 1.2 # Last modified: 24 October 2011 # # Automatically downloads and 'installs' my choice of I-Blocklist lists # prior to running Transmission (currently, there are 82 separate lists # to choose from) # # Homepage: http://www.iblocklist.com/lists.php notify-send -t 20000 -i /usr/share/icons/gnome/32x32/status/info.png "Please wait while blocklists for Transmission BitTorrent Client are downloading..." BLOCKLISTDIR="$HOME/.config/transmission/blocklists" BASEURL="http://list.iblocklist.com/?list=" ENDURL="&fileformat=p2p&archiveformat=gz" FILES=( bt_level1 bt_level2 bt_level3 us bt_dshield jcjfaxgyyshvdbceroxf ijfqtofzixtwayqovmxn bt_templist dufcxgnbjsdwmwctgfuj ) if [ ! -d $BLOCKLISTDIR ];then mkdir -p $BLOCKLISTDIR else /bin/rm -fv -R $BLOCKLISTDIR mkdir -p $BLOCKLISTDIR fi for i in "${FILES[@]}" do # wget -c $BASEURL"$i"$ENDURL -O $BLOCKLISTDIR/$i.gz curl -L --retry 10 $BASEURL"$i"$ENDURL -o $BLOCKLISTDIR/$i.gz # seems to generate less download failures than wget gunzip -f $BLOCKLISTDIR/$i.gz mv $BLOCKLISTDIR/$i $BLOCKLISTDIR/$i.txt done if [ ! $(find "$BLOCKLISTDIR" -type f -name "*.gz") ];then notify-send -t 10000 -i /usr/share/icons/gnome/32x32/status/info.png "The blocklists have finished downloading. Transmission will open momentarily..." transmission-gtk /bin/rm -fv -R $BLOCKLISTDIR/*.txt exit else notify-send -t 10000 -i /usr/share/icons/gnome/32x32/status/info.png "The blocklists have failed to completely download. Please try again." & /bin/rm -fv -R $BLOCKLISTDIR exit fi } ################################################## # Moves specified files to ~/.Trash # ################################################## ###### will not overwrite files that have the same name function trashit() { local trash_dir=$HOME/.Trash for file in "$@" ; do if [[ -d $file ]] ; then local already_trashed=$trash_dir/`basename $file` if [[ -n `/bin/ls -d $already_trashed*` ]] ; then local count=`/bin/ls -d $already_trashed* | /usr/bin/wc -l` count=$((++count)) /bin/mv --verbose "$file" "$trash_dir/$file$count" continue fi fi /bin/mv --verbose --backup=numbered "$file" $HOME/.Trash done } ################################################## # Tree stuff # ################################################## ###### shows directory tree (requires 'tree': sudo apt-get install tree) function treecd() { builtin cd "${@}" &>/dev/null . $BSNG_RC_DIR/dirinfo/display dirinfo_display echo -e "${epink}content:" tree -L 1 $TREE_OPTS echo "$PWD" > $HOME/.lastpwd } ###### displays a tree of the arborescence function treefind() { find "$@" | sed 's/[^/]*\//| /g;s/| *\([^| ]\)/+--- \1/' } ################################################## # Search for a show at TV.COM # ################################################## function tvcom() { firefox "http://www.tv.com/search.php?type=11&stype=all&tag=search%3Bfrontdoor&qs="${@}"&stype=program" & } ################################################## # TV/Monitor switch on/off (good for wanting to # # watch video from computer through S-Video out) # ################################################## ###### use the command: "xrandr" to discover what # the proper connected video outputs there are attached # such as VGA-0 (monitor), LVDS1 (Laptop screen), S-video, VGA1 # (VGA-to-TV Converter Box), etc. function tv-monitor-switch-end() { mode="$(xrandr -q|grep -A1 "LVDS1 connected"| tail -1 |awk '{ print $1 }')" if [ -n "$mode" ]; then mode1="$(xrandr -q|grep -A1 "VGA1 connected"| tail -1 |awk '{ print $1 }')" if [ -n "$mode1" ]; then xrandr --output LVDS1 --mode 1280x800 --output VGA1 --off else echo "No VGA1 monitor is connected so nothing to do." fi else mode2="$(xrandr -q|grep -A1 "VGA-0 connected"| tail -1 |awk '{ print $1 }')" if [ -n "$mode2" ]; then mode3="$(xrandr -q|grep -A1 "S-video connected"| tail -1 |awk '{ print $1 }')" if [ -n "$mode3" ]; then xrandr --output VGA-0 --mode 1024x768 --output S-video --off else echo "No S-video monitor is connected so nothing to do." fi else echo "No other monitor is connected so nothing to do." fi fi } function tv-monitor-switch-start() { mode="$(xrandr -q|grep -A1 "LVDS1 connected"| tail -1 |awk '{ print $1 }')" if [ -n "$mode" ]; then mode1="$(xrandr -q|grep -A1 "VGA1 connected"| tail -1 |awk '{ print $1 }')" if [ -n "$mode1" ]; then xrandr --addmode VGA1 1024x768 xrandr --output LVDS1 --mode 1024x768 --output VGA1 --mode 1024x768 --same-as LVDS1 else echo "No VGA1 monitor is connected so nothing to do." fi else mode2="$(xrandr -q|grep -A1 "VGA-0 connected"| tail -1 |awk '{ print $1 }')" if [ -n "$mode2" ]; then mode3="$(xrandr -q|grep -A1 "S-video connected"| tail -1 |awk '{ print $1 }')" if [ -n "$mode3" ]; then xrandr --addmode S-video 800x600 xrandr --output VGA-0 --mode 800x600 --output S-video --mode 800x600 --same-as VGA-0 else echo "No S-video monitor is connected so nothing to do." fi else echo "No other monitor is connected so nothing to do." fi fi } ################################################## # Convert text file to pdf # ################################################## # Requires: sudo apt-get install txt2html python-pisa function txt2pdf() { xhtml2pdf -b "${1%.*}" < <(txt2html "$1"); } ################################################## # Adds "-c" canonical option to bash "type" # # builtin command to follow symbolic links # ################################################## function type() { if [ "$1" = "-c" ]; then shift; for f in "$@"; do ff=$(builtin type -p "$f"); readlink -f "$ff"; done; else builtin type $typeopts "$@"; fi; } ################################################## # Changes spaces to underscores in names # ################################################## function underscore() { for f in * ; do [ "${f}" != "${f// /_}" ] mv -- "${f}" "${f// /_}" done } ################################################## # Decompiler for jar files using jad # ################################################## function unjar() { mkdir -p /tmp/unjar/$1 ; unzip -d /tmp/unjar/$1 $1 *class 1>/dev/null && find /tmp/unjar/$1 -name *class -type f | xargs jad -ff -nl -nonlb -o -p -pi99 -space -stat ; rm -r /tmp/unjar/$1 ; } ################################################## # Remove all files created by latex # ################################################## function unlatex() { if [ "$1" == "" ]; then return fi i=${1%%.*} rm -f $i.aux $i.toc $i.lof $i.lot $i.los $i.?*~ $i.loa $i.log $i.bbl $i.blg $i.glo rm -f $i.odt $i.tns $i.fax $i.bm $i.out $i.nav $i.snm rm -f $i.mtc* $i.bmt mv -f $i.dvi .$i.dvi mv -f $i.ps .$i.ps mv -f $i.pdf .$i.pdf rm -f $i.dvi $i.ps $i.pdf unset i } ################################################## # Up to top directory # ################################################## function up() { # copyright 2007 - 2010 Christopher Bratusek [ "${1/[^0-9]/}" == "$1" ] && { local ups="" for ((i=1; i<=$1; i++)) do ups=$ups"../" done cd $ups } } ################################################## # Move all files in current directory # # (recursively) up a level # ################################################## function upalevel() { find . -type f | perl -pe '(s!(\./.*/)(.*)!mv "\1\2" "\1../\2"!);' | sh } ################################################## # Short URLs with ur1.ca # ################################################## function ur1() { curl -s --url http://ur1.ca/ -d longurl="$1" | sed -n -e '/Your ur1/!d;s/.*.*$/\1/;p' ; } ################################################## # Easily decode unix-time (function) # ################################################## function utime() { perl -e "print localtime($1).\"\n\"";} ################################################## # Echo a command, then execute it # ################################################## function v_() { echo "$@"; "$@"; } ################################################## # Checks to ensure that all # # environment variables are valid # ################################################## ###### looks at SHELL, HOME, PATH, EDITOR, MAIL, and PAGER function validator() { errors=0 function in_path() { # given a command and the PATH, try to find the command. Returns # 1 if found, 0 if not. Note that this temporarily modifies the # the IFS input field seperator, but restores it upon completion. cmd=$1 path=$2 retval=0 oldIFS=$IFS; IFS=":" for directory in $path do if [ -x $directory/$cmd ] ; then retval=1 # if we're here, we found $cmd in $directory fi done IFS=$oldIFS return $retval } function validate() { varname=$1 varvalue=$2 if [ ! -z $varvalue ] ; then if [ "${varvalue%${varvalue#?}}" = "/" ] ; then if [ ! -x $varvalue ] ; then echo "** $varname set to $varvalue, but I cannot find executable." errors=$(( $errors + 1 )) fi else if in_path $varvalue $PATH ; then echo "** $varname set to $varvalue, but I cannot find it in PATH." errors=$(( $errors + 1 )) fi fi fi } ####### Beginning of actual shell script ####### if [ ! -x ${SHELL:?"Cannot proceed without SHELL being defined."} ] ; then echo "** SHELL set to $SHELL, but I cannot find that executable." errors=$(( $errors + 1 )) fi if [ ! -d ${HOME:?"You need to have your HOME set to your home directory"} ] then echo "** HOME set to $HOME, but it's not a directory." errors=$(( $errors + 1 )) fi # Our first interesting test: are all the paths in PATH valid? oldIFS=$IFS; IFS=":" # IFS is the field separator. We'll change to ':' for directory in $PATH do if [ ! -d $directory ] ; then echo "** PATH contains invalid directory $directory" errors=$(( $errors + 1 )) fi done IFS=$oldIFS # restore value for rest of script # Following can be undefined, & also be a progname, rather than fully qualified path. # Add additional variables as necessary for your site and user community. validate "EDITOR" $EDITOR validate "MAILER" $MAILER validate "PAGER" $PAGER # and, finally, a different ending depending on whether errors > 0 if [ $errors -gt 0 ] ; then echo "Errors encountered. Please notify sysadmin for help." else echo "Your environment checks out fine." fi } ################################################## # Converts VCD/SVCD to MPEG files # ################################################## function vcd2mpeg() { # Made by ioccatflashdancedotcx # Version 1.6, Thu Aug 4 00:43:44 CEST 2005 if [ -n "$(ls 2>/dev/null *001|grep *001)" ]; then rar x *01.rar if [ -n "$(ls 2>/dev/null *bin)" ]; then for i in *bin ; do vcdxrip -p --bin-file="$i" ; done mv *mpg cd.mpg rm *cue *bin *.xml _cdi_cdi_* _extra_svcdinfo.txt &>/dev/null fi fi if [ -n "$(ls 2>/dev/null *01.rar|grep *01.rar)" ]; then rar x *01.rar if [ -n "$(ls 2>/dev/null *bin)" ]; then for i in *bin ; do vcdxrip -p --bin-file="$i" ; done mv *mpg cd.mpg rm *cue *bin *.xml _cdi_cdi_* _extra_svcdinfo.txt &>/dev/null fi fi if [ -n "$(ls 2>/dev/null *.rar|grep *.rar)" ]; then rar x *rar if [ -n "$(ls 2>/dev/null *bin)" ]; then for i in *bin ; do vcdxrip -p --bin-file="$i" ; done mv *mpg cd.mpg rm *cue *bin *.xml _cdi_cdi_* _extra_svcdinfo.txt &>/dev/null fi fi for cddir in CD1 CD2 CD3 CD4 CD5 CD6 Cd1 Cd2 Cd3 Cd4 Cd5 Cd6 cd1 cd2 cd3 cd4 cd5 cd6; do if cd ${cddir} &>/dev/null; then if [ -n "$(ls 2>/dev/null *001|grep *001)" ]; then rar x *001 if [ -n "$(ls 2>/dev/null *bin)" ]; then for i in *bin ; do vcdxrip -p --bin-file="$i" ; done if [ -n "$(ls 2>/dev/null avseq02.mpg)" ]; then rm avseq01.mpg fi mv *mpg ../${cddir}.mpg rm *cue *bin *.xml _cdi_cdi_* _extra_svcdinfo.txt &>/dev/null cd .. for i in ${cddir}.mpg ; do mv -- $i `echo $i|tr A-Z a-z` ; done elif [ -n "$(ls 2>/dev/null *mpg)" ]; then mv *mpg ../${cddir}.mpg cd .. for i in ${cddir}.mpg ; do mv -- $i `echo $i|tr A-Z a-z` ; done elif [ -n "$(ls 2>/dev/null *avi)" ]; then mv *avi ../${cddir}.avi cd .. for i in ${cddir}.avi ; do mv -- $i `echo $i|tr A-Z a-z` ; done fi else if [ -n "$(ls 2>/dev/null *01.rar|grep *01.rar)" ]; then rar x *01.rar if [ -n "$(ls 2>/dev/null *bin)" ]; then for i in *bin ; do vcdxrip -p --bin-file="$i" ; done if [ -n "$(ls 2>/dev/null avseq02.mpg)" ]; then rm avseq01.mpg fi mv *mpg ../${cddir}.mpg rm *cue *bin *.xml _cdi_cdi_* _extra_svcdinfo.txt &>/dev/null cd .. for i in ${cddir}.mpg ; do mv -- $i `echo $i|tr A-Z a-z` ; done elif [ -n "$(ls 2>/dev/null *mpg)" ]; then mv *mpg ../${cddir}.mpg cd .. for i in ${cddir}.mpg ; do mv -- $i `echo $i|tr A-Z a-z` ; done elif [ -n "$(ls 2>/dev/null *avi)" ]; then mv *avi ../${cddir}.avi cd .. for i in ${cddir}.avi ; do mv -- $i `echo $i|tr A-Z a-z` ; done fi else if [ -n "$(ls 2>/dev/null *.rar|grep *.rar)" ]; then rar x *rar if [ -n "$(ls 2>/dev/null *bin)" ]; then for i in *bin ; do vcdxrip -p --bin-file="$i" ; done if [ -n "$(ls 2>/dev/null avseq02.mpg)" ]; then rm avseq01.mpg fi mv *mpg ../${cddir}.mpg rm *cue *bin *.xml _cdi_cdi_* _extra_svcdinfo.txt &>/dev/null cd .. for i in ${cddir}.mpg ; do mv -- $i `echo $i|tr A-Z a-z` ; done elif [ -n "$(ls 2>/dev/null *mpg)" ]; then mv *mpg ../${cddir}.mpg cd .. for i in ${cddir}.mpg ; do mv -- $i `echo $i|tr A-Z a-z` ; done elif [ -n "$(ls 2>/dev/null *avi)" ]; then mv *avi ../${cddir}.avi cd .. for i in ${cddir}.avi ; do mv -- $i `echo $i|tr A-Z a-z` ; done fi fi fi fi fi done } ################################################## # Copy a file prefixed with a version number to a# # subdirectory # ################################################## function vers() { ( IFS=$'\n'; suf="_versions"; mkdir -p "$1$suf"; nr=`ls "$1$suf" | wc -l`; nr=`printf "%02d" $(($nr + 1))`; cp "$1" "$1$suf/v${nr}_$1" ) ; } ################################################## # Edit a executable script # ################################################## function vie() { vi $(which $1); } ################################################## # Run a command, redirecting output to a file, # # then edit the file with vim # ################################################## function vimcmd() { $1 > $2 && vim $2; } ################################################## # Text message on wallpaper # ################################################## function wallpaperWarn() { BG="/desktop/gnome/background/picture_filename"; convert "`gconftool-2 -g $BG`" -pointsize 70 -draw "gravity center fill red text 0,-360 'Warn' fill white text 0,360 'Warn'" /tmp/w.jpg; gconftool-2 --set $BG -t string "/tmp/w.jpg" ; } ################################################## # Crawl a webpage for links # ################################################## function webcrawl() { lynx -dump $1 | grep -A999 "^References$" | tail -n +3 | awk '{print $2 }' } ################################################## # Download all files of a certain type with wget # ################################################## ###### usage: wgetall mp3 http://example.com/download/ function wgetall() { wget -r -l2 -nd -Nc -A.$@ $@ ; } ################################################## # Telling you from where your commit come from # ################################################## function where() { COUNT=0; while [ `where_arg $1~$COUNT | wc -w` == 0 ]; do let COUNT=COUNT+1; done; echo "$1 is ahead of "; where_arg $1~$COUNT; echo "by $COUNT commits";};function where_arg() { git log $@ --decorate -1 | head -n1 | cut -d ' ' -f3- ; } ################################################## # Which PATH variable should use for this script?# ################################################## function whichpath() { local -A path; local c p; for c; do p=$(type -P "$c"); p=${p%/*}; path[${p:-/}]=1; done; local IFS=:; printf '%s\n' "${!path[*]}"; } ################################################## # Check hosts that are online # ################################################## ###### for those who DO NOT USE their /etc/hosts file for name resolution # Function whoisonline adapted by: dewar1 # This can look through resolv.conf file for address of nameservers # (note: THIS WILL ONLY WORK IF YOU USE LOCAL NAMESERVERS! Nameservers # from your ISP will render this function useless). It then cuts result to # show just first 3 octets of IP address and runs nmap just as original function. if which nmap 2>&1 > /dev/null; then function whodat() { if [ -n "$1" ]; then net="$1" else net=$(cat /etc/resolv.conf | grep 'nameserver' | cut -c12-26 | awk -F '.' '{print $1"."$2"."$3".0/24"}') fi echo "testing $net for online hosts" nmap -sP $net | awk '/Host/ && /up/ { print $0; }' echo "done" } fi ###### for those who USE their /etc/hosts file for name resolution #if which nmap 2>&1 > /dev/null; then # function whoisonline() # { # if [ -n "$1" ]; then # net="$1" # else # net=$(grep `hostname` /etc/hosts | awk -F '.' '{ print $1"."$2"."$3".0/24"}') # fi # sh_info "testing $net for online boxes" # sudo nmap -sP $net | awk '/Host/ && /up/ { print $0; }' # sh_success "done" # } #fi ################################################## # Wipe command (uses 'shred', not 'wipe', # # which I think is better (sudo apt-get # # install wipe)) # ################################################## function wipe_() { # copyright 2007 - 2010 Christopher Bratusek cryptsetup -d /dev/urandom -c aes-xts-plain create delete $1 shred -vzn 0 /dev/mapper/delete sync && sleep 4 cryptsetup remove delete } ################################################## # Wordcount # ################################################## ###### counts frequency of words in a file function wordfreq() { cat "$1"|tr -d '[:punct:]'|tr '[:upper:]' '[:lower:]'|tr -s ' ' '\n'|sort|uniq -c|sort -rn } ###### word counter function words() { # words.sh # counts words in selection and displays result in zenity window # dependencies xsel, wc, zenity text=$(xsel) words=$(wc -w <<<$text) zenity --info --title "Word Count" --text "Words in selection:\n${words}\n\n\"${text}\"" } ################################################## # ISO-writer # ################################################## function writeiso() { # copyright 2007 - 2010 Christopher Bratusek if [[ $CD_WRITER ]]; then cdrecord dev=$CD_WRITER "$1" else cdrecord deV=/dev/dvdrw "$1" fi } ################################################## # Xchown something # ################################################## function xchown() { # copyright 2007 - 2010 Christopher Bratusek user="$1" shift for df in "$@"; do su -c "chown -R $user:$user \"$df\""; done } ################################################## # X delete - removes files with desired name # # in current directory # ################################################## if [[ ${BASH_VERSINFO[0]} -ge "4" ]]; then function xdel() { # copyright 2007 - 2010 Christopher Bratusek shopt -s globstar [[ "$@" != "" ]] && { for argv in "$@"; do rm -fv ./**/*"$argv" done } } fi ################################################## # This function uses xmllint to evaluate xpaths # ################################################## ###### usage: xpath /some/xpath XMLfile function xpath() { xmllint --format --shell "$2" <<< "cat $1" | sed '/^\/ >/d' ; } ################################################## # Adds some text in the terminal frame # ################################################## function xtitle() { case "$TERM" in *term | rxvt) echo -n -e "\033]0;$*\007" ;; *) ;; esac } ################################################## # Parallel XZ with progress bar # ################################################## function xzv() { THREADS=`grep processor /proc/cpuinfo | wc -l`; for file in $*; do pv -s `stat -c%s $file` < $file | pxz -q -T $THREADS > $file.xz ; done; } ################################################## # Busted... (Yaourt) # ################################################## function yaourt() { EDITORBACKUP="$EDITOR"; export EDITOR=cat; sudo yaourt "$@"; export EDITOR="$EDITORBACKUP"; export EDITORBACKUP= } ################################################## # Overwrite a file with zeros # ################################################## function zero() { case "$1" in "") echo "Usage: zero " return -1; esac filesize=`wc -c "$1" | awk '{print $1}'` `dd if=/dev/zero of=$1 count=$filesize bs=1` } ################################################## # To create a ZIP archive of a file or folder # ################################################## function zipf() { zip -r "$1".zip "$1" ; } ################################################## ################################################## ################################################## ###################################################################################################################################################### ###### ALIASES ###### ALIASES ###### ALIASES ###### ALIASES ###### ALIASES ###### ALIASES ###### ALIASES ###### ALIASES ###### ALIASES ###### ALIASES ###### ###################################################################################################################################################### ################################################## # App-specific # ################################################## alias audio='ncmpcpp' # music player alias compiz-reset='gconftool-2 --recursive-unset /apps/compiz-1 && unity --reset' # to reset Compiz alias daemon-status='for a in deluged deluge rtorrent; do (ps -u $USER|grep $a$ > /dev/null && echo $a running.) || echo $a not running.; done' # list the status of the daemons :p alias daggerfall='dosbox -conf ~/.dosbox.conf.daggerfall' # launch dosbox with preset config for Daggerfall # alias deluge-link='echo http://'`hostname`':'$USER_WPRT'/' alias ftp='ncftp Personal' alias gnome-fallback-session='gsettings set org.gnome.desktop.session session-name "gnome-fallback"' # GNOME3 desktop session alias gnome-fallback-set='sudo /usr/lib/lightdm/lightdm-set-defaults -s gnome-fallback' # auto login under set GNOME3 desktop alias gnome-shell-reset='gnome-shell --replace' # to reset Gnome Shell alias gnome-shell-session='gsettings set org.gnome.desktop.session session-name "gnome-shell"' # GNOME3 desktop session alias gnome-shell-set='sudo /usr/lib/lightdm/lightdm-set-defaults -s gnome-shell' # auto login under set GNOME3 desktop alias instaluj='sudo pacman-color -S' alias links2g='links2 -g' alias nano='nano -W -m' # disable annoying line wrapping alias notify-osd-reset='pkill notify-osd' # to reset notify-osd (handy for Leolik's customized notify-osd) alias pacclean='sudo yaourt -Scc' # clean package cache alias pacin='sudo yaourt -S' # install a specific package alias pacman='yaourt' # switches from Pacman to Yaourt so can troll AUR alias pacout='sudo yaourt -Rs' # Remove a specific package alias pacsync='sudo yaourt -Sy' # Sync alias pacup='sudo yaourt -Syu' # Sync & Update alias rc='ssh ${MEDIAPCHOSTNAME} env DISPLAY=:0.0 rhythmbox-client --no-start' # remote control for Rhythmbox on an Ubuntu Media PC alias refresh='nautilus -q && gconftool-2 --shutdown && pkill gnome-panel' # safely close/refresh nautilus and gnome-panel alias scrot='scrot -c -d 7' alias skypefix='mv ~/.Skype/shared.xml ~/.Skype/shared~.xml' # Skype fix for inability to log back in crash alias spotify_next='$HOME/spotifycmd/spotify_cmd.exe next; $HOME/spotifycmd/spotify_cmd.exe status' alias spotify_playpause='$HOME/spotifycmd/spotify_cmd.exe playpause' alias spotify_prev='$HOME/spotifycmd/spotify_cmd.exe prev; $HOME/spotifycmd/spotify_cmd.exe status' alias spotify_status='$HOME/spotifycmd/spotify_cmd.exe status' alias spotify_stop='$HOME/spotifycmd/spotify_cmd.exe stop' alias ss='gnome-screensaver-command -a' alias start-deluged='start-stop-daemon -S --pidfile $HOME/.deluged.pid -u $USER -d $HOME -a /usr/bin/deluged -- --pidfile $HOME/.deluged.pid' alias start-deluge-webui='start-stop-daemon -S --pidfile $HOME/.deluge-web.pid --background --make-pidfile -u $USER -d $HOME -a /usr/bin/deluge -- -u web' alias start-rtorrent='(screen -ls|grep rtorrent > /dev/null || (screen -dmS rtorrent rtorrent && false)) && echo rtorrent is already running.' alias start-vnc='vncserver :$USER_VPRT' alias stop-deluged='start-stop-daemon -K --pidfile $HOME/.deluged.pid -u $USER -d $HOME -a /usr/bin/deluged -- --pidfile $HOME/.deluged.pid || killall -v -u $USER deluged' alias stop-deluge-webui='start-stop-daemon -K --pidfile $HOME/.deluge-web.pid --make-pidfile -u $USER -d $HOME -a /usr/bin/deluge -- -u web;rm $HOME/.deluge-web.pid;' alias stop-rtorrent='killall -u $USER rtorrent -q || echo rtorrent is not running' alias stop-vnc='vncserver -kill :$USER_VPRT' alias tetris='bastet' # bastardly tetris... awesome but deadly alias tvtime-video0='tvtime-configure -d /dev/video0' alias tvtime-video1='tvtime-configure -d /dev/video1' alias tvtime-video2='tvtime-configure -d /dev/video2' alias tvtime-video3='tvtime-configure -d /dev/video3' alias tvtime-video4='tvtime-configure -d /dev/video4' alias tvtime-video5='tvtime-configure -d /dev/video5' alias unity-reset-icons='unity --reset-icons' # to reset Unity launcher icons alias unity-reset='unity --reset' # to reset Unity alias unity-session='gsettings set org.gnome.desktop.session session-name "unity"' # GNOME3 desktop session alias unity-set='sudo /usr/lib/lightdm/lightdm-set-defaults -s unity' # auto login under set GNOME3 desktop alias wgeturlfromfile='wget -r -l1 -H -t1 -nd -N -np -A.jpg -erobots=off -i' # -i file.txt alias wget='wget -c' alias yr='yaourt -Rs -C' alias yss='yaourt -Ss -C' alias ys='yaourt -S -C' alias ysyu='yaourt -Syu -C' alias ysy='yaourt -Sy -C' ################################################## # Apt-cache stuff # ################################################## alias aptadd='sudo apt-cache add' alias aptdepends='apt-cache depends' alias aptdotty='sudo apt-cache dotty' alias aptdumpavail='sudo apt-cache dumpavail' alias aptdump='apt-cache dump' alias aptgencaches='sudo apt-cache gencaches' alias aptpkgnames='apt-cache pkgnames' alias aptpolicy='apt-cache policy' alias aptrdepends='apt-cache rdepends' alias aptsearch='apt-cache search' alias aptshowpkg='apt-cache showpkg' alias aptshowsrc='apt-cache showsrc' alias aptshow='apt-cache show' alias aptstats='apt-cache stats' alias aptunmet='apt-cache unmet' alias aptxvcg='sudo apt-cache xvcg' ################################################## # Apt-get stuff # ################################################## alias autoremove='sudo apt-get autoremove' alias check='sudo apt-get check' alias dist-upgrade='sudo apt-get dist-upgrade' alias dselect-upgrade='sudo apt-get dselect-upgrade' alias source='sudo apt-get source' ################################################## # Apt-history Stuff # ################################################## alias historya='apt-history' alias historyi='apt-history install' alias historyre='apt-history remove' alias historyro='apt-history rollback' alias historyu='apt-history upgrade' ################################################## # Aptitude stuff # ################################################## alias autoclean='sudo aptitude autoclean' alias build-dep='sudo aptitude build-dep' alias changelog='aptitude changelog' alias clean='sudo aptitude clean' alias download='aptitude download' alias forbid-version='sudo aptitude forbid-version' alias forget-new='sudo aptitude forget-new' alias full-upgrade='sudo aptitude full-upgrade' alias hold='sudo aptitude hold' alias install='sudo aptitude install' alias linux-image='aptitude search linux-image' # linux-image kernel update check alias markauto='sudo aptitude markauto' alias purge='sudo aptitude purge' alias reinstall='sudo aptitude reinstall' alias remove='sudo aptitude remove' alias search='aptitude search' alias show='aptitude show' alias unhold='sudo aptitude unhold' alias unmarkauto='sudo aptitude unmarkauto' alias update='sudo aptitude update' alias upgrade='sudo aptitude safe-upgrade' alias why-not='aptitude why-not' alias why='aptitude why' ################################################## # Chown substitution # ################################################## alias chown-backgrounds='sudo chown -R $USER:$USER ~/Pictures/Backgrounds' alias chown-backups='sudo chown -R $USER:$USER ~/Backups' alias chown-books='sudo chown -R $USER:$USER ~/eBooks' alias chown-desktop='sudo chown -R $USER:$USER ~/Desktop' alias chown-documents='sudo chown -R $USER:$USER ~/Documents' alias chown-downloads='sudo chown -R $USER:$USER ~/Downloads' alias chown-drive-c='sudo chown -R $USER:$USER ~/.wine/drive_c' alias chown-home='sudo chown -R $USER:$USER ~/' alias chown-images='sudo chown -R $USER:$USER ~/Images' alias chown-localhost='sudo chown -R $USER:$USER ~/var/www' alias chown-music='sudo chown -R $USER:$USER ~/Music' alias chown-nautilus-scripts='sudo chown -R $USER:$USER ~/.gnome2/nautilus-scripts' alias chown-nemo-scripts='sudo chown -R $USER:$USER ~/.gnome2/nemo-scripts' alias chown-packages='sudo chown -R $USER:$USER ~/Packages' alias chown-pictures='sudo chown -R $USER:$USER ~/Pictures' alias chown-ppc='sudo chown -R $USER:$USER ~/PPC' alias chown-public='sudo chown -R $USER:$USER ~/Public' alias chown='sudo chown -R $USER:$USER' alias chown-temp='sudo chown -R $USER:$USER ~/Temp' alias chown-torrents='sudo chown -R $USER:$USER ~/Torrents' alias chown-ubuntu-texts='sudo chown -R $USER:$USER ~/Documents/"Ubuntu Texts"' alias chown-videos='sudo chown -R $USER:$USER ~/Videos' ################################################## # Command substitution # ################################################## alias abs='sudo abs' alias a='ssh-agent;ssh-add' alias br='sudo service bluetooth restart' # restart Bluetooth from terminal alias bt='aria2c --max-upload-limit=10K --seed-time=60 --listen-port=8900-8909' # shortcut for downloading a torrent file on the command line alias c='clear' alias ci='vim' alias ck='killall conky && conky -d' alias cls='clear' alias cn_='cat > /dev/null' # for pasting code/data into terminal without it doing anything alias contents='/bin/tar -tzf' # can View the contents of a Tar file alias cp='cp -iv' alias d_='ssh 192.168.1.4' alias dr='dirs -v' alias ds_='dig +noauthority +noadditional +noqr +nostats +noidentify +nocmd +noquestion +nocomments' # short and sweet output from dig(1) alias e='espeak' alias egrep='egrep –color=auto' alias enote='vi ~/todo;~/motd.pl' alias fgrep='fgrep –color=auto' alias ge='geany' alias go='startx' alias grep='grep --color=auto' # highlight matched pattern alias g_='mocp -G' alias halt='sudo /sbin/halt' alias h='history | grep $1' alias hib='sudo pm-hibernate' alias ie='wine iexplore.exe' # browse the Internet using Internet Explorer alias im='centerim' # terminal based instant messaging client alias img='imgurbash' # uploads image to imgur alias irc='irssi' # terminal based IRC # alias irssi='screen -wipe; screen -A -U -x -R -S irssi irssi' # for creating screen session containing IRSSI, named irssi, while checking if existing session is created alias j='jobs -l' alias kfx='killall firefox-bin' alias kgp='killall gnome-panel' alias k='kill' alias kk='sendmail -d0.4 -bv root |less' alias kn='killall nautilus' alias last='last -a' alias lock='clear && vlock -c' # clear and lock console (non-X) terminal alias logs='tail -f /var/log/messages /var/log/*log' alias m='~/bin/motd.pl' alias mc='metacafe-dl -t' alias me_='vi ~/.muttrc' alias mkdir='mkdir -p -v' alias mktd='tdir=`mktemp -d` && cd $tdir' # make a temp dir, then immediately cd into it alias m=mutt alias more='less' alias mp='screen -d -m mousepad' alias mv='mv -iv' alias na='nano' alias n='nautilus & exit' alias np='mpc --format "np: [[%artist%] - [%title%] - #[[%album%] ##[%track%]#]]|[%file%]" | head -n 1' alias nq='nautilus -q' alias oe='wine msimn.exe' # read email with Outlook Express alias packup='/bin/tar -czvf' # compress a file in tar format alias parts='cat /proc/partitions' # alias paste='ix' # pastes to ix.ox pastebin service alias paste_='pastebinit' alias path='echo -e ${PATH//:/\\n}' alias pe='vi ~/.procmailrc' alias pg='ps aux | grep'* # requires an argument alias pi='`cat ~/.pi | grep ' ; alias addpi='echo "cd `pwd`" >> ~/.pi' # fast access to any of your favorite directory. alias ping='ping -c 10' alias pjet='enscript -h -G -fCourier9 -d $LPDEST' # pretty-print using enscript alias print='/usr/bin/lp -o nobanner -d $LPDEST' # assumes LPDEST is defined (default printer) alias ps='ps auxf' alias p_='for ((n=0;n<1;n++)); do dd if=/dev/urandom count=1 2> /dev/null | uuencode -m -| sed -ne 2p | cut -c-8; done' # creating password alias :q='exit' alias q='exit' alias rcci='svn ci ~/rc/' alias rcup='~/bin/rc_sync.sh' alias rd='cd "`pwd -P`"' # if in directory containing symlink in path, change to "real" path alias real_location='readlink -f' # get real location of file alias reboot='sudo /sbin/reboot' # alias reboot='sudo shutdown -r now' # easy shutdown management alias rgrep='find . \( ! -name .svn -o -prune \) -type f -print0 | xargs -0 grep' # rgrep: recursive grep without .svn alias rh='rehash' alias rmdir='rmdir -v' alias rm_='rm -iv' alias root='sudo bash -l' # generic shortcut for switching to root user depending on system # alias root='sudo -i' # generic shortcut for switching to root user depending on system # alias root='su -' # generic shortcut for switching to root user depending on system alias scx='screen -x' alias sdi='sudo dpkg -i' alias se='vi ~/.screenrc' alias sg='sudo geany' alias shutdown='sudo shutdown -h now' # proper restart alias shutdownde='for ((;;)) do pgrep wget ||shutdown -h now; sleep 5; done' # if download end, shutdown alias sn='sudo nano' alias split='split -d' alias sr='screen -d -RR' # alias s='sudo' # alias s_='screen -X screen'; s top; s vi; s man ls; # start a new command in a new screen window alias sshdo='ssh -q -t root@localhost -- cd $PWD \&\& sudo' # an alternative to sudo alias sus='sudo pm-suspend' alias svi='sudo vim' alias tc='tar cfvz' alias te='tail -50f /var/log/qmail/qmail-send/current | elog' alias tf='tail -50f /var/log/iptables.log' alias tm='tail -50f /var/log/messages.log' alias ts='tail -50f /var/log/auth.log' alias tweet_='bti' alias tx='tar xfvz' alias u='mocp -P && sudo pm-suspend ; sleep 1s && mocp -U && setxkbmap -option terminate:ctrl_alt_bksp && xmodmap .config/caps-esc && ~/.fehbg' # something is messed up somewhere, dirty fix alias unpack='/bin/tar -xzvpf' # uncompress a a Tar file alias updatefont='fc-cache -v -f' alias url='tinyurl' alias urlping="ping -q -c 1 www.google.com|awk -F/ 'END{print $5}'" # do one ping to URL: good in MRTG gauge graph to monitor connectivity alias v='zless -N' # -N means display line numbers (turn off line numbers with -n) alias ve='vi ~/.vimrc' alias vi='vim' alias web='w3m' # terminal based web browser alias which='type -all' alias win='/media/win' alias wtf='watch -n 1 w -hs' alias xee='cat /var/log/Xorg.0.log |grep EE' alias xevs="xev | grep 'keycode\|button'" # only show button events for xev alias xp='xprop | grep "WM_WINDOW_ROLE\|WM_CLASS" && echo "WM_CLASS(STRING) = \"NAME\", \"CLASS\""' alias x='startx' alias xww='cat /var/log/Xorg.0.log |grep WW' alias z='zenity --info --text="You will not believe it, but your command has finished now! :-)" --display :0.0' # get a desktop notification from the terminal alias zen='fortune /usr/share/fortune/zen' ################################################## # Command substitution (for typos) # ################################################## alias findgrep='grepfind' alias mann='man' alias moer='more' alias moew='more' alias updtae='update' alias vf='cd' alias xs='cd' alias yauort='yaourt' alias yoaurt='yaourt' alias youart='yaourt' alias yuaort='yaourt' alias yuoart='yaourt' ################################################## # Computer cleanup # ################################################## alias adobecleanup='sudo rm -fr ~/.adobe && sudo rm -fr ~/.macromedia && sudo rm -fr /root/.adobe && sudo rm -fr /root/.macromedia' alias bleachbitcleanup='sudo bleachbit --clean --preset' alias cachecleanup='sudo rm -fr /root/.cache/* && sudo rm -fr ~/.cache/*' # cleanup cache alias cleanup="sudo apt-get -y autoclean && sudo apt-get -y autoremove && sudo apt-get -y clean && sudo apt-get -y remove && sudo aptitude -y purge `dpkg --get-selections | grep deinstall | awk '{print $1}'` && sudo deborphan | xargs sudo apt-get -y remove --purge && sudo bleachbit --clean --preset && find ~ -type f -name ".DS_Store" -exec rm {} \; && find ~ -type f -name "Thumbs.db" -exec rm {} \; && find ~ -type f -regex ".*~" -exec rm {} \; && sudo rm -rvf ~/.adobe ~/.adobe/Acrobat/*/Cache/ ~/.adobe/Acrobat/*/Preferences/reader_prefs ~/.adobe/Flash_Player/AssetCache/ ~/.amsn/*/*/cache/ ~/.amsn/*/logs/ ~/.amsn/*/voiceclips/ ~/.amsn/*/webcam/ ~/.aMule/logfile ~/.aMule/logfile.bak ~/.aMule/Temp/ ~/.azureus/active/*.bak ~/.azureus/ipfilter.cache ~/.azureus/*.log ~/.azureus/logs/ ~/.azureus/tmp/ ~/.bash_history ~/.beagle/Indexes/ ~/.beagle/Log/ ~/.beagle/TextCache/ ~/.cache/ ~/.cache/* ~/.cache/audacious/thumbs/ ~/.cache/chromium/ ~/.cache/gedit/gedit-metadata.xml ~/.cache/google-chrome/ ~/.cache/vlc/ ~/.compiz/session/ ~/.config/audacious/log ~/.config/audacious/playlist.xspf ~/.config/chromium/Default/Bookmarks.bak ~/.config/chromium/Default/Cookies ~/.config/chromium/Default/Current\ Session ~/.config/chromium/Default/Current\ Tabs ~/.config/chromium/Default/databases/Databases.db ~/.config/chromium/Default/databases/http*/ ~/.config/chromium/Default/Extension\ Cookies ~/.config/chromium/Default/Favicons/ ~/.config/chromium/Default/*History* ~/.config/chromium/Default/*History*/ ~/.config/chromium/Default/*-journal ~/.config/chromium/Default/Last\ Session ~/.config/chromium/Default/Last\ Tabs ~/.config/chromium/Default/Local\ Storage/*localstorage ~/.config/chromium/Default/Thumbnails* ~/.config/chromium/Default/Top\ Sites ~/.config/chromium/Default/Visited\ Links ~/.config/chromium/Default/Web\ Data/chrome.autofill ~/.config/chromium/Default/Web\ Data/chrome.keywords ~/.config/chromium/Local\ State/HostReferralList.json ~/.config/chromium/Local\ State/StartupDNSPrefetchList.json ~/.config/compiz/ ~/.config/emesene*/*/cache/ ~/.config/emesene*/*/log* ~/.config/emesene*/*/logs/ ~/.config/google-chrome/Default/Cookies ~/.config/google-chrome/Default/Current\ Session ~/.config/google-chrome/Default/Current\ Tabs ~/.config/google-chrome/Default/databases/Databases.db ~/.config/google-chrome/Default/databases/http*/ ~/.config/google-chrome/Default/Extension\ Cookies ~/.config/google-chrome/Default/Favicons/ ~/.config/google-chrome/Default/*History* ~/.config/google-chrome/Default/History/ ~/.config/google-chrome/Default/Last\ Session ~/.config/google-chrome/Default/Last\ Tabs ~/.config/google-chrome/Default/Local\ Storage/http*localstorage ~/.config/google-chrome/Default/Preferences/dns_prefetching.json ~/.config/google-chrome/Default/Thumbnails* ~/.config/google-chrome/Default/Top\ Sites ~/.config/google-chrome/Default/Visited\ Links ~/.config/google-chrome/Default/Web\ Data/chrome.autofill ~/.config/google-chrome/Default/Web\ Data/chrome.keywords ~/.config/google-chrome/Local\ State/HostReferralList.json ~/.config/google-chrome/Local\ State/StartupDNSPrefetchList.json ~/.config/gpodder/cache/ ~/.config/menus/*.menu.undo-* ~/.config/real/rpcookies.txt ~/.config/Screenlets/*.log ~/.config/transmission/blocklists/ ~/.config/transmission/resume/ ~/.easytag/easytag.log ~/.elinks/cookies ~/.elinks/*hist /etc/apt/sources.list.d/* ~/.evolution/cache/ ~/.exaile/cache/ ~/.exaile/covers/ ~/.exaile/exaile.log ~/.exaile/podcasts/ ~/.filezilla/recentservers.xml ~/.gconf/apps/gnome-settings/gnome-panel/%gconf.xml ~/.gconf/apps/gnome-settings/gnome-search-tool/%gconf.xml ~/.gftp/cache/ ~/.gftp/gftp.log ~/.gimp-*/tmp/ ~/.gl-117/logfile.txt ~/.gnome2/epiphany/ephy-favicon-cache.xml ~/.gnome2/epiphany/ephy-history.xml ~/.gnome2/epiphany/favicon_cache/ ~/.gnome2/epiphany/mozilla/epiphany/Cache/ ~/.gnome2/epiphany/mozilla/epiphany/cookies* ~/.gnome2/gedit-metadata.xml ~/.gnome2/rhythmbox/jamendo/ ~/.gnome2/rhythmbox/magnatune/ ~/.googleearth/Cache/dbCache.* ~/.googleearth/Temp/ ~/.goutputstream-* ~/.hippo_opensim_viewer/cache/ ~/.hippo_opensim_viewer/logs/ ~/.icedteaplugin/cache/ ~/.java/deployment/cache/ ~/.kde/cache-*/ ~/.kde*/share/apps/gwenview/recent*/*rc ~/.kde/share/apps/kcookiejar/cookies ~/.kde/share/apps/konqueror/autosave/ ~/.kde/share/apps/konqueror/closeditems_saved ~/.kde/share/apps/konqueror/konq_history ~/.kde*/share/apps/RecentDocuments/*.desktop ~/.kde/share/config/konq_history ~/.kde/tmp-*/ ~/.kde/tmp-localhost.localdomain/ ~/.libreoffice/*/*/*/cache/ ~/.libreoffice/*/*/registry/data/org/openoffice/Office/Common.xcu ~/.liferea_*/cache/ ~/.liferea_*/mozilla/liferea/Cache/ ~/.liferea_*/mozilla/liferea/cookies.sqlite ~/.links2/links.his ~/.local/share/gvfs-metadata/*.log ~/.local/share/gvfs-metadata/uuid* ~/.local/share/Trash/ ~/.local/share/Trash/* ~/.luckyBackup/logs/ ~/.luckyBackup/snaps/ ~/.macromedia ~/.macromedia/Flash_Player/ ~/.mc/filepos ~/.mc/history ~/.miro/icon-cache/ ~/.miro/miro-*log* ~/.miro/mozilla/Cache/ ~/.mozilla/default/Cache/ ~/.mozilla/extensions ~/.mozilla/firefox/Crash\ Reports/ ~/.mozilla/firefox/*.default/adblockplus/patterns-backup* ~/.mozilla/firefox/*.default/bookmarkbackups/ ~/.mozilla/firefox/*.default/Cache/ ~/.mozilla/firefox/*.default/cookies.* ~/.mozilla/firefox/*.default/downloads.sqlite ~/.mozilla/firefox/*.default/formhistory.sqlite ~/.mozilla/firefox/*.default/history.dat ~/.mozilla/firefox/*.default/minidumps/ ~/.mozilla/firefox/*.default/mozilla-media-cache/ ~/.mozilla/firefox/*.default/OfflineCache/ ~/.mozilla/firefox/*.default/reminderfox/*.bak* ~/.mozilla/firefox/*.default/sessionstore.* ~/.mozilla/firefox/*.default/startupCache/ ~/.mozilla/firefox/*.default/webappsstore.sqlite ~/.mozilla/seamonkey/*/Cache/ ~/.mozilla/seamonkey/*.default/cookies.sqlite ~/.mozilla/seamonkey/*.default/downloads.sqlite ~/.mozilla/seamonkey/*.default/urlbarhistory.sqlite ~/.mozilla/*/*.slt/chatzilla/logs/*log ~/.mozilla/*/*.slt/cookies.txt ~/.mozilla/*/*.slt/history.dat ~/.mozilla-thunderbird/*.default/signons.txt ~/.nautilus/metafiles/*/*.xml ~/.nautilus/saved-session-?????? ~/.nexuiz/data/dlcache/ ~/.ntrc_*/cookies.txt ~/.ntrc_*/history* ~/.openoffice.org/*/*/*/cache/ ~/.openoffice.org/*/*/registry/data/org/openoffice/Office/Common.xcu ~/.opera/*cache*/ ~/.opera/cookies4.dat ~/.opera/download.dat ~/.opera/global.dat ~/.opera/*history* ~/.opera/icons/ ~/.opera/pstorage/ ~/.opera/sessions/ ~/.opera/temporary_downloads/ ~/.opera/thumbnails/ ~/.opera/vlink4.dat ~/.opera/vps/????/md.dat ~/.purple/icons/ ~/.purple/logs/ ~/.recently-used.xbel ~/.recoll/xapiandb/ /root/.adobe /root/.cache/* /root/.local/share/Trash/* /root/.macromedia /root/.thumbnails/* /root/.Trash ~/.secondlife/cache/ ~/.secondlife/logs/ ~/.Skype/*/chatmsg[0-9]*.dbb ~/.Skype/*/chatsync/*/*.dat ~/.sw35/swiftweasel/*/Cache/ ~/.synaptic/log/ ~/.thumbnails/ ~/.thumbnails/* ~/.thunderbird/*.default/Cache/ ~/.thunderbird/*.default/cookies.sqlite ~/.thunderbird/*.default/signons.sqlite ~/.thunderbird/*.default/signons.txt ~/.thunderbird/default/*.slt/Cache/ ~/.thunderbird/default/*.slt/cookies.sqlite ~/.thunderbird/default/*.slt/signons3.txt ~/.thunderbird/default/*.slt/signons.sqlite ~/.thunderbird/default/*.slt/signons.txt ~/.thunderbird/Profiles/*.default/Cache/ ~/.thunderbird/Profiles/*.default/cookies.sqlite ~/.thunderbird/Profiles/*.default/signons.sqlite ~/.Trash ~/.tremulous/servercache.dat /var/backups/ /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/tmp/ ~/.viminfo ~/.wine/drive_c/winetrickstmp/ ~/.winetrickscache/ ~/.xbmc/addons/Navi-X/cache/images/* ~/.xbmc/addons/packages/* ~/xbmc*.log ~/.xbmc/userdata/Database/Textures* ~/.xbmc/userdata/Thumbnails/* ~/.xchat2/logs/*log ~/.xchat2/scrollback/ ~/.xchat2/xchatlogs/*log ~/.xine/catalog.cache ~/.xsession-errors ~/.xsession-errors.old" alias configpurge="sudo aptitude -y purge `dpkg --get-selections | grep deinstall | awk '{print $1}'`" # purge configuration files of removed packages on debian systems alias kernelcleanup="dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge" # remove all unused Linux Kernel headers, images & modules alias orphaned='sudo deborphan | xargs sudo apt-get -y remove --purge' alias thumbnailcleanup='sudo rm -fr /root/.thumbnails/* && sudo rm -fr ~/.thumbnails/*' alias tp='trash-put' # sends files to trash instead of perm deleting w/rm alias trash='sudo rm -fr ~/.local/share/Trash/* && sudo rm -fr /root/.local/share/Trash/* && sudo rm -fr /root/.Trash && sudo rm -fr ~/.Trash' ################################################## # DD substitution # ################################################## # alias backup-sda='sudo dd if=/dev/sda of=/dev/hda bs=64k conv=notrunc,noerror' # to backup the existing drive to ??? # alias backup-sdb='sudo dd if=/dev/sdb of=/dev/hda bs=64k conv=notrunc,noerror' # to backup the existing drive to ??? # alias backup-sdc='sudo dd if=/dev/sdc of=/dev/hda bs=64k conv=notrunc,noerror' # to backup the existing drive to ??? # alias backup-sdd='sudo dd if=/dev/sdd of=/dev/hda bs=64k conv=notrunc,noerror' # to backup the existing drive to ??? # alias backup-sde='sudo dd if=/dev/sde of=/dev/hda bs=64k conv=notrunc,noerror' # to backup the existing drive to ??? # alias backup-sdf='sudo dd if=/dev/sdf of=/dev/hda bs=64k conv=notrunc,noerror' # to backup the existing drive to ??? # alias backup-sdg='sudo dd if=/dev/sdg of=/dev/hda bs=64k conv=notrunc,noerror' # to backup the existing drive to ??? # alias cdcopy='dd if=/dev/cdrom of=cd.iso' # to backup a cd from a cdrom drive to an ISO # alias dd-sda-full='sudo dd if=/dev/urandom of=/dev/sda bs=8b conv=notrunc,noerror' # to wipe hard drive with random data option (1) # alias dd-sda-r='sudo dd if=/dev/urandom of=/dev/sda bs=102400' # to wipe hard drive with random data option (2) # alias dd-sda='sudo dd if=/dev/zero of=/dev/sda conv=notrunc' # to wipe hard drive with zero # alias dd-sdb-full='sudo dd if=/dev/urandom of=/dev/sdb bs=8b conv=notrunc,noerror' # to wipe hard drive with random data option (1) # alias dd-sdb-r='sudo dd if=/dev/urandom of=/dev/sdb bs=102400' # to wipe hard drive with random data option (2) # alias dd-sdb='sudo dd if=/dev/zero of=/dev/sdb conv=notrunc' # to wipe hard drive with zero # alias dd-sdc-full='sudo dd if=/dev/urandom of=/dev/sdc bs=8b conv=notrunc,noerror' # to wipe hard drive with random data option (1) # alias dd-sdc-r='sudo dd if=/dev/urandom of=/dev/sdc bs=102400' # to wipe hard drive with random data option (2) # alias dd-sdc='sudo dd if=/dev/zero of=/dev/sdc conv=notrunc' # to wipe hard drive with zero # alias dd-sdd-full='sudo dd if=/dev/urandom of=/dev/sdd bs=8b conv=notrunc,noerror' # to wipe hard drive with random data option (1) # alias dd-sdd-r='sudo dd if=/dev/urandom of=/dev/sdd bs=102400' # to wipe hard drive with random data option (2) # alias dd-sdd='sudo dd if=/dev/zero of=/dev/sdd conv=notrunc' # to wipe hard drive with zero # alias dd-sde-full='sudo dd if=/dev/urandom of=/dev/sde bs=8b conv=notrunc,noerror' # to wipe hard drive with random data option (1) # alias dd-sde-r='sudo dd if=/dev/urandom of=/dev/sde bs=102400' # to wipe hard drive with random data option (2) # alias dd-sde='sudo dd if=/dev/zero of=/dev/sde conv=notrunc' # to wipe hard drive with zero # alias dd-sdf-full='sudo dd if=/dev/urandom of=/dev/sdf bs=8b conv=notrunc,noerror' # to wipe hard drive with random data option (1) # alias dd-sdf-r='sudo dd if=/dev/urandom of=/dev/sdf bs=102400' # to wipe hard drive with random data option (2) # alias dd-sdf='sudo dd if=/dev/zero of=/dev/sdf conv=notrunc' # to wipe hard drive with zero # alias dd-sdg-full='sudo dd if=/dev/urandom of=/dev/sdg bs=8b conv=notrunc,noerror' # to wipe hard drive with random data option (1) # alias dd-sdg-r='sudo dd if=/dev/urandom of=/dev/sdg bs=102400' # to wipe hard drive with random data option (2) # alias dd-sdg='sudo dd if=/dev/zero of=/dev/sdg conv=notrunc' # to wipe hard drive with zero # alias diskcopy='dd if=/dev/dvd of=disk.iso' # to backup the disc (cd/dvd/whatever) to an ISO # alias floppycopy='dd if=/dev/fd0 of=floppy.image' # to duplicate a floppy disk to hard drive image file # alias partitioncopy='sudo dd if=/dev/sda1 of=/dev/sda2 bs=4096 conv=notrunc,noerror' # to duplicate one hard disk partition to another # alias restore-sda='sudo dd if=/dev/hda of=/dev/sda bs=64k conv=notrunc,noerror' # to restore from ??? to the existing drive # alias restore-sdb='sudo dd if=/dev/hda of=/dev/sdb bs=64k conv=notrunc,noerror' # to restore from ??? to the existing drive # alias restore-sdc='sudo dd if=/dev/hda of=/dev/sdc bs=64k conv=notrunc,noerror' # to restore from ??? to the existing drive # alias restore-sdd='sudo dd if=/dev/hda of=/dev/sdd bs=64k conv=notrunc,noerror' # to restore from ??? to the existing drive # alias restore-sde='sudo dd if=/dev/hda of=/dev/sde bs=64k conv=notrunc,noerror' # to restore from ??? to the existing drive # alias restore-sdf='sudo dd if=/dev/hda of=/dev/sdf bs=64k conv=notrunc,noerror' # to restore from ??? to the existing drive # alias restore-sdg='sudo dd if=/dev/hda of=/dev/sdg bs=64k conv=notrunc,noerror' # to restore from ??? to the existing drive # alias scsicopy='sudo dd if=/dev/scd0 of=cd.iso' # if cdrom is scsi} ###### DD substitution using PV to show progress # requires: sudo apt-get install pv alias backup-sda='sudo pv /dev/sda | dd of=/dev/hda bs=64k conv=notrunc,noerror' # to backup the existing drive to ??? alias backup-sdb='sudo pv /dev/sdb | dd of=/dev/hda bs=64k conv=notrunc,noerror' # to backup the existing drive to ??? alias backup-sdc='sudo pv /dev/sdc | dd of=/dev/hda bs=64k conv=notrunc,noerror' # to backup the existing drive to ??? alias backup-sdd='sudo pv /dev/sdd | dd of=/dev/hda bs=64k conv=notrunc,noerror' # to backup the existing drive to ??? alias backup-sde='sudo pv /dev/sde | dd of=/dev/hda bs=64k conv=notrunc,noerror' # to backup the existing drive to ??? alias backup-sdf='sudo pv /dev/sdf | dd of=/dev/hda bs=64k conv=notrunc,noerror' # to backup the existing drive to ??? alias backup-sdg='sudo pv /dev/sdg | dd of=/dev/hda bs=64k conv=notrunc,noerror' # to backup the existing drive to ??? alias cdcopy='pv /dev/cdrom | dd of=cd.iso' # to backup a cd from a cdrom drive to an ISO alias dd-sda-full='sudo pv /dev/urandom | dd of=/dev/sda bs=8b conv=notrunc,noerror' # to wipe hard drive with random data option (1) alias dd-sda-r='sudo pv /dev/urandom | dd of=/dev/sda bs=102400' # to wipe hard drive with random data option (2) alias dd-sda='sudo pv /dev/zero | dd of=/dev/sda conv=notrunc' # to wipe hard drive with zero alias dd-sdb-full='sudo pv /dev/urandom | dd of=/dev/sdb bs=8b conv=notrunc,noerror' # to wipe hard drive with random data option (1) alias dd-sdb-r='sudo pv /dev/urandom | dd of=/dev/sdb bs=102400' # to wipe hard drive with random data option (2) alias dd-sdb='sudo pv /dev/zero | dd of=/dev/sdb conv=notrunc' # to wipe hard drive with zero alias dd-sdc-full='sudo pv /dev/urandom | dd of=/dev/sdc bs=8b conv=notrunc,noerror' # to wipe hard drive with random data option (1) alias dd-sdc-r='sudo pv /dev/urandom | dd of=/dev/sdc bs=102400' # to wipe hard drive with random data option (2) alias dd-sdc='sudo pv /dev/zero | dd of=/dev/sdc conv=notrunc' # to wipe hard drive with zero alias dd-sdd-full='sudo pv /dev/urandom | dd of=/dev/sdd bs=8b conv=notrunc,noerror' # to wipe hard drive with random data option (1) alias dd-sdd-r='sudo pv /dev/urandom | dd of=/dev/sdd bs=102400' # to wipe hard drive with random data option (2) alias dd-sdd='sudo pv /dev/zero | dd of=/dev/sdd conv=notrunc' # to wipe hard drive with zero alias dd-sde-full='sudo pv /dev/urandom | dd of=/dev/sde bs=8b conv=notrunc,noerror' # to wipe hard drive with random data option (1) alias dd-sde-r='sudo pv /dev/urandom | dd of=/dev/sde bs=102400' # to wipe hard drive with random data option (2) alias dd-sde='sudo pv /dev/zero | dd of=/dev/sde conv=notrunc' # to wipe hard drive with zero alias dd-sdf-full='sudo pv /dev/urandom | dd of=/dev/sdf bs=8b conv=notrunc,noerror' # to wipe hard drive with random data option (1) alias dd-sdf-r='sudo pv /dev/urandom | dd of=/dev/sdf bs=102400' # to wipe hard drive with random data option (2) alias dd-sdf='sudo pv /dev/zero | dd of=/dev/sdf conv=notrunc' # to wipe hard drive with zero alias dd-sdg-full='sudo pv /dev/urandom | dd of=/dev/sdg bs=8b conv=notrunc,noerror' # to wipe hard drive with random data option (1) alias dd-sdg-r='sudo pv /dev/urandom | dd of=/dev/sdg bs=102400' # to wipe hard drive with random data option (2) alias dd-sdg='sudo pv /dev/zero | dd of=/dev/sdg conv=notrunc' # to wipe hard drive with zero alias diskcopy='pv /dev/dvd | dd of=disk.iso' # to backup the disc (cd/dvd/whatever) to an ISO alias floppycopy='pv /dev/fd0 | dd of=floppy.image' # to duplicate a floppy disk to hard drive image file alias partitioncopy='sudo pv /dev/sda1 | dd of=/dev/sda2 bs=4096 conv=notrunc,noerror' # to duplicate one hard disk partition to another alias restore-sda='sudo pv /dev/hda | dd of=/dev/sda bs=64k conv=notrunc,noerror' # to restore from ??? to the existing drive alias restore-sdb='sudo pv /dev/hda | dd of=/dev/sdb bs=64k conv=notrunc,noerror' # to restore from ??? to the existing drive alias restore-sdc='sudo pv /dev/hda | dd of=/dev/sdc bs=64k conv=notrunc,noerror' # to restore from ??? to the existing drive alias restore-sdd='sudo pv /dev/hda | dd of=/dev/sdd bs=64k conv=notrunc,noerror' # to restore from ??? to the existing drive alias restore-sde='sudo pv /dev/hda | dd of=/dev/sde bs=64k conv=notrunc,noerror' # to restore from ??? to the existing drive alias restore-sdf='sudo pv /dev/hda | dd of=/dev/sdf bs=64k conv=notrunc,noerror' # to restore from ??? to the existing drive alias restore-sdg='sudo pv /dev/hda | dd of=/dev/sdg bs=64k conv=notrunc,noerror' # to restore from ??? to the existing drive alias scsicopy='sudo pv /dev/scd0 | dd of=cd.iso' # if cdrom is scsi} ################################################## # Defragmenting and Fragmentation-Checking # # Tools # ################################################## alias defrag-home='defrag ~' # uses 'defrag' function alias defrag-root='defrag /root' # uses 'defrag' function alias defrag-system='defrag /' # uses 'defrag' function alias defrag2-home='defrag2 ~' # uses 'defrag2' function alias defrag2-root='defrag2 /root' # uses 'defrag2' function alias defrag2-system='defrag2 /' # uses 'defrag2' function alias fragcheck-home='fragcheck ~' # uses 'fragcheck' function alias fragcheck-root='fragcheck /root' # uses 'fragcheck' function alias fragcheck-system='fragcheck /' # uses 'fragcheck' function alias fragcheck2-home='fragcheck2 ~' # uses 'fragcheck2' function alias fragcheck2-root='fragcheck2 /root' # uses 'fragcheck2' function alias fragcheck2-system='fragcheck2 /' # uses 'fragcheck2' function ################################################## # Directory shortcuts # ################################################## alias back='cd $OLDPWD' alias backgrounds='cd ~/Pictures/Backgrounds' alias backups='cd ~/Backups' alias books='cd ~/eBooks' alias ..='cd ..' alias ...='cd ../..' alias ....='cd ../../..' alias .....='cd ../../../..' alias ......='cd ../../../../..' alias documents='cd ~/Documents' alias downloads='cd ~/Downloads' alias drive-c='cd ~/.wine/drive_c' alias dropbox='cd ~/Dropbox' alias home='cd ~/' alias images='cd ~/Images' alias localhost='cd /var/www' alias movies='cd ~/Videos' alias music='cd ~/Music' alias nautilus-scripts='cd ~/.gnome2/nautilus-scripts' alias nemo-scripts='cd ~/.gnome2/nemo-scripts' alias packages='cd ~/Packages' alias packets='cd ~/.packets' alias pictures='cd ~/Pictures' alias ppc='cd ~/PPC' alias public='cd ~/Public' alias temp='cd ~/Temp' alias test='cd ~/.test' alias torrents='cd ~/Torrents' alias ubuntu-texts='cd ~/Documents/"Ubuntu Texts"' alias videos='cd ~/Videos' alias webdesign='cd ~/Web/Design' alias whereami='display_info' ################################################## # Espeak commands # ################################################## alias espeak-file='espeak -s 150 -f' alias espeak-us='espeak -v en-us -s 150' alias espeak-wav='espeak -s 150 -w voice.wav' alias espeak-wav-file='espeak -s 150 -w voice.wav -f' ################################################## # Extundelete stuff from ext3/ext4 filesystems # ################################################## alias extundelete-d='sudo extundelete "$1" --restore-directory "$2"' # restore all files possible from specified dir. ("$2" = path/to/directory) alias extundelete-f='sudo extundelete "$1" --restore-files "$2"' # restore list of files (use to restore single file) ("$2" = filename) alias extundelete-r='sudo extundelete "$1" --restore-all' # restore all files possible to undelete alias extundelete-sda='sudo extundelete /dev/sda --restore-all' # restore all files possible to undelete alias extundelete-sda-d='sudo extundelete /dev/sda --restore-directory "$1"' # restore all files possible from specified dir. ("$1" = path/to/directory) alias extundelete-sda-f='sudo extundelete /dev/sda --restore-files "$1"' # restore list of files (use to restore single file) ("$1" = filename) alias extundelete-sdb='sudo extundelete /dev/sdb --restore-all' # restore all files possible to undelete alias extundelete-sdb-d='sudo extundelete /dev/sdb --restore-directory "$1"' # restore all files possible from specified dir. ("$1" = path/to/directory) alias extundelete-sdb-f='sudo extundelete /dev/sdb --restore-files "$1"' # restore list of files (use to restore single file) ("$1" = filename) alias extundelete-sdc='sudo extundelete /dev/sdc --restore-all' # restore all files possible to undelete alias extundelete-sdc-d='sudo extundelete /dev/sdc --restore-directory "$1"' # restore all files possible from specified dir. ("$1" = path/to/directory) alias extundelete-sdc-f='sudo extundelete /dev/sdc --restore-files "$1"' # restore list of files (use to restore single file) ("$1" = filename) alias extundelete-sdd='sudo extundelete /dev/sdd --restore-all' # restore all files possible to undelete alias extundelete-sdd-d='sudo extundelete /dev/sdd --restore-directory "$1"' # restore all files possible from specified dir. ("$1" = path/to/directory) alias extundelete-sdd-f='sudo extundelete /dev/sdd --restore-files "$1"' # restore list of files (use to restore single file) ("$1" = filename) alias extundelete-sde='sudo extundelete /dev/sde --restore-all' # restore all files possible to undelete alias extundelete-sde-d='sudo extundelete /dev/sde --restore-directory "$1"' # restore all files possible from specified dir. ("$1" = path/to/directory) alias extundelete-sde-f='sudo extundelete /dev/sde --restore-files "$1"' # restore list of files (use to restore single file) ("$1" = filename) alias extundelete-sdf='sudo extundelete /dev/sdf --restore-all' # restore all files possible to undelete alias extundelete-sdf-d='sudo extundelete /dev/sdf --restore-directory "$1"' # restore all files possible from specified dir. ("$1" = path/to/directory) alias extundelete-sdf-f='sudo extundelete /dev/sdf --restore-files "$1"' # restore list of files (use to restore single file) ("$1" = filename) alias extundelete-sdg='sudo extundelete /dev/sdg --restore-all' # restore all files possible to undelete alias extundelete-sdg-d='sudo extundelete /dev/sdg --restore-directory "$1"' # restore all files possible from specified dir. ("$1" = path/to/directory) alias extundelete-sdg-f='sudo extundelete /dev/sdg --restore-files "$1"' # restore list of files (use to restore single file) ("$1" = filename) ################################################## # Git stuff # ################################################## alias gitouch='find . \( -type d -empty \) -and \( -not -regex ./\.git.* \) -exec touch {}/.gitignore \;' alias gitup='git pull' alias gitci='git commit -a -m' alias gitco='git clone' alias gita='git add' alias gitb='git branch' alias gitc='git checkout' ################################################## # Hardware Shortcuts # ################################################## alias 0='amixer set PCM 0' alias -- -='amixer set PCM 2-' alias +='amixer set PCM 2+' alias blankcd='cdrecord -v dev=/dev/cdrom blank=fast gracetime=3' alias blankdvd='cdrecord -v dev=/dev/dvd blank=fast gracetime=3' alias blueoff='sudo /etc/rc.d/bluetooth stop' alias blueon='sudo /etc/rc.d/bluetooth start' alias blueres='sudo /etc/rc.d/bluetooth restart' alias brand='growisofs -Z /dev/cdrw -v -l -R -J -joliet-long' alias burnaudiocd='mkdir ./temp && for i in *.[Mm][Pp]3;do mpg123 -w "./temp/${i%%.*}.wav" "$i";done;cdrecord -pad ./temp/* && rm -r ./temp' # burn a directory of mp3s to an audio cd alias cdc='eject -t /dev/cdrecorder' alias cdo='eject /dev/cdrecorder' alias cruzer='mount /media/cruzer' alias dvdc='eject -t /dev/dvd' alias dvdo='eject /dev/dvd' alias ipod='mount /media/ipod && cd /media/ipod' alias keject='sudo eject Kindle' # ejects Kindle devices but keeps it charging (simple 'eject' doesn't work) alias kingston='mount /media/kingston && cd /media/kingston' alias laptop_display='sudo cat /proc/acpi/video/VGA/LCD/brightness' # set laptop display brightness (path may vary depending on laptop model alias laptop_displays='echo > /proc/acpi/video/VGA/LCD/brightness' # to discover the possible values for your display alias mountcd='sudo mount -t is09660 /dev/sr0 /media/cdrom' alias mountedinfo='df -hT' alias mountiso='sudo mount ${1} ${2} -t iso9660 -o ro,loop=/dev/loop0' alias mountwin='mount -t ntfs /dev/sda1 /media/win' alias mp3='mount /media/mp3 && cd /media/mp3' alias playm='for i in *.mp3; do play $i; done' alias playo='for i in *.ogg; do play $i; done' alias playw='for i in *.wav; do play $i; done' alias scan='scanimage -L' alias sd='mount /media/sd' alias ucruzer='umount /media/cruzer' alias uipod='umount /media/ipod' alias ukingston='umount /media/kingston' alias umountiso='sudo umount /media/iso' alias ump3='umount /media/mp3' alias usd='umount /media/sd' alias uverbatim='umount /media/verbatim' alias verbatim='mount /media/verbatim && cd /media/verbatim' ################################################## # Information # ################################################## alias acpi='acpi -V' # shows all of acpi's info (battery, adapter, thermal, cooling) alias battery='acpi -bi' # find large files in current directory alias big='function BIG() { find . -size +${1}M -ls; }; BIG $1' # find large files in current directory alias biggest='BLOCKSIZE=1048576; du -x | sort -nr | head -10' # show biggest directories alias biggest_user="ac -p | sort -nk 2 | awk '/total/{print x};{x=$1}" # show which user has the most accumulated login time alias boothistory='for wtmp in `dir -t /var/log/wtmp*`; do last reboot -f $wtmp; done | less' alias charcount='wc -c $1' # count number of characters in text file alias codename='lsb_release -cs | sed "s/^./\u&/"' # Linux version detail - just codename (Natty, Oneiric, etc) alias color1='sh ~/.scripts/termcolor1' # displays colorset 1 alias color2='sh ~/.scripts/termcolor2' # displays colerset 2 alias color3='sh ~/.scripts/termcolor3' # displays colorset 3 alias cooling='acpi -c' # shows cooling for processors alias counts='sort | uniq -c | sort -nr' # a nice command for summarising repeated information alias cpu_hogs='ps wwaxr -o pid,stat,%cpu,time,command | head -10' # to find CPU hogs alias cpus='grep -c ^processor /proc/cpuinfo' # number of CPU's in a system alias cpus_='grep "processor" /proc/cpuinfo | wc -l' # number of CPU's in a system alias cpu='sudo dmidecode | grep Core' # CPU info in a system alias cputemp='while sleep 1; do acpi -t | osd_cat -p bottom; done &' # to get the CPU temperature continuously on the desktop alias ctemp='sensors -f && sensors' # to get the computer temperature in Fahrenheit and Celcius alias df='df -h -x tmpfs -x usbfs' # displays global disk usage by partition, excluding supermounted devices alias directorydiskusage='du -s -k -c * | sort -rn' alias dir='ls --color=auto --format=vertical' alias diskwho='sudo iotop' alias distro='lsb_release -is' # Linux distro version (Ubuntu, Linux Mint, Debian, Fedora, etc) alias distro_='cat /etc/lsb-release | grep DISTRIB_ID | cut -d '=' -f 2' # Linux distro version (Ubuntu, Linux Mint, Debian, Fedora, etc) alias distro_ver='lsb_release -rs' # Linux version detail - just codename version (11.04, 11.10, etc) alias distro_vers='lsb_release -ds' # Linux distro and version details (Ubuntu 11.04) alias dmidecode='sudo dmidecode --type 17 | more' # check RAM sed and type in Linux alias ducks='ls -A | grep -v -e '\''^\.\.$'\'' |xargs -i du -ks {} |sort -rn |head -16 | awk '\''{print $2}'\'' | xargs -i du -hs {}' # useful alias to browse your filesystem for heavy usage quickly # to show processes reading/writing to disk alias du='du -h --max-depth=1' # displays disk usage by directory, in human readable format alias dush='du -sm *|sort -n|tail' # easily find megabyte eating files or directories alias env2='for _a in {A..Z} {a..z};do _z=\${!${_a}*};for _i in `eval echo "${_z}"`;do echo -e "$_i: ${!_i}";done;done|cat -Tsv' # print all environment variables, including hidden ones alias ffind='sudo find / -name $1' alias free='free -m' # RAM and SWAP detail in MBs alias freqwatch='watch --interval 1 "cat /proc/acpi/thermal_zone/THRM/*; cat /proc/cpuinfo | grep MHz; cat /proc/acpi/processor/*/throttling"' # monitor cpu freq and temperature alias hardware='sudo lshw -html > hardware.html' # overview of the hardware in the computer # alias hgrep='history | grep --color=always' # search commands history alias hiddenpnps='unhide (proc|sys|brute)' # forensic tool to find hidden processes and ports alias hogc='ps -e -o %cpu,pid,ppid,user,cmd | sort -nr | head' # display the processes that are using the most CPU time and memory alias hogm='ps -e -o %mem,pid,ppid,user,cmd | sort -nr | head' # display the processes that are using the most CPU time and memory alias la_='ls -Al' # show hidden files alias l?='cat ~/technical/tips/ls' alias lc='ls -ltcr' # sort by and show change time, most recent last alias ldir='ls -lhA |grep ^d' alias ld='ls -ltr' # sort by date alias lfiles='ls -lhA |grep ^-' alias lf="ls -Alh --color | awk '{k=0;for(i=0;i<=8;i++)k+=((substr(\$1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf(\" %0o \",k);print}'" # full ls with octal+symbolic permissions alias lgg='ls --color=always | grep --color=always -i' # quick case-insenstive partial filename search alias lh='ls -Al' # show hidden files alias lh='ls -lAtrh' # sort by date and human readable alias libpath='echo -e ${LD_LIBRARY_PATH//:/\\n}' alias li='ls -ai1|sort' # sort by index number alias linecount='wc -l $1' # count number of lines in text file alias lk='ls -lSr' # sort by size alias llllll='ls -FlaXo --color=auto' # sort the extensions alphabetically; good for winfiles alias lllll='ls -Fla --full-time -o -Q --color=auto' # whatever alias llll='ls -laS --color=auto' # sort by size alias lll='ls -Falot --color=auto' # sort by mod time alias ll_='ls -l' # long listing alias l.='ls -d .[[:alnum:]]* 2> /dev/null || echo "No hidden file here..."' # list only hidden files alias l='ls -hF --color' # quick listing alias lm_='ls -al |more' # pipe through 'more' alias ln='ln -s' alias lr='ls -lR' # recursice ls alias lrt='ls -lart' # list files with last modified at the end alias lsam='ls -am' # List files horizontally alias lsdd='ls -latr' # sort by date alias lsd='ls -l | grep "^d"' # list only directories alias lsize='ls --sort=size -lhr' # list by size alias lsl='ls -lah' # long list, human-readable alias ls='ls -hF --color' # add colors for filetype recognition alias lsnew='ls -Alh --color=auto --time-style=+%D | grep `date +%D`' alias lss='ls -shaxSr' # sort by size alias lsss='ls -lrt | grep $1' # to see something coming into ls output: lss alias lsx='ls -ax' # sort right to left rather then in columns alias lt_='ls -alt|head -20' # 20, all, long listing, modification time alias lt='ls -ltr' # sort by date, most recent last alias lu='ls -ltur' # sort by and show access time, most recent last alias lx='ls -lXB' # sort by extension # alias man='TERMINFO=~/.terminfo TERM=mostlike LESS=C PAGER=less man' # cool colors for manpages alias mem_hogs_ps='ps wwaxm -o pid,stat,vsize,rss,time,command | head -10' # to find memory hogs alias mem_hogs_top='top -l 1 -o rsize -n 10' # to find memory hogs # alias mem='~/.scripts/realmem' # estimates memory usage alias mypc="hal-get-property --udi /org/freedesktop/Hal/devices/computer --key 'system.hardware.product'" # show computer model alias myps='/bin/ps -u "$USER" -o user,pid,ppid,pcpu,pmem,args|less' # ps alias numFiles='echo $(ls -1 | wc -l)' # numFiles: number of (non-hidden) files in current directory alias ontime='date -d @$(echo $(($(date +%s)-$(cat /proc/uptime|cut -d. -f1))))' # knowing when a machine is turned on alias packagelist_="sudo aptitude search -F %p ~i --disable-columns | sed 's/$/,/' | tr '\n\r' ' ' | sed 's/, $//'" # list all packages (1-liner) alias packagelist="sudo aptitude search -F %p ~i --disable-columns" # show list of all packages (columns) # alias packagelist='sudo dpkg --get-selections' # show llist of all packages (columns) alias phonesearch='grep '[0-9]\{3\}-[0-9]\{4\}' "$1"' # search phone #'s in file (requires XXX-XXX-XXXX format) alias processbycpuusage="ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d'" alias processbymemusage='ps -e -o rss=,args= | sort -b -k1,1n | pr -TW$COLUMNS' alias processtree='ps -e -o pid,args --forest' alias pss='ps -ef | grep $1' # to check a process is running in a box with a heavy load: pss alias rcommand='ls /usr/bin | shuf -n 1' # get a random command # alias rcommand='man $(ls /usr/bin | shuf -n 1)' # get a random command alias sete='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/q;p"' # display environment vars only, using set alias showallaliases='compgen -A alias' # list bash alias defined in .bash_profile or .bashrc alias showallfunctions='compgen -A function' # list bash functions defined in .bash_profile or .bashrc alias sizeof='du -sh' alias space='df -h' # disk space usage alias sshall='logwatch --service sshd --range all --detail high --print --archives' alias sshtoday='logwatch --service sshd --range today --detail high --print --archives' alias superfind='sudo find / ! \( -path /proc -prune -o -path /tmp -prune -o -path /dev -prune -o -path /mnt -prune \) -name' alias temperature='acpi -tf && acpi -t' # shows computer temperature, in Fahrenheit and Celsius alias top20='du -xk | sort -n | tail -20' # find the 20 biggest directories on the current filesystem alias top-commands='history | awk "{print $2}" | awk "BEGIN {FS="|"} {print $1}" |sort|uniq -c | sort -rn | head -10' # show most popular commands alias topforever='top -l 0 -s 10 -o cpu -n 15' # continual 'top' listing (every 10 sec) showing top 15 CPU things alias topten='du -sk $(/bin/ls -A) | sort -rn | head -10' # displays the top ten biggest folders/files in the current directory alias top_='xtitle Processes on $HOST && top' # uses the function 'xtitle' alias top_processes="watch -n 1 'ps -aux | sort -nrk 4 | head'" # monitoring which processes most use CPU alias treefind_="find . | sed 's/[^/]*\//| /g;s/| *\([^| ]\)/+--- \1/'" # displays a tree of the arborescence alias tree='tree -Cs' # nice alternative to 'ls' alias unusedkernels="dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'" # show installed but unused linux headers, image, or modules alias vdir='ls --color=auto --format=long' alias ver='cat /etc/lsb-release' # Ubuntu version details alias version='sudo apt-show-versions' # show version alias whichall='{ command alias; command declare -f; } | command which --read-functions --read-alias -a' # which alias alias WHOAMI='getent passwd $(whoami) | cut -f 5 -d: | cut -f 1 -d,' # prints out what the users name, notifyed in the gecos field is alias wordcount='wc -w $1' # count number of words in text file ################################################## # Information (clock and date stuff) # ################################################## alias am-pm='date +"%p"' # AM/PM (ex. AM) alias bdate2="date +'%a %Y-%m-%d %H:%M:%S %z'" # date command (ex. Sun 2011-01-23 05:39:26 -0500) alias bdate3='date "+%Y-%m-%d %A %T %Z"' # date command (ex. 2011-01-23 Sunday 05:39:23 EST) alias bdate="date '+%a, %b %d %Y %T %Z'" # date command (ex. Sun, Jan 23 2011 05:39:13 EST) alias cal='cal -3' # show 3 months by default alias date_='TZ=$TZ-72 date +%d.%m.%Y' # solaris: get current date + 72 hours alias dateformatcodes='date --help | sed -n '/^FORMAT/,/%Z/p'' # alias for seeing date's format codes alias dateh='date --help|sed "/^ *%a/,/^ *%Z/!d;y/_/!/;s/^ *%\([:a-z]\+\) \+/\1_/gI;s/%/#/g;s/^\([a-y]\|[z:]\+\)_/%%\1_%\1_/I"|while read L;do date "+${L}"|sed y/!#/%%/;done|column -ts_' # view all date formats, quick reference help alias alias day='date +%A' # day of the week (ex. Saturday) alias DAY='date "+%A" | tr '[a-z]' '[A-Z]'' # day (text) (ex. SATURDAY) alias day#='date +%d' # date (numeric) (ex. 22) alias daysleft='echo "There are $(($(date +%j -d"Dec 31, $(date +%Y)")-$(date +%j))) left in year $(date +%Y)."' # how many days until the end of the year alias epochdaysleft="perl -e 'printf qq{%d\n}, time/86400;'" # perl one-liner to determine number of days since the Unix epoch alias epochtime='date +%s' # report number of seconds since the Epoch (ex. 1295779549) alias month='date +%B' # month (ex. January) alias MONTH='date "+%B" | tr '[a-z]' '[A-Z]'' # month (text) (ex. JANUARY) alias mytime='date +%H:%M:%S' # shows just the current time (ex. 05:46:05) alias ntpdate='sudo ntpdate ntp.ubuntu.com pool.ntp.org' # time synchronisation with NTP (ex. 23 Jan 05:46:29) alias oclock='read -a A<<<".*.**..*....*** 8 9 5 10 6 0 2 11 7 4";for C in `date +"%H%M"|fold -w1`;do echo "${A:${A[C+1]}:4}";done' # odd clock alias onthisday='grep -h -d skip `date +%m/%d` /usr/share/calendar/*' # on this day alias onthisday_='firefox http://en.wikipedia.org/wiki/$(date +'%b_%d')' # what happened on this day in history? alias secconvert='date -d@1234567890' # convert seconds to human-readable format (ex. Fri Feb 13 18:31:30 EST 2009) alias stamp='date "+%Y%m%d%a%H%M"' # timestamp (ex. 20110123Sun0545) alias time2='date +"%I:%M"' # time (hours:minutes) (ex. 05:13) alias time3='date +"%l:%M %p"' # time (ex. 5:13 AM) alias time4='date +"%H:%M"' # time (hours:minutes) (ex. 05:13) alias timestamp='date "+%Y%m%dT%H%M%S"' # timestamp (ex. 20110123T054906) alias today='date +"%A, %B %-d, %Y"' # date command (ex. Sunday, January 23, 2011) alias weeknum='date +%V' # perl one-liner to get the current week number (ex. 03) ################################################## # Miscellaneous # ################################################## alias -- --='-;-' alias -- ---='-;-;-' alias -- ----='-;-;-;-' alias -- -----='-;-;-;-;-' alias ++='+;+' alias +++='+;+;+' alias ++++='+;+;+;+' alias +++++='+;+;+;+;+' alias 7z_it='7z a -mx=9 -ms=on archive.7z $1' # create solid archive (best compression) with 7z alias addrepo='sudo add-apt-repository' # add a repo to repo .list alias alert_helper='history|tail -n1|sed -e "s/^\s*[0-9]\+\s*//" -e "s/;\s*alert$//"' # notified when job run in terminal is done using NotifyOSD alias alert='notify-send -i gnome-terminal "Finished Terminal Job" "[$?] $(alert_helper)"' # usage: sleep 5; alert alias alph='cat "$1" | sort > "$1"' # alphabetizes a file alias alsamixer='alsamixer -V all' alias bashrc-copy-r='sudo cp /root/.bashrc ~/.bashrc' alias bashrc-copy='sudo cp ~/.bashrc /root/.bashrc' alias bashrc-cpr='sudo cp ~/.bashrc /root/.bashrc && cp ~/.bashrc ~/Temp && gedit ~/.bashrc && exit' alias bashrc='gedit ~/.bashrc & exit' alias bashrc-root='sudo gedit ~/.bashrc & exit' alias bashrc-temp='cp ~/.bashrc ~/Temp' alias bbc='lynx -term=vt100 http://news.bbc.co.uk/text_only.stm' alias bedit='vim ~/.bashrc; source ~/.bashrc' alias beep='echo -en "\007"' # ring the bell alias bgedit='gedit ~/.bashrc; source ~/.bashrc' alias blipfm="mpg123 `curl -s http://blip.fm/all | sed -e 's#"#\n#g' | grep mp3$ | xargs`" # play random music from blip.fm alias capture='IMAGE="$HOME/Pictures/capture-`date +%Y%m%d%H%M%S`.png"; import -frame $IMAGE; echo "Image saved as $IMAGE"' # save portion of desktop as image alias cic='set completion-ignore-case On' # make tab-completion case-insensitive alias clisp='clisp -q' alias commentremove="sed 's/[[:blank:]]*#.*//; /^$/d' "$1"" # this will remove comments that are at the end of lines alias compiz-replace='compiz --replace' # refreshes compiz (fixes drag/drop issue, among others) alias cut80='/usr/bin/cut -c 1-80' # truncate lines longer than 80 characters (for use in pipes) alias debrepack='sudo dpkg-repack' # just an easier-to-remember alias for 'dpkg-repack' alias differ='sdiff --suppress-common-lines' # bash alias for sdiff: differ alias dmregister='lynx http://desmoinesregister.com' alias dos2unix_='perl -pi -e 's/\r\n/\n/g' *' alias downNuncompress='wget http://URL/FILE.tar.gz -O- | tar xz' # download a file and uncompress it while it downloads # alias downNuncompress='curl http://URL/FILE.tar.gz | tar xz' # download a file and uncompress it while it downloads alias du0='du --max-depth=0' alias du1='du --max-depth=1' alias ebrc='nano ~/.bashrc' alias ebrcupdate='source ~/.bashrc' alias edit='nano' alias elog='tai64nlocal' alias encryptall='for f in * ; do [ -f $f ] && openssl enc -aes-256-cbc -salt -in $f -out $f.enc -pass file:/tmp/password-file ; done' # encrypt every file in current directory with 256-bit AES, retaining original alias fixmount='sudo e2fsck -f /dev/sda1' # repair device booting/mounting error (for /dev/sda1) alias fixopera='rm -r ~/.opera/{mail,lock}' alias fixres='xrandr --size 1600x1200' # reset resolution alias fix_stty='stty sane' # restore terminal settings when they get completely screwed up alias flv2ogg='for i in $(ls *.flv); do ffmpeg2theora -v 6 --optimize $i; done' # convert all FLV's in a directory to Ogg Theora (video) alias foldpb='pbpaste | fold -s | pbcopy' # make text in clipboard wrap so as to not exceed 80 characters alias funkcje="grep -o '^[a-zA-Z]\{1,\}.(*)' ~/.bashrc" alias gdbbt='gdb -q -n -ex bt -batch' # print stack trace of a core file without needing to enter gdb interactively alias gifted='giftd -d && giFTcurs' alias gitk='screen -d -m gitk' alias gmail='sh /$HOME/.scripts/gmail.sh' alias googlevideo='wget -qO- "VURL" | grep -o "googleplayer.swf?videoUrl\\\x3d\(.\+\)\\\x26thumbnailUrl\\\x3dhttp" | grep -o "http.\+" | sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e | sed 's/.\{22\}$//g' | xargs wget -O "$1"' # Google video download alias gsop='gmplayer http://localhost:8909 -prefer-ipv4' alias head='head -n $((${LINES:-`tput lines 2>/dev/null||echo -n 12`} - 2))' # alias HEAD for automatic smart output alias hiresvideo='mplayer -framedrop -vfm ffmpeg -lavdopts lowres=1:fast:skiploopfilter=all' # play high-res video files on a slow processor alias image2pdf='convert -adjoin -page A4 *.jpeg multipage.pdf' # convert images to a multi-page pdf alias irb='irb --readline -r irb/completion -rubygems' alias jargon='wget -m http://catb.org/~esr/jargon/html/ -nH --cut-dirs=2 -np -L -P ~/Jargon/' alias kernbuild='make -j3 && make modules_install && ls -ld ../linux && date' # compile kernel, install modules, display kernel vers & date alias kfire='for i in `ps aux | grep [F]irefox `; do echo $i; kill $(($i)); done; ' # alias kfire='kill $(pidof firefox)' # alias kfire='kill $(ps aux | awk '/firefox/ {print $2}' | tr '\n' ' ')' alias killall='killall -u $USER -v' # only kill our own processes, and also be verbose about it alias killall_wine='wineserver -k' # stop all Wine apps and processes alias lastlog='lastlog | grep -v Never' alias less='less -Mw' alias lssd='ps ax | grep -v grep | grep -i firefox | while read pid; do kill "${pid%% *}"; done' alias lstexfont='ls {/usr/share/texmf-dist/tex/latex/psnfss/*.sty,/usr/share/texmf-dist/tex/latex/pxfonts/*.sty}' alias lvim="vim -c \"normal '0\"" # open the last file you edited in Vim. alias makepasswd='makepasswd -minchars 8' alias make_='xtitle Making $(basename $PWD) ; make' # uses the function 'xtitle' alias mencoder-join='mencoder -forceidx -ovc copy -oac copy -o' # just add: whatever.avi whatever.pt1.avi whatever.pt2.avi ... alias memlimit='ulimit -v 1000000; $1' # limit memory usage per script/program alias mic_record='arecord -q -f cd -r 44100 -c2 -t raw | lame -S -x -h -b 128 - `date +%Y%m%d%H%M`.mp3' # record microphone input and output to date stamped mp3 file alias mid='printf "\e[8;24;80;t"' # resize participating terminals to classic 80x24 size alias minicom='minicom -c on' # enable colour (sudo apt-get install minicom) alias mkdirday='mkdir `date +%Y%m%d`_$1' # (by Karl Voit) creates directory that starts with current day alias mkdsp='sudo mknod /dev/dsp c 14 3 && sudo chmod 777 /dev/dsp' # remake /dev/dsp alias mkpkg='makepkg -csi' alias mp3ogg='mp32ogg *.mp3 && rm *.mp3' alias mpfb='mplayer -vo fbdev -xy 1024 -fs -zoom "$1"' # watch a movie in linux without the X windows system alias mpfb_='mplayer -vo fbdev2 -fs -zoom -xy 1440' alias mtrue='sudo truecrypt /media/usbdisk/$USER.tc ~/$USER' alias n2r='sudo /etc/init.d/nginx stop && sleep 2 && sudo /etc/init.d/nginx start' alias ncftp='xtitle ncFTP ; ncftp' # uses the function 'xtitle' alias nytimes='lynx -term=vt100 http://nytimes.com' alias passwords='passwd && rm -rf ~/.gnome2/keyrings/*' # removes keyring passwords and lets you change user password alias pipinstall='sudo pip install' alias ppa-purge='sudo ppa-purge' alias pstree='/sw/bin/pstree -g 2 -w' alias puttyreload='export TERM=putty && source ~/.bashrc' alias quota='quota -s' # human readable quota! alias recursivetouch='find . -exec touch {} \;' # be careful with this as it can modify time stamp of files alias repo='gksudo gedit /etc/apt/sources.list' alias restart-apache='sudo /etc/init.d/apache2 restart' alias retheme='sudo gnome-settings-daemon' # refreshes the theme to fix grey basic theme error at startup alias rkhunter='sudo rkhunter -c' alias rmao='find . -iname a.out -exec rm {} \;' alias rm_DS_Store_files='find . -name .DS_Store -exec rm {} \;' # removes all .DS_Store file from the current dir and below alias rsync-me='sudo rsync -a -v --progress --delete --modify-window=1 -s $HOME /home/rsync' alias scpresume='rsync --partial --progress --rsh=ssh' # alias screencast='ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -r 30 -s 1280x800+0+0 -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 -y output.mkv' # alias screencast='ffmpeg -f x11grab -r 30 -s 1280x800 -i :0.0 $HOME/outputFile.mpg' # record a screencast and convert it to an mpeg alias screencast="ffmpeg -y -f alsa -ac 2 -i pulse -f x11grab -r 30 -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -i :0.0 -acodec pcm_s16le output.wav -an -vcodec libx264 -vpre lossless_ultrafast -threads 0 output.mp4" # capture video of a linux desktop alias screenr='screen -r $(screen -ls | egrep -o -e '[0-9]+' | head -n 1)' # quick enter into a single screen session alias screen_restart='sudo /etc/init.d/gdm restart' # restarts screen to login screen so as to get back in alias sdiff='/usr/bin/sdiff --expand-tabs --ignore-all-space --strip-trailing-cr --width=160' # sdiff the way it was at IBM alias sdirs='source ~/.dirs' alias service='sudo service' # access a system service alias sh_diff='diff -abBpur' alias sh_indent='indent -nsaf -npcs -cli2 -i2 -lp -nprs -nsaw -nut -cbi2 -bli0 -bls -nbad -npsl' alias shot!='archey && scrot -d 5 -c screen_`date +%Y-%m-%d`.png' # is also a function of shot which does the screen for one window alias show_='cat ~/.dirs' alias show-colors='~/.bin/colors.sh' alias show-info='~/.bin/info.pl' alias show_options='shopt' # show_options: display bash options settings alias showrepo='cat /etc/apt/sources.list `ls /etc/apt/sources.list.d/*.list` | egrep -v "^$"' alias sh_svnstat="svn status | awk '/^[^?]/'" alias sourcea='source ~/.aliases.bash' # to source this file (to make changes active after editing) alias spaceremover="sed -i 's/\s\+/ /g;s/\s*$//' $1" # get rid of multiple spaces/tabs in a text file alias ssinfo='perl ~/.scripts/ssinfo.pl' # alias svnaddall='find "$PWD" -exec svn add {} 2>/dev/null \;' # add all files recursively alias svnaddall='svn status | grep "^\?" | awk "{print \$2}" | xargs svn add' alias svndelall='svn status | grep "^\!" | awk "{print \$2}" | xargs svn delete' alias svnrmallentries='find . -name .svn -print0 | xargs -0 rm -rf' # remove all .svn directories recursively alias tailm='multitail' alias tarred='( ( D=`builtin pwd`; F=$(date +$HOME/`sed "s,[/ ],#,g" <<< ${D/${HOME}/}`#-%F.tgz); tar --ignore-failed-read --transform "s,^${D%/*},`date +${D%/*}.%F`,S" -czPf "$"F "$D" &>/dev/null ) & )' # create date-based tgz of current dir (runs in background) # alias themeinfo='perl ~/Scripts/info.pl' alias thumbit='mogrify -resize 25%' alias tinyurl='~/.scripts/tinyurl' # converts url to tinyurl alias tkeys='tmux list-keys' # shows all tmux keys alias trace='~/.scripts/trace' # visual traceroute alias txt2md='rename 's/\.txt$/\.md$/i' *' # batch rename extension of all .txt files to .md files in a folder alias ugrub2='sudo update-grub2' # update grub2 alias ugrub='sudo update-grub' # update grub alias updatedb='sudo updatedb' alias updatefonts='sudo fc-cache -vf' alias usbb='rsync -avz /media/usbdisk/ ~/backup/usb/' alias utrue='sudo truecrypt -d' alias viaco='task="$(basename "$(pwd)")"; if [ -f "$task.c" ]; then vi -c "set mouse=n" -c "set autoread" -c "vsplit $task.out" -c "split $task.in" -c "wincmd l" -c "wincmd H" $task.c; fi' # setup Vim environment for USACO coding alias video_record='mencoder -tv driver=v4l2:device=/dev/video1:input=1:norm=ntsc:alsa=1:adevice=hw.1:audiorate=48000:immediatemode=0:amode=1 tv:// -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1600:vhq:v4mv:keyint=250 -vf pp=de,pullup,softskip -oac mp3lame -lameopts abr:br=64:vol=2 -ffourcc xvid -o /home/me/Temp/$1.avi' # record external video feed alias webcam='mplayer -cache 128 -tv driver=v4l2:width=176:height=177 -vo xv tv:// -noborder -geometry "95%:93%" -ontop' # mplayer webcam window for screencasts alias webcam_record='ffmpeg -an -f video4linux2 -s 640x480 -r 15 -i /dev/video0 -vcodec mpeg4 -vtag XVID /home/me/Temp/webcam_$1.avi' # webcam record alias webshare='python -c "import SimpleHTTPServer; SimpleHTTPServer.test();"' alias wiki='wikipedia2text -p' # convert wiki to text output alias xinitrc='vim ~/.xinitrc' alias xsnow='(killall xsnow ; sleep 3 ; exec xsnow -nosanta -notrees -norudolf -nokeepsnow >& /dev/null &)' # xsnow ################################################## # Miscellaneous Fun # ################################################## alias 99bottles='x="bottles of beer";y="on the wall";for b in {99..1};do echo "$b $x $y, $b $x. Take one down pass it around, $(($b-1)) $x $y"; sleep 3;done' alias addictive='count="1" ; while true ; do read next ; if [[ "$next" = "$last" ]] ; then count=$(($count+1)) ; echo "$count" ; else count="1" ; echo $count ; fi ; last="$next" ; done' # simple addicting bash game alias aljazeera='rtmpdump -v -r rtmp://livestfslivefs.fplive.net/livestfslive-live/ -y "aljazeera_en_veryhigh" -a "aljazeeraflashlive-live" -o -| mplayer -' # watch Aljazeera live alias awesome='while $i;do `notify-send -t 200 "You are awesome :)"`;sleep 60; done;' # get informed periodically by your box that you are awesome alias busy='for i in `seq 0 100`;do timeout 6 dialog --gauge "Install..." 6 40 "$i";done' # pretend to be busy in office to enjoy a cup of coffee alias busy2='my_file=$(find /usr/include -type f | sort -R | head -n 1); my_len=$(wc -l $my_file | awk "{print $1}"); let "r = $RANDOM % $my_len" 2>/dev/null; vim +$r $my_file' alias busy3='cat /dev/urandom | hexdump -C | highlight ca fe 3d 42 e1 b3 ae f8 | perl -MTime::HiRes -pnE "Time::HiRes::usleep(rand()*1000000)"' # alias earth='mv ~/Pictures/Backgrounds/mercator.jpg ~/Pictures/Backgrounds/mercator.`timestamp`.jpg | wget -r -N http://static.die.net/earth/mercator/1600.jpg -O ~/Pictures/Backgrounds/mercator.jpg && gconftool-2 --type string --set /desktop/gnome/background/picture_filename ~/Pictures/Backgrounds/mercator.jpg' # live earth wallpaper (downloads and saves each time) (GNOME2) # alias earth='mv ~/Pictures/Backgrounds/mercator.jpg ~/Pictures/Backgrounds/mercator.`timestamp`.jpg | wget -r -N http://static.die.net/earth/mercator/1600.jpg -O ~/Pictures/Backgrounds/mercator.jpg && gsettings set org.gnome.desktop.background picture-uri "file://$HOME/Pictures/Backgrounds/mercator.jpg"' # live earth wallpaper (downloads and saves each time) (GNOME3) # alias earth='rm -f ~/Pictures/Backgrounds/mercator.jpg && wget -r -N http://static.die.net/earth/mercator/1600.jpg -O ~/Pictures/Backgrounds/mercator.jpg && gconftool-2 --type string --set /desktop/gnome/background/picture_filename ~/Pictures/Backgrounds/mercator.jpg' # live earth wallpaper (GNOME2) alias earth='rm -f ~/Pictures/Backgrounds/mercator.jpg && wget -r -N http://static.die.net/earth/mercator/1600.jpg -O ~/Pictures/Backgrounds/mercator.jpg && gsettings set org.gnome.desktop.background picture-uri "file://$HOME/Pictures/Backgrounds/mercator.jpg"' # live earth wallpaper (GNOME3) alias einsteiny='A=1;B=100;X=0;C=0;N=$[$RANDOM%$B+1];until [ $X -eq $N ];do read -p "N between $A and $B. Guess? " X;C=$(($C+1));A=$(($X<$N?$X:$A));B=$(($X>$N?$X:$B));done;echo "Took you $C tries, Einstein";' # numbers guessing game alias etchasketch='c=12322123;x=20;y=20;while read -sn1 p;do k=${c:(p-1)*2:2};let x+=$((k/10-2));let y+=$((k%10-2));echo -en \\033[$y\;"$x"HX;done' # use the 1 2 3 and 4 keys to move the cursor around the screen (It's an etch-a-sketch for your terminal!) alias excuses='echo `telnet bofh.jeffballard.us 666 2>/dev/null` |grep --color -o "Your excuse is:.*$"' # excuses alias freechess='telnet fics.freechess.org 5000' # connects to a telnet server for free internet chess alias funfacts='wget http://www.randomfunfacts.com -O - 2>/dev/null | grep \ | sed "s;^.*\(.*\).*$;\1;";' alias funknet='telnet the-funk.net 7000' # Access to Funk.net alias futurama='curl -Is slashdot.org | sed -n '5p' | sed 's/^X-//'' # get Futurama quotations from slashdot.org servers alias guitartune='for n in E2 A2 D3 G3 B3 E4;do play -n synth 4 pluck $n repeat 2;done' # tune your guitar from the command line alias iamcow='fortune | cowsay' alias iamsurprise='fortune | cowsay -f $(random_cow)' alias insults='wget http://www.randominsults.net -O - 2>/dev/null | grep \ | sed "s;^.*\(.*\).*$;\1;";' alias lotto='shuf -i 1-49 -n 6 | sort -n | xargs' # lotto generator alias matrix='echo -e "\e[32m"; while :; do for i in {1..16}; do r="$(($RANDOM % 2))"; if [[ $(($RANDOM % 5)) == 1 ]]; then if [[ $(($RANDOM % 4)) == 1 ]]; then v+="\e[1m $r "; else v+="\e[2m $r "; fi; else v+=" "; fi; done; echo -e "$v"; v=""; done' alias matrix2='echo -e "\e[31m"; while $t; do for i in `seq 1 30`;do r="$[($RANDOM % 2)]";h="$[($RANDOM % 4)]";if [ $h -eq 1 ]; then v="\e[1m $r";else v="\e[2m $r";fi;v2="$v2 $v";done;echo -e $v2;v2="";done;' alias matrix3='COL=$(( $(tput cols) / 2 )); clear; tput setaf 2; while :; do tput cup $((RANDOM%COL)) $((RANDOM%COL)); printf "%$((RANDOM%COL))s" $((RANDOM%2)); done' alias matrix4='echo -ne "\e[32m" ; while true ; do echo -ne "\e[$(($RANDOM % 2 + 1))m" ; tr -c "[:print:]" " " < /dev/urandom | dd count=1 bs=50 2> /dev/null ; done' alias matrix5='tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=lcase,unblock | GREP_COLOR="1;32" grep --color "[^ ]"' alias roulette='[ $[ $RANDOM % 6 ] == 0 ] && echo Die || echo Live' # command line Russian roulette alias screensaver='for ((;;)); do echo -ne "\033[$((1+RANDOM%LINES));$((1+RANDOM%COLUMNS))H\033[$((RANDOM%2));3$((RANDOM%8))m$((RANDOM%10))"; sleep 0.1 ; done' # terminal screensaver alias starwars='telnet towel.blinkenlights.nl' # the famous starwars ASCII version from telnet alias termvideo_bw='mplayer -vo aa' # watch movies in ASCII (just direct to the video) alias termvideo='mplayer -vo caca' # watch movies in ASCII (just direct to the video) alias wooters='telnet zerocarbs.wooters.us' # connects to a telnet service monitoring Woot (Gives you an updating woot! item tracker!) ################################################## # Network/Internet -oriented stuff # ################################################## alias appson="netstat -lantp | grep -i stab | awk -F/ '{print $2}' | sort | uniq" # view only the process name using an internet connection alias bandwidth='dd if=/dev/zero of=/dev/null bs=1M count=32768' # processor / memory bandwidthd? in GB/s alias browse_bonjour='dns-sd -B' # browse services advertised via Bonjour # alias daemons='ls /var/run/daemons' # daemon managment (ommited for function) alias dbdumpcp='scp -P 1234 username@12.34.56.78:$HOME/Backup/www/data/someSite/db.sql $HOME/Backup/data/db.sql' # copy remote db to local alias dns='cat /etc/resolv.conf' # view DNS numbers alias domain2ban='~/.scripts/Domain2Ban.sh' alias estab='ss -p | grep STA' # view only established sockets (fails if "ss" is screensaver alias) alias finchsync='java -jar ~/finchsync/finchsync.jar' # start FinchSync Admin # alias ftop='watch -d -n 2 'df; ls -FlAt;'' # like top, but for files alias hdinfo='hdparm -i[I] /dev/sda' # hard disk information - model/serial no. alias hostip='wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1' alias hostname_lookup='lookupd -d' # interactive debugging mode for lookupd (use tab-completion) alias http_trace='pkt_trace port 80' # to show all HTTP packets alias iftop='sudo iftop -i eth0' # start "iftop" program (sudo apt-get install iftop) alias ip4grep="grep -E '([0-9]{1,3}\.){3}[0-9]{1,3}'" # look for IPv4 address in files alias ip='curl www.whatismyip.org' alias ip_info='ipconfig getpacket en1' # info on DHCP server, router, DNS server, etc (for en0 or en1) alias ipt80='sudo iptstate -D 80' # check out only iptables state of http port 80 (requires iptstate) alias ip_trace='pkt_trace ip' # to show all IP packets alias ipttrans='sudo iptstate -D 51413' # iptables state of Transmission-Daemon port (requires iptstate) alias listen='sudo netstat -pnutl' # lists all listening ports together with PID of associated process alias lsock='sudo /usr/sbin/lsof -i -P' # to display open sockets ( -P option to lsof disables port names) alias memrel='free && sync && echo 3 > /proc/sys/vm/drop_caches && free' # release memory used by the Linux kernel on caches alias net1='watch --interval=2 "sudo netstat -apn -l -A inet"' alias net2='watch --interval=2 "sudo netstat -anp --inet --inet6"' alias net3='sudo lsof -i' alias net4='watch --interval=2 "sudo netstat -p -e --inet --numeric-hosts"' alias net5='watch --interval=2 "sudo netstat -tulpan"' alias net6='sudo netstat -tulpan' alias net7='watch --interval=2 "sudo netstat -utapen"' alias net8='watch --interval=2 "sudo netstat -ano -l -A inet"' alias netapps="lsof -P -i -n | cut -f 1 -d ' '| uniq | tail -n +2" alias nethogs='sudo nethogs eth0' # start "nethogs" program (sudo apt-get install nethogs) alias netl='sudo nmap -sT -O localhost' alias netscan='sudo iwlist wlan0 scan' # to scan your environment for available networks, do the following alias netstats='sudo iwspy wlan0' # if card supports it, you can collect wireless statistics by using alias network='sudo lshw -C network' # view network device info alias networkdump='sudo tcpdump not port 22' # dump all the network activity except ssh stuff alias nmr='sudo /etc/rc.d/networkmanager restart' alias nsl='netstat -f inet | grep -v CLOSE_WAIT | cut -c-6,21-94 | tail +2' # show all programs connected or listening on a network port alias ns='netstat -alnp --protocol=inet | grep -v CLOSE_WAIT | cut -c-6,21-94 | tail +2' alias openports='sudo netstat -nape --inet' # view open ports alias oports="echo 'User: Command: Port:'; echo '----------------------------' ; lsof -i 4 -P -n | grep -i 'listen' | awk '{print \$3, \$1, \$9}' | sed 's/ [a-z0-9\.\*]*:/ /' | sort -k 3 -n |xargs printf '%-10s %-10s %-10s\n' | uniq" # lsof (cleaned up for just open listening ports) alias pkt_trace='sudo tcpflow -i `active_net_iface` -c' alias ports='lsof -i -n -P' # view programs using an internet connection alias portstats='sudo netstat -s' # show statistics for all ports alias proxy1='ssh -p 1234 -D 5678 username@12.34.56.78' # SOCKS proxy - these anonomise browsing - 12.34.56.78 alias proxy2='ssh -p 8765 -D 4321 username@87.65.43.21' # SOCKS proxy - these anonomise browsing - 87.65.43.21 alias QUERY='psql -h $MYDBHOST -p 5432 -d $MYDB -U $MYLOGIN --no-align' # lazy SQL QUERYING alias randomip='echo $((RANDOM%256)).$((RANDOM%256)).$((RANDOM%256)).$((RANDOM%256))' # generate a random IP address alias ramvalue='sudo dd if=/dev/mem | cat | strings' # will show you all the string (plain text) values in ram alias randommac='python -c "from itertools import imap; from random import randint; print ':'.join(['%02x'%x for x in imap(lambda x:randint(0,255), range(6))])"' # generate random valid mac addresses alias rdp='rdesktop -u "$USER" -g 1600x1200 -D -r disk:home=/home -r clipboard:PRIMARYCLIPBOARD' # quick full screen RDP connection alias remote='ssh -p 1234 12.34.56.78' # access some remote host alias restartnet='sudo /etc/rc.d/network restart;sudo /etc/rc.d/wicd restart' alias rssup='php /srv/http/rssupdate.php' alias setessid='sudo iwconfig wlan0 essid network-essid' # set the essid, which identifies the network access point you want alias smtp_trace='pkt_trace port smtp' # to show all SMTP packets alias someDBdump='sudo mysqldump someDB -uroot -p > $HOME/www/_dbs/someDB.sql' alias spavr='gtkterm -c avr' # alias spavr='sudo chmod a=rw /dev/ttyUSB0; gtkterm -c avr' alias speedtest='speedtest --share' # speedtest - test internet speed and share image of results alias spk800i='gtkterm -c k800i' # alias spk800i='sudo chmod a=rw /dev/rfcomm0; gtkterm -c k800i' alias sql='mysql -p -u root' alias sync='java -jar ~/finchsync/finchsync.jar -nogui' # sync to PDA .. well, that'll be a sync then! - start FinchSync SVR alias syncoff='java -jar ~/Apps/FinchSync/finchsync.jar -stopserver' # sync to PDA .. well, that'll be a sync then! - stop FinchSync SVR alias tcpstats='sudo netstat -st' # show statistics for tcp ports alias tcp_='sudo netstat -atp' # list all TCP ports alias tcp_trace='pkt_trace tcp' # to show all TCP packets alias topsites='curl -s -O http://s3.amazonaws.com/alexa-static/top-1m.csv.zip ; unzip -q -o top-1m.csv.zip top-1m.csv ; head -1000 top-1m.csv | cut -d, -f2 | cut -d/ -f1 > topsites.txt' # get a list of top 1000 sites from alexa alias tproxy='ssh -ND 8118 user@server&; export LD_PRELOAD="/usr/lib/libtsocks.so"' # creates a proxy based on tsocks alias udpstats='sudo netstat -su' # show statistics for udp ports alias udp='sudo netstat -aup' # list all UDP ports alias udp_trace='pkt_trace udp' # to show all UDP packets alias uploads='cd /some/folder' # access some folder alias vncup='x11vnc -nopw -ncache 10 -display :0 -localhost' alias website_dl='wget --random-wait -r -p -e robots=off -U mozilla "$1"' # download an entire website alias website_images='wget -r -l1 --no-parent -nH -nd -P/tmp -A".gif,.jpg" "$1"' # download all images from a site alias whois='whois -H' alias wireless_sniffer='sudo ettercap -T -w out.pcap -i wlan0 -M ARP // //' # sniff who are using wireless. Use wireshark to watch out.pcap alias wscan_='iwlist scan' # terminal network scan for wireless signals alias wwwmirror2='wget -k -r -l ${2} ${1}' # wwwmirror2 usage: wwwmirror2 [level] [site_url] alias wwwmirror='wget -ErkK -np ${1}' ################################################## # Package holding, making, and installation # ################################################## alias checkinstall-force='sudo checkinstall --dpkgflags "--force-overwrite"' alias checkinstall-noinstall='sudo checkinstall -y --fstrans=no --install=no' alias checkinstall='sudo checkinstall -y --fstrans=no' alias debinstall-force='sudo dpkg -i --force-overwrite' alias debinstall='sudo dpkg -i' alias diffinstall='diff /tmp/install.pre /tmp/install.pos | grep \"^>\" | sed \"s/^> //g\"' # run diffinstall fourth, after diffinstall to show what files were copied in your system alias postinstall='sudo find / ! \( -path /proc -prune -o -path /tmp -prune -o -path /dev -prune -o -path /mnt -prune \) > /tmp/install.pos' # run postinstall third, after "make install" alias preinstall='sudo find / ! \( -path /proc -prune -o -path /tmp -prune -o -path /dev -prune -o -path /mnt -prune \) > /tmp/install.pre' # run preinstall first, then "make install" ################################################## # Permissions # ################################################## alias 000='chmod 000 -R' alias 640='chmod 640 -R' alias 644='chmod 644 -R' # default permission for ('~/.dmrc' file) alias 755='chmod 755 -R' # default permissions for $HOME (excluding '~/.dmrc' file) alias 775='chmod 775 -R' alias 777='chmod 777 -R' alias mx='chmod a+x' alias perm='stat --printf "%a %n \n "' # requires a file name e.g. perm file alias permall='777' alias permhome='chmod 755 -R $HOME && chmod 644 $HOME/.dmrc' alias restoremod='chgrp users -R .;chmod u=rwX,g=rX,o=rX -R .;chown $(pwd |cut -d / -f 3) -R .' # restore user,group and mod of an entire website ################################################## # Personal help # ################################################## alias a?='cat ~/.alias.help' alias dn='OPTIONS=$(\ls -F | grep /$); select s in $OPTIONS; do cd $PWD/$s; break;done' alias espanol='echo -e \"á Á é É í Í ó Ó ú Ú ñ Ñ ü Ü ¿ ¡ ¢ ‘ ’ “ ” „ ‚ …\"' alias f?='cat ~/.function.help' alias help='OPTIONS=$(\ls ~/.tips -F);select s in $OPTIONS; do less ~/.tips/$s; break;done' alias testh='help test|sed -e :a -e "$!N;s/\(-n STRING\)\n/\1, /;s/\n\( \{23\}\| \{4\}\([a-z]\)\)/ \2/;ta;P;D"|sed "s/ \{1,\}/ /g;/^ $/d;/:$/s/^/\n/"|sed -n "/File operators:/,\$p"' # test quick help alias ################################################## # Relinux stuff # ################################################## alias relinux-clean='sudo relinux clean $HOME/.relinux.conf' # cleans up files made by relinux # alias relinux-clean='sudo relinux clean $HOME/relinux.conf' # cleans up files made by relinux alias relinux-config='sudo relinux config' # generates a configuration file in the current directory # alias relinux-fullclean='sudo relinux fullclean $HOME/relinux.conf' # cleans up files made by relinux, including the ISO file alias relinux-fullclean='sudo relinux fullclean $HOME/.relinux.conf' # cleans up files made by relinux, including the ISO file # alias relinux-iso='sudo relinux iso $HOME/relinux.conf' # runs both 'relinux-onlyiso' & 'relinux-squashfs' alias relinux-iso='sudo relinux iso $HOME/.relinux.conf' # runs both 'relinux-onlyiso' & 'relinux-squashfs' # alias relinux-onlyiso='sudo relinux onlyiso $HOME/relinux.conf' # generates .iso file based on .squashfs file from 'relinux-squashfs' alias relinux-onlyiso='sudo relinux onlyiso $HOME/.relinux.conf' # generates .iso file based on .squashfs file from 'relinux-squashfs' # alias relinux-squashfs='sudo relinux squashfs $HOME/relinux.conf' # generates a .squashfs file from your system alias relinux-squashfs='sudo relinux squashfs $HOME/.relinux.conf' # generates a .squashfs file from your system ################################################## # Remastersys stuff # ################################################## alias remastersys-backup-custom='sudo remastersys backup custom.iso' # to make a livecd/dvd backup and call the iso custom.iso alias remastersys-backup='sudo remastersys backup' # to make a livecd/dvd backup of your system alias remastersys-clean='sudo remastersys clean' # to clean up temporary files of remastersys alias remastersys-dist-cdfs='sudo remastersys dist cdfs' # to make a distributable livecd/dvd filesystem only alias remastersys-dist-custom='sudo remastersys dist iso custom.iso' # to make a distributable iso named custom.iso but only if cdfs is present alias remastersys-dist='sudo remastersys dist' # to make a distributable livecd/dvd of your system ################################################## # Secure-delete substitution # ################################################## alias sfill-freespace='sudo sfill -I -l -l -v' alias sfill-f='sudo sfill -f -l -l -v -z' alias sfill='sudo sfill -l -l -v -z' alias sfill-usedspace='sudo sfill -i -l -l -v' alias smem-f='sudo sdmem -f -l -l -v' alias smem-secure='sudo sdmem -v' alias smem='sudo sdmem -l -l -v' alias srm-m='sudo srm -f -m -z -v' alias srm='sudo srm -f -s -z -v' alias sswap-sda5='sudo sswap -f -l -l -v -z /dev/sda5' alias sswap='sudo sswap -f -l -l -v -z' alias swapoff='sudo swapoff /dev/sda5' alias swapon='sudo swapon /dev/sda5' ################################################## # Set up auto extension stuff # ################################################## ###### If -s flags present, define suffix alias: if command word on command line is in form `text.name', # where text is any non-empty string, its replaced by text 'value text.name'. Note that names treated as literal # string, not pattern. A trailing space in value is not special in this case. For example, alias -s ps=gv # will cause command `*.ps' to be expanded to `gv *.ps'. As alias expansion is carried out earlier than globbing, # `*.ps' will then be expanded. Suffix aliases constitute different name space from other aliases (so in above # example its still possible to create alias for command ps) and two sets are never listed together. # alias -s avi=mplayer # alias -s bz2=tar -xjvf # alias -s com=$BROWSER # alias -s cpp=vim # alias -s doc=soffice # alias -s eps=eog # alias -s gif=eog # alias -s gz=tar -xzvf # alias -s html=$BROWSER # alias -s img=mplayer # alias -s install=$EDITOR # alias -s iso=mplayer # alias -s java=$EDITOR # alias -s jpg=eog # alias -s mkv=mplayer # alias -s mp3=mplayer # alias -s mpeg=mplayer # alias -s mpg=mplayer # alias -s mws=maple # alias -s net=$BROWSER # alias -s odt=soffice # alias -s org=$BROWSER # alias -s pdf=evince # alias -s php=$BROWSER # alias -s PKGBUILD=vim # alias -s png=eog # alias -s ppt=soffice # alias -s ps=gv # alias -s se=$BROWSER # alias -s sh=vim # alias -s sxw=soffice # alias -s tex=$EDITOR # alias -s txt=$EDITOR # alias -s wmv=mplayer # alias -s xls=soffice ################################################## # Shred substitution # ################################################## alias shred-sda-r='sudo shred -v -z -n 1 /dev/sda' alias shred-sda='sudo shred -v -z -n 0 /dev/sda' alias shred-sdb-r='sudo shred -v -z -n 1 /dev/sdb' alias shred-sdb='sudo shred -v -z -n 0 /dev/sdb' alias shred-sdc-r='sudo shred -v -z -n 1 /dev/sdc' alias shred-sdc='sudo shred -v -z -n 0 /dev/sdc' alias shred-sdd-r='sudo shred -v -z -n 1 /dev/sdd' alias shred-sdd='sudo shred -v -z -n 0 /dev/sdd' alias shred-sde-r='sudo shred -v -z -n 1 /dev/sde' alias shred-sde='sudo shred -v -z -n 0 /dev/sde' alias shred-sdf-r='sudo shred -v -z -n 1 /dev/sdf' alias shred-sdf='sudo shred -v -z -n 0 /dev/sdf' alias shred-sdg-r='sudo shred -v -z -n 1 /dev/sdg' alias shred-sdg='sudo shred -v -z -n 0 /dev/sdg' ################################################## # Xterm and Aterm # ################################################## alias aterm='xterm -ls -fg gray -bg black' alias termb='xterm -bg AntiqueWhite -fg NavyBlue &' alias termg='xterm -bg AntiqueWhite -fg OliveDrab &' alias termr='xterm -bg AntiqueWhite -fg DarkRed &' alias term='xterm -bg AntiqueWhite -fg Black &' alias xsu='xterm -fn 7x14 -bg DarkOrange4 -fg white -e su &' alias xtop='xterm -fn 6x13 -bg LightSlateGray -fg black -e top &' ################################################## ################################################## ################################################## ###################################################################################################################################################### #----- MY CUSTOM STARTS HERE ------ MY CUSTOM STARTS HERE ------ MY CUSTOM STARTS HERE ------ MY CUSTOM STARTS HERE ------ MY CUSTOM STARTS HERE ------ ###################################################################################################################################################### ###################################################################################################################################################### ###### REQUIRES MY ULTIMATE NEMO/NAUTILUS SCRIPTS PACK AND FOR YOU TO CHANGE THE USERNAME AND DIRECTORY (NEMO OR NAUTILUS) TO YOUR OWN ###### ###################################################################################################################################################### ################################################## # My aliases and functions for scripts # ################################################## ###### defrag3 alias defrag3-home='sudo /usr/bin/python ~/.gnome2/nemo-scripts/"File System Management"/Fragtools/Defrag-3.py ~' alias defrag3-root='sudo /usr/bin/python ~/.gnome2/nemo-scripts/"File System Management"/Fragtools/Defrag-3.py /root' alias defrag3='sudo /usr/bin/python ~/.gnome2/nemo-scripts/"File System Management"/Fragtools/Defrag-3.py' alias defrag3-system='sudo /usr/bin/python ~/.gnome2/nemo-scripts/"File System Management"/Fragtools/Defrag-3.py /' ###### games alias doom='cd ~/.gnome2/nemo-scripts/Games/.doomrl && ./doomrl' alias dopewars='~/.gnome2/nemo-scripts/Games/Dopewars.sh' alias fifteen='~/.gnome2/nemo-scripts/Games/Fifteen-Puzzle.sh' alias guessnumber='~/.gnome2/nemo-scripts/Games/Random-Number-Guessing.sh' alias guessword='~/.gnome2/nemo-scripts/Games/Guessword.sh' alias hangman='~/.gnome2/nemo-scripts/Games/Hangman.sh' alias hanoi='~/.gnome2/nemo-scripts/Games/The-Towers-Of-Hanoi.sh' alias knights='~/.gnome2/nemo-scripts/Games/The-Knights-Tour.sh' alias nim='~/.gnome2/nemo-scripts/Games/Game-Of-Nim.sh' alias petals='~/.gnome2/nemo-scripts/Games/Petals-Around-The-Rose.sh' alias quakey='~/.gnome2/nemo-scripts/Games/Quakey.sh' alias statecaps='~/.gnome2/nemo-scripts/Games/State-Capitals.sh' alias worldcaps='~/.gnome2/nemo-scripts/Games/World-Capitals.sh' ###### jokes and quotes alias blondes='shuf -n1 /home/me/.gnome2/nemo-scripts/My_Scripts/Jokes/Blonde-Jokes/.blonde-jokes.txt' alias chuck-norris='shuf -n1 /home/me/.gnome2/nemo-scripts/My_Scripts/Jokes/Chuck-Norris-Jokes/.chuck-norris-jokes.txt' alias famous-quotes='shuf -n1 /home/me/.gnome2/nemo-scripts/My_Scripts/Jokes/Famous-Quotes/.famous-quotes.txt' alias fortune-cookie='shuf -n1 /home/me/.gnome2/nemo-scripts/My_Scripts/Jokes/Fortune-Cookie-Quotes/.fortune-cookie-quotes.txt' alias fun-facts='shuf -n1 /home/me/.gnome2/nemo-scripts/My_Scripts/Jokes/Fun-Facts/.fun-facts.txt' alias one-liners='shuf -n1 /home/me/.gnome2/nemo-scripts/My_Scripts/Jokes/One-Liners/.one-liners.txt' alias yo-mama='shuf -n1 /home/me/.gnome2/nemo-scripts/My_Scripts/Jokes/Yo-Mama-Jokes/.yo-mama-jokes.txt' ###### morsecode alias morse-di='~/.gnome2/nemo-scripts/My_Scripts/MorseCode/MorseCode.pl -d -i' alias morse-ds='~/.gnome2/nemo-scripts/My_Scripts/MorseCode/MorseCode.pl -d -s' alias morse-dt='~/.gnome2/nemo-scripts/My_Scripts/MorseCode/MorseCode.pl -d -t' alias morse-ei='~/.gnome2/nemo-scripts/My_Scripts/MorseCode/MorseCode.pl -e -i' alias morse-es='~/.gnome2/nemo-scripts/My_Scripts/MorseCode/MorseCode.pl -e -s' alias morse-et='~/.gnome2/nemo-scripts/My_Scripts/MorseCode/MorseCode.pl -e -t' alias morse='~/.gnome2/nemo-scripts/My_Scripts/MorseCode/MorseCode.pl' ###### nasa wallpaper (GNOME2 only) alias nasa='~/.gnome2/nemo-scripts/"System Configuration"/"Wallpaper Stuff"/Random-Nasa-Wallpaper.pl' ###### random music alias random-music='~/.gnome2/nemo-scripts/My_Scripts/Random-Music.sh' ################################################## ################################################## ################################################## ###################################################################################################################################################### #----- BASHRC ENDS HERE ------ BASHRC ENDS HERE ------ BASHRC ENDS HERE ------ BASHRC ENDS HERE ------ BASHRC ENDS HERE ------ BASHRC ENDS HERE ------ ###################################################################################################################################################### fi # end interactive check ###################################################################################################################################################### ################################### MY BASHRC FILE ################################### MY BASHRC FILE ################################### MY BASHRC FILE ######################################################################################################################################################