config/modules/home/shell/fish/functions/ops.fish
2025-06-15 18:15:28 -04:00

75 lines
No EOL
2.7 KiB
Fish

function ops --description "Search 1Password with grep-like functionality"
set -l options 'h/help' 'c/category=' 't/tag=' 'v/vault=' 'f/field=' 'j/json' 'd/detail' 'n/nushell' 'p/password'
argparse $options -- $argv
if set -q _flag_help
echo "ops - Fish wrapper for opsearch (1Password search utility)"
echo
echo "Usage:"
echo " ops [search_term] [options]"
echo
echo "Options:"
echo " -c/--category [category] Filter by category (login, password, document, etc.)"
echo " -t/--tag [tag] Filter by tag"
echo " -v/--vault [vault] Specify vault to search in"
echo " -f/--field [field] Search only in specific fields"
echo " -j/--json Output results in JSON format"
echo " -d/--detail Show detailed output for each item"
echo " -n/--nushell Use Nushell for output formatting (if available)"
echo " -p/--password Retrieve and copy password after selection"
echo " -h/--help Show this help message"
echo
echo "Examples:"
echo " ops github # Search for \"github\" in all items"
echo " ops amazon -c login # Search for \"amazon\" in login items"
echo " ops bank -v Personal # Search for \"bank\" in the Personal vault"
echo " ops -t finance # Show all items with \"finance\" tag"
echo " ops email -f username # Search for \"email\" in username fields"
echo " ops ssh -d # Show detailed info for SSH items"
echo " ops github -p # Get GitHub password after selection"
return 0
end
set -l cmd_args
# Convert fish options to bash-style options for the shell script
if set -q _flag_category
set -a cmd_args "--category" $_flag_category
end
if set -q _flag_tag
set -a cmd_args "--tag" $_flag_tag
end
if set -q _flag_vault
set -a cmd_args "--vault" $_flag_vault
end
if set -q _flag_field
set -a cmd_args "--field" $_flag_field
end
if set -q _flag_json
set -a cmd_args "--json"
end
if set -q _flag_detail
set -a cmd_args "--detail"
end
if set -q _flag_nushell
set -a cmd_args "--nushell"
end
if set -q _flag_password
set -a cmd_args "--password"
end
# Add search term if provided
if test (count $argv) -gt 0
set -a cmd_args $argv
end
# Execute the shell script with all arguments
$HOME/.local/bin/opsearch.sh $cmd_args
end