Skip to content
Snippets Groups Projects
Commit a64d1acf authored by Derek Stavis's avatar Derek Stavis
Browse files

Implement safe shell reloading inside omf plugin

This commit adds an improved reload code for Oh My Fish, besides
saving the history now the reloading technique keeps directory
history and stack and clears fish_greeting, for a transparent
transition.

The reloading code is now safe regarding to background jobs. exec
wipes fish job control, so the user-facing code under the (just-
introduced by this commit) `omf reload`, and usages under
`omf remove` and `omf update` are now kept safe by a warning.

Recap of the commit:
- Add improved reload code (omf.reload)
- Add a safe reload code (omf.cli.reload)
- Add `omf reload` command
parent a188b7b0
No related merge requests found
function omf.cli.reload
if not contains -- --force $argv
if count (jobs) >/dev/null ^&1
__omf.cli.reload.job_warning
return 1
end
end
omf.reload
end
function __omf.cli.reload.job_warning
echo (set_color -u)"Reload aborted. There are background jobs:"(set_color normal)
echo
jobs
echo
echo "For your safety, finish all background jobs before reloading Oh My Fish."
echo "If you are absolutely sure of what you are doing, you can bypass this check using --force."
end
...@@ -7,6 +7,7 @@ function omf.cli.remove -a name ...@@ -7,6 +7,7 @@ function omf.cli.remove -a name
switch $code switch $code
case 0 case 0
echo (omf::em)"$name successfully removed."(omf::off) echo (omf::em)"$name successfully removed."(omf::off)
omf.cli.reload
case 1 case 1
echo (omf::err)"$name could not be removed."(omf::off) 1^&2 echo (omf::err)"$name could not be removed."(omf::off) 1^&2
case 2 case 2
......
...@@ -9,4 +9,6 @@ function omf.cli.update ...@@ -9,4 +9,6 @@ function omf.cli.update
for package in (omf.packages.list --installed) for package in (omf.packages.list --installed)
omf.packages.update $package omf.packages.update $package
end end
omf.cli.reload
end end
function omf.reload -d "Reload fish process via exec(1), keeping some context"
set -q CI; and return 0
history --save
set -gx dirprev $dirprev
set -gx dirnext $dirnext
set -gx dirstack $dirstack
set -gx fish_greeting ''
exec fish
end
...@@ -40,6 +40,9 @@ function omf -d "Oh My Fish" ...@@ -40,6 +40,9 @@ function omf -d "Oh My Fish"
case "doctor" case "doctor"
omf.cli.doctor omf.cli.doctor
case "reload"
omf.cli.reload $arguments
case "i" "install" "get" case "i" "install" "get"
omf.cli.install $arguments omf.cli.install $arguments
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment