all repos — dotfiles @ 1461681f364214fb709c3c1d7234b43a7f12fab1

my *nix dotfiles

nix/bin/scr.nix (view raw)

 1{ pkgs, ... }:
 2
 3let
 4  name = "scr";
 5  import = "${pkgs.imagemagick}/bin/import";
 6  xclip = "${pkgs.xclip}/bin/xclip";
 7  xdotool = "${pkgs.xdotool}/bin/xdotool";
 8in
 9pkgs.writeShellScriptBin name
10  ''
11    scr_path=~/pics/scrots
12    output="$(tr -dc 'a-zA-Z0-9' < /dev/random | fold -w 5 | head -n 1)"
13
14    usage() {
15        echo "usage:"
16        echo "  scr [option]"
17        echo "options:"
18        echo "  -f    full screenshot"
19        echo "  -w    window screenshot"
20        echo "  -s    selection screenshot"
21    }
22
23    while getopts fws option
24    do
25        case $option in
26            f)
27                ${import} -window root "$scr_path/$output.png"
28                ;;
29            w)
30                ${import} -window "$(${xdotool} getwindowfocus)" "$scr_path/$output.png"
31                ;;
32            s)
33                ${import} "$scr_path/$output.png"
34                ;;
35            * | ?)
36                usage
37                exit;;
38            esac
39    done
40
41    if [ $OPTIND -eq 1 ]; then
42        echo "scr: missing argument"
43        usage
44        exit
45    fi
46
47
48    ${xclip} -selection clipboard -t image/png -i "$scr_path/$output.png"
49    cp "$scr_path/$output.png" "$scr_path/latest.png"
50  ''