Quality of Life
This & That
Refer to 'that last thing', and 'the first thing':
1fortune -l > file1
2cat !$ | tr -d u
3diff !^ !$
NB: this can go wrong:
1ls -l file1 file2
2cat !^
Done
<C-d>
- If you have a command, Control + d will execute the command.
- If you have nothing,
exit
.
Input Run-Commands (~/.inputrc
)
Alias Expansion
1echo '"\C- ": shell-expand-line' >> ~/.inputrc
2exec bash
Now you can expand all aliases with 'Control + Space'.
Try just ls
, then 'Control + Space'.
Glob Expansion (*
)
1echo '"\C-x": glob-expand-word' >> ~/.inputrc
2exec bash
3ls *<C-x>
- Are you sure you want to delete that?
rm -r *<C-x>
- Clean up the Downloads folder:
rm Downloads/*pdf<C-x>
Arbitrary Commands
Use \n
as a 'newline' character to automatically press <Return>
.
1echo 'Control-y: "| lolcat\n"' >> ~/.inputrc
2exec bash
3ls<C-y>
1Control-l: "\C-u clear -x && ls\n"
2exec bash
3cd /etc/<C-l>
Readline as Vi
1echo 'set editing-mode vi' >> ~/.inputrc
2echo 'set keymap vi-insert' >> ~/.inputrc
3exec bash
The prompt now works according to vi
-motions.
This goes much further than the bash-option, set -o vi
('set option: vi
').
It changes the cursor in the terminal, not just bash.
Try:
ls <C-n>
ls <C-p>
- Type some words.
<Esc>0dw$p
to normal-mode, and go back with 'b', and forward with 'e'. 4b
to step back four times.cE
<Esc>kcw
- ls -a
xxxx
Works with python
too:
1im<C-n>os<Return>
2os.li<C-n><Return>
3<Esc>kfn
4<C-d>
Fix Globs!
If you tried the previous commands then they will not work any more, because the vi
-commands overwrite the other commands.
Remove them.
1sed '/ vi/d' ~/.inputrc
2sed -i '/ vi/d' ~/.inputrc
3
4sed '1 i set editing-mode vi' .inputrc
5sed -i '1 i set editing-mode vi' ~/.inputrc
6sed -i '2 i set keymap vi-insert' ~/.inputrc
Vi-sibility
The readline
prompt becomes confusing if you don't remember if you're in insert or normal mode.
But you can show the current mode in the prompt:
1echo 'set show-mode-in-prompt on' >> ~/.inputrc
2exec bash
Set new symbols for normal and insert mode:
1echo 'set vi-ins-mode-string " "' >> ~/.inputrc
2echo 'set vi-cmd-mode-string " "' >> ~/.inputrc
Fuzzy Sort
Check your repos for sk-im
, and install.
The program is called sk
.
1FUZZY=sk
If you don't have it, fzy
or fzf
should work the same way.
1FUZZY=fzy
Find some 'read-config' files to check out:
1find . -maxdepth 2 -name "*rc"
2find . -maxdepth 2 -name "*rc" | $FUZZY
And read some:
1PAGER='less -R'
2$PAGER "$(find . -maxdepth 2 -name "*rc" | $FUZZY)"
Make the change long-term:
1alias rrc='$PAGER "$(find . -maxdepth 2 -name "*rc" | sk)"'
2alias | grep rrc= >> ~/.bash_aliases