Clean up i3 scripts

This commit is contained in:
2022-12-16 19:34:06 +01:00
parent 2e8708a616
commit 8aeb9d9f27
9 changed files with 10 additions and 222 deletions

View File

@@ -226,7 +226,7 @@ assign [class="^Wine$"] $workspace10
bindsym $mod+Shift+v exec --no-startup-id redshift-toggle
bindsym $mod+$pim_toggle exec --no-startup-id ~/.i3/scripts/swap-from-workspace.sh $workspace10
bindsym $mod+$pim_toggle exec --no-startup-id ~/.i3/scripts/swap-from-workspace $workspace10
################################################################################
### MODES ######################################################################
@@ -319,20 +319,20 @@ bindsym $mod+F9 exec --no-startup-id evolution
################################################################################
bindsym XF86Sleep exec --no-startup-id $scriptdir/i3exit suspend
bindsym XF86AudioMute exec --no-startup-id $scriptdir/pa-volume mute-toggle
bindsym XF86AudioRaiseVolume exec --no-startup-id $scriptdir/pa-volume set-vol +3
bindsym XF86AudioLowerVolume exec --no-startup-id $scriptdir/pa-volume set-vol -3
bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute '@DEFAULT_SINK@' toggle
bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume '@DEFAULT_SINK@' +5%
bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume '@DEFAULT_SINK@' -5%
bindsym XF86AudioPlay exec $scriptdir/spotify-control toggle
bindsym XF86AudioNext exec $scriptdir/spotify-control next
bindsym XF86AudioPrev exec $scriptdir/spotify-control previous
bindsym XF86AudioPlay exec --no-startup-id playerctl -p spotify play-pause
bindsym XF86AudioNext exec --no-startup-id playerctl -p spotify next
bindsym XF86AudioPrev exec --no-startup-id playerctl -p spotify previous
# keys seemingly switched
bindsym XF86MonBrightnessUp exec --no-startup-id xbacklight -inc 8 ; exec --no-startup-id $scriptdir/update-status
bindsym XF86MonBrightnessDown exec --no-startup-id xbacklight -dec 8 ; exec --no-startup-id $scriptdir/update-status
bindsym $mod+m exec --no-startup-id $scriptdir/pa-volume mute-toggle-mic
bindsym $mod+space exec --no-startup-id $scriptdir/pa-volume mute-toggle-mic
bindsym $mod+m exec --no-startup-id pactl set-source-mute '@DEFAULT_SOURCE@' toggle
bindsym $mod+space exec --no-startup-id pactl set-source-mute '@DEFAULT_SOURCE@' toggle
##############################################################################
### BARS #######################################################################

View File

@@ -56,7 +56,7 @@ block = "toggle"
format = "  $icon "
command_on = "$HOME/.i3/scripts/presentation-mode toggle ; pkill -SIGRTMIN+0 i3status-rs"
command_off = "$HOME/.i3/scripts/presentation-mode toggle ; pkill -SIGRTMIN+0 i3status-rs"
command_state = "[[ $($HOME/.i3/scripts/presentation-mode status) == off ]] || echo active"
command_state = "[[ $($HOME/.i3/scripts/presentation-mode status) == on ]] && echo active"
[[block]]
block = "toggle"

View File

@@ -1,9 +0,0 @@
#!/bin/bash
if [[ "$1" ]] ; then
modules="$1"
else
modules=all
fi
py3-cmd refresh "$modules"

View File

