Compare commits

...

4 commits

Author SHA1 Message Date
dabruh
4973b9f4d2 Fix bugs on empty input 2024-04-18 20:37:00 +02:00
dabruh
c7145e8b4a Add home setup 2024-04-18 19:46:27 +02:00
dabruh
4cac467d32 Streamline monitors_exist with usb_devices_exist 2024-04-17 18:34:48 +02:00
dabruh
f5676e638d Add verbosity 2024-04-17 18:26:01 +02:00
2 changed files with 34 additions and 15 deletions

View file

@ -16,6 +16,7 @@ export CHROME_EXECUTABLE=chromium # For Flutter
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
export XDG_DATA_DIRS="${XDG_DATA_DIRS:-/usr/share}"
# Clean home:
export ANDROID_HOME="$XDG_DATA_HOME/Android/Sdk"
@ -64,26 +65,27 @@ rm_env_path_entry() {
del_entry="${2:?Missing entry to delete}"
new_entries=""
echo "$src_entries" | $_tr ':' '\n' | while read -r entry; do
for entry in $(echo "$src_entries" | $_tr ':' ' '); do
if [ "$entry" != "$del_entry" ]; then
new_entries="$new_entries:$entry"
fi
done
trim "$new_entries" ":"
[ -n "$new_entries" ] && trim "$new_entries" ":"
echo
}
modify_env_path() {
mode="${1:?Missing mode}"
entries="${2:?Missing entries}"
entries="$2"
change="${3:?Missing change}"
entries="$(trim "$entries" ":")"
[ -n "$entries" ] && entries="$(trim "$entries" ":")"
case "$mode" in
prepend)
temp_entries="" # Will hold the new entries in the correct order
echo "$change" | $_tr ':' '\n' | while read -r entry; do
for entry in $(echo "$change" | $_tr ':' ' '); do
[ -z "$entry" ] && continue # Skip empty entries
[ -d "$entry" ] || continue # Skip non-existent directories
temp_entries="$temp_entries:$entry"
@ -94,15 +96,16 @@ modify_env_path() {
entries="${temp_entries#:}:$entries"
;;
append)
echo "$change" | $_tr ':' '\n' | while read -r entry; do
for entry in $(echo "$change" | $_tr ':' ' '); do
[ -z "$entry" ] && continue # Skip empty entries
[ -d "$entry" ] || continue # Skip non-existent directories
entries="$entries:$entry"
done
;;
delete)
echo "$change" | $_tr ':' '\n' | while read -r entry; do
for entry in $(echo "$change" | $_tr ':' ' '); do
[ -z "$entry" ] && continue # Skip empty entries
[ -z "$entries" ] && break # nothing left to remove
entries=$(rm_env_path_entry "$entries" "$entry")
done
;;
@ -112,7 +115,8 @@ modify_env_path() {
;;
esac
trim "$entries" ":"
[ -n "$entries" ] && trim "$entries" ":"
echo
}
prepend_paths="$HOME/.local/bin:$HOME/.cargo/bin:$FLUTTER_HOME/bin:$GOPATH/bin:$KREW_ROOT/bin"

View file

@ -65,14 +65,20 @@ monitor_exist() {
# monitors_exist checks if the specified monitors are connected to the system
# $1..$n: The monitor names to search for
monitors_exist() {
local monitor
local monitor matches=0
for monitor in "$@"; do
if ! monitor_exist "$monitor"; then
return 1
if monitor_exist "$monitor"; then
echo "$monitor"
matches=$((matches + 1))
fi
done
if [ "$matches" -ne "$#" ]; then
echo "Amount of devices does not match the amount of arguments" 1>&2
return 1
fi
return 0
}
@ -285,7 +291,7 @@ move_nonexistent_i3_workspaces() {
}
main() {
local primary_monitor monitor_count monitors=() profile_found=false
local primary_monitor monitor_count monitors=() profile_found=false exists
primary_monitor=$(get_monitors primary | cut -d',' -f1)
monitor_count=$(get_monitors connected | wc -l)
echo "Monitors connected: $monitor_count"
@ -294,7 +300,7 @@ main() {
echo "Applying laptop-only profile"
xrandr --auto
profile_found=true
elif usb_devices_exist all exact "HP, Inc HP USB-C Universal Dock" >/dev/null; then
elif usb_devices_exist all exact "HP, Inc HP USB-C Universal Dock" >/dev/null 2>&1; then
monitors=(
"eDP-1,DVI-I-1-1,DVI-I-2-2"
"eDP-1,DVI-I-2-2,DVI-I-3-3"
@ -302,8 +308,8 @@ main() {
for monitor in "${monitors[@]}"; do
IFS=',' read -r -a monitor_array <<<"$monitor"
if monitors_exist "${monitor_array[@]}"; then
echo "Applying dock profile for ${monitor_array[*]}"
if monitors_exist "${monitor_array[@]}" >/dev/null; then
echo "Applying work profile for ${monitor_array[*]}"
xrandr \
--output "${monitor_array[0]}" --mode 1920x1200 --rotate normal --pos 1200x1474 --primary \
--output "${monitor_array[1]}" --mode 1920x1200 --rotate left --pos 0x0 \
@ -312,6 +318,15 @@ main() {
break
fi
done
elif usb_devices_exist all exact "Lenovo ThinkPad USB-C Dock Audio" >/dev/null 2>&1; then
monitor_array=(eDP-1 DP-1-0.3 DP-1-0.1)
if monitors_exist "${monitor_array[@]}" >/dev/null; then
echo "Applying home profile for ${monitor_array[*]}"
xrandr \
--output "${monitor_array[0]}" --mode 2560x1440 --rotate normal --pos 0x480 --primary \
--output "${monitor_array[1]}" --mode 3440x1440 --rotate normal --pos 2560x480 \
--output "${monitor_array[2]}" --mode 1920x1200 --rotate right --pos 6000x0
fi
fi
if ! "$profile_found"; then