Open Artoria2e5 opened 8 years ago
thefuck
actually has a long way to go regarding whitespace/metachar-safety. Take 237f43e as an example (I found the cd issue when searching for 'whitespace' in issues to make sure that I didn't get a dup):
return 'cd "{0}"'.format(cwd)
This is unfortunately not the safe thing to do, e.g.:
cd "$(mktemp -d)"
mkdir aaaa\"
thefuck cd aaa
You will get some output like:
cd "/tmp/tmp.R71CQrZT1O/aaaa""
Unbalanced quotes.
The Right Thing™ to do is to actually use lists as the data structure for internal representation of single simple commands, i.e.
return ['cd', cwd]
And finally do some quoting based on shell-dependent rules before outputting (already there in the source).
Note that POSIX shells don't consider quoted things like 'if'
as keywords, and that's why I am putting emphasis on simple.
Yep, you're right. I'll think about how it can be made.
In some shells' thefuck alias, e.g. for bash, the core part falls to:
But
$(fc -ln -1)
is not a safe thing to try. In python terminology,$(fc -ln -1)
is something like:which is almost certainly not the thing you are looking for. Similarly,
$TF_CMD
gets split and globbed and list-joined (and' '.join()
'ed byeval
) ineval $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:
(using sh for some arg dump that makes sense)