Convert change_wallpaper.sh using nix writeShellApplication
This commit is contained in:
parent
294fd9dcf3
commit
c6651a7eb6
4 changed files with 85 additions and 77 deletions
|
@ -39,6 +39,7 @@
|
||||||
wl-clipboard
|
wl-clipboard
|
||||||
(import ./scripts/colorpicker.nix { inherit pkgs; })
|
(import ./scripts/colorpicker.nix { inherit pkgs; })
|
||||||
(import ./scripts/currently-playing.nix { inherit pkgs; })
|
(import ./scripts/currently-playing.nix { inherit pkgs; })
|
||||||
|
(import ./scripts/change-wallpaper.nix { inherit pkgs; })
|
||||||
(pkgs.buildEnv {
|
(pkgs.buildEnv {
|
||||||
name = "desktop-scripts";
|
name = "desktop-scripts";
|
||||||
paths = [ ./scripts_legacy ];
|
paths = [ ./scripts_legacy ];
|
||||||
|
|
|
@ -158,9 +158,9 @@
|
||||||
extraConfig = ''
|
extraConfig = ''
|
||||||
submap = Fondo de pantalla
|
submap = Fondo de pantalla
|
||||||
|
|
||||||
bind = , H, exec, change_wallpaper.sh previous
|
bind = , H, exec, change-wallpaper previous
|
||||||
bind = , L, exec, change_wallpaper.sh next
|
bind = , L, exec, change-wallpaper next
|
||||||
bind = , M, exec, change_wallpaper.sh open-menu
|
bind = , M, exec, change-wallpaper open-menu
|
||||||
bindl = , escape, submap, reset
|
bindl = , escape, submap, reset
|
||||||
bindl = MOD3, w, submap, reset
|
bindl = MOD3, w, submap, reset
|
||||||
|
|
||||||
|
|
81
hosts/totsugeki/desktop/scripts/change-wallpaper.nix
Normal file
81
hosts/totsugeki/desktop/scripts/change-wallpaper.nix
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
{ pkgs }:
|
||||||
|
|
||||||
|
pkgs.writeShellApplication {
|
||||||
|
name = "change-wallpaper";
|
||||||
|
runtimeInputs = with pkgs; [ dunst rofi swww ];
|
||||||
|
text = ''
|
||||||
|
shopt -s nullglob
|
||||||
|
|
||||||
|
WALLPAPER_PATH="$HOME/.local/share/wallpapers"
|
||||||
|
WALLPAPERS=("$WALLPAPER_PATH"/*)
|
||||||
|
|
||||||
|
if [ ! -f "$WALLPAPER_PATH/.current_path" ]; then
|
||||||
|
# Current wallpaper file does not exist, create it
|
||||||
|
echo "''${WALLPAPERS[0]}" > "$WALLPAPER_PATH/.current_path"
|
||||||
|
fi
|
||||||
|
|
||||||
|
CURRENT_WALLPAPER=$(cat "$WALLPAPER_PATH/.current_path")
|
||||||
|
CURRENT_WP_INDEX=-1
|
||||||
|
# Get the current wallpaper's index
|
||||||
|
for index in "''${!WALLPAPERS[@]}"; do
|
||||||
|
if [ "''${WALLPAPERS[$index]}" = "$CURRENT_WALLPAPER" ]; then
|
||||||
|
CURRENT_WP_INDEX=$index
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$CURRENT_WP_INDEX" -eq -1 ]; then
|
||||||
|
CURRENT_WP_INDEX=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$1" = "previous" ]; then
|
||||||
|
WALLPAPER="''${WALLPAPERS[$CURRENT_WP_INDEX - 1]}"
|
||||||
|
TRANSITION_ANGLE=300
|
||||||
|
elif [ "$1" = "next" ]; then
|
||||||
|
NEXT_INDEX=$((CURRENT_WP_INDEX + 1))
|
||||||
|
if [ "$NEXT_INDEX" = "''${#WALLPAPERS[@]}" ]; then
|
||||||
|
NEXT_INDEX=0
|
||||||
|
fi
|
||||||
|
WALLPAPER=''${WALLPAPERS[$NEXT_INDEX]}
|
||||||
|
TRANSITION_ANGLE=120
|
||||||
|
elif [ "$1" = "open-menu" ]; then
|
||||||
|
INPUT=""
|
||||||
|
for index in "''${!WALLPAPERS[@]}"; do
|
||||||
|
if [ "$index" = "$CURRENT_WP_INDEX" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
_WALLPAPER=''${WALLPAPERS[$index]}
|
||||||
|
_WALLPAPER_NAME=$(basename "$_WALLPAPER")
|
||||||
|
INPUT+="$_WALLPAPER_NAME\0icon\x1f$_WALLPAPER"
|
||||||
|
if [ ! $((index + 1)) -eq ''${#WALLPAPERS[@]} ]; then
|
||||||
|
INPUT+=$'\n'
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if ! WALLPAPER=$(echo -en "$INPUT" | rofi -dmenu -mesg "Cambiar fondo de pantalla" -p "" -i -theme ~/.config/rofi/wallpaper_selector.rasi); then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
WALLPAPER="$WALLPAPER_PATH/$WALLPAPER"
|
||||||
|
TRANSITION_ANGLE=270
|
||||||
|
else
|
||||||
|
echo "Unknown first argument: $1"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$WALLPAPER" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
WALLPAPER_NAME=$(basename "$WALLPAPER")
|
||||||
|
echo "Setting wallpaper to $WALLPAPER"
|
||||||
|
echo "$WALLPAPER" > "$WALLPAPER_PATH/.current_path"
|
||||||
|
ln -sf "$WALLPAPER" "$WALLPAPER_PATH/.current_image"
|
||||||
|
dunstify -i "$WALLPAPER" -t 2800 "Cambiando fondo de pantalla" "Cambiando a $WALLPAPER_NAME"
|
||||||
|
swww img\
|
||||||
|
--transition-type wipe\
|
||||||
|
--transition-angle $TRANSITION_ANGLE\
|
||||||
|
--transition-step 90\
|
||||||
|
--transition-duration 1\
|
||||||
|
--transition-fps 165\
|
||||||
|
"$WALLPAPER"
|
||||||
|
|
||||||
|
'';
|
||||||
|
}
|
|
@ -1,74 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
shopt -s nullglob
|
|
||||||
|
|
||||||
WALLPAPER_PATH=~/.local/share/wallpapers
|
|
||||||
WALLPAPERS=($WALLPAPER_PATH/*)
|
|
||||||
|
|
||||||
if [ ! -f "$WALLPAPER_PATH/.current_path" ]; then
|
|
||||||
# Current wallpaper file does not exist, create it
|
|
||||||
echo ${WALLPAPERS[0]} > "$WALLPAPER_PATH/.current_path"
|
|
||||||
fi
|
|
||||||
|
|
||||||
CURRENT_WALLPAPER=$(cat "$WALLPAPER_PATH/.current_path")
|
|
||||||
# Get the current wallpaper's index
|
|
||||||
for index in ${!WALLPAPERS[@]}; do
|
|
||||||
if [ "${WALLPAPERS[$index]}" = "$CURRENT_WALLPAPER" ]; then
|
|
||||||
CURRENT_WP_INDEX=$index
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -z $CURRENT_WP_INDEX ]; then
|
|
||||||
CURRENT_WP_INDEX=0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $1 = "previous" ]; then
|
|
||||||
WALLPAPER=${WALLPAPERS[$CURRENT_WP_INDEX - 1]}
|
|
||||||
TRANSITION_ANGLE=300
|
|
||||||
elif [ $1 = "next" ]; then
|
|
||||||
NEXT_INDEX=$((CURRENT_WP_INDEX + 1))
|
|
||||||
if [ $NEXT_INDEX = ${#WALLPAPERS[@]} ]; then
|
|
||||||
NEXT_INDEX=0
|
|
||||||
fi
|
|
||||||
WALLPAPER=${WALLPAPERS[$NEXT_INDEX]}
|
|
||||||
TRANSITION_ANGLE=120
|
|
||||||
elif [ $1 = "open-menu" ]; then
|
|
||||||
INPUT=$''
|
|
||||||
for index in ${!WALLPAPERS[@]}; do
|
|
||||||
if [ $index = $CURRENT_WP_INDEX ]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
_WALLPAPER="${WALLPAPERS[$index]}"
|
|
||||||
_WALLPAPER_NAME=$(basename "$_WALLPAPER")
|
|
||||||
INPUT+="$_WALLPAPER_NAME\0icon\x1f$_WALLPAPER"
|
|
||||||
if [ ! $(($index + 1)) = ${#WALLPAPERS[@]} ]; then
|
|
||||||
INPUT+=$'\n'
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
WALLPAPER=$(echo -en "$INPUT" | rofi -dmenu -mesg "Cambiar fondo de pantalla" -p "" -i -theme ~/.config/rofi/wallpaper_selector.rasi)
|
|
||||||
if [ ! $? = 0 ]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
WALLPAPER="${WALLPAPER_PATH}/${WALLPAPER}"
|
|
||||||
TRANSITION_ANGLE=270
|
|
||||||
else
|
|
||||||
echo "Unknown first argument: $1"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z $WALLPAPER ]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
WALLPAPER_NAME=$(basename "$WALLPAPER")
|
|
||||||
echo "Setting wallpaper to $WALLPAPER, args: $@"
|
|
||||||
echo "$WALLPAPER" > "$WALLPAPER_PATH/.current_path"
|
|
||||||
ln -sf "$WALLPAPER" "$WALLPAPER_PATH/.current_image"
|
|
||||||
dunstify -i "$WALLPAPER" -t 2800 "Cambiando fondo de pantalla" "Cambiando a $WALLPAPER_NAME"
|
|
||||||
swww img\
|
|
||||||
--transition-type wipe\
|
|
||||||
--transition-angle $TRANSITION_ANGLE\
|
|
||||||
--transition-step 90\
|
|
||||||
--transition-duration 1\
|
|
||||||
--transition-fps 165\
|
|
||||||
"$WALLPAPER"
|
|
Loading…
Add table
Add a link
Reference in a new issue