######################################################################## # file: $HOME/.bashrc # available: http://www.guckes.net/Setup/bashrc # purpose: setup file for the shell "bash" # written by: Sven Guckes # feedback: guckes-bashrc(at)guckes.net # Latest change: Sun Nov 27 05:23:42 CET 2016 ######################################################################## AUTHOR="Sven Guckes" EMAIL="bash_help_me@guckes.net" # previous versions: # 2008-11-20,2014-03-20,2015-03-24,2015-05-02,2015-12-15 VERSION=2016-11-27 # display the current version of the shell and the setup file # alias version="echo 'BASH_VERSION='$BASH_VERSION;echo bashrc: 2016-11-27" version () { echo BASH_VERSION=$BASH_VERSION echo bashrc: $VERSION } ######################################################################## # Bash keyboard shortcuts # http://programmingishard.com/code/451 # http://linuxhelp.blogspot.com/2005/08/bash-shell-shortcuts.html ######################################################################## ######################################################################## # Homepage: https://www.gnu.org/software/bash/ # source: ftp://ftp.gnu.org/gnu/bash/ # # maintainer's page: http://tiswww.case.edu/php/chet/bash/bashtop.html # link to latest snapshot: # http://git.savannah.gnu.org/cgit/bash.git/snapshot/bash-master.tar.gz ######################################################################## ######################################################################## # BINDINGS # bind -l -> List the names of all readline functions. # $ bind -l | wc -l # 162 # # bash-3.1.17: bind -l | wc -l --> 146 # bash-4.2.37: bind -l | wc -l --> 159 # bash-4.3.30: bind -l | wc -l --> 162 # bash-4.3.30: bind -p | wc -l --> 480 # bash-4.4.5: bind -p | wc -l --> 483 ######################################################################## # 2008-11-20, 2014-03-20 # help_me is a function which lists info about # commands for key combinations with alt and control # and some common tab expansions. help_me () { cat< IGNOREEOF Ctrl-e end - Move cursor to the end of the line Ctrl-f forward - Move forward a char Ctrl-g glocke - Insert bell character Ctrl-h backspace- Delete the character before cursor Ctrl-i indent - Insert a TAB character, ie use TAB expansion Ctrl-j - Insert a NEWLINE character, ie complete current input Ctrl-k kill - Delete unto end of line (EOL) Ctrl-l cLear - Clear the screen; keep current input line Ctrl-m - Insert a CR character; complete current input Ctrl-n next - next-history - switch to next line in history Ctrl-o - (self-insert) Ctrl-p previous - previous-history - switch to previous line in history Ctrl-q - (self-insert) -> START Ctrl-r reverse - Start incremental reverse search in history backwards Ctrl-R reverse - same as ctrl-r but with multiple occurrences Ctrl-s - forward-search-history Ctrl-t transpose- transpose-chars - switch char under cursor with the one before Ctrl-u undo - unix-line-discard - Delete from current position to begin of line (BOL) Ctrl-v verbose - quoted-insert - Quote the next character for input Ctrl-w word_del - Delete until previous begin of word (BOW) Ctrl-x eXchange - Switch cursor position between BOL and current position Ctrl-x @ - Show possible hostname completions (eg "ssh ^x@") Ctrl-y yank - Insert latest deleted text from kill ring Ctrl-z zzzZZZ - Suspend the current command Key Mnemonic - Description Alt-< . Move to the first line in the history Alt-> . Move to the last line in the history Alt-? . Show current completion list for current pattern Alt-* . Insert all possible completions Alt-/ . Attempt to complete filename Alt-. . Insert last argument of previous commands Alt-b . Move cursor back to previous begin of word (BOW) Alt-c . Capitalize current word Alt-d . Delete to the next end of word (EOW) Alt-f . Move cursor forward to the next start of word (SOW) Alt-l . Lowercase all characters until the next end of word (EOW) Alt-n . Search the history forwards non-incremental Alt-p . Search the history backwards non-incremental Alt-r . Recall command (?) Alt-t transpose Exchange current and previous word Alt-u . Uppercase all characters until the next end of word (EOW) Alt-BS Delete until previous begin of word (BOW) TAB expansion: Here "2T" means Press TAB twice $ (string)2T - All available commands starting with (string) $ 2T - All available commands(common) $ /2T - Entire directory structure including Hidden one $ 2T - Only Sub Dirs inside including Hidden one $ *2T - Only Sub Dirs inside without Hidden one $ ~2T - All Present Users on system from "/etc/passwd" $ $2T - All Sys variables $ @2T - Entries from "/etc/hosts" $ =2T - Output like ls or dir see also: $ man bash /^SHELL BUILTIN COMMANDS /bind example: show file listing of current directory with CTRL-F: bind -x '"\C-f":find . -maxdepth 1 -type f -printf "%AF %AH:%AM %f\n"|less' then type CTRL-F anywhere in the input line to see a listing of files within the current directory. type 'q' to quite "less" and return to the input line. TIP: have you just installed a new version of a command? use "hash -r" to forget the hashes that bash is using. written by $AUTHOR $EMAIL latest change: $VERSION END_OF_HELP } ######################################################################## # source some other setup files as well. # do this first - so further setup can override them. ######################################################################## # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi ######################################################################## # OPTIONS ######################################################################## set bell-style=visual # set editing-mode vi set editing-mode emacs ######################################################################## # PROMPT ######################################################################## # more info: # bash manual, section PROMPTING # $ man bash:q:q # /^PROMPTING # # for the prompt there are quite a few # backslash-escaped special characters: # \@!#$[] ADHTVW adehjlnrstuvw # here are the most commonly used ones: # \u username # \h hostname (without the domain) # \H full hostname, ie with domain # \v version (short) # \V version + patch level # \w full working directory # \W basename of working directory # # IDEA: # use "_" to switch to the short prompt - # and "__" to switch to the long prompt. # # minimal prompt: alias _0='PS1="$ "' alias _=_0 # -> "$ " # # prompt default: alias _1='PS1="[\u@\h \W]\$"' # -> "[guckes@kudu ~]$" # # default as described in the manual # 1999-01-20 and 2001-11-13 (v2.05): alias _2='PS1="\s-\v\$ "' # -> "bash-4.4$" # # showing user and hostname is usually fine: alias _3='PS1="\u@\h> "' # -> "guckes@kudu>" # # .. but to see the working directory (\w) is nicer: alias _4='PS1="\u@\h \w>"' # -> "guckes@kudu /etc>" # # however, there are so many versions of bash around # that i like to *know* which one i'm using right now: # "ooh, baby, that's what ah like!" :-) alias _5='PS1="\V \u@\h:\w> "' # -> "4.4.5 guckes@kudu:/etc>" # # 2020-03-12 # add LINESxCOLUMNS: alias _6='PS1="\V ${LINES}x${COLUMNS} \u@\h:\w>"' # my personal choice: alias __=_5 # use it now: _5 # 2016-11-27 TODO: make "_" a function # which switches between short and long prompt. ######################################################################## # internal variables ######################################################################## # CDPATH - when you "cd dirname" let bash test these directories, too: CDPATH=..:~/.P:~/.P/EVENTS:~/.P/PERSONS: # MAILPATH - check for changes in files # MAILPATH=/var/spool/mail/$USER # for i in `echo ~/Mail.IN/*` # do # MAILPATH=$MAILPATH:$i # done # export MAILPATH # unset i # def_path should reset the $PATH to a useful default value: alias def_path='/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games' # PATH # the $PATH should have my binaries+scripts from ~/bin first: PATH=~/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games # 2005-01-08 # cdable_vars: # If set, an argument to the cd builtin command that # is not a directory is assumed to be the name of a # variable whose value is the directory to change to. # # example: # $ FOO=/usr/share/doc # $ cd foo # bash: cd: foo: Not a directory # $ cd FOO # /usr/share/doc # $ pwd # /usr/share/doc ######################################################################## # HISTORY -> # HISTCMD HISTCONTROL HISTFILE HISTFILESIZE HISTSIZE HISTIGNORE HISTTIMEFORMAT ######################################################################## # 2016-11-27 HISTFILE=~/.bash_history # 2015-12-15, 2016-11-27 HISTFILESIZE=-23 # negative: unlimited! HISTSIZE=-42 # negative: unlimited! # 2015-12-15 HISTCONTROL=ignoreboth # "A value of ignoreboth is shorthand for ignorespace and ignoredups." # If the list of values includes "ignorespace", # lines which begin with a space character # are not saved in the history list. # A value of "ignoredups" causes lines matching # the previous history entry to not be saved. # 2015-12-15 export HISTIGNORE=\ "bg:cd:date:df:du:exit:fg:history:ll:ls:mutt:neomutt:pwd:rehash:source:su:sudo:top:w" # 2015-12-15 HISTTIMEFORMAT='%F %T ' # example: "2016-11-27 05:42:23" # 2015-12-15 # PROMPT_COMMAND='history -a' # 2005-01-08 shopt -s cmdhist lithist # SHELL BUILTIN COMMANDS -> shopt -> cmdhist: # cmdhist: If set, bash attempts to save all lines of # a multiple-line command in the same history entry. # This allows easy re-editing of multi-line commands. # SHELL BUILTIN COMMANDS -> shopt -> lithist: # If set, and the cmdhist option is enabled, multi-line # commands are saved to the history with embedded newlines # rather than using semicolon separators where possible. # 2015-12-15 shopt -s histappend # 2015-12-15 shopt -s cmdhist ######################################################################## # exported variables ######################################################################## # tell "bc" where to find its setup file # (no, it does not look for ~/.bcrc itself - go figure) # export BC_ENV_ARGS=/home/guckes/.bcrc export BC_ENV_ARGS=$HOME/.bcrc # colorful output for GNU ls - coloring by extension: export LS_COLORS='no=0:fi=0:di=32:ln=36:or=1;40:mi=1;40:pi=31:so=33:bd=44;37:cd=44;37:ex=35:*.jpg=1;32:*.jpeg=1;32:*.JPG=1;32:*.gif=1;32:*.png=1;32:*.jpeg=1;32:*.ppm=1;32:*.pgm=1;32:*.pbm=1;32:*.c=1;33:*.C=1;33:*.h=1;33:*.cc=1;33:*.awk=1;33:*.pl=1;33:*.gz=1;31:*.tar=1;31:*.zip=1;31:*.lha=1;31:*.lzh=1;31:*.arj=1;31:*.tgz=1;31:*.taz=1;31:*.html=1;34:*.htm=1;34:*.doc=1;34:*.txt=1;34:*.o=1;36:*.a=1;36' # TODO: include all that stuff about DIRCOLORS # my default editor! # www.vim.org export EDITOR=vim # my default PAGER! # "less is more"! :-) export PAGER=less # try also: "most" ##==================================================== # ALIASES! ##==================================================== # use "l file" to "look (at) file": alias l=$PAGER # example: l /etc/passwd # common abbreviation for # "list in long style": alias ll="ls -l" # example: ll /etc/passwd # list "reverse time and long": alias lsnew='ls -rtl | tail' # use "lsnew -20" to list the latest *20* files. alias lsold='ls -tl | head' # "list directories" # show (current dir's) subdirectories only: alias lsd='ls -d $(find . -maxdepth 1 -type d)' alias lld='ls -dl $(find . -maxdepth 1 -type d)' # list big files: # alias lsbig='gls -lS `find . -type f` | head' # note: makes use of option "-S" which # is only available with "GNU ls". # TODO : got to add a test for "ls" # whether it is a GNU version or not. # list the dot files of the current directory: # alias lsdots='ls -adCG `find . -type f .??*`' # LarsWM Window Manager [http://www.fnurt.net/larswm]: # display the exact time as taken from # the time server here at the Free University Berlin: # alias START='larsremote message `telnet time.fu-berlin.de 13|grep :`' # query the time of the time server au Free University Berlin: alias futime='/usr/sbin/ntpdate -q time.fu-berlin.de' # note: usually takes some six seconds to respond. # this stuff resets terminals. unfortunately lost a reference. alias vtn='echo "X[mX(BX)0OX[?5lX7X[rX8" | tr "XO" "\033\017"' ##==================================================== # KNOPPIX setup ##==================================================== # for work from one a machine running knoppix. if [ `hostname` == Knoppix ]; then # Knoppix 3.4 now has "links" on it - yay! :-) BROWSER=links # special prompt # PS1='\v guckes@knoppix:\w> ' PS1='\u@knoppix:\w> ' # Aliases alias k='screen -t KUDU ssh guckes@kudu.in-berlin.de' # knoppix does not give these aliases per default: alias la='ls -lA --color=auto' # 'A': do no show '.' and '..' dirs alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias which="type -path" alias getsetup='wget http://www.guckes.net/Setup/bashrc -O ~/.bashrc' # querying and setting the current time from a time server: TIMESERVER=time.fu-berlin.de alias dt=" /usr/sbin/ntpdate -q $TIMESERVER" alias DT="sudo /usr/sbin/ntpdate $TIMESERVER" fi ##==================================================== ## OLD stuff ##==================================================== # Anyone remember ISDN? # Checking the ISDN logs on home machine: # alias ONLINE="isdnctrl dial ippp0" # alias OFFLINE="isdnctrl hangup ippp0" # alias STATUS="isdnctrl status ippp0" # alias CALLS="grep 'call from' /var/log/messages | less +G" ##==================================================== ## Dvorak ##==================================================== # on the "normal" (read: US) keyboard and # on the Dvorak keyboard both the 'a' and 'm' # have the same location. so here are two # aliases which switch to either of these: # "come home to 'mama'!" alias mama='loadkeys us' # krauts would rather spell it "Mamma" - so that's # the one to switch to the German layout: alias mamma='loadkeys de-latin1-nodeadkeys' # and here's to switch to dvorak: alias dvorak='loadkeys dvorak' alias mamama='loadkeys dvorak' alias h.soav='loadkeys dvorak' # 2010-06-20, 2015-03-24 # color test #_color_test () { # for code in {000..255}; do # echo -n -e "\e[38;05;${code}m [$code]" # if [[ $(($code%8)) == 7 ]]; then echo; fi # done # } # catch with "less -r" # # 2015-09-11 bash chokes on numbers with leading zeros: # echo $(( 08%8 )) # -> 'bash: 08: value too great for base (error token is "08")' # 2016-11-29 still true for bash-4.4.5 # 2015-05-02 # switching back to the $OLDPWD # requires /version # alias -- -='cd -' # TODO # us2dvorak: simulate the output when typing on a keyboard # with US layout - but output is in dvorak layout: alias us2dvorak='tr qwertyuiop[]asdfghjkl\;\"zxcvbnm,./ \",.pyfgcrl/=aoeuidhtns[-]\;qjkxbmwvz' # us upper: qwertyuiop[] # dvorak upper: ',.pyfgcrl/= # --------------------------------- # us middle: asdfghjkl;' # dvorak middle: aoeuidhtns- # --------------------------------- # us bottom: zxcvbnm,./ # dvorak bottom: ;qjkxbmwvz # bind -p -> Display readline function names and # bindings in such a way that they can be re-read. # slurp contents of a file into the clipboard: xs () { xsel -b < $1 } # show what currently is in the clipboard: xp () { xsel --clipboard --output } # 2015-11-02, 2015-11-20 # GNU screen - load special sessions alias scm='screen -c ~/.screenrc.monitor' alias scw='screen -c ~/.screenrc.work' # vim: set et ft=sh sw=4: THPXRF EOF