white-space safe 'thefuck' with the history line passed as a single arg?
#490 创建于 2016年4月1日
仓库指标
- 星标
- (97,710 个星标)
- PR 合并指标
- (30 天内没有已合并 PR)
描述
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)