@@ -1,137 +0,0 @@
#!/bin/bash
# name of the sink. execute pactl list sinks to get a list
SINKNAME="$(pactl info | grep '^Default Sink:' | cut -d ' ' -f 3-)"
# name of the sink. execute pactl list sinks to get a list
SOURCENAME="$(pactl info | grep '^Default Source:' | cut -d ' ' -f 3-)"
#SINKNAME="alsa_output.usb-Logitech_Logitech_Wireless_Headset_88C626354D45-00.analog-stereo"
# this is the worst
SINK=$(( $(pactl list sinks | grep "Name: " | grep -n "${SINKNAME}"$ | grep -o "^[[:digit:]]*") -1))
SOURCE=$(( $(pactl list sources | grep "Name: " | grep -n "${SOURCENAME}"$ | grep -o "^[[:digit:]]*") -1))
getvol() {
echo $(pactl list sinks | grep "^[[:space:]]*Volume" | head -n $(( $SINK + 1 )) | tail -n 1 | grep -o "[[:digit:]]*%" | head -n 1 | cut -d "%" -f 1)
}
setvol() {
if [[ $1 =~ [+-][0-9]+ ]] ; then
oldvol="$(getvol)"
echo "oldvol $oldvol"
delta="$(echo "$1" | cut -c 2-)"
echo "delta $delta"
if [[ "$(echo "$1" | cut -c 1)" == "+" ]] ; then
echo "+"
newvol=$(( $oldvol + $delta ))
else
echo "-"
newvol=$(( $oldvol - $delta ))
echo $newvol
fi
if [[ $newvol -gt 100 ]]; then
echo "capping at 100 percent"
newvol=100
fi
if [[ $newvol -lt 0 ]]; then
echo "capping at 0 percent"
newvol=0
fi
echo "newvol $newvol"
else
newvol="$1"
fi
pactl set-sink-volume $SINKNAME $(( $newvol * 65536 / 100 ))
}
ismuted() {
muted=$(pactl list sinks | grep "^[[:space:]]*Mute" | head -n $(( $SINK + 1 )) | tail -n 1 | cut -d " " -f 2)
if [[ $muted == "no" ]]; then
echo 0
else
echo 1
fi
}
mute() {
pactl set-sink-mute $SINKNAME 1
}
unmute() {
pactl set-sink-mute $SINKNAME 0
}
mute-toggle() {
pactl set-sink-mute $SINKNAME toggle
}
mute-toggle-mic() {
pactl set-source-mute $SOURCENAME toggle
}
status() {
if [[ $(ismuted) == "1" ]] ; then
echo "mute"
return
fi
echo "$(getvol)%"
}
usage() {
echo "Usage:"
echo
echo "$0 get-vol"
echo "$0 set-vol VOL_PERC"
}
update_status_bar_sink() {
~/.i3/scripts/bar-update "volume_status output"
}
update_status_bar_source() {
~/.i3/scripts/bar-update "volume_status input"
}
case "$1" in
"sink")
echo $SINKNAME
echo $SINK
;;
"get-vol")
echo $(getvol)
;;
"set-vol")
if [[ -z "$2" ]] ; then
usage
else
setvol "$2"
fi
update_status_bar_sink
;;
"mute")
mute
update_status_bar_sink
;;
"unmute")
unmute
update_status_bar_sink
;;
"mute-toggle")
mute-toggle
update_status_bar_sink
;;
"mute-toggle-mic")
mute-toggle-mic
update_status_bar_source
;;
"is-muted")
echo $(ismuted)
;;
"status")
echo $(status)
;;
*)
usage
esac

View File

@@ -1,7 +1,6 @@
#!/usr/bin/env bash
_status_file="${XDG_RUNTIME_DIR}/presentation-mode-on"
_autostart="$HOME/.autostart.sh"
is_on() {
[[ -e "${_status_file}" ]]
@@ -12,9 +11,6 @@ switch_on() {
dunstctl set-paused true &
systemctl --user --no-block stop redshift.service
systemctl --user --no-block stop spotify.service
~/.i3/scripts/bar-update "external_script presentation_mode"
~/.i3/scripts/bar-update "systemd redshift"
~/.i3/scripts/bar-update "systemd spotify"
}
switch_off() {
@@ -22,9 +18,6 @@ switch_off() {
dunstctl set-paused false &
systemctl --user --no-block start redshift.service
systemctl --user --no-block start spotify.service
~/.i3/scripts/bar-update "external_script presentation_mode"
~/.i3/scripts/bar-update "systemd redshift"
~/.i3/scripts/bar-update "systemd spotify"
}
@@ -32,10 +25,8 @@ case "$1" in
status)
if is_on ; then
printf "on\n"
printf '#F4BF75'
else
printf "off\n"
# printf '#F4BF75'
fi
;;
toggle)

View File

@@ -1,20 +0,0 @@
#!/bin/bash
case "$1" in
toggle)
cmd="play-pause"
;;
next)
cmd="next"
;;
previous)
cmd="previous"
;;
*)
echo "wrong argument $1"
exit 1
;;
esac
playerctl -p spotify "${cmd}"
~/.i3/scripts/bar-update spotify

View File

@@ -1,20 +0,0 @@
#!/usr/bin/env python3
import dbus
session_bus = dbus.SessionBus()
spotify_bus = session_bus.get_object("org.mpris.MediaPlayer2.spotify",
"/org/mpris/MediaPlayer2")
spotify_properties = dbus.Interface(spotify_bus,
"org.freedesktop.DBus.Properties")
metadata = spotify_properties.Get("org.mpris.MediaPlayer2.Player", "Metadata")
# The property Metadata behaves like a python dict
# for key, value in metadata.items():
# print(key, value)
# To just print the title
print("{}: {} - [{}]".format(
metadata['xesam:artist'][0],
metadata['xesam:title'],
metadata['xesam:album']
))

View File

@@ -1,17 +0,0 @@
#!/usr/bin/env bash
app="${1:?app missing}"
unitname="${app}.service"
running() {
systemctl --user --quiet status "${unitname}" >/dev/null
}
if running ; then
systemctl --user stop "${unitname}"
else
systemctl --user start "${unitname}"
fi
py3-cmd refresh "systemd $app"