Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some shell completions #771

Merged
merged 28 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
720c833
Add cargo-make fzf completion for zsh
kachick Sep 3, 2024
7bcf0e9
Register the makers fzf completions also in bash
kachick Sep 3, 2024
e9b6b21
Add go-task fzf completions
kachick Sep 3, 2024
fe687a0
Add zellij fzf completions
kachick Sep 3, 2024
01d4c3a
Use special filter for `zellij kill-session`
kachick Sep 3, 2024
e4a0db7
Improve handling args in fzf complete hook
kachick Sep 3, 2024
1c49aff
Fix to register zellij bash comletions
kachick Sep 3, 2024
f4a8ab3
Split bash and zsh specific code
kachick Sep 3, 2024
95ba831
Fix cdnix command with use of readlink
kachick Sep 3, 2024
327d937
Fix enabling go-task zsh and fish completions (#770)
kachick Sep 3, 2024
ecbacb2
Fallback bash zellij comletion to default
kachick Sep 3, 2024
dfbbb50
Revert fzf bash completions which conflict with bash default
kachick Sep 3, 2024
7c54577
Attempt to package cargo-make shell completions [WIP] [ci skip]
kachick Sep 4, 2024
b61a9d5
Merge branch 'main' into fzf-compl
kachick Sep 5, 2024
46a60f5
Fix nix path
kachick Sep 5, 2024
a48ece0
Inject bash completion also in zsh
kachick Sep 5, 2024
0984d1a
Remove conflicting fzf bash completions
kachick Sep 5, 2024
3d9c536
Improve note about cargo-make zsh completions
kachick Sep 5, 2024
1fdba8c
Attempt to delegate to source_sh for completion
kachick Sep 5, 2024
f76841e
Revert "Attempt to delegate to source_sh for completion"
kachick Sep 5, 2024
c1cef14
Add note about cargo-make zsh completions
kachick Sep 5, 2024
60b6e0d
Merge branch 'main' into fzf-compl
kachick Sep 5, 2024
20c3334
Make small diff with main
kachick Sep 5, 2024
916ea00
Revert "Make small diff with main"
kachick Sep 5, 2024
024d810
Do not fmt zsh with shfmt
kachick Sep 5, 2024
fb6c9d4
Remove needless package from flake
kachick Sep 5, 2024
c416c30
Clarify depend on Nix coreutils to consider darwin
kachick Sep 5, 2024
acb0a48
Don't abstract and consider unused bash fzf completions
kachick Sep 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions home-manager/bash.nix
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@

source "${pkgs.fzf-git-sh}/share/fzf-git-sh/fzf-git.sh"
source "${pkgs.podman}/share/bash-completion/completions/podman"
source "${pkgs.zellij}/share/bash-completion/completions/zellij.bash"
source "${homemade-pkgs.cargo-make-completions}/share/bash-completion/completions/makers-completion.bash"

source "${../dependencies/dprint/completions.bash}"
source "${../dependencies/goldwarden/completions.bash}"
Expand Down
49 changes: 49 additions & 0 deletions home-manager/zsh.nix
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
completionInit = ''
# `autoload` enable to use compinit
autoload -Uz compinit && _compinit_with_interval
# for cargo-make
# AFAIK, it does not take path options. And fast for now, so needless to be cached
autoload -U +X bashcompinit && bashcompinit
'';

# Setting bindkey
Expand Down Expand Up @@ -203,6 +206,52 @@

source "${pkgs.fzf-git-sh}/share/fzf-git-sh/fzf-git.sh"
source "${pkgs.podman}/share/zsh/site-functions/_podman"
# cargo-make recommends to use bash completions for zsh
source "${homemade-pkgs.cargo-make-completions}/share/bash-completion/completions/makers-completion.bash"

# fzf completions are also possible to be used in bash, but it overrides default completions with the registering
# So currently injecting only in zsh

_fzf_complete_zellij() {
local -r subcmd=''${1#* }
if [[ "$subcmd" == kill-session* ]]; then
_fzf_complete --multi --reverse --prompt="zellij(active)> " --ansi --nth 1 -- "$@" < <(
${lib.getExe pkgs.zellij} list-sessions | ${lib.getExe pkgs.ripgrep} --invert-match --fixed-strings -e 'EXITED'
)
else
_fzf_complete --multi --reverse --prompt="zellij> " --ansi --nth 1 -- "$@" < <(
${lib.getExe pkgs.zellij} list-sessions
)
fi
}

_fzf_complete_zellij_post() {
${lib.getBin pkgs.coreutils}/bin/cut --delimiter=' ' --fields=1
}

# Do not use absolute path for makers to respect current version in each repository
# No need adding for `cargo-make`, it requires subcommand as `cargo-make make`. I'm avoiding the style
_fzf_complete_makers() {
_fzf_complete --multi --reverse --prompt="makers> " --nth 1 -- "$@" < <(
# Don't use `--output-format autocomplete`, it truncates task description
makers --list-all-steps | ${lib.getExe pkgs.ripgrep} --regexp='^\w+ -'
)
}

_fzf_complete_makers_post() {
${lib.getBin pkgs.coreutils}/bin/cut --delimiter=' ' --fields=1
}

# Do not use absolute path for go-task to respect current version in each repository
_fzf_complete_task() {
_fzf_complete --multi --reverse --prompt="task> " -- "$@" < <(
task --list-all | ${lib.getExe pkgs.ripgrep} --regexp='^\* (.+)' --replace='$1'
)
}

_fzf_complete_task_post() {
${lib.getExe pkgs.ripgrep} --regexp='(\S+?): ' --replace='$1'
}

source "${../dependencies/dprint/completions.zsh}"
source "${../dependencies/goldwarden/completions.zsh}"
Expand Down
31 changes: 31 additions & 0 deletions pkgs/cargo-make-completions/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
lib,
stdenv,
fetchFromGitHub,
installShellFiles,
}:

stdenv.mkDerivation rec {
pname = "cargo-make-completions";
version = "0.37.16";

src = fetchFromGitHub {
owner = "sagiegurari";
repo = "cargo-make";
rev = version;
hash = "sha256-OC1HzoEb9OyusYGC5jmEC4qW4U3oGApYvpy5XkZttSg=";
};

nativeBuildInputs = [ installShellFiles ];

installPhase = ''
installShellCompletion extra/shell/*.bash
'';

meta = with lib; {
description = "cargo-make shell completions which missing in nixpkgs";
homepage = "https://github.com/sagiegurari/cargo-make";
license = licenses.asl20;
platforms = platforms.all;
};
}
2 changes: 2 additions & 0 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
micro-kdl = pkgs.callPackage ./micro-kdl { };
micro-nordcolors = pkgs.callPackage ./micro-nordcolors { };

cargo-make-completions = pkgs.callPackage ./cargo-make-completions { };

kdl-vim = pkgs.callPackage ./kdl.vim { };

nix-hash-url = pkgs.callPackage ./nix-hash-url { };
Expand Down
14 changes: 14 additions & 0 deletions pkgs/posix_shared_functions/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
# - Prefer `fname() {}` style: https://unix.stackexchange.com/a/73854
# - Do not add shebang and options. It means you shouldn't select `writeShellApplication` here
#
# NOTE: You should remember difference of bash and zsh for the arguments handling in completions
# https://rcmdnk.com/blog/2015/05/15/computer-linux-mac-zsh/
#
# How to stop blinking cursor in Linux console?
# => https://web-archive-org.translate.goog/web/20220318101402/https://nutr1t07.github.io/post/disable-cursor-blinking-on-linux-console/?_x_tr_sl=auto&_x_tr_tl=ja&_x_tr_hl=ja
let
Expand Down Expand Up @@ -35,6 +38,17 @@ pkgs.writeText "posix_shared_functions.sh" (
cd "$(${pkgs.coreutils}/bin/mktemp --directory)"
}

cdnix() {
if [ $# -lt 1 ]; then
echo "Specify Nix injected command you want to dive"
return 2
fi
# TODO: Check exit code and Nix or not
local -r command="$(command -v "$1")"
# shellcheck disable=SC2164
cd "$(${pkgs.coreutils}/bin/dirname "$(${pkgs.coreutils}/bin/dirname "$(${pkgs.coreutils}/bin/readlink --canonicalize "$command")")")"
}

gch() {
fc -nrl 1 | ${lib.getExe fzf-bind-posix-shell-history-to-git-commit-message}
}
Expand Down
18 changes: 5 additions & 13 deletions pkgs/posix_shared_functions/non_nix.bash
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
cdnix() {
if [ $# -lt 1 ]; then
echo "Specify Nix injected command you want to dive"
return 2
fi
# TODO: Check exit code and Nix or not
local -r command="$(command -v "$1")"
# shellcheck disable=SC2164
cd "$(dirname "$(dirname "$(readlink --canonicalize "$command")")")"
# Actually this file is not a bash script, but dash mode is unuseful. Expecting mostly bash code will work even in zsh...

disable_blinking_cursor() {
echo -en '\033[?16;5;140c'
}

cdwin() {
if ! command -v wslpath &>/dev/null; then
# TODO: Consider inject only in WSL environment
echo "This command works only in WSL2"
fi

# shellcheck disable=SC2164
cd "$(wslpath "$1")"
}

disable_blinking_cursor() {
echo -en '\033[?16;5;140c'
}
8 changes: 7 additions & 1 deletion treefmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ includes = ["*.go"]

[formatter.shfmt]
command = "shfmt"
options = ["--language-dialect", "bash", "--write"]
options = [
"--language-dialect",
# shfmt is not supporting zsh even through specified "auto"
# https://github.com/mvdan/sh/issues/120
"bash",
"--write",
]
includes = ["*.sh", "*.bash", "*.envrc"]

[formatter.stylua]
Expand Down