Skip to content

Commit ea48467

Browse files
committed
[zsh] m: more reliable way to switch back in mscripts
1 parent f62beb6 commit ea48467

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

zsh/.config/zsh/functions

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,27 @@ q() {
8585
}
8686

8787
m() {
88+
prev_dir="$(pwd)"
8889
r >/dev/null
8990

90-
trap popd 1 2 3 6 >/dev/null
91-
9291
if [ ! -d .mscripts ]; then
93-
echo "Unable to find .mscripts" && return 1
92+
echo "Unable to find .mscripts"
93+
cd "$prev_dir" >/dev/null || return 1
94+
return 1
9495
fi
96+
9597
script="$1"
9698
[ -n "$1" ] && shift
97-
mscript="$(find .mscripts/ | tail -n+2 | xargs -n1 basename | fzf --query "$script" -1)"
99+
mscript="$(find .mscripts/ -type f -executable | tail -n+2 | xargs -n1 basename | fzf --query "$script" -1)"
98100

99101
if [ -z "$mscript" ]; then
100102
echo "No mscript available for $script"
103+
cd "$prev_dir" >/dev/null
101104
return 1
102105
fi
103106

104107
eval .mscripts/"$mscript" $*
108+
cd "$prev_dir" >/dev/null
105109
}
106110

107111
mm() {

0 commit comments

Comments
 (0)