summaryrefslogtreecommitdiff
path: root/sway-smart-spawn-foot.sh
blob: 3f84ea3f233357dd0aeb7eae42a20d0e797285ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/sh
appid=$(swaymsg -t get_tree | jq -r 'recurse(.nodes[],.floating_nodes[]) |
  select(.focused).app_id')
printf "appid = %s\n" "$appid" >> /tmp/smart-foot-spawn.log
dir=""
case "$appid" in
  foot)
    cwd="$(swaymsg -t get_tree |
      jq -r 'recurse(.nodes[],.floating_nodes[])|select(.focused).name')"
    printf "cwd = %s\n" "$cwd" >> /tmp/smart-foot-spawn.log
    case "$cwd" in
      ""|*@*:*)
        dir=$HOME ;;
      *sfeed*|foot|pulsemixer)
        dir=/dev/shm ;;
      *)
        dir="$cwd" ;;
    esac
    ;;
  ncmpc)
    dir=/media/storage/sound
    ;;
  *) # appid = null when starting from empty desktop
    dir=$HOME
    ;;
esac
[ -d "$dir" ] || dir=$HOME
exec foot -d none -D "$dir"