4 ms·
I quit fish because I missed being able to `sudo !!` to rerun the previous command with sudo. There's an alternative way to do it (something like up arrow, ctrl
by istjohn 3y ago
I quit fish because I missed being able to `sudo !!` to rerun the previous command with sudo. There's an alternative way to do it (something like up arrow, ctrl-i, "sudo", enter), but I can never remember it when I need it, which is not often enough to stay in my head, but often enough to be come quite annoying.
- 7839284023 3y agoI hope that you are joking since you just have to press `Alt` + `S` to rerun the previous command with sudo in fish-shell: > `Alt` + `S` Prepends sudo to the current commandline. If the commandline is empty, prepend sudo to the last commandline. https://fishshell.com/docs/current/interactive.html#shared-bindings https://fishshell.com/docs/current/interactive.html#shared-b...
- JNRowe 3y agoThat is a recent(-ish) addition¹, arriving in 3.1. Your interpretation of recent may be a different length to mine, but one Debian release in this instance ;) ¹ https://github.com/fish-shell/fish-shell/pull/6140 https://github.com/fish-shell/fish-shell/pull/6140
- winter_blue 3y agoI guess he wasn't aware. I use fish, and I'm learning this now too. I probably really should give the fish docs a read-through, as I imagine it could significantly improve my shell efficiency.
- istjohn 3y agoGlad to hear that's changed. There were strident statements from the developer on Github last time I researched it to the effect that implementing '!'-style history expansion was contrary to the fish philosophy and that people just need to learn the fish-y way. Looking back it, I probably could have fixed the issue for myself by setting up vi-mode in fish, but I didn't come across that option at the time.
- rileymichael 3y agoYou can set this up to work the same way with the recent abbr changes, and I believe they may add it as a default in the future. function last_history_item; echo $history[1]; end abbr -a !! --position anywhere --function last_history_item source: https://fishshell.com/docs/current/relnotes.html#id1 https://fishshell.com/docs/current/relnotes.html#id1
- deleted 3y ago[deleted]
- aquova 3y agoThat behavior was added earlier this year - https://fishshell.com/docs/current/relnotes.html#fish-3-6-0-released-january-7-2023 https://fishshell.com/docs/current/relnotes.html#fish-3-6-0-...
- alsuren 3y agoI also bounced off of fish for the same reason. This post has prompted me to give fish another go, so I looked into it again. It looks like the abbreviation system can now (since March this year) help you with !! (https://fishshell.com/docs/current/cmds/abbr.html https://fishshell.com/docs/current/cmds/abbr.html even gives it as an example) I also use `!$` (`vim script.py` and then `python !$` or `git commit !$`) but the parser rejects `!$` before it can be rewritten by the abbreviation system. [edit: https://superuser.com/a/1762626 https://superuser.com/a/1762626 points out that if you add a space before hitting enter then it works fine, so I'm guessing it's just a bug, and I should go with d below] Options seem to include: a) make a !$ replacement that is not illegal and change your muscle memory `\$` or `!\$` or `!@` or `!%` b) use a keybinding for !$ as suggested in https://github.com/fish-shell/fish-shell/issues/288 https://github.com/fish-shell/fish-shell/issues/288 c) some combination of a and b (e.g. make a `!\$` abbreviation and then make a binding so that if you type !$ it replaces it with `!\$` so that it gets past the parser without expliding) d) patch the parser to allow !$ as a special case if there is an abbr for it. I just tried b but it's pretty jarring. I think I might go with c instead. I'm actually feeling quite positive about this now. There is something I've been wanting to add to bash since forever, which is something to help me cd into a repo that I just cloned (e.g. `git clone https://github.com/fish-shell/fish-shell https://github.com/fish-shell/fish-shell` then `cd !/` could expand to `cd fish-shell`). Exciting times.
- JNRowe 3y agoBash has a range of modifiers for history expansion. You can "cd !$:t" to execute "cd <final argument of last command, basename only>" for your git example. zsh, somewhat predictably, has a superset of bash's modifiers so it works there too.