mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-29 14:23:09 +00:00
7c2dd694e0
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
16 lines
643 B
Fish
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
|