kitten choose-files: Add a new binding of Alt+Enter to modify the name of an existing file when choosing a save file name

Fixes #9387
This commit is contained in:
Kovid Goyal 2026-01-26 10:45:17 +05:30
parent ada88e063b
commit a5433b8994
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
5 changed files with 44 additions and 1 deletions

View file

@ -205,6 +205,12 @@ Detailed list of changes
- kitten @: Fix relative paths for --password-file being resolved relative to
CWD instead of the kitty config directory
- kitten choose-files: Add a new binding of :kbd:`Alt+Enter` to modify the name
of an existing file when choosing a save file name (:iss:`9387`)
- kitten choose-files: Fix TAB completion in the choose save file name prompt
not working with respect to the current working directory (:iss:`9387`)
0.45.0 [2025-12-24]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -99,7 +99,9 @@ This kitten can also be used to select non-existent files, that is a new file
for a :guilabel:`Save file` type of dialog using :option:`--mode <kitty +kitten
choose_files --mode>`:code:`=save-file`. Once you have changed to the directory
you want the file to be in (using the :kbd:`Tab` key),
press :kbd:`Ctrl+Enter` and you will be able to type in the file name.
press :kbd:`Ctrl+Enter` and you will be able to type in the file name. If you
wish to modify an existing file name use :kbd:`Alt+Enter` to modify the
filename of the current top match instead.
Selecting directories

View file

@ -479,6 +479,26 @@ func (h *Handler) switch_to_save_file_name_mode() error {
if h.state.SearchText() != "" {
name = h.state.SearchText()
}
if name == "" {
name = h.current_abspath()
if name != "" {
if r, err := filepath.Rel(h.state.CurrentDir(), name); err == nil {
name = r
}
}
}
h.initialize_save_file_name(name)
return h.draw_screen()
}
func (h *Handler) switch_to_save_file_name_mode_based_on_existing() error {
name := h.current_abspath()
if name == "" {
return h.switch_to_save_file_name_mode()
}
if r, err := filepath.Rel(h.state.CurrentDir(), name); err == nil {
name = r
}
h.initialize_save_file_name(name)
return h.draw_screen()
}
@ -573,6 +593,12 @@ func (h *Handler) dispatch_action(name, args string) (err error) {
} else {
return h.switch_to_save_file_name_mode()
}
case "modifyname":
if h.state.mode.CanSelectNonExistent() {
return h.switch_to_save_file_name_mode_based_on_existing()
} else {
h.lp.Beep()
}
case "toggle":
switch args {
case "preview":

View file

@ -133,6 +133,13 @@ When choosing existing directories, will accept the directory whoose
contents are being currently displayed as the choice.
Does not work when selecting files to open rather than to save.
''')
map('Modify file name', 'modifyname alt+enter modifyname', long_text='''
Modify the name of an existing file and select it for saving.
Useful when specifying a file or directory name for saving that does not yet exist,
but is based on an existing file name.
Does not work when selecting files to open rather than to save.
''')
map('Next result', 'next_result down next 1')
map('Previous result', 'prev_result up next -1')

View file

@ -24,6 +24,7 @@ func FilePromptCompleter(getcwd func() string) func(string, string) *cli.Complet
return ans
}
}
debugprintln(1111111, getcwd())
return func(before_cursor, after_cursor string) (ans *cli.Completions) {
defer func() {
if r := recover(); r != nil {
@ -39,6 +40,7 @@ func FilePromptCompleter(getcwd func() string) func(string, string) *cli.Complet
prefix = d + utils.IfElse(strings.HasSuffix(d, string(os.PathSeparator)), "", string(os.PathSeparator))
}
dir := ""
debugprintln(2222222, getcwd())
if path == "" {
path = getcwd()
dir = path