├── LICENSE ├── README.md ├── conf.d └── puffer_fish_key_bindings.fish ├── functions ├── _puffer_fish_expand_bang.fish ├── _puffer_fish_expand_dots.fish └── _puffer_fish_expand_lastarg.fish └── media ├── dot-dot-demo.gif └── exclamation-demo.gif /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright © Nicholas Boyle 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Puffer Fish 2 | 3 | > Text Expansions for [Fish](https://fishshell.com/) 4 | 5 | Typing consecutive dots after `..` will automatically expand to `../..`, then `../../..` and so on. It expands in place as you type to allow directory tab-completion to work. This can be useful with any command where you want to reference a parent directory that is more than one back. i.e. `cd ....` or `vi .../Cargo.toml`. 6 | 7 | ![dot dot demo](./media/dot-dot-demo.gif) 8 | 9 | It's a little hard to see in the demo because it expands as you type, but `cp ..../template/Makefile .` is being typed. 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | Typing `!!` will expand to the previous command, similar to Zsh, Bash, and other shells. For example, if you type `apt update` you will likely see a permisison error. You can then type `sudo !!` and it will expand to `sudo apt update`. 14 | 15 | ![exclamation demo](./media/exclamation-demo.gif) 16 | 17 | This can be especially useful if you don't want to retype a long command, or navigate around with the arrow keys. Or if you want to re-run a command as part of pipeline. 18 | 19 | ```console 20 | > some-long-command -abcdef --long-option --another-long-option /a/long/path/to/somewhere 21 | ... 22 | > cat file1 file2 | !! | grep 'search-key' | wrap -s 23 | ... 24 | ``` 25 | 26 | -------------------------------------------------------------------------------- 27 | 28 | Typing `!$` will expand to the last argument. For example, if you searched packages with pacman and found nothing, you'd like to also search in the AUR. 29 | 30 | ```console 31 | > pacman -Ss something 32 | ... 33 | > paru -Ss !$ 34 | ... 35 | ``` 36 | 37 | ## Installation 38 | 39 | Install with [Fisher](https://github.com/jorgebucaran/fisher "fish plugin manager"): 40 | 41 | ```console 42 | fisher install nickeb96/puffer-fish 43 | ``` 44 | 45 | #### Manually 46 | 47 | Just copy `functions/*` and `conf.d/*` to your `$__fish_config_dir` directory. Make sure to create them if they don't already exist. 48 | 49 | ## LICENSE 50 | 51 | [MIT](LICENSE) 52 | -------------------------------------------------------------------------------- /conf.d/puffer_fish_key_bindings.fish: -------------------------------------------------------------------------------- 1 | status is-interactive || exit 2 | 3 | function _puffer_fish_key_bindings --on-variable fish_key_bindings 4 | set -l modes 5 | if test "$fish_key_bindings" = fish_default_key_bindings 6 | set modes default insert 7 | else 8 | set modes insert default 9 | end 10 | 11 | bind --mode $modes[1] . _puffer_fish_expand_dots 12 | bind --mode $modes[1] ! _puffer_fish_expand_bang 13 | bind --mode $modes[1] '$' _puffer_fish_expand_lastarg 14 | bind --mode $modes[2] --erase . ! '$' 15 | end 16 | 17 | _puffer_fish_key_bindings 18 | 19 | set -l uninstall_event puffer_fish_key_bindings_uninstall 20 | 21 | function _$uninstall_event --on-event $uninstall_event 22 | bind -e . 23 | bind -e ! 24 | bind -e '$' 25 | end 26 | -------------------------------------------------------------------------------- /functions/_puffer_fish_expand_bang.fish: -------------------------------------------------------------------------------- 1 | function _puffer_fish_expand_bang 2 | switch (commandline -t) 3 | case '!' 4 | commandline -t $history[1] 5 | case '*' 6 | commandline -i '!' 7 | end 8 | end 9 | 10 | -------------------------------------------------------------------------------- /functions/_puffer_fish_expand_dots.fish: -------------------------------------------------------------------------------- 1 | function _puffer_fish_expand_dots -d 'expand ... to ../.. etc' 2 | set -l cmd (commandline --cut-at-cursor) 3 | set -l split (string split -- ' ' $cmd) 4 | if string match --quiet --regex -- '^(\.\./)*\.\.$' $split[-1] 5 | commandline --insert '/..' 6 | else 7 | commandline --insert '.' 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /functions/_puffer_fish_expand_lastarg.fish: -------------------------------------------------------------------------------- 1 | function _puffer_fish_expand_lastarg 2 | switch (commandline -t) 3 | case '!' 4 | commandline -t "" 5 | commandline -f history-token-search-backward 6 | case '*' 7 | commandline -i '$' 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /media/dot-dot-demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nickeb96/puffer-fish/12d062eae0ad24f4ec20593be845ac30cd4b5923/media/dot-dot-demo.gif -------------------------------------------------------------------------------- /media/exclamation-demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nickeb96/puffer-fish/12d062eae0ad24f4ec20593be845ac30cd4b5923/media/exclamation-demo.gif --------------------------------------------------------------------------------