{"id":487,"date":"2012-11-11T14:03:33","date_gmt":"2012-11-11T14:03:33","guid":{"rendered":"http:\/\/blog.bachi.net\/?p=487"},"modified":"2019-08-06T16:44:41","modified_gmt":"2019-08-06T16:44:41","slug":"bash-prompt","status":"publish","type":"post","link":"https:\/\/blog.bachi.net\/?p=487","title":{"rendered":"Bash prompt"},"content":{"rendered":"<p><a href=\"http:\/\/unix.stackexchange.com\/questions\/2897\/clicolor-and-ls-colors-in-bash\">CLICOLOR and LS_COLORS in bash<\/a><br \/>\n<a href=\"http:\/\/unix.stackexchange.com\/questions\/94299\/dircolors-modify-color-settings-globaly\">dircolors: modify color settings globaly<\/a><br \/>\n<a href=\"http:\/\/linux-sxs.org\/housekeeping\/lscolors.html\">COLORS-Lscolors<\/a><\/p>\n<pre class=\"brush: bash; title: .profile; notranslate\" title=\".profile\">\r\nif &#x5B; -f ~\/.bashrc ]; then\r\n      . ~\/.bashrc\r\nfi\r\n\r\n# .profile doesn't been parsed by &quot;su&quot;\r\nif &#x5B; -f \/usr\/local\/etc\/bashrc ]; then\r\n      . \/usr\/local\/etc\/bashrc\r\nfi\r\n\r\n<\/pre>\n<p><a href=\"http:\/\/askubuntu.com\/questions\/145618\/how-can-i-shorten-my-command-line-bash-prompt\">How can I shorten my command line (bash) prompt?<\/a><br \/>\n<a href=\"https:\/\/wiki.archlinux.org\/index.php\/Color_Bash_Prompt\">Color Bash Prompt<\/a><br \/>\n<a href=\"http:\/\/ithaca.arpinum.org\/2013\/01\/02\/git-prompt.html\">Don\u2019t Reinvent the Wheel<\/a><\/p>\n<pre class=\"brush: bash; title: trim path; notranslate\" title=\"trim path\">\r\nPROMPT_DIRTRIM=3\r\n<\/pre>\n<pre class=\"brush: bash; title: Linux File\/Directory; notranslate\" title=\"Linux File\/Directory\">\r\nLS_COLORS=&quot;rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:&quot;\r\n<\/pre>\n<pre class=\"brush: bash; title: FreeBSD File\/Directory; notranslate\" title=\"FreeBSD File\/Directory\">\r\nCLICOLOR=yes\r\nLSCOLORS=Exfxcxdxbxegedabagacad\r\n<\/pre>\n<pre class=\"brush: bash; title: Common; notranslate\" title=\"Common\">\r\nTITLEBAR='\\&#x5B;\\e]0;\\u@\\h: \\w\\a\\]'\r\n\r\nNONE=&quot;\\&#x5B;&#92;&#48;33&#x5B;0m\\]&quot;    # unsets color to term's fg color\r\n\r\n# regular colors\r\nK=&quot;\\&#x5B;&#92;&#48;33&#x5B;0;30m\\]&quot;    # black\r\nR=&quot;\\&#x5B;&#92;&#48;33&#x5B;0;31m\\]&quot;    # red\r\nG=&quot;\\&#x5B;&#92;&#48;33&#x5B;0;32m\\]&quot;    # green\r\nY=&quot;\\&#x5B;&#92;&#48;33&#x5B;0;33m\\]&quot;    # yellow\r\nB=&quot;\\&#x5B;&#92;&#48;33&#x5B;0;34m\\]&quot;    # blue\r\nM=&quot;\\&#x5B;&#92;&#48;33&#x5B;0;35m\\]&quot;    # magenta\r\nC=&quot;\\&#x5B;&#92;&#48;33&#x5B;0;36m\\]&quot;    # cyan\r\nW=&quot;\\&#x5B;&#92;&#48;33&#x5B;0;37m\\]&quot;    # white\r\n\r\n# emphasized (bolded) colors\r\nEMK=&quot;\\&#x5B;&#92;&#48;33&#x5B;1;30m\\]&quot;\r\nEMR=&quot;\\&#x5B;&#92;&#48;33&#x5B;1;31m\\]&quot;\r\nEMG=&quot;\\&#x5B;&#92;&#48;33&#x5B;1;32m\\]&quot;\r\nEMY=&quot;\\&#x5B;&#92;&#48;33&#x5B;1;33m\\]&quot;\r\nEMB=&quot;\\&#x5B;&#92;&#48;33&#x5B;1;34m\\]&quot;\r\nEMM=&quot;\\&#x5B;&#92;&#48;33&#x5B;1;35m\\]&quot;\r\nEMC=&quot;\\&#x5B;&#92;&#48;33&#x5B;1;36m\\]&quot;\r\nEMW=&quot;\\&#x5B;&#92;&#48;33&#x5B;1;37m\\]&quot;\r\n\r\n# background colors\r\nBGK=&quot;\\&#x5B;&#92;&#48;33&#x5B;40m\\]&quot;\r\nBGR=&quot;\\&#x5B;&#92;&#48;33&#x5B;41m\\]&quot;\r\nBGG=&quot;\\&#x5B;&#92;&#48;33&#x5B;42m\\]&quot;\r\nBGY=&quot;\\&#x5B;&#92;&#48;33&#x5B;43m\\]&quot;\r\nBGB=&quot;\\&#x5B;&#92;&#48;33&#x5B;44m\\]&quot;\r\nBGM=&quot;\\&#x5B;&#92;&#48;33&#x5B;45m\\]&quot;\r\nBGC=&quot;\\&#x5B;&#92;&#48;33&#x5B;46m\\]&quot;\r\nBGW=&quot;\\&#x5B;&#92;&#48;33&#x5B;47m\\]&quot;\r\n\r\nUC=$EMW               # user's color\r\n&#x5B; $UID -eq &quot;0&quot; ] &amp;&amp; UC=$R   # root's color\r\n\r\nPS1=&quot;${TITLEBAR}${EMR}&#x5B;${UC}\\u${EMR}@${UC}\\h ${EMB}\\w${EMR}]${UC}\\\\$ ${NONE}&quot;\r\n<\/pre>\n<pre class=\"brush: bash; title: PS1 with trimmed path support; notranslate\" title=\"PS1 with trimmed path support\">\r\n#!\/usr\/bin\/env bash\r\n \r\n# Linux\r\n#export LS_COLORS=&quot;rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:&quot;\r\neval &quot;$(dircolors -b \/etc\/DIR_COLORS)&quot;\r\nalias ls='ls -F --color --show-control-chars'\r\n\r\n# FreeBSD\r\nDIR=Ex\r\nSYM_LINK=Gx\r\nSOCKET=Fx\r\nPIPE=dx\r\nEXE=Cx\r\nBLOCK_SP=Dx\r\nCHAR_SP=Dx\r\nEXE_SUID=hb\r\nEXE_GUID=ad\r\nDIR_STICKY=Ex\r\nDIR_WO_STICKY=Ex\r\nexport LSCOLORS=&quot;$DIR$SYM_LINK$SOCKET$PIPE$EXE$BLOCK_SP$CHAR_SP$EXE_SUID$EXE_GUID$DIR_STICKY$DIR_WO_STICKY&quot;\r\nexport CLICOLOR=&quot;YES&quot;\r\n \r\nbash_prompt_command() {\r\n    # How many characters of the $PWD should be kept\r\n    local pwdmaxlen=30\r\n    # Indicate that there has been dir truncation\r\n    local trunc_symbol=&quot;..&quot;\r\n    local dir=${PWD##*\/}\r\n    pwdmaxlen=$(( ( pwdmaxlen &lt; ${#dir} ) ? ${#dir} : pwdmaxlen ))\r\n    NEW_PWD=${PWD\/#$HOME\/\\~}\r\n    local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))\r\n    if &#x5B; ${pwdoffset} -gt &quot;0&quot; ]\r\n    then\r\n        NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}\r\n        NEW_PWD=${trunc_symbol}\/${NEW_PWD#*\/}\r\n    fi\r\n}\r\n \r\nbash_prompt() {\r\n    case $TERM in\r\n     xterm*|rxvt*)\r\n         local TITLEBAR='\\&#x5B;&#92;&#48;33]0;\\u:${NEW_PWD}&#92;&#48;07\\]'\r\n          ;;\r\n     *)\r\n         local TITLEBAR=&quot;&quot;\r\n          ;;\r\n    esac\r\n    local NONE=&quot;\\&#x5B;&#92;&#48;33&#x5B;0m\\]&quot;    # unsets color to term's fg color\r\n \r\n    # regular colors\r\n    local K=&quot;\\&#x5B;&#92;&#48;33&#x5B;0;30m\\]&quot;    # black\r\n    local R=&quot;\\&#x5B;&#92;&#48;33&#x5B;0;31m\\]&quot;    # red\r\n    local G=&quot;\\&#x5B;&#92;&#48;33&#x5B;0;32m\\]&quot;    # green\r\n    local Y=&quot;\\&#x5B;&#92;&#48;33&#x5B;0;33m\\]&quot;    # yellow\r\n    local B=&quot;\\&#x5B;&#92;&#48;33&#x5B;0;34m\\]&quot;    # blue\r\n    local M=&quot;\\&#x5B;&#92;&#48;33&#x5B;0;35m\\]&quot;    # magenta\r\n    local C=&quot;\\&#x5B;&#92;&#48;33&#x5B;0;36m\\]&quot;    # cyan\r\n    local W=&quot;\\&#x5B;&#92;&#48;33&#x5B;0;37m\\]&quot;    # white\r\n \r\n    # emphasized (bolded) colors\r\n    local EMK=&quot;\\&#x5B;&#92;&#48;33&#x5B;1;30m\\]&quot;\r\n    local EMR=&quot;\\&#x5B;&#92;&#48;33&#x5B;1;31m\\]&quot;\r\n    local EMG=&quot;\\&#x5B;&#92;&#48;33&#x5B;1;32m\\]&quot;\r\n    local EMY=&quot;\\&#x5B;&#92;&#48;33&#x5B;1;33m\\]&quot;\r\n    local EMB=&quot;\\&#x5B;&#92;&#48;33&#x5B;1;34m\\]&quot;\r\n    local EMM=&quot;\\&#x5B;&#92;&#48;33&#x5B;1;35m\\]&quot;\r\n    local EMC=&quot;\\&#x5B;&#92;&#48;33&#x5B;1;36m\\]&quot;\r\n    local EMW=&quot;\\&#x5B;&#92;&#48;33&#x5B;1;37m\\]&quot;\r\n \r\n    # background colors\r\n    local BGK=&quot;\\&#x5B;&#92;&#48;33&#x5B;40m\\]&quot;\r\n    local BGR=&quot;\\&#x5B;&#92;&#48;33&#x5B;41m\\]&quot;\r\n    local BGG=&quot;\\&#x5B;&#92;&#48;33&#x5B;42m\\]&quot;\r\n    local BGY=&quot;\\&#x5B;&#92;&#48;33&#x5B;43m\\]&quot;\r\n    local BGB=&quot;\\&#x5B;&#92;&#48;33&#x5B;44m\\]&quot;\r\n    local BGM=&quot;\\&#x5B;&#92;&#48;33&#x5B;45m\\]&quot;\r\n    local BGC=&quot;\\&#x5B;&#92;&#48;33&#x5B;46m\\]&quot;\r\n    local BGW=&quot;\\&#x5B;&#92;&#48;33&#x5B;47m\\]&quot;\r\n \r\n    local UC=$EMW               # user's color\r\n    &#x5B; $UID -eq &quot;0&quot; ] &amp;&amp; UC=$R   # root's color\r\n \r\n    PS1=&quot;${TITLEBAR}${EMR}&#x5B;${UC}\\u${EMR}@${UC}\\h ${EMB}\\${NEW_PWD}${EMR}]${UC}\\\\$ ${NONE}&quot;\r\n \r\n    # without colors: PS1=&quot;&#x5B;\\u@\\h \\${NEW_PWD}]\\\\$ &quot;\r\n    # extra backslash in front of \\$ to make bash colorize the prompt\r\n}\r\n \r\nPROMPT_COMMAND=bash_prompt_command\r\nbash_prompt\r\n<\/pre>\n<pre class=\"brush: bash; collapse: true; light: false; title: Emmanuel Rouat&#039;s ~\/.bashrc; toolbar: true; notranslate\" title=\"Emmanuel Rouat&#039;s ~\/.bashrc\">\r\n# =============================================================== #\r\n#\r\n# PERSONAL $HOME\/.bashrc FILE for bash-3.0 (or later)\r\n# By Emmanuel Rouat &#x5B;no-email]\r\n#\r\n# Last modified: Tue Nov 20 22:04:47 CET 2012\r\n\r\n#  This file is normally read by interactive shells only.\r\n#+ Here is the place to define your aliases, functions and\r\n#+ other interactive features like your prompt.\r\n#\r\n#  The majority of the code here assumes you are on a GNU\r\n#+ system (most likely a Linux box) and is often based on code\r\n#+ found on Usenet or Internet.\r\n#\r\n#  See for instance:\r\n#  http:\/\/tldp.org\/LDP\/abs\/html\/index.html\r\n#  http:\/\/www.caliban.org\/bash\r\n#  http:\/\/www.shelldorado.com\/scripts\/categories.html\r\n#  http:\/\/www.dotfiles.org\r\n#\r\n#  The choice of colors was done for a shell with a dark background\r\n#+ (white on black), and this is usually also suited for pure text-mode\r\n#+ consoles (no X server available). If you use a white background,\r\n#+ you'll have to do some other choices for readability.\r\n#\r\n#  This bashrc file is a bit overcrowded.\r\n#  Remember, it is just just an example.\r\n#  Tailor it to your needs.\r\n#\r\n# =============================================================== #\r\n\r\n# --&gt; Comments added by HOWTO author.\r\n\r\n# If not running interactively, don't do anything\r\n&#x5B; -z &quot;$PS1&quot; ] &amp;&amp; return\r\n\r\n\r\n#-------------------------------------------------------------\r\n# Source global definitions (if any)\r\n#-------------------------------------------------------------\r\n\r\n\r\nif &#x5B; -f \/etc\/bashrc ]; then\r\n      . \/etc\/bashrc   # --&gt; Read \/etc\/bashrc, if present.\r\nfi\r\n\r\n\r\n#--------------------------------------------------------------\r\n#  Automatic setting of $DISPLAY (if not set already).\r\n#  This works for me - your mileage may vary. . . .\r\n#  The problem is that different types of terminals give\r\n#+ different answers to 'who am i' (rxvt in particular can be\r\n#+ troublesome) - however this code seems to work in a majority\r\n#+ of cases.\r\n#--------------------------------------------------------------\r\n\r\nfunction get_xserver ()\r\n{\r\n    case $TERM in\r\n        xterm )\r\n            XSERVER=$(who am i | awk '{print $NF}' | tr -d ')''(' )\r\n            # Ane-Pieter Wieringa suggests the following alternative:\r\n            #  I_AM=$(who am i)\r\n            #  SERVER=${I_AM#*(}\r\n            #  SERVER=${SERVER%*)}\r\n            XSERVER=${XSERVER%%:*}\r\n            ;;\r\n            aterm | rxvt)\r\n            # Find some code that works here. ...\r\n            ;;\r\n    esac\r\n}\r\n\r\nif &#x5B; -z ${DISPLAY:=&quot;&quot;} ]; then\r\n    get_xserver\r\n    if &#x5B;&#x5B; -z ${XSERVER}  || ${XSERVER} == $(hostname) ||\r\n       ${XSERVER} == &quot;unix&quot; ]]; then\r\n          DISPLAY=&quot;:0.0&quot;          # Display on local host.\r\n    else\r\n       DISPLAY=${XSERVER}:0.0     # Display on remote host.\r\n    fi\r\nfi\r\n\r\nexport DISPLAY\r\n\r\n#-------------------------------------------------------------\r\n# Some settings\r\n#-------------------------------------------------------------\r\n\r\n#set -o nounset     # These  two options are useful for debugging.\r\n#set -o xtrace\r\nalias debug=&quot;set -o nounset; set -o xtrace&quot;\r\n\r\nulimit -S -c 0      # Don't want coredumps.\r\nset -o notify\r\nset -o noclobber\r\nset -o ignoreeof\r\n\r\n\r\n# Enable options:\r\nshopt -s cdspell\r\nshopt -s cdable_vars\r\nshopt -s checkhash\r\nshopt -s checkwinsize\r\nshopt -s sourcepath\r\nshopt -s no_empty_cmd_completion\r\nshopt -s cmdhist\r\nshopt -s histappend histreedit histverify\r\nshopt -s extglob       # Necessary for programmable completion.\r\n\r\n# Disable options:\r\nshopt -u mailwarn\r\nunset MAILCHECK        # Don't want my shell to warn me of incoming mail.\r\n\r\n\r\n#-------------------------------------------------------------\r\n# Greeting, motd etc. ...\r\n#-------------------------------------------------------------\r\n\r\n# Color definitions (taken from Color Bash Prompt HowTo).\r\n# Some colors might look different of some terminals.\r\n# For example, I see 'Bold Red' as 'orange' on my screen,\r\n# hence the 'Green' 'BRed' 'Red' sequence I often use in my prompt.\r\n\r\n\r\n# Normal Colors\r\nBlack='\\e&#x5B;0;30m'        # Black\r\nRed='\\e&#x5B;0;31m'          # Red\r\nGreen='\\e&#x5B;0;32m'        # Green\r\nYellow='\\e&#x5B;0;33m'       # Yellow\r\nBlue='\\e&#x5B;0;34m'         # Blue\r\nPurple='\\e&#x5B;0;35m'       # Purple\r\nCyan='\\e&#x5B;0;36m'         # Cyan\r\nWhite='\\e&#x5B;0;37m'        # White\r\n\r\n# Bold\r\nBBlack='\\e&#x5B;1;30m'       # Black\r\nBRed='\\e&#x5B;1;31m'         # Red\r\nBGreen='\\e&#x5B;1;32m'       # Green\r\nBYellow='\\e&#x5B;1;33m'      # Yellow\r\nBBlue='\\e&#x5B;1;34m'        # Blue\r\nBPurple='\\e&#x5B;1;35m'      # Purple\r\nBCyan='\\e&#x5B;1;36m'        # Cyan\r\nBWhite='\\e&#x5B;1;37m'       # White\r\n\r\n# Background\r\nOn_Black='\\e&#x5B;40m'       # Black\r\nOn_Red='\\e&#x5B;41m'         # Red\r\nOn_Green='\\e&#x5B;42m'       # Green\r\nOn_Yellow='\\e&#x5B;43m'      # Yellow\r\nOn_Blue='\\e&#x5B;44m'        # Blue\r\nOn_Purple='\\e&#x5B;45m'      # Purple\r\nOn_Cyan='\\e&#x5B;46m'        # Cyan\r\nOn_White='\\e&#x5B;47m'       # White\r\n\r\nNC=&quot;\\e&#x5B;m&quot;               # Color Reset\r\n\r\n\r\nALERT=${BWhite}${On_Red} # Bold White on red background\r\n\r\n\r\n\r\necho -e &quot;${BCyan}This is BASH ${BRed}${BASH_VERSION%.*}${BCyan}\\\r\n- DISPLAY on ${BRed}$DISPLAY${NC}\\n&quot;\r\ndate\r\nif &#x5B; -x \/usr\/games\/fortune ]; then\r\n    \/usr\/games\/fortune -s     # Makes our day a bit more fun.... :-)\r\nfi\r\n\r\nfunction _exit()              # Function to run upon exit of shell.\r\n{\r\n    echo -e &quot;${BRed}Hasta la vista, baby${NC}&quot;\r\n}\r\ntrap _exit EXIT\r\n\r\n#-------------------------------------------------------------\r\n# Shell Prompt - for many examples, see:\r\n#       http:\/\/www.debian-administration.org\/articles\/205\r\n#       http:\/\/www.askapache.com\/linux\/bash-power-prompt.html\r\n#       http:\/\/tldp.org\/HOWTO\/Bash-Prompt-HOWTO\r\n#       https:\/\/github.com\/nojhan\/liquidprompt\r\n#-------------------------------------------------------------\r\n# Current Format: &#x5B;TIME USER@HOST PWD] &gt;\r\n# TIME:\r\n#    Green     == machine load is low\r\n#    Orange    == machine load is medium\r\n#    Red       == machine load is high\r\n#    ALERT     == machine load is very high\r\n# USER:\r\n#    Cyan      == normal user\r\n#    Orange    == SU to user\r\n#    Red       == root\r\n# HOST:\r\n#    Cyan      == local session\r\n#    Green     == secured remote connection (via ssh)\r\n#    Red       == unsecured remote connection\r\n# PWD:\r\n#    Green     == more than 10% free disk space\r\n#    Orange    == less than 10% free disk space\r\n#    ALERT     == less than 5% free disk space\r\n#    Red       == current user does not have write privileges\r\n#    Cyan      == current filesystem is size zero (like \/proc)\r\n# &gt;:\r\n#    White     == no background or suspended jobs in this shell\r\n#    Cyan      == at least one background job in this shell\r\n#    Orange    == at least one suspended job in this shell\r\n#\r\n#    Command is added to the history file each time you hit enter,\r\n#    so it's available to all shells (using 'history -a').\r\n\r\n\r\n# Test connection type:\r\nif &#x5B; -n &quot;${SSH_CONNECTION}&quot; ]; then\r\n    CNX=${Green}        # Connected on remote machine, via ssh (good).\r\nelif &#x5B;&#x5B; &quot;${DISPLAY%%:0*}&quot; != &quot;&quot; ]]; then\r\n    CNX=${ALERT}        # Connected on remote machine, not via ssh (bad).\r\nelse\r\n    CNX=${BCyan}        # Connected on local machine.\r\nfi\r\n\r\n# Test user type:\r\nif &#x5B;&#x5B; ${USER} == &quot;root&quot; ]]; then\r\n    SU=${Red}           # User is root.\r\nelif &#x5B;&#x5B; ${USER} != $(logname) ]]; then\r\n    SU=${BRed}          # User is not login user.\r\nelse\r\n    SU=${BCyan}         # User is normal (well ... most of us are).\r\nfi\r\n\r\n\r\n\r\nNCPU=$(grep -c 'processor' \/proc\/cpuinfo)    # Number of CPUs\r\nSLOAD=$(( 100*${NCPU} ))        # Small load\r\nMLOAD=$(( 200*${NCPU} ))        # Medium load\r\nXLOAD=$(( 400*${NCPU} ))        # Xlarge load\r\n\r\n# Returns system load as percentage, i.e., '40' rather than '0.40)'.\r\nfunction load()\r\n{\r\n    local SYSLOAD=$(cut -d &quot; &quot; -f1 \/proc\/loadavg | tr -d '.')\r\n    # System load of the current host.\r\n    echo $((10#$SYSLOAD))       # Convert to decimal.\r\n}\r\n\r\n# Returns a color indicating system load.\r\nfunction load_color()\r\n{\r\n    local SYSLOAD=$(load)\r\n    if &#x5B; ${SYSLOAD} -gt ${XLOAD} ]; then\r\n        echo -en ${ALERT}\r\n    elif &#x5B; ${SYSLOAD} -gt ${MLOAD} ]; then\r\n        echo -en ${Red}\r\n    elif &#x5B; ${SYSLOAD} -gt ${SLOAD} ]; then\r\n        echo -en ${BRed}\r\n    else\r\n        echo -en ${Green}\r\n    fi\r\n}\r\n\r\n# Returns a color according to free disk space in $PWD.\r\nfunction disk_color()\r\n{\r\n    if &#x5B; ! -w &quot;${PWD}&quot; ] ; then\r\n        echo -en ${Red}\r\n        # No 'write' privilege in the current directory.\r\n    elif &#x5B; -s &quot;${PWD}&quot; ] ; then\r\n        local used=$(command df -P &quot;$PWD&quot; |\r\n                   awk 'END {print $5} {sub(\/%\/,&quot;&quot;)}')\r\n        if &#x5B; ${used} -gt 95 ]; then\r\n            echo -en ${ALERT}           # Disk almost full (&gt;95%).\r\n        elif &#x5B; ${used} -gt 90 ]; then\r\n            echo -en ${BRed}            # Free disk space almost gone.\r\n        else\r\n            echo -en ${Green}           # Free disk space is ok.\r\n        fi\r\n    else\r\n        echo -en ${Cyan}\r\n        # Current directory is size '0' (like \/proc, \/sys etc).\r\n    fi\r\n}\r\n\r\n# Returns a color according to running\/suspended jobs.\r\nfunction job_color()\r\n{\r\n    if &#x5B; $(jobs -s | wc -l) -gt &quot;0&quot; ]; then\r\n        echo -en ${BRed}\r\n    elif &#x5B; $(jobs -r | wc -l) -gt &quot;0&quot; ] ; then\r\n        echo -en ${BCyan}\r\n    fi\r\n}\r\n\r\n# Adds some text in the terminal frame (if applicable).\r\n\r\n\r\n# Now we construct the prompt.\r\nPROMPT_COMMAND=&quot;history -a&quot;\r\ncase ${TERM} in\r\n  *term | rxvt | linux)\r\n        PS1=&quot;\\&#x5B;\\$(load_color)\\]&#x5B;\\A\\&#x5B;${NC}\\] &quot;\r\n        # Time of day (with load info):\r\n        PS1=&quot;\\&#x5B;\\$(load_color)\\]&#x5B;\\A\\&#x5B;${NC}\\] &quot;\r\n        # User@Host (with connection type info):\r\n        PS1=${PS1}&quot;\\&#x5B;${SU}\\]\\u\\&#x5B;${NC}\\]@\\&#x5B;${CNX}\\]\\h\\&#x5B;${NC}\\] &quot;\r\n        # PWD (with 'disk space' info):\r\n        PS1=${PS1}&quot;\\&#x5B;\\$(disk_color)\\]\\W]\\&#x5B;${NC}\\] &quot;\r\n        # Prompt (with 'job' info):\r\n        PS1=${PS1}&quot;\\&#x5B;\\$(job_color)\\]&gt;\\&#x5B;${NC}\\] &quot;\r\n        # Set title of current xterm:\r\n        PS1=${PS1}&quot;\\&#x5B;\\e]0;&#x5B;\\u@\\h] \\w\\a\\]&quot;\r\n        ;;\r\n    *)\r\n        PS1=&quot;(\\A \\u@\\h \\W) &gt; &quot; # --&gt; PS1=&quot;(\\A \\u@\\h \\w) &gt; &quot;\r\n                               # --&gt; Shows full pathname of current dir.\r\n        ;;\r\nesac\r\n\r\n\r\n\r\nexport TIMEFORMAT=$'\\nreal %3R\\tuser %3U\\tsys %3S\\tpcpu %P\\n'\r\nexport HISTIGNORE=&quot;&amp;:bg:fg:ll:h&quot;\r\nexport HISTTIMEFORMAT=&quot;$(echo -e ${BCyan})&#x5B;%d\/%m %H:%M:%S]$(echo -e ${NC}) &quot;\r\nexport HISTCONTROL=ignoredups\r\nexport HOSTFILE=$HOME\/.hosts    # Put a list of remote hosts in ~\/.hosts\r\n\r\n\r\n#============================================================\r\n#\r\n#  ALIASES AND FUNCTIONS\r\n#\r\n#  Arguably, some functions defined here are quite big.\r\n#  If you want to make this file smaller, these functions can\r\n#+ be converted into scripts and removed from here.\r\n#\r\n#============================================================\r\n\r\n#-------------------\r\n# Personnal Aliases\r\n#-------------------\r\n\r\nalias rm='rm -i'\r\nalias cp='cp -i'\r\nalias mv='mv -i'\r\n# -&gt; Prevents accidentally clobbering files.\r\nalias mkdir='mkdir -p'\r\n\r\nalias h='history'\r\nalias j='jobs -l'\r\nalias which='type -a'\r\nalias ..='cd ..'\r\n\r\n# Pretty-print of some PATH variables:\r\nalias path='echo -e ${PATH\/\/:\/\\\\n}'\r\nalias libpath='echo -e ${LD_LIBRARY_PATH\/\/:\/\\\\n}'\r\n\r\n\r\nalias du='du -kh'    # Makes a more readable output.\r\nalias df='df -kTh'\r\n\r\n#-------------------------------------------------------------\r\n# The 'ls' family (this assumes you use a recent GNU ls).\r\n#-------------------------------------------------------------\r\n# Add colors for filetype and  human-readable sizes by default on 'ls':\r\nalias ls='ls -h --color'\r\nalias lx='ls -lXB'         #  Sort by extension.\r\nalias lk='ls -lSr'         #  Sort by size, biggest last.\r\nalias lt='ls -ltr'         #  Sort by date, most recent last.\r\nalias lc='ls -ltcr'        #  Sort by\/show change time,most recent last.\r\nalias lu='ls -ltur'        #  Sort by\/show access time,most recent last.\r\n\r\n# The ubiquitous 'll': directories first, with alphanumeric sorting:\r\nalias ll=&quot;ls -lv --group-directories-first&quot;\r\nalias lm='ll |more'        #  Pipe through 'more'\r\nalias lr='ll -R'           #  Recursive ls.\r\nalias la='ll -A'           #  Show hidden files.\r\nalias tree='tree -Csuh'    #  Nice alternative to 'recursive ls' ...\r\n\r\n\r\n#-------------------------------------------------------------\r\n# Tailoring 'less'\r\n#-------------------------------------------------------------\r\n\r\nalias more='less'\r\nexport PAGER=less\r\nexport LESSCHARSET='latin1'\r\nexport LESSOPEN='|\/usr\/bin\/lesspipe.sh %s 2&gt;&amp;-'\r\n                # Use this if lesspipe.sh exists.\r\nexport LESS='-i -N -w  -z-4 -g -e -M -X -F -R -P%t?f%f \\\r\n:stdin .?pb%pb\\%:?lbLine %lb:?bbByte %bb:-...'\r\n\r\n# LESS man page colors (makes Man pages more readable).\r\nexport LESS_TERMCAP_mb=$'\\E&#x5B;01;31m'\r\nexport LESS_TERMCAP_md=$'\\E&#x5B;01;31m'\r\nexport LESS_TERMCAP_me=$'\\E&#x5B;0m'\r\nexport LESS_TERMCAP_se=$'\\E&#x5B;0m'\r\nexport LESS_TERMCAP_so=$'\\E&#x5B;01;44;33m'\r\nexport LESS_TERMCAP_ue=$'\\E&#x5B;0m'\r\nexport LESS_TERMCAP_us=$'\\E&#x5B;01;32m'\r\n\r\n\r\n#-------------------------------------------------------------\r\n# Spelling typos - highly personnal and keyboard-dependent :-)\r\n#-------------------------------------------------------------\r\n\r\nalias xs='cd'\r\nalias vf='cd'\r\nalias moer='more'\r\nalias moew='more'\r\nalias kk='ll'\r\n\r\n\r\n#-------------------------------------------------------------\r\n# A few fun ones\r\n#-------------------------------------------------------------\r\n\r\n# Adds some text in the terminal frame (if applicable).\r\n\r\nfunction xtitle()\r\n{\r\n    case &quot;$TERM&quot; in\r\n    *term* | rxvt)\r\n        echo -en  &quot;\\e]0;$*\\a&quot; ;;\r\n    *)  ;;\r\n    esac\r\n}\r\n\r\n\r\n# Aliases that use xtitle\r\nalias top='xtitle Processes on $HOST &amp;&amp; top'\r\nalias make='xtitle Making $(basename $PWD) ; make'\r\n\r\n# .. and functions\r\nfunction man()\r\n{\r\n    for i ; do\r\n        xtitle The $(basename $1|tr -d .&#x5B;:digit:]) manual\r\n        command man -a &quot;$i&quot;\r\n    done\r\n}\r\n\r\n\r\n#-------------------------------------------------------------\r\n# Make the following commands run in background automatically:\r\n#-------------------------------------------------------------\r\n\r\nfunction te()  # wrapper around xemacs\/gnuserv\r\n{\r\n    if &#x5B; &quot;$(gnuclient -batch -eval t 2&gt;&amp;-)&quot; == &quot;t&quot; ]; then\r\n       gnuclient -q &quot;$@&quot;;\r\n    else\r\n       ( xemacs &quot;$@&quot; &amp;);\r\n    fi\r\n}\r\n\r\nfunction soffice() { command soffice &quot;$@&quot; &amp; }\r\nfunction firefox() { command firefox &quot;$@&quot; &amp; }\r\nfunction xpdf() { command xpdf &quot;$@&quot; &amp; }\r\n\r\n\r\n#-------------------------------------------------------------\r\n# File &amp; strings related functions:\r\n#-------------------------------------------------------------\r\n\r\n\r\n# Find a file with a pattern in name:\r\nfunction ff() { find . -type f -iname '*'&quot;$*&quot;'*' -ls ; }\r\n\r\n# Find a file with pattern $1 in name and Execute $2 on it:\r\nfunction fe() { find . -type f -iname '*'&quot;${1:-}&quot;'*' \\\r\n-exec ${2:-file} {} \\;  ; }\r\n\r\n#  Find a pattern in a set of files and highlight them:\r\n#+ (needs a recent version of egrep).\r\nfunction fstr()\r\n{\r\n    OPTIND=1\r\n    local mycase=&quot;&quot;\r\n    local usage=&quot;fstr: find string in files.\r\nUsage: fstr &#x5B;-i] \\&quot;pattern\\&quot; &#x5B;\\&quot;filename pattern\\&quot;] &quot;\r\n    while getopts :it opt\r\n    do\r\n        case &quot;$opt&quot; in\r\n           i) mycase=&quot;-i &quot; ;;\r\n           *) echo &quot;$usage&quot;; return ;;\r\n        esac\r\n    done\r\n    shift $(( $OPTIND - 1 ))\r\n    if &#x5B; &quot;$#&quot; -lt 1 ]; then\r\n        echo &quot;$usage&quot;\r\n        return;\r\n    fi\r\n    find . -type f -name &quot;${2:-*}&quot; -print0 | \\\r\nxargs -0 egrep --color=always -sn ${case} &quot;$1&quot; 2&gt;&amp;- | more\r\n\r\n}\r\n\r\n\r\nfunction swap()\r\n{ # Swap 2 filenames around, if they exist (from Uzi's bashrc).\r\n    local TMPFILE=tmp.$$\r\n\r\n    &#x5B; $# -ne 2 ] &amp;&amp; echo &quot;swap: 2 arguments needed&quot; &amp;&amp; return 1\r\n    &#x5B; ! -e $1 ] &amp;&amp; echo &quot;swap: $1 does not exist&quot; &amp;&amp; return 1\r\n    &#x5B; ! -e $2 ] &amp;&amp; echo &quot;swap: $2 does not exist&quot; &amp;&amp; return 1\r\n\r\n    mv &quot;$1&quot; $TMPFILE\r\n    mv &quot;$2&quot; &quot;$1&quot;\r\n    mv $TMPFILE &quot;$2&quot;\r\n}\r\n\r\nfunction extract()      # Handy Extract Program\r\n{\r\n    if &#x5B; -f $1 ] ; then\r\n        case $1 in\r\n            *.tar.bz2)   tar xvjf $1     ;;\r\n            *.tar.gz)    tar xvzf $1     ;;\r\n            *.bz2)       bunzip2 $1      ;;\r\n            *.rar)       unrar x $1      ;;\r\n            *.gz)        gunzip $1       ;;\r\n            *.tar)       tar xvf $1      ;;\r\n            *.tbz2)      tar xvjf $1     ;;\r\n            *.tgz)       tar xvzf $1     ;;\r\n            *.zip)       unzip $1        ;;\r\n            *.Z)         uncompress $1   ;;\r\n            *.7z)        7z x $1         ;;\r\n            *)           echo &quot;'$1' cannot be extracted via &gt;extract&lt;&quot; ;;\r\n        esac\r\n    else\r\n        echo &quot;'$1' is not a valid file!&quot;\r\n    fi\r\n}\r\n\r\n\r\n# Creates an archive (*.tar.gz) from given directory.\r\nfunction maketar() { tar cvzf &quot;${1%%\/}.tar.gz&quot;  &quot;${1%%\/}\/&quot;; }\r\n\r\n# Create a ZIP archive of a file or folder.\r\nfunction makezip() { zip -r &quot;${1%%\/}.zip&quot; &quot;$1&quot; ; }\r\n\r\n# Make your directories and files access rights sane.\r\nfunction sanitize() { chmod -R u=rwX,g=rX,o= &quot;$@&quot; ;}\r\n\r\n#-------------------------------------------------------------\r\n# Process\/system related functions:\r\n#-------------------------------------------------------------\r\n\r\n\r\nfunction my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,bsdtime,command ; }\r\nfunction pp() { my_ps f | awk '!\/awk\/ &amp;&amp; $0~var' var=${1:-&quot;.*&quot;} ; }\r\n\r\n\r\nfunction killps()   # kill by process name\r\n{\r\n    local pid pname sig=&quot;-TERM&quot;   # default signal\r\n    if &#x5B; &quot;$#&quot; -lt 1 ] || &#x5B; &quot;$#&quot; -gt 2 ]; then\r\n        echo &quot;Usage: killps &#x5B;-SIGNAL] pattern&quot;\r\n        return;\r\n    fi\r\n    if &#x5B; $# = 2 ]; then sig=$1 ; fi\r\n    for pid in $(my_ps| awk '!\/awk\/ &amp;&amp; $0~pat { print $1 }' pat=${!#} )\r\n    do\r\n        pname=$(my_ps | awk '$1~var { print $5 }' var=$pid )\r\n        if ask &quot;Kill process $pid &lt;$pname&gt; with signal $sig?&quot;\r\n            then kill $sig $pid\r\n        fi\r\n    done\r\n}\r\n\r\nfunction mydf()         # Pretty-print of 'df' output.\r\n{                       # Inspired by 'dfc' utility.\r\n    for fs ; do\r\n\r\n        if &#x5B; ! -d $fs ]\r\n        then\r\n          echo -e $fs&quot; :No such file or directory&quot; ; continue\r\n        fi\r\n\r\n        local info=( $(command df -P $fs | awk 'END{ print $2,$3,$5 }') )\r\n        local free=( $(command df -Pkh $fs | awk 'END{ print $4 }') )\r\n        local nbstars=$(( 20 * ${info&#x5B;1]} \/ ${info&#x5B;0]} ))\r\n        local out=&quot;&#x5B;&quot;\r\n        for ((j=0;j&lt;20;j++)); do\r\n            if &#x5B; ${j} -lt ${nbstars} ]; then\r\n               out=$out&quot;*&quot;\r\n            else\r\n               out=$out&quot;-&quot;\r\n            fi\r\n        done\r\n        out=${info&#x5B;2]}&quot; &quot;$out&quot;] (&quot;$free&quot; free on &quot;$fs&quot;)&quot;\r\n        echo -e $out\r\n    done\r\n}\r\n\r\n\r\nfunction my_ip() # Get IP adress on ethernet.\r\n{\r\n    MY_IP=$(\/sbin\/ifconfig eth0 | awk '\/inet\/ { print $2 } ' |\r\n      sed -e s\/addr:\/\/)\r\n    echo ${MY_IP:-&quot;Not connected&quot;}\r\n}\r\n\r\nfunction ii()   # Get current host related info.\r\n{\r\n    echo -e &quot;\\nYou are logged on ${BRed}$HOST&quot;\r\n    echo -e &quot;\\n${BRed}Additionnal information:$NC &quot; ; uname -a\r\n    echo -e &quot;\\n${BRed}Users logged on:$NC &quot; ; w -hs |\r\n             cut -d &quot; &quot; -f1 | sort | uniq\r\n    echo -e &quot;\\n${BRed}Current date :$NC &quot; ; date\r\n    echo -e &quot;\\n${BRed}Machine stats :$NC &quot; ; uptime\r\n    echo -e &quot;\\n${BRed}Memory stats :$NC &quot; ; free\r\n    echo -e &quot;\\n${BRed}Diskspace :$NC &quot; ; mydf \/ $HOME\r\n    echo -e &quot;\\n${BRed}Local IP Address :$NC&quot; ; my_ip\r\n    echo -e &quot;\\n${BRed}Open connections :$NC &quot;; netstat -pan --inet;\r\n    echo\r\n}\r\n\r\n#-------------------------------------------------------------\r\n# Misc utilities:\r\n#-------------------------------------------------------------\r\n\r\nfunction repeat()       # Repeat n times command.\r\n{\r\n    local i max\r\n    max=$1; shift;\r\n    for ((i=1; i &lt;= max ; i++)); do  # --&gt; C-like syntax\r\n        eval &quot;$@&quot;;\r\n    done\r\n}\r\n\r\n\r\nfunction ask()          # See 'killps' for example of use.\r\n{\r\n    echo -n &quot;$@&quot; '&#x5B;y\/n] ' ; read ans\r\n    case &quot;$ans&quot; in\r\n        y*|Y*) return 0 ;;\r\n        *) return 1 ;;\r\n    esac\r\n}\r\n\r\nfunction corename()   # Get name of app that created a corefile.\r\n{\r\n    for file ; do\r\n        echo -n $file : ; gdb --core=$file --batch | head -1\r\n    done\r\n}\r\n\r\n\r\n\r\n#=========================================================================\r\n#\r\n#  PROGRAMMABLE COMPLETION SECTION\r\n#  Most are taken from the bash 2.05 documentation and from Ian McDonald's\r\n# 'Bash completion' package (http:\/\/www.caliban.org\/bash\/#completion)\r\n#  You will in fact need bash more recent then 3.0 for some features.\r\n#\r\n#  Note that most linux distributions now provide many completions\r\n# 'out of the box' - however, you might need to make your own one day,\r\n#  so I kept those here as examples.\r\n#=========================================================================\r\n\r\nif &#x5B; &quot;${BASH_VERSION%.*}&quot; \\&lt; &quot;3.0&quot; ]; then\r\n    echo &quot;You will need to upgrade to version 3.0 for full \\\r\n          programmable completion features&quot;\r\n    return\r\nfi\r\n\r\nshopt -s extglob        # Necessary.\r\n\r\ncomplete -A hostname   rsh rcp telnet rlogin ftp ping disk\r\ncomplete -A export     printenv\r\ncomplete -A variable   export local readonly unset\r\ncomplete -A enabled    builtin\r\ncomplete -A alias      alias unalias\r\ncomplete -A function   function\r\ncomplete -A user       su mail finger\r\n\r\ncomplete -A helptopic  help     # Currently same as builtins.\r\ncomplete -A shopt      shopt\r\ncomplete -A stopped -P '%' bg\r\ncomplete -A job -P '%'     fg jobs disown\r\n\r\ncomplete -A directory  mkdir rmdir\r\ncomplete -A directory   -o default cd\r\n\r\n# Compression\r\ncomplete -f -o default -X '*.+(zip|ZIP)'  zip\r\ncomplete -f -o default -X '!*.+(zip|ZIP)' unzip\r\ncomplete -f -o default -X '*.+(z|Z)'      compress\r\ncomplete -f -o default -X '!*.+(z|Z)'     uncompress\r\ncomplete -f -o default -X '*.+(gz|GZ)'    gzip\r\ncomplete -f -o default -X '!*.+(gz|GZ)'   gunzip\r\ncomplete -f -o default -X '*.+(bz2|BZ2)'  bzip2\r\ncomplete -f -o default -X '!*.+(bz2|BZ2)' bunzip2\r\ncomplete -f -o default -X '!*.+(zip|ZIP|z|Z|gz|GZ|bz2|BZ2)' extract\r\n\r\n\r\n# Documents - Postscript,pdf,dvi.....\r\ncomplete -f -o default -X '!*.+(ps|PS)'  gs ghostview ps2pdf ps2ascii\r\ncomplete -f -o default -X \\\r\n'!*.+(dvi|DVI)' dvips dvipdf xdvi dviselect dvitype\r\ncomplete -f -o default -X '!*.+(pdf|PDF)' acroread pdf2ps\r\ncomplete -f -o default -X '!*.@(@(?(e)ps|?(E)PS|pdf|PDF)?\\\r\n(.gz|.GZ|.bz2|.BZ2|.Z))' gv ggv\r\ncomplete -f -o default -X '!*.texi*' makeinfo texi2dvi texi2html texi2pdf\r\ncomplete -f -o default -X '!*.tex' tex latex slitex\r\ncomplete -f -o default -X '!*.lyx' lyx\r\ncomplete -f -o default -X '!*.+(htm*|HTM*)' lynx html2ps\r\ncomplete -f -o default -X \\\r\n'!*.+(doc|DOC|xls|XLS|ppt|PPT|sx?|SX?|csv|CSV|od?|OD?|ott|OTT)' soffice\r\n\r\n# Multimedia\r\ncomplete -f -o default -X \\\r\n'!*.+(gif|GIF|jp*g|JP*G|bmp|BMP|xpm|XPM|png|PNG)' xv gimp ee gqview\r\ncomplete -f -o default -X '!*.+(mp3|MP3)' mpg123 mpg321\r\ncomplete -f -o default -X '!*.+(ogg|OGG)' ogg123\r\ncomplete -f -o default -X \\\r\n'!*.@(mp&#x5B;23]|MP&#x5B;23]|ogg|OGG|wav|WAV|pls|\\\r\nm3u|xm|mod|s&#x5B;3t]m|it|mtm|ult|flac)' xmms\r\ncomplete -f -o default -X '!*.@(mp?(e)g|MP?(E)G|wma|avi|AVI|\\\r\nasf|vob|VOB|bin|dat|vcd|ps|pes|fli|viv|rm|ram|yuv|mov|MOV|qt|\\\r\nQT|wmv|mp3|MP3|ogg|OGG|ogm|OGM|mp4|MP4|wav|WAV|asx|ASX)' xine\r\n\r\n\r\n\r\ncomplete -f -o default -X '!*.pl'  perl perl5\r\n\r\n\r\n#  This is a 'universal' completion function - it works when commands have\r\n#+ a so-called 'long options' mode , ie: 'ls --all' instead of 'ls -a'\r\n#  Needs the '-o' option of grep\r\n#+ (try the commented-out version if not available).\r\n\r\n#  First, remove '=' from completion word separators\r\n#+ (this will allow completions like 'ls --color=auto' to work correctly).\r\n\r\nCOMP_WORDBREAKS=${COMP_WORDBREAKS\/=\/}\r\n\r\n\r\n_get_longopts()\r\n{\r\n  #$1 --help | sed  -e '\/--\/!d' -e 's\/.*--\\(&#x5B;^&#x5B;:space:].,]*\\).*\/--\\1\/'| \\\r\n  #grep ^&quot;$2&quot; |sort -u ;\r\n    $1 --help | grep -o -e &quot;--&#x5B;^&#x5B;:space:].,]*&quot; | grep -e &quot;$2&quot; |sort -u\r\n}\r\n\r\n_longopts()\r\n{\r\n    local cur\r\n    cur=${COMP_WORDS&#x5B;COMP_CWORD]}\r\n\r\n    case &quot;${cur:-*}&quot; in\r\n       -*)      ;;\r\n        *)      return ;;\r\n    esac\r\n\r\n    case &quot;$1&quot; in\r\n       \\~*)     eval cmd=&quot;$1&quot; ;;\r\n         *)     cmd=&quot;$1&quot; ;;\r\n    esac\r\n    COMPREPLY=( $(_get_longopts ${1} ${cur} ) )\r\n}\r\ncomplete  -o default -F _longopts configure bash\r\ncomplete  -o default -F _longopts wget id info a2ps ls recode\r\n\r\n_tar()\r\n{\r\n    local cur ext regex tar untar\r\n\r\n    COMPREPLY=()\r\n    cur=${COMP_WORDS&#x5B;COMP_CWORD]}\r\n\r\n    # If we want an option, return the possible long options.\r\n    case &quot;$cur&quot; in\r\n        -*)     COMPREPLY=( $(_get_longopts $1 $cur ) ); return 0;;\r\n    esac\r\n\r\n    if &#x5B; $COMP_CWORD -eq 1 ]; then\r\n        COMPREPLY=( $( compgen -W 'c t x u r d A' -- $cur ) )\r\n        return 0\r\n    fi\r\n\r\n    case &quot;${COMP_WORDS&#x5B;1]}&quot; in\r\n        ?(-)c*f)\r\n            COMPREPLY=( $( compgen -f $cur ) )\r\n            return 0\r\n            ;;\r\n        +(&#x5B;^Izjy])f)\r\n            ext='tar'\r\n            regex=$ext\r\n            ;;\r\n        *z*f)\r\n            ext='tar.gz'\r\n            regex='t\\(ar\\.\\)\\(gz\\|Z\\)'\r\n            ;;\r\n        *&#x5B;Ijy]*f)\r\n            ext='t?(ar.)bz?(2)'\r\n            regex='t\\(ar\\.\\)bz2\\?'\r\n            ;;\r\n        *)\r\n            COMPREPLY=( $( compgen -f $cur ) )\r\n            return 0\r\n            ;;\r\n\r\n    esac\r\n\r\n    if &#x5B;&#x5B; &quot;$COMP_LINE&quot; == tar*.$ext' '* ]]; then\r\n        # Complete on files in tar file.\r\n        #\r\n        # Get name of tar file from command line.\r\n        tar=$( echo &quot;$COMP_LINE&quot; | \\\r\n                        sed -e 's|^.* \\(&#x5B;^ ]*'$regex'\\) .*$|\\1|' )\r\n        # Devise how to untar and list it.\r\n        untar=t${COMP_WORDS&#x5B;1]\/\/&#x5B;^Izjyf]\/}\r\n\r\n        COMPREPLY=( $( compgen -W &quot;$( echo $( tar $untar $tar \\\r\n                                2&gt;\/dev\/null ) )&quot; -- &quot;$cur&quot; ) )\r\n        return 0\r\n\r\n    else\r\n        # File completion on relevant files.\r\n        COMPREPLY=( $( compgen -G $cur\\*.$ext ) )\r\n\r\n    fi\r\n\r\n    return 0\r\n\r\n}\r\n\r\ncomplete -F _tar -o default tar\r\n\r\n_make()\r\n{\r\n    local mdef makef makef_dir=&quot;.&quot; makef_inc gcmd cur prev i;\r\n    COMPREPLY=();\r\n    cur=${COMP_WORDS&#x5B;COMP_CWORD]};\r\n    prev=${COMP_WORDS&#x5B;COMP_CWORD-1]};\r\n    case &quot;$prev&quot; in\r\n        -*f)\r\n            COMPREPLY=($(compgen -f $cur ));\r\n            return 0\r\n            ;;\r\n    esac;\r\n    case &quot;$cur&quot; in\r\n        -*)\r\n            COMPREPLY=($(_get_longopts $1 $cur ));\r\n            return 0\r\n            ;;\r\n    esac;\r\n\r\n    # ... make reads\r\n    #          GNUmakefile,\r\n    #     then makefile\r\n    #     then Makefile ...\r\n    if &#x5B; -f ${makef_dir}\/GNUmakefile ]; then\r\n        makef=${makef_dir}\/GNUmakefile\r\n    elif &#x5B; -f ${makef_dir}\/makefile ]; then\r\n        makef=${makef_dir}\/makefile\r\n    elif &#x5B; -f ${makef_dir}\/Makefile ]; then\r\n        makef=${makef_dir}\/Makefile\r\n    else\r\n       makef=${makef_dir}\/*.mk         # Local convention.\r\n    fi\r\n\r\n\r\n    #  Before we scan for targets, see if a Makefile name was\r\n    #+ specified with -f.\r\n    for (( i=0; i &lt; ${#COMP_WORDS&#x5B;@]}; i++ )); do\r\n        if &#x5B;&#x5B; ${COMP_WORDS&#x5B;i]} == -f ]]; then\r\n            # eval for tilde expansion\r\n            eval makef=${COMP_WORDS&#x5B;i+1]}\r\n            break\r\n        fi\r\n    done\r\n    &#x5B; ! -f $makef ] &amp;&amp; return 0\r\n\r\n    # Deal with included Makefiles.\r\n    makef_inc=$( grep -E '^-?include' $makef |\r\n                 sed -e &quot;s,^.* ,&quot;$makef_dir&quot;\/,&quot; )\r\n    for file in $makef_inc; do\r\n        &#x5B; -f $file ] &amp;&amp; makef=&quot;$makef $file&quot;\r\n    done\r\n\r\n\r\n    #  If we have a partial word to complete, restrict completions\r\n    #+ to matches of that word.\r\n    if &#x5B; -n &quot;$cur&quot; ]; then gcmd='grep &quot;^$cur&quot;' ; else gcmd=cat ; fi\r\n\r\n    COMPREPLY=( $( awk -F':' '\/^&#x5B;a-zA-Z0-9]&#x5B;^$#\\\/\\t=]*:(&#x5B;^=]|$)\/ \\\r\n                               {split($1,A,\/ \/);for(i in A)print A&#x5B;i]}' \\\r\n                                $makef 2&gt;\/dev\/null | eval $gcmd  ))\r\n\r\n}\r\n\r\ncomplete -F _make -X '+($*|*.&#x5B;cho])' make gmake pmake\r\n\r\n\r\n\r\n\r\n_killall()\r\n{\r\n    local cur prev\r\n    COMPREPLY=()\r\n    cur=${COMP_WORDS&#x5B;COMP_CWORD]}\r\n\r\n    #  Get a list of processes\r\n    #+ (the first sed evaluation\r\n    #+ takes care of swapped out processes, the second\r\n    #+ takes care of getting the basename of the process).\r\n    COMPREPLY=( $( ps -u $USER -o comm  | \\\r\n        sed -e '1,1d' -e 's#&#x5B;]\\&#x5B;]##g' -e 's#^.*\/##'| \\\r\n        awk '{if ($0 ~ \/^'$cur'\/) print $0}' ))\r\n\r\n    return 0\r\n}\r\n\r\ncomplete -F _killall killall killps\r\n\r\n\r\n\r\n# Local Variables:\r\n# mode:shell-script\r\n# sh-shell:bash\r\n# End:\r\n<\/pre>\n<pre class=\"brush: bash; collapse: true; light: false; title: Andrzej Szelachowski&#039;s ~\/.bash_profile; toolbar: true; notranslate\" title=\"Andrzej Szelachowski&#039;s ~\/.bash_profile\">\r\n# From Andrzej Szelachowski's ~\/.bash_profile:\r\n\r\n\r\n#  Note that a variable may require special treatment\r\n#+ if it will be exported.\r\n\r\nDARKGRAY='\\e&#x5B;1;30m'\r\nLIGHTRED='\\e&#x5B;1;31m'\r\nGREEN='\\e&#x5B;32m'\r\nYELLOW='\\e&#x5B;1;33m'\r\nLIGHTBLUE='\\e&#x5B;1;34m'\r\nNC='\\e&#x5B;m'\r\n\r\nPCT=&quot;\\`if &#x5B;&#x5B; \\$EUID -eq 0 ]]; then T='$LIGHTRED' ; else T='$LIGHTBLUE'; fi; \r\necho \\$T \\`&quot;\r\n\r\n#  For &quot;literal&quot; command substitution to be assigned to a variable,\r\n#+ use escapes and double quotes:\r\n#+       PCT=&quot;\\` ... \\`&quot; . . .\r\n#  Otherwise, the value of PCT variable is assigned only once,\r\n#+ when the variable is exported\/read from .bash_profile,\r\n#+ and it will not change afterwards even if the user ID changes.\r\n\r\n\r\nPS1=&quot;\\n$GREEN&#x5B;\\w] \\n$DARKGRAY($PCT\\t$DARKGRAY)-($PCT\\u$DARKGRAY)-($PCT\\!\r\n$DARKGRAY)$YELLOW-&gt; $NC&quot;\r\n\r\n#  Escape a variables whose value changes:\r\n#        if &#x5B;&#x5B; \\$EUID -eq 0 ]],\r\n#  Otherwise the value of the EUID variable will be assigned only once,\r\n#+ as above.\r\n\r\n#  When a variable is assigned, it should be called escaped:\r\n#+       echo \\$T,\r\n#  Otherwise the value of the T variable is taken from the moment the PCT \r\n#+ variable is exported\/read from .bash_profile.\r\n#  So, in this example it would be null.\r\n\r\n#  When a variable's value contains a semicolon it should be strong quoted:\r\n#        T='$LIGHTRED',\r\n#  Otherwise, the semicolon will be interpreted as a command separator.\r\n\r\n\r\n#  Variables PCT and PS1 can be merged into a new PS1 variable:\r\n\r\nPS1=&quot;\\`if &#x5B;&#x5B; \\$EUID -eq 0 ]]; then PCT='$LIGHTRED';\r\nelse PCT='$LIGHTBLUE'; fi; \r\necho '\\n$GREEN&#x5B;\\w] \\n$DARKGRAY('\\$PCT'\\t$DARKGRAY)-\\\r\n('\\$PCT'\\u$DARKGRAY)-('\\$PCT'\\!$DARKGRAY)$YELLOW-&gt; $NC'\\`&quot;\r\n\r\n# The trick is to use strong quoting for parts of old PS1 variable.\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>CLICOLOR and LS_COLORS in bash dircolors: modify color settings globaly COLORS-Lscolors if &#x5B; -f ~\/.bashrc ]; then . ~\/.bashrc fi # .profile doesn&#8217;t been parsed by &quot;su&quot; if &#x5B; -f \/usr\/local\/etc\/bashrc ]; then . \/usr\/local\/etc\/bashrc fi How can I shorten my command line (bash) prompt? Color Bash Prompt Don\u2019t Reinvent the Wheel PROMPT_DIRTRIM=3 LS_COLORS=&quot;rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:&quot; CLICOLOR=yes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,4,10],"tags":[],"class_list":["post-487","post","type-post","status-publish","format-standard","hentry","category-debian","category-freebsd","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/487","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=487"}],"version-history":[{"count":14,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/487\/revisions"}],"predecessor-version":[{"id":9839,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/487\/revisions\/9839"}],"wp:attachment":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}