all repos — dotfiles @ 37ec77a37800354dbf07d259cf2ccac9152ce647

my *nix dotfiles

bin: add scr and kctx
Anirudh Oppiliappan x@icyphox.sh
Thu, 05 May 2022 10:43:17 +0530
commit

37ec77a37800354dbf07d259cf2ccac9152ce647

parent

852c222278be3d4f074713027b78b66de35604bd

3 files changed, 70 insertions(+), 0 deletions(-)

jump to
M nix/bin/default.nixnix/bin/default.nix

@@ -60,6 +60,12 @@ cputil = import ./cputil.nix pkgs;

# password manager pw = import ./pw.nix pkgs; + + # screenshot tool + scr = import ./scr.nix pkgs; + + # kubectx wrapper + kctx = import ./kctx.nix pkgs; in [ git-new-push-remote

@@ -74,4 +80,6 @@ invert

nvidia-offload cputil pw + scr + kctx ]
A nix/bin/kctx.nix

@@ -0,0 +1,12 @@

+{ pkgs, ... }: + +let + name = "kctx"; + kubectx = "${pkgs.kubectx}/bin/kubectx"; + fzy = "${pkgs.fzy}/bin/fzy"; +in +pkgs.writeShellScriptBin name + '' + ctx="$(${kubectx} | ${fzy})" + ${kubectx} "$ctx" + ''
A nix/bin/scr.nix

@@ -0,0 +1,50 @@

+{ pkgs, ... }: + +let + name = "scr"; + import = "${pkgs.imagemagick}/bin/import"; + xclip = "${pkgs.xclip}/bin/xclip"; + xdotool = "${pkgs.xdotool}/bin/xdotool"; +in +pkgs.writeShellScriptBin name + '' + scr_path=~/pics/scrots + output="$(tr -dc 'a-zA-Z0-9' < /dev/random | fold -w 5 | head -n 1)" + + usage() { + echo "usage:" + echo " scr [option]" + echo "options:" + echo " -f full screenshot" + echo " -w window screenshot" + echo " -s selection screenshot" + } + + while getopts fws option + do + case $option in + f) + ${import} -window root "$scr_path/$output.png" + ;; + w) + ${import} -window "$(${xdotool} getwindowfocus)" "$scr_path/$output.png" + ;; + s) + ${import} "$scr_path/$output.png" + ;; + * | ?) + usage + exit;; + esac + done + + if [ $OPTIND -eq 1 ]; then + echo "scr: missing argument" + usage + exit + fi + + + ${xclip} -selection clipboard -t image/png -i "$scr_path/$output.png" + cp "$scr_path/$output.png" "$scr_path/latest.png" + ''