diff --git a/scripts/_diffr b/scripts/_diffr new file mode 100644 index 0000000..f387dd7 --- /dev/null +++ b/scripts/_diffr @@ -0,0 +1,12 @@ +#!/bin/sh + +exec diffr \ + --colors 'refine-added:foreground:green:underline' \ + --colors 'refine-added:background:none' \ + --colors 'refine-removed:foreground:red:underline' \ + --colors 'refine-removed:background:none' \ + --colors 'added:foreground:green' \ + --colors 'added:background:none' \ + --colors 'removed:foreground:red' \ + --colors 'removed:background:none' \ + "$@" diff --git a/scripts/default.nix b/scripts/default.nix index 2a31771..d471c2a 100644 --- a/scripts/default.nix +++ b/scripts/default.nix @@ -16,21 +16,20 @@ inherit name runtimeInputs; text = ''exec ${script_body} "$@"''; checkPhase = ""; - }) - ); + })); create_scripts = lib.mapAttrs (name: deps: create_script name ./${name} deps); in create_scripts { br = [ ]; bmenu = [ bemenu dhist fish j4-dmenu-desktop jq sway ]; + _diffr = [ diffr ]; + kak-pager = [ fish _diffr ]; + terminal = [ alacritty ]; + wpass = [ bmenu fd pass sd wl-clipboard wtype ]; + screenshotsh = + [ capitaine-cursors grim jq sway wl-clipboard xdg-user-dirs ]; } // lib.mapAttrs import_script { wdmenu = ./wdmenu.nix; wlauncher = ./wlauncher.nix; - # bmenu = ./bmenu.nix; - _diffr = ./diffr.nix; - kak-pager = ./kak-pager.nix; - terminal = ./terminal.nix; - wpass = ./wpass.nix; - screenshotsh = ./screenshotsh.nix; _gpg-unlock = ./_gpg-unlock.nix; }) diff --git a/scripts/diffr.nix b/scripts/diffr.nix deleted file mode 100644 index f47243c..0000000 --- a/scripts/diffr.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ config, pkgs, lib, ... }: -pkgs.writeShellScriptBin "diffr" '' - exec ${pkgs.diffr}/bin/diffr \ - --colors 'refine-added:foreground:green:underline' \ - --colors 'refine-added:background:none' \ - --colors 'refine-removed:foreground:red:underline' \ - --colors 'refine-removed:background:none' \ - --colors 'added:foreground:green' \ - --colors 'added:background:none' \ - --colors 'removed:foreground:red' \ - --colors 'removed:background:none' \ - $@ -'' diff --git a/scripts/kak-pager b/scripts/kak-pager new file mode 100644 index 0000000..33af67b --- /dev/null +++ b/scripts/kak-pager @@ -0,0 +1,33 @@ +#!/usr/bin/env fish + +if test (count $argv) -ne 0 + for i in $argv + cat "$i" + end | eval (status filename) + exit 0 +end + +set term_line_count (tput lines) + +while read line + set -a input_lines "$line" + + set input_line_count (printf "%s\n" $input_lines | wc -l) + + if test "$term_line_count" -lt "$input_line_count" + begin + printf "%s\n" $input_lines + cat + end | kak -e ' + exec + map global normal q :q; + rmhl global/number-lines; + set global scrolloff 10,0; + ' + + exit 0 + end + +end + +printf "%s\n" $input_lines diff --git a/scripts/kak-pager.nix b/scripts/kak-pager.nix deleted file mode 100644 index ebe7de4..0000000 --- a/scripts/kak-pager.nix +++ /dev/null @@ -1,36 +0,0 @@ -{ config, pkgs, lib, ... }: -pkgs.writeScriptBin "kak-pager" '' - #!/usr/bin/env fish - - if test (count $argv) -ne 0 - for i in $argv - cat "$i" - end | eval (status filename) - exit 0 - end - - set term_line_count (tput lines) - - while read line - set -a input_lines "$line" - - set input_line_count (printf "%s\n" $input_lines | wc -l) - - if test "$term_line_count" -lt "$input_line_count" - begin - printf "%s\n" $input_lines - cat - end | kak -e ' - exec - map global normal q :q; - rmhl global/number-lines; - set global scrolloff 10,0; - ' - - exit 0 - end - - end - - printf "%s\n" $input_lines -'' diff --git a/scripts/screenshotsh b/scripts/screenshotsh new file mode 100644 index 0000000..98aa17e --- /dev/null +++ b/scripts/screenshotsh @@ -0,0 +1,49 @@ +#!/bin/sh + +export XCURSOR_SIZE=40 +export XCURSOR_THEME='capitaine-cursors-light' + +screenshot="grim" +copy="wl-copy -t image/png" + +if which xdg-user-dir >/dev/null 2>&1; then + DESTFOLDER="$(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 + $screenshot "$DESTFILE" + echo "$DESTFILE" + ;; + + area) + # Screen area to file + $screenshot -g "$(slurp -d -b 30303088)" "$DESTFILE" + echo "$DESTFILE" + ;; + area-clip) + # Screen area to clipboard + $screenshot -g "$(slurp -d -b 30303088)" - | $copy + ;; + + clip) + # Focused monitor to clipboard + cur_output=$(swaymsg -t get_outputs | + jq -r '.[] | select(.focused) | .name') + + test -n "$cur_output" && + $screenshot -o "$cur_output" - | $copy || + $screenshot - | $copy + ;; +esac diff --git a/scripts/screenshotsh.nix b/scripts/screenshotsh.nix deleted file mode 100644 index dc44224..0000000 --- a/scripts/screenshotsh.nix +++ /dev/null @@ -1,50 +0,0 @@ -{ config, pkgs, lib, ... }: -pkgs.writeShellScriptBin "screenshotsh" '' - export XCURSOR_SIZE=40 - export XCURSOR_THEME='capitaine-cursors-light' # ${pkgs.capitaine-cursors} - - screenshot="${pkgs.grim}/bin/grim" - copy="${pkgs.wl-clipboard}/bin/wl-copy -t image/png" - - 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 - $screenshot "$DESTFILE" - echo "$DESTFILE" - ;; - - area) - # Screen area to file - $screenshot -g "$(slurp -d -b 30303088)" "$DESTFILE" - echo "$DESTFILE" - ;; - area-clip) - # Screen area to clipboard - $screenshot -g "$(slurp -d -b 30303088)" - | $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" && - $screenshot -o "$cur_output" - | $copy || - $screenshot - | $copy - ;; - esac -'' diff --git a/scripts/terminal b/scripts/terminal new file mode 100644 index 0000000..e125b8b --- /dev/null +++ b/scripts/terminal @@ -0,0 +1,20 @@ +#!/bin/sh + +CLASS="terminal" + +while test $# -gt 0;do + case $1 in + -c|--class) + shift + CLASS=$1 + shift + ;; + *) + break + ;; + esac +done + +test $# -gt 0 && + exec alacritty --class "$CLASS" -e $@ || + exec alacritty --class "$CLASS" diff --git a/scripts/terminal.nix b/scripts/terminal.nix deleted file mode 100644 index fd2ba36..0000000 --- a/scripts/terminal.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ config, pkgs, lib, ... }: -pkgs.writeScriptBin "terminal" '' - #!/bin/sh - - CLASS="terminal" - - while test $# -gt 0;do - case $1 in - -c|--class) - shift - CLASS=$1 - shift - ;; - *) - break - ;; - esac - done - - test $# -gt 0 && - exec alacritty --class "$CLASS" -e $@ || - exec alacritty --class "$CLASS" -'' diff --git a/scripts/wpass b/scripts/wpass new file mode 100644 index 0000000..6af51e1 --- /dev/null +++ b/scripts/wpass @@ -0,0 +1,43 @@ +_gpg-unlock +set -xe + +find_file() { + fd --strip-cwd-prefix '\.gpg$' | + sd ".gpg$" "" | + bmenu -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=`pass show "$entry" 2>/dev/null | perl -ne 'print $2 if /^(login|user|email): (.*)/'` + password=`pass show "$entry" 2>/dev/null | head -n 1` + + action=`printf "Autotype\nUsername -> $username\nPassword" | bmenu -p Action` + + case $action in + Autotype) + autotype + ;; + Username*) + printf '%s' "$username" | wl-copy;; + Password) + printf '%s' "$password" | wl-copy;; + esac + +} + +autotype(){ + env wtype -s 100 "$username" + env wtype -s 100 -k tab + env wtype -s 100 "$password" +} + +main diff --git a/scripts/wpass.nix b/scripts/wpass.nix deleted file mode 100644 index 7e0ec00..0000000 --- a/scripts/wpass.nix +++ /dev/null @@ -1,50 +0,0 @@ -{ config, pkgs, lib, ... }: -pkgs.writeShellScriptBin "wpass" '' - _gpg-unlock - set -xe - - wtype=${pkgs.wtype}/bin/wtype - # dmenu=${pkgs.bmenu}/bin/bmenu - dmenu="wdmenu -i" - - 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 $2 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 -'' diff --git a/user/git.nix b/user/git.nix index 3aa8c6e..8b4be0f 100644 --- a/user/git.nix +++ b/user/git.nix @@ -20,9 +20,9 @@ in { autoStash = true; }; pager = { - log = "${pkgs._diffr}/bin/diffr | ${pkgs.kak-pager}/bin/kak-pager"; - show = "${pkgs._diffr}/bin/diffr | ${pkgs.kak-pager}/bin/kak-pager"; - diff = "${pkgs._diffr}/bin/diffr | ${pkgs.kak-pager}/bin/kak-pager"; + log = "${pkgs._diffr}/bin/_diffr | ${pkgs.kak-pager}/bin/kak-pager"; + show = "${pkgs._diffr}/bin/_diffr | ${pkgs.kak-pager}/bin/kak-pager"; + diff = "${pkgs._diffr}/bin/_diffr | ${pkgs.kak-pager}/bin/kak-pager"; }; alias = { graph = "log --graph --oneline --all";