thefuck
thefuck copied to clipboard
Feature Request: Correct me when I type `figlet moo | cowsay`
I would love for fuck
to fix when I forget the -n
piping figlet
into cowsay
:
⋊> ~ figlet moo | cowsay -n 15:38:05
_________________________
/ \
| _ __ ___ ___ ___ |
| | '_ ` _ \ / _ \ / _ \ |
| | | | | | | (_) | (_) | |
| |_| |_| |_|\___/ \___/ |
\ /
-------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
⋊> ~ figlet moo | cowsay 15:38:09
_________________________________________
/ \
| |
| _ __ ___ ___ ___ | '_ ` _ \ / _ \ / _ \ |
| | | | | | | (_) | (_) | |_| |_| |
\ |_|\___/ \___/ /
-----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
⋊> ~ fuck 15:38:10
No fucks given
I'll write a custom rule for this after work today for my own system, I'm more just checking if anyone else wants a copy when I'm done.
I'm in. And thank you in advance.
~> cat ~/.config/thefuck/rules/cowsay-figlet.py
def match(command):
piped_commands = command.script.split('|')
index_figlet = next((i for i,x in enumerate(piped_commands)
if x.strip().startswith('figlet')), None)
index_cowsay = next((i for i,x in enumerate(piped_commands)
if x.strip().startswith('cowsay')), None)
return (index_cowsay != None and index_figlet != None and index_cowsay > index_figlet and
any(x.strip().startswith('cowsay') and '-n' not in x for x in piped_commands))
def get_new_command(command):
piped_commands = command.script.split('|')
for i,x in enumerate(piped_commands):
if x.strip().startswith('cowsay') and '-n' not in x:
piped_commands[i] = x + ' -n'
return '|'.join(piped_commands)