1

Here's a function that executes a selected alias using fzf:

fa() { 
  eval $(alias | fzf | cut -d'=' -f2 | sd -p "'" '') 
}

The problem is that sometimes you want to add more arguments to an alias rather than immediately execute it. Is this possible?

1 Answer 1

2

Solution using zsh:

fa() { 
  print -z $(alias | fzf | cut -d'=' -f2 | sd -p "'" '') 
}
4
  • Unfortunately, print -z interfers with sed command. For example, escaping special characters, such as ' or (, with sed no longer works. It would have been easier if fzf offered a way to print selected items onto the prompt only.
    – Faxopita
    Commented Jun 8, 2023 at 22:48
  • As a workaround, I had to use a combination of awk '{printf "%s ", $0}' (to convert multi-line into single line) and pbcopy (to copy formatted output to clipboard). Then, manually pasting with ^V (or ⌘V).
    – Faxopita
    Commented Jun 9, 2023 at 9:15
  • I think you're assuming sd means sed? sd is different and doesn't seem to have that problem
    – jsuth
    Commented Jun 9, 2023 at 9:23
  • Just tried with sd, same issue. Tried piping fzf output to sd -p "(\(|\)| |')" '\$1', but only blank space get escaped.
    – Faxopita
    Commented Jun 9, 2023 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.