nvbn/thefuck

white-space safe 'thefuck' with the history line passed as a single arg?

Open

#490 geöffnet am 1. Apr. 2016

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Python (3.949 Forks)batch import
help wanted

Repository-Metriken

Stars
 (96.953 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

In some shells' thefuck alias, e.g. for bash, the core part falls to:

# https://github.com/nvbn/thefuck/blob/master/thefuck/shells/bash.py#L13
eval $(BUNCH_OF_VARIABLES=something thefuck $(fc -ln -1)))

But $(fc -ln -1) is not a safe thing to try. In python terminology, $(fc -ln -1) is something like:

reduce(op.add, (glob.glob(i) or [i] for i in shell_stdout(['fc', '-ln', '-1']).split()))

which is almost certainly not the thing you are looking for. Similarly, $TF_CMD gets split and globbed and list-joined (and ' '.join()'ed by eval) in eval $TF_CMD.

For POSIX shells like bash and zsh (well, POSIX-ish) this can be solved by passing in the whole history string and actually interpreting the results of shlex.split(thestring) (which seems to be done already somewhere in the source). For other shells.. perhaps a custom lexer?

tcsh seems to suffer from the same problem, but I am not a tcsh expert so I may be wrong:

A2:~# sh -xvc ': "$@"' -- `echo 'foo bar /*'`
: "$@"
+ : foo bar /bin /boot /dev /etc /home /initrd.img /initrd.img.old /lib /lib32 /lib64 /libx32 /lost+found /media /mnt /opt /proc /pub /root /run /sbin /srv /sys /tmp /usr /var /vmlinuz /vmlinuz.old

(using sh for some arg dump that makes sense)

Contributor Guide