haimgel / display-switch

Turn a $30 USB switch into a full-featured multi-monitor KVM switch
https://haim.dev/posts/2020-07-28-dual-monitor-kvm/
MIT License
2.82k stars 110 forks source link

FR expand ~ in on_usb_connect_execute #123

Closed charger89 closed 8 months ago

charger89 commented 10 months ago

Similar to how dotter (a dotfile manager written in rust) handles paths, ~ should be handled on both unix & windows as expected; on windows it'd become C:\Users\<USERNAME>\

This would allow us to define executable path such as

on_usb_connect_execute = "powershell -File ~\\scripts\\myscript.ps1"

as opposed to

on_usb_connect_execute = "powershell -File C:\\Users\\charger\\scripts\\myscript.ps1"

Bonus points if path separator was made platform-agnostic as well (ie always use fwd slash in path definitions): powershell -File ~/scripts/myscript.ps1


For reference, dotter appears to be expanding tildes here

haimgel commented 8 months ago

Thank you for the suggestion. I find this somewhat problematic:

  1. Tilde is customarily parsed as home directory only on Linux & MacOS, not on Windows.
  2. Some people are running display-switch as root on Linux (because of udev permissions), tilde is typically expanded to $HOME, and that could point to either user's home directory, or /root, depending on how root was obtained.
  3. Given that this function basically runs an executable when someone connects a USB device, I'd rather have as little magic here as possible, and while I agree that ~ makes this function more ergonomic, I prefer not to implement it at this time.