Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,26 @@ run '' 'bet' "$ctrl_n" >/dev/null || true
assert_log 'ctrl-n creates from the query even with a match highlighted' \
'ATTACH:\[bet] PWD:*'

reset_log
rc=0
run '' "$tab" "$ctrl_n" >/dev/null || rc=$?
if [[ $rc -eq 1 && -z $(log) ]]; then
ok 'ctrl-n with an empty query errors out, ignoring marks'
else
not_ok 'ctrl-n with an empty query errors out, ignoring marks' \
"rc=$rc log=$(log)"
fi

reset_log
run '' 'zzz-new' "$enter" >/dev/null || true
assert_log 'enter on an unmatched query creates a session' \
'ATTACH:\[zzz-new] PWD:*'

reset_log
run '' "$tab" "$enter" >/dev/null || true
assert_log 'enter follows the cursor even with other rows marked' \
'ATTACH:\[alpha.2] PWD:*'

reset_log
run '' "$tab$tab" "$ctrl_x" "$esc" >/dev/null || true
assert_log 'ctrl-x kills all marked sessions in one call' \
Expand Down
16 changes: 11 additions & 5 deletions zp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# shellcheck disable=SC2016 # literal $VARs in single quotes are deliberate
set -euo pipefail

version=0.2.1
version=0.2.2

# Absolute path to this script, for fzf reload bindings.
self=$(cd "$(dirname "$0")" && pwd)/${0##*/}
Expand Down Expand Up @@ -277,6 +277,7 @@ select_session() {
--ellipsis='…' \
--prompt='zmx> ' \
--header=$'Enter: select/create | Tab: mark\n^N: new from query | ^X: kill' \
--bind='enter:clear-selection+accept' \
--bind="ctrl-x:execute-silent(printf '%s\n' {+} | $kill_cmd)+reload($reload_cmd)" \
--bind="focus:transform:test {1} = session && echo 'change-preview-window(follow)' || echo 'change-preview-window(nofollow)'" \
--preview="$preview_cmd" \
Expand All @@ -296,11 +297,16 @@ select_session() {
key=$(sed -n '2p' <<<"$output")
selected=$(sed -n '3p' <<<"$output")

if [[ $key == ctrl-n && -n $query ]]; then
# Force a new session named after the query, even when a
# fuzzy match is highlighted.
if [[ $key == ctrl-n ]]; then
# Ctrl-N means "new from the query": force a session named
# after it even when a fuzzy match is highlighted, and never
# fall through to marked rows.
if [[ -z $query ]]; then
printf 'ctrl-n needs a typed query to name the new session\n' >&2
return 1
fi
zmx attach "$query"
return
return 0
fi

if [[ -n $selected ]]; then
Expand Down
Loading