Skip to content

Commit 3257867

Browse files
committed
feat(job stack): surface the current job's identity
1 parent 9244dc6 commit 3257867

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

zsh-abbr.zsh

+21-4
Original file line numberDiff line numberDiff line change
@@ -922,20 +922,26 @@ _zsh_abbr_job_push() {
922922
local job
923923
local job_dir
924924
local job_group
925+
local job_path
925926
local timeout_age
926927

927928
job=${(q)1}
928929
job_group=${(q)2}
929930
timeout_age=30 # seconds
930931

931-
job_dir=${TMPDIR:-/tmp}/zsh-abbr-jobs/${job_group}
932+
job_dir=${TMPDIR:-/tmp}zsh-abbr-jobs/${job_group}
933+
job_path=$job_dir/$job
932934

933935
function add_job() {
934936
if ! [ -d $job_dir ]; then
935937
mkdir -p $job_dir
936938
fi
937939

938-
echo $job_group > $job_dir/$job
940+
if ! [ -d ${TMPDIR:-/tmp}zsh-abbr-jobs/current ]; then
941+
mkdir ${TMPDIR:-/tmp}zsh-abbr-jobs/current
942+
fi
943+
944+
echo $job_group > $job_path
939945
}
940946

941947
function get_next_job() {
@@ -952,7 +958,8 @@ _zsh_abbr_job_push() {
952958
echo "Please report this at https://github.com/olets/zsh-abbr/issues/new"
953959
echo
954960

955-
rm $next_job_path
961+
rm $next_job_path &>/dev/null
962+
rm "${TMPDIR:-/tmp}zsh-abbr-jobs/current/$job_group*" &>/dev/null
956963
}
957964

958965
function wait_turn() {
@@ -966,6 +973,8 @@ _zsh_abbr_job_push() {
966973

967974
sleep 0.01
968975
done
976+
977+
cp $job_path "${TMPDIR:-/tmp}zsh-abbr-jobs/current/$job_group-$job"
969978
}
970979

971980
add_job
@@ -979,13 +988,21 @@ _zsh_abbr_job_push() {
979988
}
980989

981990
_zsh_abbr_job_pop() {
991+
local currents
982992
local job
983993
local job_group
984994

985995
job=${(q)1}
986996
job_group=$2
987997

988-
rm "${TMPDIR:-/tmp}/zsh-abbr-jobs/${job_group}/${job}"
998+
typeset -a currents
999+
currents=(${(@f)$(ls -d ${TMPDIR:-/tmp}zsh-abbr-jobs/current/$job_group* 2>/dev/null)})
1000+
1001+
for current in $currents; do
1002+
rm $current &>/dev/null
1003+
done
1004+
1005+
rm "${TMPDIR:-/tmp}zsh-abbr-jobs/${job_group}/${job}" &>/dev/null
9891006
}
9901007

9911008
_zsh_abbr_job_name() {

0 commit comments

Comments
 (0)