Skip to content

Commit

Permalink
✨ (script): screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
elythh committed Nov 21, 2024
1 parent 444b5d1 commit baaeeef
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
7 changes: 4 additions & 3 deletions modules/home/opt/wayland/hyprland/config/binds.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ in
bind =
let
monocle = "dwindle:no_gaps_when_only";
screenshot = import ../scripts/screenshot.nix { inherit pkgs; };
in
[
# Compositor commands
Expand Down Expand Up @@ -98,9 +99,9 @@ in
"SUPER, O, exec, run-as-service wl-ocr"

# Screenshot
"SUPERSHIFT, S, exec, grimblast copy area --notify"
"CTRLSHIFT, S, exec, grimblast --notify --cursor copysave output"
"SUPERSHIFT, T, exec, kitty -e twt"
"SUPERSHIFT, S, exec, ${screenshot}/bin/screenshot s"
"SUPERALT, S, exec, ${screenshot}/bin/screenshot f"
",print, exec, ${screenshot}/bin/screenshot f"
]
++ workspaces;

Expand Down
47 changes: 47 additions & 0 deletions modules/home/opt/wayland/hyprland/scripts/screenshot.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{ pkgs, ... }:
pkgs.writeShellScriptBin "screenshot" ''
SCREENSHOT_DIR="$HOME/Pictures/Screenshots"
mkdir -p "$SCREENSHOT_DIR"
IMAGE_NAME=$(date +'%y%m%d_%Hh%Mm%Ss_screenshot.png')
SAVED_IMAGE="$SCREENSHOT_DIR/$IMAGE_NAME"
TMP_SCREENSHOT="/tmp/$IMAGE_NAME"
case $1 in
"f")
${pkgs.wayshot}/bin/wayshot -f $TMP_SCREENSHOT
;;
"s")
${pkgs.wayshot}/bin/wayshot -s "$(${pkgs.slurp}/bin/slurp)" -f $TMP_SCREENSHOT
;;
*)
exit
;;
esac
${pkgs.wl-clipboard}/bin/wl-copy < $TMP_SCREENSHOT
if [ ! -f "$TMP_SCREENSHOT" ]; then
exit
fi
ACTION=$(${pkgs.libnotify}/bin/notify-send "Screenshot" "Screenshot copied to clipboard." -i "multimedia-photo-viewer-symbolic" -A "save=Save")
case "$ACTION" in
"save")
SWAPPY_DIR="$HOME/.config/swappy/"
mkdir -p $SWAPPY_DIR
echo -e "[Default]\nsave_dir=$SCREENSHOT_DIR\nsave_filename_format=$IMAGE_NAME" > $SWAPPY_DIR/config
${pkgs.swappy}/bin/swappy -f $TMP_SCREENSHOT
if [ -f "$SAVED_IMAGE" ]; then
${pkgs.libnotify}/bin/notify-send "Image Saved" "Image saved successfully." -i "multimedia-photo-viewer-symbolic"
rm "$TMP_SCREENSHOT"
fi
;;
*)
exit
;;
esac
''
1 change: 1 addition & 0 deletions modules/nixos/opt/fonts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
lexend
noto-fonts
roboto
google-fonts

(nerdfonts.override {
fonts = [
Expand Down

0 comments on commit baaeeef

Please sign in to comment.