home, scripts: use fetchers

This commit is contained in:
Guanran Wang 2023-12-05 15:48:54 +08:00
parent ccb2708096
commit 4cfc603a0e
Signed by: nyancat
SSH key fingerprint: SHA256:8oWGKciPALWut/6WA27oFKofX+6Wtc0gQnsefXLQx/8
5 changed files with 17 additions and 121 deletions

View file

@ -9,7 +9,7 @@ $wp = ~/.local/bin/wrapped-swww
$dwp = ~/.local/bin/wrapped-mpvpaper
$changevolume = ~/.local/bin/wrapped-pamixer # use swayosd instead
$changebrightness = ~/.local/bin/wrapped-brightnessctl
$screenshot = ~/.local/bin/wrapped-grim
$screenshot = ~/.local/bin/screenshot
$inputfix = ~/.local/bin/minecraft-inputfix
$video_path = ~/.var/app/com.valvesoftware.Steam/data/Steam/steamapps/workshop/content/431960
@ -41,7 +41,7 @@ bind = SUPER SHIFT, L, exec, rofi -modi "power-men
# screenshot
bind = ,Print, exec, $screenshot fullscreen
bind = SUPER SHIFT, S, exec, $screenshot region
bind = ALT SHIFT, S, exec, $screenshot region edit
bind = ALT SHIFT, S, exec, $screenshot swappy
# wallpaper switching
bind = SHIFT ALT, 1, exec, $wp /usr/share/backgrounds/odin.jpg # pkg: elementary-wallpapers

View file

@ -97,7 +97,7 @@
inherit (config.wayland.windowManager.sway.config) modifier;
setBrightness = "/home/guanranwang/.local/bin/wrapped-brightnessctl";
setVolume = "/home/guanranwang/.local/bin/wrapped-pamixer";
screenshot = "/home/guanranwang/.local/bin/wrapped-grim";
screenshot = "/home/guanranwang/.local/bin/screenshot";
in {
### Sway itself
# Window
@ -148,9 +148,8 @@
# Screenshot
"${modifier}+Shift+s" = "exec ${screenshot} region";
"${modifier}+Control+Shift+s" = "exec ${screenshot} region edit";
"Print" = "exec ${screenshot} fullscreen";
"Print+Control" = "exec ${screenshot} fullscreen edit";
"Print+Control" = "exec ${screenshot} swappy";
# Fn keys
"XF86MonBrightnessUp" = "exec ${setBrightness} up";

View file

@ -1,56 +0,0 @@
#!/bin/sh
# Original script based on some early version of https://github.com/moverest/sway-interactive-screenshot
# modified for use with key bindings. For now supports sway & Hyprland.
SWAY=$(echo "$SWAYSOCK")
HYPR=$(echo "$HYPRLAND_INSTANCE_SIGNATURE")
if [[ -n "$SWAY" && -n "$HYPR" ]]; then
echo "This script only works on sway or Hyprland, terminating.";
exit 1
fi
list_geometry()
{
swaymsg -t get_tree | jq -r '.. | try select(.'"$1"' and .pid) | "\(.rect.x),\(.rect.y) \(.rect.width)x\(.rect.height)''"'
}
list_geometry_hypr()
{
hyprctl -j activewindow | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])''"'
}
CHOICE=$1
EDIT=$2
DIR=${SCREENSHOT_DIR:=~/Pictures/Screenshots}
mkdir -p "$DIR"
if [[ -n "$SWAY" ]]; then
FOCUSED=$(list_geometry focused)
FILENAME="${DIR/#\~/$HOME}/$(date +'%Y-%m-%d-%H%M%S_sway_screenshot.png')"
case $CHOICE in
fullscreen) grim "$FILENAME" ;;
region) grim -g "$(slurp)" "$FILENAME" ;;
focused) grim -g "$FOCUSED" "$FILENAME" ;;
display) grim -o "$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')" "$FILENAME" ;;
esac
fi
if [[ -n "$HYPR" ]]; then
FOCUSED=$(list_geometry_hypr)
FILENAME="${DIR/#\~/$HOME}/$(date +'%Y-%m-%d-%H%M%S_hypr_screenshot.png')"
case $CHOICE in
fullscreen) grim "$FILENAME" ;;
region) grim -g "$(slurp)" "$FILENAME" ;;
focused) grim -g "$FOCUSED" "$FILENAME" ;;
display) grim -o "$(hyprctl -j monitors | jq -r '.[] | select(.focused) | .name')" "$FILENAME" ;;
esac
fi
wl-copy < "$FILENAME"
notify-send "Screenshot" "File saved as <i>'$FILENAME'</i> and copied to the clipboard." -i "$FILENAME"
if [[ "$EDIT" = "edit" ]]; then
swappy -f "$FILENAME"
fi

