Skip to content

Commit

Permalink
chore: add tests and fix for fish shell
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesmithgh committed Dec 17, 2024
1 parent 3272038 commit 81f7e01
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -883,15 +883,15 @@ The API is available via the `kitty-scrollback.api` module. e.g., `require('kitt
> [!NOTE]
> Command-line editing is only supported for `bash`, `fish`, or `zsh`
Generate the shell configuration and add them to the appropriate location. The comments in the shell configuration will provide
Generate the configuration and add it to the appropriate location. The comments in the configuration will provide
additional setup instructions. `KittyScrollbackGenerateCommandLineEditing` requires one parameter, either `bash`, `fish`, or `zsh`.
```sh
nvim --headless +'KittyScrollbackGenerateCommandLineEditing <shell>' # replace <shell> with bash, fish, or zsh
```

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.
This allows [Kitten Arguments](#kitten-arguments) setup specific to opening kitty-scrollback.nvim in command-line editing mode
that you may want to configure differently your standard kitty-scrollback.nvim setup.
that you may want to configure differently than your standard kitty-scrollback.nvim setup.

### Example setups
<details>
Expand Down
18 changes: 16 additions & 2 deletions scripts/edit_command_line.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ fi
# the last argument is used because in the case of zsh, commands maybe be passed before the filename e.g., (-c)
for input_file; do true; done

case "$input_file" in
*.fish)
shell_type="fish"
;;
*.zsh)
shell_type="zsh"
;;
*)
shell_type="bash"
;;
esac

# after exiting this script and before it has been read by kitty-scrollback.nvim
# the contents of the original input_file may be altered
# avoid this by copying the input_file to a new file that will be referenced
Expand All @@ -26,5 +38,7 @@ kitty @ kitten "$ksb_dir/python/kitty_scrollback_nvim.py" --env "KITTY_SCROLLBAC
# has had time to get the scrollback buffer from kitty
sleep 1

# exit non-zero so that the command is not executed in bash
exit 1
if [ "$shell_type" = "bash" ]; then
# exit non-zero so that the command is not executed in bash
exit 1
fi
9 changes: 9 additions & 0 deletions tests/kitty-scrollback/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ M.open_tmux_kitty_scrollback_nvim = function()
}
end

M.alt_e = function()
return {
[[\x1be]],
opts = {
send_by = 'string',
},
}
end

M.control_enter = function()
return {
[[\x1b[13;5u]],
Expand Down
43 changes: 43 additions & 0 deletions tests/kitty-scrollback/kitty_scrollback_fish_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ describe('kitty-scrollback.nvim', function()
function fish_prompt
echo "fish \$ "
end
function kitty_scrollback_edit_command_buffer
set -lx VISUAL ']] .. ksb_dir .. [[/scripts/edit_command_line.sh'
edit_command_buffer
commandline ''
end
bind --mode default \\ee kitty_scrollback_edit_command_buffer
]]),
h.with_pause_seconds_before(h.send_without_newline(h.clear())),
})
Expand Down Expand Up @@ -110,4 +116,41 @@ Press ENTER or type command to continue.*]],
}
)
end)

it('should open command in command-line editing mode', function()
h.assert_screen_equals(
h.feed_kitty({
h.with_pause_seconds_before(h.send_without_newline([[nacho cheese]])),
h.alt_e(),
h.with_pause_seconds_before(h.send_without_newline([[ciwecho]]), 2),
h.send_without_newline(h.control_enter()),
}),
{
stdout = [[
fish $ echo cheese
cheese
fish $
]],
cursor_y = 3,
cursor_x = 8,
}
)
end)

it('should clear command if no-op in command-line editing mode', function()
h.assert_screen_equals(
h.feed_kitty({
h.with_pause_seconds_before(h.send_without_newline([[nacho cheese]])),
h.alt_e(),
h.with_pause_seconds_before([[:qa!]]),
}),
{
stdout = [[
fish $
]],
cursor_y = 1,
cursor_x = 8,
}
)
end)
end)
2 changes: 2 additions & 0 deletions tests/kitty.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ map kitty_mod+g kitty_scrollback_nvim --config ksb_builtin_last_cmd_output
mouse_map kitty_mod+right press ungrabbed combine : mouse_select_command_output : kitty_scrollback_nvim --config ksb_builtin_last_visited_cmd_output

## Extras
macos_option_as_alt yes

font_family MonoLisa Variable
symbol_map U+23FB-U+23FE,U+2665,U+26A1,U+2B58,U+E000-U+F8FF FiraCode Nerd Font

Expand Down

0 comments on commit 81f7e01

Please sign in to comment.