From 2d29f4abf2c69ff88c80a53fbb6ff1dc3cce3112 Mon Sep 17 00:00:00 2001 From: Bez Hermoso Date: Wed, 18 Oct 2017 13:21:01 -0700 Subject: [PATCH] Add "History" section in `bash` cheatsheet History sub-sections: * Commands * Expansions * Operations * Slices --- bash.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/bash.md b/bash.md index 10ca4cdad..523658f87 100644 --- a/bash.md +++ b/bash.md @@ -439,6 +439,40 @@ set -o globstar # Allow ** for recursive matches ('lib/**/*.rb' => 'lib/a/b/c Set `GLOBIGNORE` as a colon-separated list of patterns to be removed from glob matches. +History +------- + +### Commands + +| `history` | Show history | +| `shopt -s histverify` | Don't execute expanded result immediately | + +### Expansions + +| `!$` | Expand last parameter of most recent command | +| `!*` | Expand all parameters of most recent command | +| `!-n` | Expand `n`th most recent command | +| `!n` | Expand `n`th command in history | +| `!` | Expand most recent invocation of command `` | + +### Operations + +| `!!:s///` | Replace first occurence of `` to `` in most recent command | +| `!!:gs///` | Replace all occurences of `` to `` in most recent command | +| `!$:t` | Expand only basename from last parameter of most recent command | +| `!$:h` | Expand only directory from last parameter of most recent command | + +`!!` and `!$` can be replaced with any valid expansion. + +### Slices + +| `!!:n` | Expand only `n`th token from most recent command (command is `0`; first param is `1`) | +| `!!:n-m` | Expand range of tokens from most recent command | +| `!!:n-$` | Expand `n`th token to last from most recent command | + +`!!` can be replaced with any valid expansion i.e. `!cat`, `!-2`, `!42`, etc. + + Miscellaneous -------------