Dotfiles for my tiling window manager + terminal workflow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
5.6 KiB

5 days ago
  1. # Copyright (C) 2012-2014 Dmitry Medvinsky <me@dmedvinsky.name>. All Rights Reserved.
  2. # This file is licensed under the GPLv2+. Please see COPYING for more information.
  3. set -l PROG 'pass'
  4. function __fish_pass_get_prefix
  5. if set -q PASSWORD_STORE_DIR
  6. realpath -- "$PASSWORD_STORE_DIR"
  7. else
  8. echo "$HOME/.password-store"
  9. end
  10. end
  11. function __fish_pass_needs_command
  12. [ (count (commandline -opc)) -eq 1 ]
  13. end
  14. function __fish_pass_uses_command
  15. set -l cmd (commandline -opc)
  16. if [ (count $cmd) -gt 1 ]
  17. if [ $argv[1] = $cmd[2] ]
  18. return 0
  19. end
  20. end
  21. return 1
  22. end
  23. function __fish_pass_print_gpg_keys
  24. gpg2 --list-keys | grep uid | sed 's/.*<\(.*\)>/\1/'
  25. end
  26. function __fish_pass_print
  27. set -l ext $argv[1]
  28. set -l strip $argv[2]
  29. set -l prefix (__fish_pass_get_prefix)
  30. set -l matches $prefix/**$ext
  31. printf '%s\n' $matches | sed "s#$prefix/\(.*\)$strip#\1#"
  32. end
  33. function __fish_pass_print_entry_dirs
  34. __fish_pass_print "/"
  35. end
  36. function __fish_pass_print_entries
  37. __fish_pass_print ".gpg" ".gpg"
  38. end
  39. function __fish_pass_print_entries_and_dirs
  40. __fish_pass_print_entry_dirs
  41. __fish_pass_print_entries
  42. end
  43. function __fish_pass_git_complete
  44. set -l prefix (__fish_pass_get_prefix)
  45. set -l git_cmd (commandline -opc) (commandline -ct)
  46. set -e git_cmd[1 2] # Drop "pass git".
  47. complete -C"git -C $prefix $git_cmd"
  48. end
  49. complete -c $PROG -f -n '__fish_pass_needs_command' -a help -d 'Command: show usage help'
  50. complete -c $PROG -f -n '__fish_pass_needs_command' -a version -d 'Command: show program version'
  51. complete -c $PROG -f -n '__fish_pass_needs_command' -a init -d 'Command: initialize new password storage'
  52. complete -c $PROG -f -n '__fish_pass_uses_command init' -s p -l path -d 'Assign gpg-id for specified sub folder of password store'
  53. complete -c $PROG -f -n '__fish_pass_needs_command' -a ls -d 'Command: list passwords'
  54. complete -c $PROG -f -n '__fish_pass_uses_command ls' -a "(__fish_pass_print_entry_dirs)"
  55. complete -c $PROG -f -n '__fish_pass_needs_command' -a insert -d 'Command: insert new password'
  56. complete -c $PROG -f -n '__fish_pass_uses_command insert' -s e -l echo -d 'Echo the password on console'
  57. complete -c $PROG -f -n '__fish_pass_uses_command insert' -s m -l multiline -d 'Provide multiline password entry'
  58. complete -c $PROG -f -n '__fish_pass_uses_command insert' -s f -l force -d 'Do not prompt before overwritting'
  59. complete -c $PROG -f -n '__fish_pass_uses_command insert' -a "(__fish_pass_print_entry_dirs)"
  60. complete -c $PROG -f -n '__fish_pass_needs_command' -a generate -d 'Command: generate new password'
  61. complete -c $PROG -f -n '__fish_pass_uses_command generate' -s n -l no-symbols -d 'Do not use special symbols'
  62. complete -c $PROG -f -n '__fish_pass_uses_command generate' -s c -l clip -d 'Put the password in clipboard'
  63. complete -c $PROG -f -n '__fish_pass_uses_command generate' -s f -l force -d 'Do not prompt before overwritting'
  64. complete -c $PROG -f -n '__fish_pass_uses_command generate' -s i -l in-place -d 'Replace only the first line with the generated password'
  65. complete -c $PROG -f -n '__fish_pass_uses_command generate' -a "(__fish_pass_print_entry_dirs)"
  66. complete -c $PROG -f -n '__fish_pass_needs_command' -a mv -d 'Command: rename existing password'
  67. complete -c $PROG -f -n '__fish_pass_uses_command mv' -s f -l force -d 'Force rename'
  68. complete -c $PROG -f -n '__fish_pass_uses_command mv' -a "(__fish_pass_print_entries_and_dirs)"
  69. complete -c $PROG -f -n '__fish_pass_needs_command' -a cp -d 'Command: copy existing password'
  70. complete -c $PROG -f -n '__fish_pass_uses_command cp' -s f -l force -d 'Force copy'
  71. complete -c $PROG -f -n '__fish_pass_uses_command cp' -a "(__fish_pass_print_entries_and_dirs)"
  72. complete -c $PROG -f -n '__fish_pass_needs_command' -a rm -d 'Command: remove existing password'
  73. complete -c $PROG -f -n '__fish_pass_uses_command rm' -s r -l recursive -d 'Remove password groups recursively'
  74. complete -c $PROG -f -n '__fish_pass_uses_command rm' -s f -l force -d 'Force removal'
  75. complete -c $PROG -f -n '__fish_pass_uses_command rm' -a "(__fish_pass_print_entries_and_dirs)"
  76. complete -c $PROG -f -n '__fish_pass_needs_command' -a edit -d 'Command: edit password using text editor'
  77. complete -c $PROG -f -n '__fish_pass_uses_command edit' -a "(__fish_pass_print_entries)"
  78. complete -c $PROG -f -n '__fish_pass_needs_command' -a show -d 'Command: show existing password'
  79. complete -c $PROG -f -n '__fish_pass_uses_command show' -s c -l clip -d 'Put password in clipboard'
  80. complete -c $PROG -f -n '__fish_pass_uses_command show' -a "(__fish_pass_print_entries)"
  81. # When no command is given, `show` is defaulted.
  82. complete -c $PROG -f -n '__fish_pass_needs_command' -s c -l clip -d 'Put password in clipboard'
  83. complete -c $PROG -f -n '__fish_pass_needs_command' -a "(__fish_pass_print_entries)"
  84. complete -c $PROG -f -n '__fish_pass_uses_command -c' -a "(__fish_pass_print_entries)"
  85. complete -c $PROG -f -n '__fish_pass_uses_command --clip' -a "(__fish_pass_print_entries)"
  86. complete -c $PROG -f -n '__fish_pass_needs_command' -a git -d 'Command: execute a git command'
  87. complete -c $PROG -f -n '__fish_pass_uses_command git' -a '(__fish_pass_git_complete)'
  88. complete -c $PROG -f -n '__fish_pass_needs_command' -a find -d 'Command: find a password file or directory matching pattern'
  89. complete -c $PROG -f -n '__fish_pass_needs_command' -a grep -d 'Command: search inside of decrypted password files for matching pattern'
  90. complete -c $PROG -f -n '__fish_pass_uses_command grep' -a '(begin
  91. set -l cmd (commandline -opc) (commandline -ct)
  92. set -e cmd[1 2] # Drop "pass grep".
  93. complete -C"grep $cmd"
  94. end)'