From 0cb13217b8def56c02298dc2ce584a353a7167e0 Mon Sep 17 00:00:00 2001 From: Spenser Truex Date: Thu, 28 Jan 2021 08:39:29 -0800 Subject: [PATCH] Turns out caching isn't necessary or desirable (though it is slightly faster) --- Cache-aliases-Startup.md | 50 ---------------------------------------- Multiple-aliases.md | 16 +++++++++++++ 2 files changed, 16 insertions(+), 50 deletions(-) delete mode 100644 Cache-aliases-Startup.md create mode 100644 Multiple-aliases.md diff --git a/Cache-aliases-Startup.md b/Cache-aliases-Startup.md deleted file mode 100644 index 1540899..0000000 --- a/Cache-aliases-Startup.md +++ /dev/null @@ -1,50 +0,0 @@ -Thefuck takes longer to generate aliases than it takes hell to freeze over: -```sh -time thefuck --alias -thefuck --alias 0.12s user 0.04s system 92% cpu 0.172 total -# What the fuck? -``` -This can be cached in your shell's startup script `.bashrc` or whatever: -```sh -[ -n "$XDG_RUNTIME_DIR" ] && thefuck_cache="$XDG_RUNTIME_DIR"/thefuck_cache -[ -z "$XDG_RUNTIME_DIR" ] && thefuck_cache="$HOME"/.local/share/runtime/thefuck_cache -if [ ! -f "$thefuck_cache" ]; then - thefuck --alias k | tee -a "$thefuck_cache" - thefuck --alias fk | tee -a "$thefuck_cache" - thefuck --alias fcuk | tee -a "$thefuck_cache" - thefuck --alias fuc | tee -a "$thefuck_cache" - thefuck --alias fcu | tee -a "$thefuck_cache" - thefuck --alias fuck | tee -a "$thefuck_cache" - thefuck --alias fuk | tee -a "$thefuck_cache" -fi -source "$thefuck_cache" -unset thefuck_cache -``` -Doing this with `--enable-experimental-instant-mode` requires some care, because doing it wrong will cause thefuck to run infinite processes until it fills up your memory and crashes your computer! - -This is a zsh script. To check for the login shell in bash, use `shopt -q login_shell` instead of setopt. -```zsh -#!/bin/zsh -thefuck_experimental_cache="$XDG_RUNTIME_DIR"/thefuck_experimental_cache -THEFUCK_EXPERIMENTAL_LOCK_KLUDGE="$XDG_RUNTIME_DIR"/thefuck_experimental_lock_kludge -experimentallyinstantlylockkludginglyverylongname () { - printf %s " $$ " >>"$THEFUCK_EXPERIMENTAL_LOCK_KLUDGE" - [[ ! -f "$thefuck_experimental_cache" ]] \ - && thefuck --enable-experimental-instant-mode --alias noop >"$thefuck_experimental_cache" \ - source "$thefuck_experimental_cache" -} - -[[ ! -e "$THEFUCK_EXPERIMENTAL_LOCK_KLUDGE" ]] \ - || touch "$THEFUCK_EXPERIMENTAL_LOCK_KLUDGE" - -if [[ -z "$(setopt | grep -i login)" ]]; then - [[ ! $(grep -qF -- " $$ " $THEFUCK_EXPERIMENTAL_LOCK_KLUDGE) ]] \ - && experimentallyinstantlylockkludginglyverylongname - # so here it is, not cached. -else - # Delete this file on startup so it doesn't grow indefinitely. - rm "$THEFUCK_EXPERIMENTAL_LOCK_KLUDGE" -fi -``` - -``` diff --git a/Multiple-aliases.md b/Multiple-aliases.md new file mode 100644 index 0000000..a242862 --- /dev/null +++ b/Multiple-aliases.md @@ -0,0 +1,16 @@ +Thefuck takes longer to generate aliases than it takes hell to freeze over: +```sh +time thefuck --alias +thefuck --alias 0.12s user 0.04s system 92% cpu 0.172 total +# What the fuck? +``` +**Don't run thefuck --alias more than once.** + +Instead: run it, then use `alias thing=fuck`. +```sh +thefuck --alias +alias fk=fuck +alias f=fuck +alias k=fuck +alias fu=fuck +``` \ No newline at end of file