dots

my dotfiles
git clone https://git.awy.one/dots
Log | Files | Refs | Submodules | README | LICENSE

singboxwrap (845B) - View raw


 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
29
30
31
32
33
34
#!/bin/sh

config_dir="/mnt/ssd/settings/sing-box"
default_path="${XDG_DATA_HOME:-$HOME/.local/share}/singboxcfg"

input=$1

run_singbox() {
  [ -z "${1}" ] && exit
  sing-box check -c "$1" && {
    pidof sing-box >/dev/null && killall sing-box
    setsid -f sing-box -c "$1" run
    if [ "$input" = menu ]; then
      notify-send "sing-box with $(readlink "$1") is running now"
    fi
  } || notify-send "Config check has failed. Check your configuration at $(readlink "$1")" &
  exit 1
}

choose_menu() {
  choose="$(fd --format="{/}" . $config_dir -d 1 -t f | mew -c -l 10 -p "sing-box cfg: ")"
  [ -z "${choose}" ] && exit
  ln -sf "$config_dir/$choose" "$default_path"
  echo "$default_path"
}

if [ ! -f "$default_path" ]; then
  input="menu"
fi

case $input in
menu) run_singbox "$(choose_menu)" ;;
*) run_singbox "$default_path" ;;
esac