nix: nixify pw script
Anirudh Oppiliappan x@icyphox.sh
Mon, 02 May 2022 10:02:37 +0530
3 files changed,
19 insertions(+),
31 deletions(-)
M
nix/bin/cputil.nix
→
nix/bin/cputil.nix
@@ -12,21 +12,10 @@ case "$mode" in
"perf") doas ${cpufreqctl} --governor --set=performance ${asusctl} profile -P performance - printf "turning on cores... " - for i in {8..15}; do - printf "$i " - doas ${cpufreqctl} --on --core=$i - done - printf "\n" ;; "save") doas ${cpufreqctl} --governor --set=powersave ${asusctl} profile -P quiet - printf "turning off cores... " - for i in {8..15}; do - printf "$i " - doas ${cpufreqctl} --off --core=$i - done printf "\n" esac ''
M
nix/bin/default.nix
→
nix/bin/default.nix
@@ -57,6 +57,9 @@ nvidia-offload = import ./nvidia-offload.nix pkgs;
# power profiles script cputil = import ./cputil.nix pkgs; + + # password manager + pw = import ./pw.nix pkgs; in [ git-new-push-remote@@ -70,4 +73,5 @@ xurls
invert nvidia-offload cputil + pw ]
M
nix/bin/pw.nix
→
nix/bin/pw.nix
@@ -1,20 +1,15 @@
-{ pkgs, theme, ... }: +{ pkgs, ... }: let name = "pw"; - pamixer = "${pkgs.pamixer}/bin/pamixer"; - lemonbar = "${pkgs.lemonbar-xft}/bin/lemonbar"; + gpg = "${pkgs.gnupg}/bin/gpg"; + pwgen = "${pkgs.pwgen}/bin/pwgen"; + git = "${pkgs.git}/bin/git"; + xclip = "${pkgs.xclip}/bin/xclip"; in pkgs.writeShellScriptBin name '' - #!/usr/bin/env bash # pw - a mnml password manager - command -v gpg >/dev/null 2>&1 && gpg=gpg - command -v gpg2 >/dev/null 2>&1 && gpg=gpg2 - # check if xclip or pbcopy exist - # command -v xclip >/dev/null 2>&1 && copy="xclip -rmlastnl -selection clipboard" - # command -v pbcopy >/dev/null 2>&1 && copy="pbcopy | tr -d '\n'" - # export PW_DIR to your own path [[ -z "$PW_DIR" ]] && PW_DIR="$HOME/.pw" init() { if [[ ! -e "$PW_DIR" ]]; then@@ -33,23 +28,23 @@ if [[ "$#" -eq 2 ]]; then
pass="$2" else # uses default length of 25 chars, unless PW_LEN is set - pass="$(pwgen "${PW_LEN:-25}" 1 -s)" + pass="$(${pwgen} "''${PW_LEN:-25}" 1 -s)" printf "pw: generated password for %s\n" "$1" fi if [[ ! -f "$PW_DIR/$1.gpg" ]]; then - printf "%s" "$pass" | "$gpg" -aer "$PW_KEY" -o "$PW_DIR/$1.gpg" + printf "%s" "$pass" | ${gpg} -aer "$PW_KEY" -o "$PW_DIR/$1.gpg" printf "pw: %s/%s.gpg created\n" "$PW_DIR" "$1" else die "the file $PW_DIR/$1.gpg exists" fi ( cd $PW_DIR - git add . - git commit -m "$(date)" - remote="$(git remote show)" - branch="$(git branch --show-current)" - git pull -r "$remote" "$branch" - git push "$remote" "$branch" + ${git} add . + ${git} commit -m "$(date)" + remote="$(${git} remote show)" + branch="$(${git} branch --show-current)" + ${git} pull -r "$remote" "$branch" + ${git} push "$remote" "$branch" ) } list() {@@ -66,7 +61,7 @@ }
} show() { checkf "$PW_DIR/$1.gpg" - "$gpg" --decrypt --quiet --use-agent "$PW_DIR/$1.gpg" + ${gpg} --decrypt --quiet --use-agent "$PW_DIR/$1.gpg" } # TODO: rework having to checkf twice copy() {@@ -74,7 +69,7 @@ checkf "$PW_DIR/$1.gpg"
if [[ "$OSTYPE" =~ darwin* ]]; then show "$1" | head -1 | pbcopy | tr -d '\n' else - show "$1" | head -1 | xclip -rmlastnl -selection clipboard + show "$1" | head -1 | ${xclip} -rmlastnl -selection clipboard fi printf "pw: copied %s to clipboard\n" "$1" }