Skip to content

Commit

Permalink
fix: shell completions working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jmattaa committed Dec 24, 2024
1 parent d2a9c9d commit 41b9ffe
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 85 deletions.
35 changes: 11 additions & 24 deletions completions/bash/lsr
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
Dec 15 11:09  ---  jonathan  .
Dec 12 00:13  ---  jonathan  ..
Nov 07 09:07  ---  jonathan  .cache
Dec 15 11:22  ---  jonathan  .git
Nov 07 09:01  ---  jonathan  .github
Nov 30 21:57  ---  jonathan  assets
Dec 15 10:52  ---  jonathan  build
Nov 24 21:27  ---  jonathan  completions
Dec 13 17:35  ---  jonathan  include
Dec 11 22:34  ---  jonathan  lua
Dec 15 11:22  ---  jonathan  scripts
Dec 15 10:52  ---  jonathan  src
Oct 13 18:24  863 B  jonathan  .clang-format
Nov 30 21:57  72 B  jonathan  .gitignore
Dec 15 10:45  110 B  jonathan  .quickmarks
Dec 13 16:40  2.47 KB  jonathan  CMakeLists.txt
Dec 12 23:07  7.81 KB  jonathan  CONFIGURATION.md
Nov 30 21:57  5.40 KB  jonathan  CONTRIBUTING.md
Dec 13 16:40  938 B  jonathan  FindLibgit2.cmake
Nov 24 21:27  1.05 KB  jonathan  LICENSE
Dec 15 11:09  4.18 KB  jonathan  README.md
Nov 30 21:57  910 B  jonathan  cmake_uninstall.cmake.in
Dec 08 16:53  5.68 KB  jonathan  compile_commands.json
Dec 15 10:53  230 B  jonathan  todo
_lsr() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
opts="-a --all -F --Files -D --Directories -S --Symlinks -G --Git -g --git-status -i --git-ignored -l --long -r --recursive -f --filter -v --version -h --help --completions "
if [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
fi
return 0
}
complete -F _lsr lsr
38 changes: 14 additions & 24 deletions completions/fish/lsr.fish
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
Dec 15 11:09  ---  jonathan  .
Dec 12 00:13  ---  jonathan  ..
Nov 07 09:07  ---  jonathan  .cache
Dec 15 11:22  ---  jonathan  .git
Nov 07 09:01  ---  jonathan  .github
Nov 30 21:57  ---  jonathan  assets
Dec 15 10:52  ---  jonathan  build
Nov 24 21:27  ---  jonathan  completions
Dec 13 17:35  ---  jonathan  include
Dec 11 22:34  ---  jonathan  lua
Dec 15 11:22  ---  jonathan  scripts
Dec 15 10:52  ---  jonathan  src
Oct 13 18:24  863 B  jonathan  .clang-format
Nov 30 21:57  72 B  jonathan  .gitignore
Dec 15 10:45  110 B  jonathan  .quickmarks
Dec 13 16:40  2.47 KB  jonathan  CMakeLists.txt
Dec 12 23:07  7.81 KB  jonathan  CONFIGURATION.md
Nov 30 21:57  5.40 KB  jonathan  CONTRIBUTING.md
Dec 13 16:40  938 B  jonathan  FindLibgit2.cmake
Nov 24 21:27  1.05 KB  jonathan  LICENSE
Dec 15 11:09  4.18 KB  jonathan  README.md
Nov 30 21:57  910 B  jonathan  cmake_uninstall.cmake.in
Dec 08 16:53  5.68 KB  jonathan  compile_commands.json
Dec 15 10:53  230 B  jonathan  todo
# Fish completions for lsr
complete -c lsr -s a -l all -d 'Show all entries, including hidden'
complete -c lsr -s F -l Files -d 'Show files only'
complete -c lsr -s D -l Directories -d 'Show directories only'
complete -c lsr -s S -l Symlinks -d 'Show symlinks only'
complete -c lsr -s G -l Git -d 'Do not show ignored git files and show git status'
complete -c lsr -s g -l git-status -d 'Show git status for entries'
complete -c lsr -s i -l git-ignored -d 'Ignore git ignored files'
complete -c lsr -s l -l long -d 'Use long format'
complete -c lsr -s r -l recursive -d 'Show in tree format'
complete -c lsr -s f -l filter -d 'Filter out files using lua filters (`L_filters` in lsr.lua)'
complete -c lsr -s v -l version -d 'Print the current version'
complete -c lsr -s h -l help -d 'Print help message'
complete -c lsr -l completions -d 'Generate shell completions'
44 changes: 20 additions & 24 deletions completions/zsh/_lsr
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
Dec 15 11:09  ---  jonathan  .
Dec 12 00:13  ---  jonathan  ..
Nov 07 09:07  ---  jonathan  .cache
Dec 15 11:22  ---  jonathan  .git
Nov 07 09:01  ---  jonathan  .github
Nov 30 21:57  ---  jonathan  assets
Dec 15 10:52  ---  jonathan  build
Nov 24 21:27  ---  jonathan  completions
Dec 13 17:35  ---  jonathan  include
Dec 11 22:34  ---  jonathan  lua
Dec 15 11:22  ---  jonathan  scripts
Dec 15 10:52  ---  jonathan  src
Oct 13 18:24  863 B  jonathan  .clang-format
Nov 30 21:57  72 B  jonathan  .gitignore
Dec 15 10:45  110 B  jonathan  .quickmarks
Dec 13 16:40  2.47 KB  jonathan  CMakeLists.txt
Dec 12 23:07  7.81 KB  jonathan  CONFIGURATION.md
Nov 30 21:57  5.40 KB  jonathan  CONTRIBUTING.md
Dec 13 16:40  938 B  jonathan  FindLibgit2.cmake
Nov 24 21:27  1.05 KB  jonathan  LICENSE
Dec 15 11:09  4.18 KB  jonathan  README.md
Nov 30 21:57  910 B  jonathan  cmake_uninstall.cmake.in
Dec 08 16:53  5.68 KB  jonathan  compile_commands.json
Dec 15 10:53  230 B  jonathan  todo
#compdef lsr
autoload -U is-at-least
_lsr() {
_arguments -s \
'(-a --all)'{-a,--all}'[Show all entries, including hidden]' \
'(-F --Files)'{-F,--Files}'[Show files only]' \
'(-D --Directories)'{-D,--Directories}'[Show directories only]' \
'(-S --Symlinks)'{-S,--Symlinks}'[Show symlinks only]' \
'(-G --Git)'{-G,--Git}'[Do not show ignored git files and show git status]' \
'(-g --git-status)'{-g,--git-status}'[Show git status for entries]' \
'(-i --git-ignored)'{-i,--git-ignored}'[Ignore git ignored files]' \
'(-l --long)'{-l,--long}'[Use long format]' \
'(-r --recursive)'{-r,--recursive}'[Show in tree format]' \
'(-f --filter)'{-f,--filter}'[Filter out files using lua filters (`L_filters` in lsr.lua)]' \
'(-v --version)'{-v,--version}'[Print the current version]' \
'(-h --help)'{-h,--help}'[Print help message]' \
'--completions[Generate shell completions]' \
'*:file:_files'
}
compdef _lsr lsr
2 changes: 1 addition & 1 deletion include/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <git2/types.h>
#include <stdio.h>

