Eduardo Bellido Bellido
Systems Engineer at Adevinta Spain. FLOSS lover, and passionate about Agile and DevOps. Podcasting in https://www.entredevyops.es
by
with bash!
Let's go...
When bash starts as login shell:
~/.bash_profile
When bash starts interactively:
~/.bashrc
GNU Readline config file:
~/.inputrc
Put all your configuration in .bashrc
Then, in .bash_profile, put:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
autocd → enter directories without typing cd
cdspell → correct minor spelling errors in directory names
extglob → enable extended pattern matching features
globstar → enable the pattern '**'
histappend → history list is appended rather than overwrited
$ history
1 cd /tmp
2 wget https://www.kernel.org/pub/linux/kern
el/v4.x/linux-4.0.4.tar.xz
3 tar xvJf linux-4.0.4.tar.xz
4 cd linux-4.0.4
5 make oldconfig
6 make -j 4
7 make modules_install
8 make install
# append history lines from current session to the history file
$ history -a
# read the history file and append the contents to the history list
$ history -r
!n → Refer to command line n
!-n → Refer to the current command minus n
!! → Refer to the previous command (tip: sudo !!)
!string → Refer to the most recent command preceding the current position in the history list starting with string
!?string[?] → Refer to the most recent command preceding the current position in the history list containing string
^string1^string2^ → Repeat the previous command, replacing string1 with string2
C-p → Move 'back' through the history list, fetching the previous command
C-n → Move 'forward' through the history list, fetching the next command
M-< → Move to the first line in the history
M-> → Move to the end of the input history, i.e., the line currently being entered
C-r → Search backward starting at the current line and moving 'up' through the history as necessary
C-s → Search forward starting at the current line and moving 'down' through the the history as necessary (try "stty -ixon" if doesn't work)
C-g → Escape from history searching mode
HISTCONTROL='ignorespace:ignoredups:erasedups'
HISTSIZE=1000
HISTFILESIZE=3000
HISTTIMEFORMAT='[%F %T] '
Some variables to control the history behavior:
Expands the history commands
Enable it:
# Add those lines to your .inputrc file
$if Bash
Space: magic-space
$endif
Bonus:
C-M-e → expand the line as the shell does
C-a → Move to the start of the current line
C-e → Move to the end of the line
C-f → Move forward a character
C-b → Move back a character
M-f → Move forward to the end of the next word
M-b → Move back to the start of the current or previous word
M-Del → Delete the Word before the cursor
M-d → Delete the Word after the cursor
C-d → Delete character under the cursor
C-h → Delete character before the cursor (Backspace)
C-w → Cut the Word before the cursor to the clipboard
C-k → Cut the Line after the cursor to the clipboard
C-u → Cut/delete the Line before the cursor to the clipboard
C-y → Paste the last thing to be cut (yank)
C-_ → Undo
?(pattern-list)
Matches zero or one occurrence of the given patterns
*(pattern-list)
Matches zero or more occurrences of the given patterns
+(pattern-list)
Matches one or more occurrences of the given patterns
@(pattern-list)
Matches one of the given patterns
!(pattern-list)
Matches anything except one of the given patterns
${parameter:=word}
Assign Default Values
${parameter:offset}
${parameter:offset:length}
Substring Expansion
${parameter#word}
${parameter##word}
Remove matching prefix pattern
${parameter%word}
${parameter%%word}
Remove matching suffix pattern
${parameter/pattern/string}
Pattern substitution
${parameter^pattern}
${parameter^^pattern}
${parameter,pattern}
${parameter,,pattern}
Case modification
Prompt improvements, written in python, a bit slow. Also supports more applications, Vim, Tmux...
Collections of scripts, aliases, and completions for Bash, also provides some useful improvements for the prompt.
Prompt improvements, supports plugins, currently only have a few.
Improved git prompt, very very verbose.
$ sudo applause
By Eduardo Bellido Bellido
Systems Engineer at Adevinta Spain. FLOSS lover, and passionate about Agile and DevOps. Podcasting in https://www.entredevyops.es