From 8a9a378f189a034bc6747da047fdedc235f36d76 Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Sun, 7 Apr 2024 00:07:45 -0400 Subject: [PATCH] Updates to nvim to harden for gopass --- nvim/m-housh/lua/user/autocmd.lua | 4 +++ scripts/scripts/raycast/pass-attribute.sh | 36 ++++++++++++++++---- scripts/scripts/raycast/pass-copy.sh | 41 +++++++++++++++++------ scripts/scripts/raycast/pass-gen.sh | 33 ++++++++++++++++++ zsh/config/.zshrc | 2 +- 5 files changed, 97 insertions(+), 19 deletions(-) create mode 100755 scripts/scripts/raycast/pass-gen.sh diff --git a/nvim/m-housh/lua/user/autocmd.lua b/nvim/m-housh/lua/user/autocmd.lua index e78bae9..279cd13 100755 --- a/nvim/m-housh/lua/user/autocmd.lua +++ b/nvim/m-housh/lua/user/autocmd.lua @@ -59,6 +59,10 @@ createCmd( } ) +vim.api.nvim_exec([[ + autocmd BufNewFile,BufRead /private/**/gopass** setlocal noswapfile nobackup noundofile shada="" + ]], false) + -- Swift -- createCmd( -- "FileType", diff --git a/scripts/scripts/raycast/pass-attribute.sh b/scripts/scripts/raycast/pass-attribute.sh index 581599c..8b79c52 100755 --- a/scripts/scripts/raycast/pass-attribute.sh +++ b/scripts/scripts/raycast/pass-attribute.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/zsh -l # Required parameters: # @raycast.schemaVersion 1 @@ -17,10 +17,32 @@ # @raycast.authorURL https://github.com/m-housh PREFIX="$HOME/.local/share/password-store" -PASS=/opt/homebrew/bin/pass -key="$1" -selected=$(find "$PREFIX" -type f -name "$2.gpg") -selected="${selected//$PREFIX/}" -selected="${selected//.gpg/}" -"$PASS" get --clip "$key" "$selected" +PASS="$(command -v pass)" + +# +# Begin program +# +[ -z "$PASS" ] && \ + echo "Error: pass utility not found." && \ + exit 1 + +key="$1" +file="$2" +selected=$(find "$PREFIX" -type f -name "$file.gpg") + +# Check if we found a password file at the path. +[ -z "$selected" ] && \ + echo "Path not found: $file" && \ + exit 1 + +# Sanitize the path to work with the pass command. +selected="${selected//$PREFIX\//}" +selected="${selected//.gpg/}" + +# Capture the result of searching for the key. +result=$("$PASS" get "$key" "$selected") + +[ -z "$result" ] && echo "Key not found" && exit 1 +echo "$result" | pbcopy +echo "$key: Copied to clipboard" diff --git a/scripts/scripts/raycast/pass-copy.sh b/scripts/scripts/raycast/pass-copy.sh index 5d068a0..86288be 100755 --- a/scripts/scripts/raycast/pass-copy.sh +++ b/scripts/scripts/raycast/pass-copy.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/zsh -l # Required parameters: # @raycast.schemaVersion 1 @@ -7,7 +7,7 @@ # Optional parameters: # @raycast.icon 🔐 -# @raycast.argument1 { "type": "text", "placeholder": "for" } +# @raycast.argument1 { "type": "text", "placeholder": "For" } # @raycast.packageName Password # Documentation: @@ -16,13 +16,32 @@ # @raycast.authorURL https://github.com/m-housh PREFIX="$HOME/.local/share/password-store" -PASS=/opt/homebrew/bin/pass -selected=$(find "$PREFIX" -type f -name "$1".gpg) -if [ -n "$selected" ]; then - selected="${selected//$PREFIX/}" - selected="${selected//.gpg/}" - "$PASS" --clip "$selected" -else - exit 1 -fi +LOG=/tmp/pass-copy.out +ISOSEC="$HOME/.local/share/scripts/isosec" +PASS="$(command -v pass)" + +_log() { + echo "$($ISOSEC) $1" >> "$LOG" +} + +# +# Begin program +# +[ -z "$PASS" ] && \ + echo "Error: pass utility not found." && \ + _log "Error: pass utility not found." && \ + exit 1 + +selected=$(find "$PREFIX" -type f -name "$1".gpg) + +[ -z "$selected" ] && \ + _log "Error: Not Found" && \ + _log "Input: $1" && \ + exit 1 + +selected="${selected//$PREFIX\//}" +selected="${selected//.gpg/}" +_log "Running pass with selection: $selected" +"$PASS" --clip "$selected" + diff --git a/scripts/scripts/raycast/pass-gen.sh b/scripts/scripts/raycast/pass-gen.sh new file mode 100755 index 0000000..ff09a80 --- /dev/null +++ b/scripts/scripts/raycast/pass-gen.sh @@ -0,0 +1,33 @@ +#!/bin/zsh -l + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title pass-gen +# @raycast.mode compact + +# Optional parameters: +# @raycast.icon 🔐 +# @raycast.argument1 { "type": "text", "placeholder": "Path" } +# @raycast.packageName Password + +# Documentation: +# @raycast.description Copy password from password-store +# @raycast.author Michael Housh +# @raycast.authorURL https://github.com/m-housh + +PREFIX="$HOME/.local/share/password-store" +PASS="$(command -v pass)" + +[ -z "$PASS" ] && \ + echo "Error: pass utility not found." && \ + exit 1 + +[ -z "$1" ] && \ + echo "Error: must supply a name/path for the password" && \ + exit 1 + +"$PASS" generate --clip "$1" + +_log "Ending" + + diff --git a/zsh/config/.zshrc b/zsh/config/.zshrc index 726581c..a6f6ea9 100755 --- a/zsh/config/.zshrc +++ b/zsh/config/.zshrc @@ -63,7 +63,7 @@ path_prepend \ "/opt/homebrew/sbin" \ "$GOROOT/bin" \ "$GOPATH/bin" \ - "$HOME/.local/bin" \ + "$XDG_DATA_HOME/bin" \ "$SCRIPTS" # last arg will be first in $FPATH