add password script

This commit is contained in:
Leonardo Eugênio 2022-08-08 20:05:06 -03:00
parent 4752ed2b4c
commit a8a8be5a59
5 changed files with 116 additions and 1 deletions

View file

@ -1,7 +1,9 @@
{ config, lib, ... }: { config, lib, ... }:
(_: pkgs: { (pkgs: _: {
bmenu = import ./bmenu.nix { inherit config pkgs lib; }; bmenu = import ./bmenu.nix { inherit config pkgs lib; };
_diffr = import ./diffr.nix { inherit config pkgs lib; }; _diffr = import ./diffr.nix { inherit config pkgs lib; };
kak-pager = import ./kak-pager.nix { inherit config pkgs lib; }; kak-pager = import ./kak-pager.nix { inherit config pkgs lib; };
terminal = import ./terminal.nix { inherit config pkgs lib; }; terminal = import ./terminal.nix { inherit config pkgs lib; };
wpass = import ./wpass.nix { inherit config pkgs lib; };
screenshotsh = import ./screenshotsh.nix { inherit config pkgs lib; };
}) })

47
scripts/screenshotsh.nix Normal file
View file

@ -0,0 +1,47 @@
{ config, pkgs, lib, ... }:
pkgs.writeShellScriptBin "screenshotsh" ''
export XCURSOR_SIZE=40
export XCURSOR_THEME='capitaine-cursors-light' # ${pkgs.capitaine-cursors}
if which xdg-user-dir >/dev/null 2>&1; then
DESTFOLDER="$(${pkgs.capitaine-cursors}/bin/xdg-user-dir PICTURES)"
else
for i in Images Imagens Pictures Fotos ""; do
DESTFOLDER="$HOME/$i"
test -d "$DESTFOLDER" &&
break
done
fi
DESTFOLDER="$DESTFOLDER/Screenshots"
mkdir -p "$DESTFOLDER"
DESTFILE="$DESTFOLDER/$(date +'%Y-%m-%d-%H%M%S_screenshot.png')"
case $1 in
def)
# Screenshot to file
${pkgs.grim}/bin/grim "$DESTFILE"
echo "$DESTFILE"
;;
area)
# Screen area to file
${pkgs.grim}/bin/grim -g "$(slurp -d -b 30303088)" "$DESTFILE"
echo "$DESTFILE"
;;
area-clip)
# Screen area to clipboard
${pkgs.grim}/bin/grim -g "$(slurp -d -b 30303088)" - | ${pkgs.wl-clipboard}/bin/wl-copy
;;
clip)
# Focused monitor to clipboard
cur_output=$(${pkgs.sway}/bin/swaymsg -t get_outputs |
${pkgs.jq}/bin/jq -r '.[] | select(.focused) | .name')
test -n "$cur_output" &&
${pkgs.grim}/bin/grim -o "$cur_output" - | ${pkgs.wl-clipboard}/bin/wl-copy ||
${pkgs.grim}/bin/grim - | ${pkgs.wl-clipboard}/bin/wl-copy
;;
esac
''

51
scripts/wpass.nix Normal file
View file

@ -0,0 +1,51 @@
{ config, pkgs, lib, ... }:
pkgs.writeShellScriptBin "wpass" ''
# passmenu, for wayland
# depends: wtype, pass
shopt -s nullglob globstar
wtype=${pkgs.wtype}/bin/wtype
dmenu=${pkgs.bmenu}/bin/bmenu
find_file() {
${pkgs.fd}/bin/fd --strip-cwd-prefix '\.gpg$' |
${pkgs.sd}/bin/sd ".gpg$" "" |
"$dmenu" -p "Password" $@
}
main() {
test -n "$PASSWORD_STORE_DIR" &&
cd "$PASSWORD_STORE_DIR" ||
cd "$HOME/.password-store"
entry=`find_file "$@"`
test -n "$entry" || exit 0
username=`${pkgs.pass}/bin/pass show "$entry" 2>/dev/null | perl -ne 'print $1 if /^(login|user|email): (.*)/'`
password=`${pkgs.pass}/bin/pass show "$entry" 2>/dev/null | head -n 1`
action=`printf "Autotype\nUsername -> $username\nPassword" | "$dmenu" -p Action`
case $action in
Autotype)
autotype
;;
Username*)
printf '%s' "$username" | ${pkgs.wl-clipboard}/bin/wl-copy;;
Password)
printf '%s' "$password" | ${pkgs.wl-clipboard}/bin/wl-copy;;
esac
}
autotype(){
env $wtype -s 100 "$username"
env $wtype -s 100 -k tab
env $wtype -s 100 "$password"
}
main
''

View file

@ -52,6 +52,8 @@ in {
volumesh volumesh
pamixer pamixer
libnotify libnotify
wpass
screenshotsh
# media # media
yt-dlp yt-dlp
ffmpeg ffmpeg

View file

@ -249,7 +249,19 @@ in {
"--locked Ctrl+${mod}+z" = "exec ${_suspend}/bin/_suspend"; "--locked Ctrl+${mod}+z" = "exec ${_suspend}/bin/_suspend";
"${mod}+Alt+c" = "exec ${_sway_idle_toggle}/bin/_sway_idle_toggle"; "${mod}+Alt+c" = "exec ${_sway_idle_toggle}/bin/_sway_idle_toggle";
}; };
screenshot_binds = {
# Screens to file
"Print" = "exec ${pkgs.screenshotsh}/bin/screenshotsh def";
# Screen area to file
"Shift+Print" = "exec ${pkgs.screenshotsh}/bin/screenshotsh area";
# Screen area to clipboard
"Control+Shift+Print" =
"exec ${pkgs.screenshotsh}/bin/screenshotsh area-clip";
# Focused monitor to clipboard
"Control+Print" = "exec ${pkgs.screenshotsh}/bin/screenshotsh clip";
};
other_binds = { other_binds = {
"${mod}+p" = "exec ${pkgs.wpass}";
"${mod}+s" = "exec ${menu}"; "${mod}+s" = "exec ${menu}";
"${mod}+Return" = "exec ${terminal}"; "${mod}+Return" = "exec ${terminal}";
"${mod}+Ctrl+Return" = "exec thunar"; "${mod}+Ctrl+Return" = "exec thunar";
@ -270,6 +282,7 @@ in {
audio_binds audio_binds
system_binds system_binds
parenting_binds parenting_binds
screenshot_binds
]; ];
terminal = pkgs.alacritty.executable; terminal = pkgs.alacritty.executable;
}; };