mirror of
https://gitlab.com/dabruh/dotfiles.git
synced 2024-12-26 03:48:12 +01:00
Compare commits
No commits in common. "4973b9f4d2abdcc8ae05884d263a7d33b34d8b56" and "a9ccc784827ed480f599886277119e46112a0c1e" have entirely different histories.
4973b9f4d2
...
a9ccc78482
2 changed files with 15 additions and 34 deletions
|
@ -16,7 +16,6 @@ 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"
|
||||
|
@ -65,27 +64,26 @@ rm_env_path_entry() {
|
|||
del_entry="${2:?Missing entry to delete}"
|
||||
new_entries=""
|
||||
|
||||
for entry in $(echo "$src_entries" | $_tr ':' ' '); do
|
||||
echo "$src_entries" | $_tr ':' '\n' | while read -r entry; do
|
||||
if [ "$entry" != "$del_entry" ]; then
|
||||
new_entries="$new_entries:$entry"
|
||||
fi
|
||||
done
|
||||
|
||||
[ -n "$new_entries" ] && trim "$new_entries" ":"
|
||||
echo
|
||||
trim "$new_entries" ":"
|
||||
}
|
||||
|
||||
modify_env_path() {
|
||||
mode="${1:?Missing mode}"
|
||||
entries="$2"
|
||||
entries="${2:?Missing entries}"
|
||||
change="${3:?Missing change}"
|
||||
|
||||
[ -n "$entries" ] && entries="$(trim "$entries" ":")"
|
||||
entries="$(trim "$entries" ":")"
|
||||
|
||||
case "$mode" in
|
||||
prepend)
|
||||
temp_entries="" # Will hold the new entries in the correct order
|
||||
for entry in $(echo "$change" | $_tr ':' ' '); do
|
||||
echo "$change" | $_tr ':' '\n' | while read -r entry; do
|
||||
[ -z "$entry" ] && continue # Skip empty entries
|
||||
[ -d "$entry" ] || continue # Skip non-existent directories
|
||||
temp_entries="$temp_entries:$entry"
|
||||
|
@ -96,16 +94,15 @@ modify_env_path() {
|
|||
entries="${temp_entries#:}:$entries"
|
||||
;;
|
||||
append)
|
||||
for entry in $(echo "$change" | $_tr ':' ' '); do
|
||||
echo "$change" | $_tr ':' '\n' | while read -r entry; do
|
||||
[ -z "$entry" ] && continue # Skip empty entries
|
||||
[ -d "$entry" ] || continue # Skip non-existent directories
|
||||
entries="$entries:$entry"
|
||||
done
|
||||
;;
|
||||
delete)
|
||||
for entry in $(echo "$change" | $_tr ':' ' '); do
|
||||
echo "$change" | $_tr ':' '\n' | while read -r entry; do
|
||||
[ -z "$entry" ] && continue # Skip empty entries
|
||||
[ -z "$entries" ] && break # nothing left to remove
|
||||
entries=$(rm_env_path_entry "$entries" "$entry")
|
||||
done
|
||||
;;
|
||||
|
@ -115,8 +112,7 @@ modify_env_path() {
|
|||
;;
|
||||
esac
|
||||
|
||||
[ -n "$entries" ] && trim "$entries" ":"
|
||||
echo
|
||||
trim "$entries" ":"
|
||||
}
|
||||
|
||||
prepend_paths="$HOME/.local/bin:$HOME/.cargo/bin:$FLUTTER_HOME/bin:$GOPATH/bin:$KREW_ROOT/bin"
|
||||
|
|
|
@ -65,20 +65,14 @@ 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 matches=0
|
||||
local monitor
|
||||
|
||||
for monitor in "$@"; do
|
||||
if monitor_exist "$monitor"; then
|
||||
echo "$monitor"
|
||||
matches=$((matches + 1))
|
||||
if ! monitor_exist "$monitor"; then
|
||||
return 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
|
||||
}
|
||||
|
||||
|
@ -291,7 +285,7 @@ move_nonexistent_i3_workspaces() {
|
|||
}
|
||||
|
||||
main() {
|
||||
local primary_monitor monitor_count monitors=() profile_found=false exists
|
||||
local primary_monitor monitor_count monitors=() profile_found=false
|
||||
primary_monitor=$(get_monitors primary | cut -d',' -f1)
|
||||
monitor_count=$(get_monitors connected | wc -l)
|
||||
echo "Monitors connected: $monitor_count"
|
||||
|
@ -300,7 +294,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 2>&1; then
|
||||
elif usb_devices_exist all exact "HP, Inc HP USB-C Universal Dock" >/dev/null; then
|
||||
monitors=(
|
||||
"eDP-1,DVI-I-1-1,DVI-I-2-2"
|
||||
"eDP-1,DVI-I-2-2,DVI-I-3-3"
|
||||
|
@ -308,8 +302,8 @@ main() {
|
|||
|
||||
for monitor in "${monitors[@]}"; do
|
||||
IFS=',' read -r -a monitor_array <<<"$monitor"
|
||||
if monitors_exist "${monitor_array[@]}" >/dev/null; then
|
||||
echo "Applying work profile for ${monitor_array[*]}"
|
||||
if monitors_exist "${monitor_array[@]}"; then
|
||||
echo "Applying dock 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 \
|
||||
|
@ -318,15 +312,6 @@ 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
|
||||
|
|
Loading…
Reference in a new issue