1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 07:08:01 +00:00

Add Fix Previous Command With fc as a Unix TIL

This commit is contained in:
jbranchaud
2025-02-20 17:42:32 -06:00
parent ee31f5b70d
commit cea3bc05b5
2 changed files with 28 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1595 TILs and counting..._ _1596 TILs and counting..._
See some of the other learning resources I work on: See some of the other learning resources I work on:
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators) - [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
@@ -1532,6 +1532,7 @@ See some of the other learning resources I work on:
- [Find Newer Files](unix/find-newer-files.md) - [Find Newer Files](unix/find-newer-files.md)
- [Find Occurrences Of Multiple Values With Ripgrep](unix/find-occurrences-of-multiple-values-with-ripgrep.md) - [Find Occurrences Of Multiple Values With Ripgrep](unix/find-occurrences-of-multiple-values-with-ripgrep.md)
- [Find Top-Level Directories Matching A Pattern](unix/find-top-level-directories-matching-a-pattern.md) - [Find Top-Level Directories Matching A Pattern](unix/find-top-level-directories-matching-a-pattern.md)
- [Fix Previous Command With fc](unix/fix-previous-command-with-fc.md)
- [Fix Shim Path After asdf Upgrade](unix/fix-shim-path-after-asdf-upgrade.md) - [Fix Shim Path After asdf Upgrade](unix/fix-shim-path-after-asdf-upgrade.md)
- [Fix Unlinked Node Binaries With asdf](unix/fix-unlinked-node-binaries-with-asdf.md) - [Fix Unlinked Node Binaries With asdf](unix/fix-unlinked-node-binaries-with-asdf.md)
- [Forward Multiple Ports Over SSH](unix/forward-multiple-ports-over-ssh.md) - [Forward Multiple Ports Over SSH](unix/forward-multiple-ports-over-ssh.md)

View File

@@ -0,0 +1,26 @@
# Fix Previous Command With fc
The `fc` command is a Bash and ZSH built-in command that allows you to interact
with the history of commands issued in the shell. The most straightforward use
case I know of for using this command is to fix or edit some aspect of the
previous run command.
When `fc` is executed with no arguments or flags, it will grab the latest entry
to the command history and load it into your default editor. For me, that is
Vim.
I can make edits in that Vim session like I'd do in any other Vim session. When
I write and quit (`:wq`) the file, the updated command will be executed. This
is useful if, say, I've made a typo in the previous command and would prefer
the ergonomics of my default editor to fix it. Or let's say I have a really
long command with many flags and long file path arguments. It would be much
easier and quicker to edit those paths from my editor than from the terminal
prompt.
If I've opened my editor (Vim) with `fc` and I decide I don't want to execute
the command after all, I can _compiler quit_ Vim (exit with an error code)
using `:cq`. The command will not be executed in this case.
See `man zshbuiltins` for more details about this command and all of its flags.
[source](https://www.computerhope.com/unix/uhistory.htm)