diff --git a/tests/run.sh b/tests/run.sh index 5c723e9..5aa82b0 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -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' \ diff --git a/zp b/zp index c42719c..6bd142c 100755 --- a/zp +++ b/zp @@ -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##*/} @@ -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" \ @@ -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