From bbaee4983107a2fa23ee4c3d605f3c40a47ec3a9 Mon Sep 17 00:00:00 2001 From: Malin Freeborn Date: Sat, 7 Dec 2024 14:06:21 +0100 Subject: [PATCH] quality of life adjustments --- basics/setup/Quality_of_Life.md | 180 ++++++++++++++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 basics/setup/Quality_of_Life.md diff --git a/basics/setup/Quality_of_Life.md b/basics/setup/Quality_of_Life.md new file mode 100644 index 0000000..8567698 --- /dev/null +++ b/basics/setup/Quality_of_Life.md @@ -0,0 +1,180 @@ +--- +title: "Quality of Life" +tags: [ "basics", "setup" ] +dependencies: [ "vi", "basics" ] +--- + +This & That +=========== + +Refer to 'that last thing', and 'the first thing': + +```bash +fortune -l > file1 +cat !$ | tr -d u +diff !^ !$ +``` + +**NB:** this can go wrong: + +```bash +ls -l file1 file2 +cat !^ +``` + +Done +---- + +`` + +- If you have a command, Control + d will execute the command. +- If you have nothing, `exit`. + +Input Run-Commands (`~/.inputrc`) +================================= + +Alias Expansion +--------------- + +```bash +echo '"\C- ": shell-expand-line' >> ~/.inputrc +exec bash +``` + +Now you can expand all aliases with 'Control + Space'. +Try just `ls`, then 'Control + Space'. + +Glob Expansion (`*`) +-------------------- + +```bash +echo '"\C-x": glob-expand-word' >> ~/.inputrc +exec bash +ls * +``` + +- Are you sure you want to delete that? + * `rm -r *` +- Clean up the Downloads folder: + * `rm Downloads/*pdf` + +Arbitrary Commands +------------------ + +Use `\n` as a 'newline' character to automatically press ``. + +```bash +echo 'Control-y: "| lolcat\n"' >> ~/.inputrc +exec bash +ls +``` + +```bash +Control-l: "\C-u clear -x && ls\n" +exec bash +cd /etc/ +``` + +Readline as Vi +-------------- + +```bash +echo 'set editing-mode vi' >> ~/.inputrc +echo 'set keymap vi-insert' >> ~/.inputrc +exec 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 ` +- `ls ` +- Type some words. +- `0dw$p` +- to normal-mode, and go back with 'b', and forward with 'e'. +- `4b` to step back four times. +- `cE` +- `kcw` +- ls -axxxx + +Works with `python` too: + +```python +imos +os.li +kfn + +``` + +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. + +```bash +sed '/ vi/d' ~/.inputrc +sed -i '/ vi/d' ~/.inputrc + +sed '1 i set editing-mode vi' .inputrc +sed -i '1 i set editing-mode vi' ~/.inputrc +sed -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: + +```bash +echo 'set show-mode-in-prompt on' >> ~/.inputrc +exec bash +``` + +Set new symbols for normal and insert mode: + +```bash +echo 'set vi-ins-mode-string " "' >> ~/.inputrc +echo 'set vi-cmd-mode-string " "' >> ~/.inputrc +``` + +Fuzzy Sort +========== + +Check your repos for `sk-im`, and install. +The program is called `sk`. + +```bash +FUZZY=sk +``` + +If you don't have it, `fzy` or `fzf` should work the same way. + +```bash +FUZZY=fzy +``` + +Find some 'read-config' files to check out: + +```bash +find . -maxdepth 2 -name "*rc" +find . -maxdepth 2 -name "*rc" | $FUZZY +``` + +And read some: + +```bash +PAGER='less -R' +$PAGER "$(find . -maxdepth 2 -name "*rc" | $FUZZY)" +``` + +Make the change long-term: + +```bash +alias rrc='$PAGER "$(find . -maxdepth 2 -name "*rc" | sk)"' +alias | grep rrc= >> ~/.bash_aliases +```