View file

@ -1,56 +0,0 @@
#!/bin/sh
# Original script based on some early version of https://github.com/moverest/sway-interactive-screenshot
# modified for use with key bindings. For now supports sway & Hyprland.
SWAY=$(echo "$SWAYSOCK")
HYPR=$(echo "$HYPRLAND_INSTANCE_SIGNATURE")
if [[ -n "$SWAY" && -n "$HYPR" ]]; then
echo "This script only works on sway or Hyprland, terminating.";
exit 1
fi
list_geometry()
{
swaymsg -t get_tree | jq -r '.. | try select(.'"$1"' and .pid) | "\(.rect.x),\(.rect.y) \(.rect.width)x\(.rect.height)''"'
}
list_geometry_hypr()
{
hyprctl -j activewindow | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])''"'
}
CHOICE=$1
EDIT=$2
DIR=${SCREENSHOT_DIR:=~/Pictures/Screenshots}
mkdir -p "$DIR"
if [[ -n "$SWAY" ]]; then
FOCUSED=$(list_geometry focused)
FILENAME="${DIR/#\~/$HOME}/$(date +'%Y-%m-%d-%H%M%S_sway_screenshot.png')"
case $CHOICE in
fullscreen) wayshot -f "$FILENAME" ;;
region) wayshot -s "$(slurp)" -f "$FILENAME" ;;
focused) wayshot -s "$FOCUSED" -f "$FILENAME" ;;
display) wayshot -o "$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')" -f "$FILENAME" ;;
esac
fi
if [[ -n "$HYPR" ]]; then
FOCUSED=$(list_geometry_hypr)
FILENAME="${DIR/#\~/$HOME}/$(date +'%Y-%m-%d-%H%M%S_hypr_screenshot.png')"
case $CHOICE in
fullscreen) wayshot -f "$FILENAME" ;;
region) wayshot -s "$(slurp)" -f "$FILENAME" ;;
focused) wayshot -s "$FOCUSED" -f "$FILENAME" ;;
display) wayshot -o "$(hyprctl -j monitors | jq -r '.[] | select(.focused) | .name')" "$FILENAME" ;;
esac
fi
wl-copy < "$FILENAME"
notify-send "Screenshot" "File saved as <i>'$FILENAME'</i> and copied to the clipboard." -i "$FILENAME"
if [[ "$EDIT" = "edit" ]]; then
swappy -f "$FILENAME"
fi

View file

@ -1,17 +1,26 @@
{pkgs, ...}: {
home.sessionPath = ["$HOME/.local/bin"];
{pkgs, ...}: let
binPATH = ".local/bin";
in {
home.sessionPath = ["$HOME/${binPATH}"];
home.file = {
".local/bin" = {
${binPATH} = {
source = ./bin;
recursive = true;
executable = true;
};
".local/bin/lofi" = {
"${binPATH}/lofi" = {
source = pkgs.fetchurl {
url = "https://raw.githubusercontent.com/lime-desu/bin/main/lofi";
hash = "sha256-hT+S/rqOHUYnnFcSDFfQht4l1DGasz1L3wDHKUWLraA=";
};
executable = true;
};
"${binPATH}/screenshot" = {
source = pkgs.fetchurl {
url = "https://raw.githubusercontent.com/nwg-piotr/nwg-shell/c29e8eb4658a2613fb221ead0b101c75f457bcaf/scripts/screenshot";
hash = "sha256-Z/fWloz8pLHsvPTPOeBxnbMsGDRTY3G3l/uePQ3ZxjU=";
};
executable = true;
};
};
}