From 9f3059b7f4f3aabe5e6b5037908227afca1eb756 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sat, 14 Apr 2018 17:11:04 -0500 Subject: [PATCH] Add wrappers for fg/bg/wait to support job expansion See commit 1c8bbfdb6d8eab6cb3e355f1cd32afd835cec961 for an alternative approach, if this isn't desired. --- share/config.fish | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/share/config.fish b/share/config.fish index 8c3779a3d..0196b7582 100644 --- a/share/config.fish +++ b/share/config.fish @@ -256,3 +256,35 @@ end # Invoke this here to apply the current value of fish_user_path after # PATH is possibly set above. __fish_reconstruct_path + +# Allow %n job expansion to be used with fg/bg/wait +# `jobs` is the only one that natively supports job expansion +function __fish_expand_pid_args + for arg in $argv + if string match -qr '^%\d+$' -- $arg + # set newargv $newargv (jobs -p $arg) + jobs -p $arg + if not test $status -eq 0 + return 1 + end + else + echo $arg + end + end +end + +function __fish_expand_fg + builtin fg (__fish_expand_pid_args $argv) +end + +function __fish_expand_bg + builtin bg (__fish_expand_pid_args $argv) +end + +function __fish_expand_wait + builtin wait (__fish_expand_pid_args $argv) +end + +alias fg __fish_expand_fg +alias bg __fish_expand_bg +alias wait __fish_expand_wait