While I use Linux, I have not yet customized my bash shell, which I use a fair amount. So, I ask: What are your favorite customizations you have for bash?
I would recommend looking at zsh
.
It is much more powerful, and you're ready for it if you're asking about shell customization.
Some killer features are path expansion:
cd /u/l/X<TAB> -> cd /usr/local/X11
and globbing
wc -l **/*.xml
(bash3 also does that, so there's some improvement)
And it is smart enough, so
for i in .*; do cp $i dotfiles; done
wouldn't land you in trouble or fail epically.
And it have a lot of options and a massive completions library.
A custom prompt is my first one. I've never liked the '$' :)
Mine own prompt is very personal to me though. It's multi-line for a start, which a lot of people aren't fans of, but it suits me fine. It's also version control system enabled - it'll report svn revisions / git branches if you're in a source tree.
- A bunch of aliases, some for typos some just to give me the behavior I want by default, some for less keystrokes.
- emcas to emacs
- ls to ls -lt
- pu to pushd
- po to popd
An important one for me is to add some color to the prompt. That makes it act as a visual delimiter when I've got two sets of output. I can easily see where one ends and the next begins.
- Colorize your command prompt
Enable some shell options:
# Make bash append rather than overwrite the history on disk shopt -s histappend # Enable cool globbing wildcards shopt -s extglob
Add some aliases:
alias ls="ls --color=auto" alias hd="hexdump -C"
Colorize
grep
output:export GREP_OPTIONS=--color=auto export GREP_COLORS='ms=01;36'
Settings for the other prompts (continuation lines, select, execution trace):
#---------------------------------------------------
# set Bash prompts
#---------------------------------------------------
export PS2='continue> '
export PS3='choose: '
export PS4='[$LINENO $SECONDS] '
I second the zsh suggestion. Though I'm pretty sure most of these will work in bash as well.
Notice the lowercase=command upercase=suffix-command convention. (some of these come from the zsh-lovers manpage)
alias -g bigfiles="find . -size +50000k -exec ls -lh {} \; | awk '{ print \$8 \": \" \$5 }'"
alias -g f="find . -name"
alias -g G='| egrep'
alias -g g="grep"
alias -g H='| head'
alias -g LL="2>&1 | less"
alias -g L="| less"
alias -g NUL="> /dev/null 2>&1"
As an ubuntu user:
alias 'Ag'='sudo apt-get install'
alias 'As'='apt-cache search'
alias 'Ai'='apt-cache show'
alias 'Ar'='sudo apt-get remove'
alias 'Au'='sudo apt-get update;sudo apt-get dist-upgrade'
As a ruby user
alias Gs='gem search --remote'
alias Gg='sudo gem install'
alias Gi='gem specification'
Also you might spend a little time wading through: http://dotfiles.org/.bashrc. There are a number of gems over there.
I usually make sure to set up Bash Completion, because it I've gotten so used to it that it annoys me when I can't tab-complete hostnames with ssh.
I set up my prompt command so that the titles of all my terminal windows tell me what host and directory I'm in:
export PROMPT_COMMAND='echo -ne "\033]0;${HOSTNAME}:${PWD}\007"'
This way I don't get a bunch of windows titled "xterm" or "Terminal" or something similar.