Improving the BASH shell

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

Improving the BASH shell

#1 Post by sc0ttman »

Improving the BASH shell

My brother keeps mentioning zsh.. Here's my answer, for now..

Settings created in your shell:

- share ~/.history across terminal windows
- auto remove duplicates from ~/.history
- add multi-line cmds to a single entry in ~/.history
- your ~/.history always saved, no need hit Ctrl-D or type 'exit'
- auto correct small typos and case mis-match in file and dir matching and TAB completions
- case insensitive file/dir matching and TAB completions
- add SHIFT-TAB completion: uses an alternate, inline, cycle-through-options style TAB completion

Add the following into your BASH settings file /root/.bashrc:

Code: Select all

# allow shortcuts to directories 
#
# usage example:   cd $docs 
#
shopt -s cdable_vars
# example shortcuts
export docs="/usr/share/docs"
export menufiles="/usr/share/applications"

# better typo support
#
#enable spell checking of files and dirs in the shell
shopt -s cdspell
#make file/dir matching case insensitive
shopt -s nocaseglob
#make TAB completion of file/dir names case insensitive
bind 'set completion-ignore-case on'

# fix cmd typos
alias ehco='echo'
alias ehoc='echo'
alias ehcp='echo'
alias dinf='find'
alias fidn='find'
alias findf='find'
alias gerp='grep'
alias gepr='grep'
alias egrp='grep'


#  better history management
#
#ignore adding duplicates to the history list, erase them too
export HISTCONTROL=erasedups
# enabled shared history across terminal windows .. histappend not needed below
#shopt -s histappend
#keep multi lines commands together on one line
shopt -s cmdhist
# the magic bit, does a few things, basically keeps your history tidy and up to date
export PROMPT_COMMAND="history -n; history -w; history -c; history -r; $PROMPT_COMMAND"

Note, adding the above to ~/.bashrc will also mean, if you're running BASH4, then you won't have to
type 'exit' or hit Ctr-D in order to save your history.. it will get saved each time you execute a command.

However, using the PROMPT_COMMAND method as above will mess up the reported line number by the history command..

Also, here's another, simpler way to filter out duplicates:

Code: Select all

export HISTIGNORE="&"
Or, to filter out duplicates and the plain 'ls' and 'exit' commands:

Code: Select all

export HISTIGNORE="&:ls:exit"
To get inline TAB completion, where you press Shft-Tab to cycle through possible file/dir matches in place, just add this to your /etc/inputrc file :

Code: Select all

# enable a second inline style of auto completion with SHIFT-TAB:
"\e[Z": menu-complete
...And here are a load of interesting, one line shell commands you might not know about,
such as comparing the output of two commands :

Code: Select all

diff <(ls dir1) <(ls dir2)
The links:

http://unix.stackexchange.com/questions ... -or-tricks

http://www.catonmat.net/blog/top-ten-on ... explained/

http://www.catonmat.net/blog/the-next-t ... explained/

http://www.catonmat.net/blog/another-te ... explained/

http://www.catonmat.net/blog/yet-anothe ... explained/
Last edited by sc0ttman on Tue 17 Sep 2013, 15:11, edited 2 times in total.
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#2 Post by Karl Godt »

http://www.murga-linux.com/puppy/viewto ... 706#583706
myself wrote:for /bin/bash you could have an internet lookup for " man bash "

the file /etc/inputrc i have altered much for testing purposes and on one installation

set match-hidden-files on
set show-all-if-ambiguous on
set completion-ignore-case on

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Improving the BASH shell

#3 Post by L18L »

http://www.murga-linux.com/puppy/viewtopic.php?p=726200

So here just another one one liner:

Code: Select all

rxvt -title "Type in initial letters of your app and the press TAB key"  -e ash

Post Reply