mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-31 02:01:13 +00:00
Turns out caching isn't necessary or desirable (though it is slightly faster)
parent
4a5b52d2f3
commit
0cb13217b8
@ -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
|
||||
```
|
||||
|
||||
```
|
16
Multiple-aliases.md
Normal file
16
Multiple-aliases.md
Normal file
@ -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
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user