Skip to content

Commit

Permalink
releng: add fish completions
Browse files Browse the repository at this point in the history
If you use fish shell, you can run `bash -c 'source ./setup.sh Debug; exec fish'` or with Nix `nix-shell --run fish`. Unfortunately, we cannot get away with using direnv for now.

direnv/direnv#443
fish-shell/fish-shell#8261
  • Loading branch information
jtojnar committed Sep 9, 2021
1 parent 6cc1e9f commit 9e004dc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions releng/tools/fish/vendor_completions.d/rcfg.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function _external_completion
# Get the current command up to a cursor.
# - Behaves correctly even with pipes and nested in commands like env.
# - Note that it returns the command verbatim (does not interpolate variables).
set -l fixed_args (commandline --current-process --tokenize --cut-at-cursor)
# --cut-at-cursor with --tokenize removes the current token so we need to add it separately.
# https://github.com/fish-shell/fish-shell/issues/7375
# Can be an empty string.
set -l current_token (commandline --current-token --cut-at-cursor)

# The completion scripts also want the index of the argv item to complete
# but the $fixed_args variable contains the program name (argv[0]) so we would need to subtract 1.
# But the variable also misses the current token so it cancels out.
set -l arg_to_complete (count $fixed_args)

env $ROFI_ROOT/releng/tools/$argv[1] $arg_to_complete $fixed_args $current_token
end

function _rcfg_completion
_external_completion _rcfg.completion.py $arguments
end

function _rmake_completion
_external_completion _rmake.completion.py $arguments
end

set util (basename (status filename) .fish)
complete --path $ROFI_ROOT/releng/tools/$util --no-files --arguments '(_'$util'_completion)'
1 change: 1 addition & 0 deletions releng/tools/fish/vendor_completions.d/rmake.fish
5 changes: 5 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ run() {
autoload bashcompinit
bashcompinit
fi

## For fish completions
backup XDG_DATA_DIRS
export XDG_DATA_DIRS="$XDG_DATA_DIRS:$ROFI_ROOT/releng/tools"

source releng/tools/_registerCompletion.sh
}

Expand Down

0 comments on commit 9e004dc

Please sign in to comment.