#define LASER_VERSION "1.4.0"
#define LASER_VERSION "1.4.1"

typedef struct laser_opts
{
Expand Down
8 changes: 4 additions & 4 deletions scripts/gen-completions.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/usr/bin/env bash

LSR="lsr"
if [[ -x "build/lsr" ]]; then
Expand All @@ -9,7 +9,7 @@ mkdir -p completions/bash
mkdir -p completions/zsh
mkdir -p completions/fish

$LSR --completions=fish > completions/fish/lsr.fish
$LSR --completions=zsh > completions/zsh/_lsr
$LSR --completions=bash > completions/bash/lsr
$LSR --completions fish > completions/fish/lsr.fish
$LSR --completions zsh > completions/zsh/_lsr
$LSR --completions bash > completions/bash/lsr

13 changes: 5 additions & 8 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static const struct option long_args[] = {
{"filter", required_argument, 0, 'f'},
{"version", 0, 0, 'v'},
{"help", 0, 0, 'h'},
{"completions", required_argument, 0, 0},
{"completions", required_argument, 0, 'C'},
{0, 0, 0, 0}};

// UPDATE THIS TO MATCH long_args!!
Expand Down Expand Up @@ -139,6 +139,7 @@ laser_opts laser_cli_parsecmd(int argc, char **argv)
if (lua_isnumber(L, -1))
recursive_depth = (int)lua_tointeger(L, -1);

// 'C' is not defined in this string because it is only long val
while ((opt = getopt_long(argc, argv, "aFDSG::g::i::r::lvhf::", long_args,
NULL)) != -1)
{
Expand Down Expand Up @@ -216,13 +217,9 @@ laser_opts laser_cli_parsecmd(int argc, char **argv)
filter_count++;

break;
case 0:
if (strcmp(long_args[optind - 1].name, "completions") == 0)
{
laser_cli_generate_completions(argv[optind - 1]);
exit(0);
}
break;
case 'C':
laser_cli_generate_completions(optarg);
exit(0);
default:
exit(1);
}
Expand Down

0 comments on commit 41b9ffe

Please sign in to comment.