Skip to content

Commit 81f7e01

Browse files
committed
chore: add tests and fix for fish shell
1 parent 3272038 commit 81f7e01

File tree

5 files changed

+72
-4
lines changed

5 files changed

+72
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,15 +883,15 @@ The API is available via the `kitty-scrollback.api` module. e.g., `require('kitt
883883
> [!NOTE]
884884
> Command-line editing is only supported for `bash`, `fish`, or `zsh`
885885
886-
Generate the shell configuration and add them to the appropriate location. The comments in the shell configuration will provide
886+
Generate the configuration and add it to the appropriate location. The comments in the configuration will provide
887887
additional setup instructions. `KittyScrollbackGenerateCommandLineEditing` requires one parameter, either `bash`, `fish`, or `zsh`.
888888
```sh
889889
nvim --headless +'KittyScrollbackGenerateCommandLineEditing <shell>' # replace <shell> with bash, fish, or zsh
890890
```
891891

892892
The generated configuration will mention the environment variable `KITTY_SCROLLBACK_NVIM_EDIT_ARGS`. This can be used to pass arguments to kitty-scrollback.nvim in command-line editing mode.
893893
This allows [Kitten Arguments](#kitten-arguments) setup specific to opening kitty-scrollback.nvim in command-line editing mode
894-
that you may want to configure differently your standard kitty-scrollback.nvim setup.
894+
that you may want to configure differently than your standard kitty-scrollback.nvim setup.
895895

896896
### Example setups
897897
<details>

scripts/edit_command_line.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ fi
99
# the last argument is used because in the case of zsh, commands maybe be passed before the filename e.g., (-c)
1010
for input_file; do true; done
1111

12+
case "$input_file" in
13+
*.fish)
14+
shell_type="fish"
15+
;;
16+
*.zsh)
17+
shell_type="zsh"
18+
;;
19+
*)
20+
shell_type="bash"
21+
;;
22+
esac
23+
1224
# after exiting this script and before it has been read by kitty-scrollback.nvim
1325
# the contents of the original input_file may be altered
1426
# avoid this by copying the input_file to a new file that will be referenced
@@ -26,5 +38,7 @@ kitty @ kitten "$ksb_dir/python/kitty_scrollback_nvim.py" --env "KITTY_SCROLLBAC
2638
# has had time to get the scrollback buffer from kitty
2739
sleep 1
2840

29-
# exit non-zero so that the command is not executed in bash
30-
exit 1
41+
if [ "$shell_type" = "bash" ]; then
42+
# exit non-zero so that the command is not executed in bash
43+
exit 1
44+
fi

tests/kitty-scrollback/helpers.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,15 @@ M.open_tmux_kitty_scrollback_nvim = function()
311311
}
312312
end
313313

314+
M.alt_e = function()
315+
return {
316+
[[\x1be]],
317+
opts = {
318+
send_by = 'string',
319+
},
320+
}
321+
end
322+
314323
M.control_enter = function()
315324
return {
316325
[[\x1b[13;5u]],

tests/kitty-scrollback/kitty_scrollback_fish_spec.lua

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ describe('kitty-scrollback.nvim', function()
3737
function fish_prompt
3838
echo "fish \$ "
3939
end
40+
function kitty_scrollback_edit_command_buffer
41+
set -lx VISUAL ']] .. ksb_dir .. [[/scripts/edit_command_line.sh'
42+
edit_command_buffer
43+
commandline ''
44+
end
45+
bind --mode default \\ee kitty_scrollback_edit_command_buffer
4046
]]),
4147
h.with_pause_seconds_before(h.send_without_newline(h.clear())),
4248
})
@@ -110,4 +116,41 @@ Press ENTER or type command to continue.*]],
110116
}
111117
)
112118
end)
119+
120+
it('should open command in command-line editing mode', function()
121+
h.assert_screen_equals(
122+
h.feed_kitty({
123+
h.with_pause_seconds_before(h.send_without_newline([[nacho cheese]])),
124+
h.alt_e(),
125+
h.with_pause_seconds_before(h.send_without_newline([[ciwecho]]), 2),
126+
h.send_without_newline(h.control_enter()),
127+
}),
128+
{
129+
stdout = [[
130+
fish $ echo cheese
131+
cheese
132+
fish $
133+
]],
134+
cursor_y = 3,
135+
cursor_x = 8,
136+
}
137+
)
138+
end)
139+
140+
it('should clear command if no-op in command-line editing mode', function()
141+
h.assert_screen_equals(
142+
h.feed_kitty({
143+
h.with_pause_seconds_before(h.send_without_newline([[nacho cheese]])),
144+
h.alt_e(),
145+
h.with_pause_seconds_before([[:qa!]]),
146+
}),
147+
{
148+
stdout = [[
149+
fish $
150+
]],
151+
cursor_y = 1,
152+
cursor_x = 8,
153+
}
154+
)
155+
end)
113156
end)

tests/kitty.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ map kitty_mod+g kitty_scrollback_nvim --config ksb_builtin_last_cmd_output
2424
mouse_map kitty_mod+right press ungrabbed combine : mouse_select_command_output : kitty_scrollback_nvim --config ksb_builtin_last_visited_cmd_output
2525

2626
## Extras
27+
macos_option_as_alt yes
28+
2729
font_family MonoLisa Variable
2830
symbol_map U+23FB-U+23FE,U+2665,U+26A1,U+2B58,U+E000-U+F8FF FiraCode Nerd Font
2931

0 commit comments

Comments
 (0)