fish-shell/share/functions/fish_commandline_prepend.fish
Johannes Altmanninger 7c2dd694e0 Provide functions to toggle commandline prefix/suffix
This introduces two functions to
- toggle a process prefix, used for adding "sudo"
- add a job suffix, used for adding "&| less"

Not sure if they are very useful; we'll see.

Closes #7905
2021-06-23 20:51:20 +02:00

16 lines
643 B
Fish

function fish_commandline_prepend --description "Prepend the given string to the command-line, or remove the prefix if already there"
if not commandline | string length -q
commandline -r $history[1]
end
set -l escaped (string escape --style=regex -- $argv[1])
set -l process (commandline -p | string collect)
if set process (string replace -r -- "^$escaped " "" $process)
commandline --replace -p -- $process
else
set -l cursor (commandline -C)
commandline -C 0 -p
commandline -i -- "$argv[1] "
commandline -C (math $cursor + (string length -- "$argv[1] "))
end
end