Add waybar utilities

52a6cc52d75336bdd744236fd40986b8fe0a17ea
Alexis Sellier committed ago 1 parent 7c69f474
bin/waybar-audio-output-selector added +23 -0
1 +
#!/bin/sh
2 +
3 +
sinks=$(pactl -f json list sinks | jq -r '.[] | [.name, .description] | @tsv')
4 +
5 +
[ -n "$sinks" ] || exit 1
6 +
7 +
default=$(pactl get-default-sink)
8 +
sink=$(
9 +
  printf '%s\n' "$sinks" |
10 +
    awk -F '\t' -v current="$default" '{
11 +
      marker = ($1 == current) ? "* " : "  "
12 +
      printf "%s\t%s%s\n", $1, marker, $2
13 +
    }' |
14 +
      fuzzel --dmenu --hide-prompt --lines=6 --width=64 \
15 +
      --with-nth=2 --accept-nth=1 --only-match --no-run-if-empty
16 +
    ) || exit 0
17 +
18 +
[ -n "$sink" ] || exit 1
19 +
20 +
pactl set-default-sink "$sink"
21 +
pactl list sink-inputs short | awk '{ print $1 }' | while read -r input; do
22 +
  pactl move-sink-input "$input" "$sink"
23 +
done
bin/waybar-clipboard added +36 -0
1 +
#!/bin/sh
2 +
3 +
refresh_waybar() {
4 +
  pkill -RTMIN+9 -x waybar
5 +
}
6 +
7 +
case "$1" in
8 +
  status)
9 +
    count=$(cliphist list 2>/dev/null | wc -l)
10 +
    printf '{"tooltip":"%s clipboard items"}\n' "$count"
11 +
    ;;
12 +
  has-items)
13 +
    command -v cliphist >/dev/null 2>&1 || exit 1
14 +
    test "$(cliphist list 2>/dev/null | wc -l)" -gt 0
15 +
    ;;
16 +
  copy)
17 +
    item=$(cliphist list | fuzzel --dmenu --width 100) || exit
18 +
    test -n "$item" || exit
19 +
    printf '%s\n' "$item" | cliphist decode | wl-copy || exit
20 +
    refresh_waybar
21 +
    ;;
22 +
  delete)
23 +
    item=$(cliphist list | fuzzel --dmenu --width 100) || exit
24 +
    test -n "$item" || exit
25 +
    printf '%s\n' "$item" | cliphist delete || exit
26 +
    refresh_waybar
27 +
    ;;
28 +
  wipe)
29 +
    cliphist wipe || exit
30 +
    refresh_waybar
31 +
    ;;
32 +
  *)
33 +
    echo "usage: waybar-clipboard {status|has-items|copy|delete|wipe}" >&2
34 +
    exit 2
35 +
    ;;
36 +
esac
bin/waybar-screenshot added +24 -0
1 +
#!/bin/sh
2 +
3 +
case "$1" in
4 +
  region)
5 +
    geometry=$(slurp) || exit
6 +
    grim -g "$geometry" - | wl-copy
7 +
    ;;
8 +
  full)
9 +
    grim -c - | wl-copy
10 +
    ;;
11 +
  window)
12 +
    geometry=$(slurp -r < "${XDG_RUNTIME_DIR:?}/swm-windows") || exit
13 +
    grim -c -g "$geometry" - | wl-copy
14 +
    ;;
15 +
  edit)
16 +
    grim -c - |
17 +
      satty --filename - --fullscreen current-screen --initial-tool crop \
18 +
      --copy-command=wl-copy --early-exit copy
19 +
    ;;
20 +
  *)
21 +
    echo "usage: waybar-screenshot {region|full|window|edit}" >&2
22 +
    exit 2
23 +
    ;;
24 +
esac