diff --git a/src/main.zig b/src/main.zig index e8e3437..87a721a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -84,10 +84,12 @@ fn printHelp() void { \\ validate NAME CODE Validate the code CODE for the authenticator with name NAME \\ \\Options: - \\ --bash Print script to set up Bash shell integration. Usage: add + \\ --bash Generate shell integration for bash. Usage: add \\ eval "$(zig-totp --bash)" \\ to your ~/.bashrc - \\ --config [path] The path to a config file (default is $XDG_CONFIG_HOME/zig-totp or $HOME/.zig-totp). + \\ --config PATH The path to a config file (default is $XDG_CONFIG_HOME/zig-totp or $HOME/.zig-totp). + \\ --fish Generate shell integration for fish. Usage: + \\ zig-totp --fish > $__fish_config_dir/completions/zig-totp.fish \\ --help Show this help \\ --version Print the version number \\ @@ -210,12 +212,39 @@ fn parseArgs(allocator: Allocator, args: []const []const u8) !Args { \\ then \\ COMPREPLY=($(compgen -A file -- "${COMP_WORDS[$COMP_CWORD]}" )) \\ else - \\ COMPREPLY=($(compgen -W "list show validate --bash --config" -- "${COMP_WORDS[$COMP_CWORD]}" )) + \\ COMPREPLY=($(compgen -W "list show validate --bash --fish --help --config" -- "${COMP_WORDS[$COMP_CWORD]}" )) \\ fi \\} \\complete -F _zig_totp_completions zig-totp \\ ; + try std.io.getStdOut().writer().print("{s}\n", .{msg}); + std.process.exit(0); + } else if (eql(u8, "--fish", arg)) { + const msg = + \\# all subcommands zig-totp knows, is useful later + \\set -l commands list show validate + \\ + \\# disable file completion so that we have more control + \\complete -c zig-totp --no-files + \\ + \\# parameters: + \\complete -c zig-totp -l bash -d "generate bash integration code" + \\complete -c zig-totp -l fish -d "generate fish integration code" + \\complete -c zig-totp -l config -d "define config location" --force-files --require-parameter -d 'override config location' + \\complete -c zig-totp -l help -d "show help" + \\ + \\# sub commands: + \\complete -c zig-totp -n "not __fish_seen_subcommand_from $commands" -a 'list' -d 'show available authenticators' + \\ + \\complete -c zig-totp -n "not __fish_seen_subcommand_from $commands" -a 'show' -d 'show the code for an authenticator' + \\complete -c zig-totp -n "__fish_prev_arg_in show" -xa '(zig-totp list)' + \\ + \\complete -c zig-totp -n "not __fish_seen_subcommand_from $commands" -a 'validate' -d 'validate code for an authenticator' + \\complete -c zig-totp -n "__fish_prev_arg_in validate" -xa '(zig-totp list)' + \\ + ; + try std.io.getStdOut().writer().print("{s}\n", .{msg}); std.process.exit(0); } else if (eql(u8, "--config", arg)) {