From 830fceae0170f5e3db417dd49714e5adde3edca6 Mon Sep 17 00:00:00 2001 From: Stephen Sherratt Date: Thu, 28 Nov 2024 15:40:16 +1100 Subject: [PATCH] Improve filename completion behaviour Set the `filenames` option when completing filenames which allows more ergonomic completion of paths. Signed-off-by: Stephen Sherratt --- CHANGES.md | 1 + examples/fake_git.ml | 3 ++- src/climate/completion.ml | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index d3d9aab..7aff785 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## Unreleased +- Improve filename completion (#3) - Stop printing spec errors (#2, fixes #1) ## 0.2.0 diff --git a/examples/fake_git.ml b/examples/fake_git.ml index 49a36d8..c3d8a1d 100644 --- a/examples/fake_git.ml +++ b/examples/fake_git.ml @@ -29,7 +29,8 @@ let commit = let open Arg_parser in let+ _amend = flag [ "amend"; "a" ] and+ _branch = named_opt [ "b"; "branch" ] branch_conv - and+ _message = named_opt [ "m"; "message" ] string in + and+ _message = named_opt [ "m"; "message" ] string + and+ _files = pos_all file in () ;; diff --git a/src/climate/completion.ml b/src/climate/completion.ml index c16f9cc..19601f4 100644 --- a/src/climate/completion.ml +++ b/src/climate/completion.ml @@ -156,6 +156,12 @@ module Add_reply = struct "Takes the word under the cursor (just the portion up to the cursor) and \ completes with files in the current directory." ; raw "COMPREPLY+=($(compgen -A file -- \"$1\"))" + ; comment + "Tell the shell that completions will be filenames. This allows for ergonomic \ + improvements such as appending a slash to directories and omitting the space \ + after completions so completion of paths can continue if the user presses tab \ + again." + ; raw "compopt -o filenames" ] ;;