-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash-console-runner-start
executable file
·84 lines (67 loc) · 1.52 KB
/
bash-console-runner-start
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/bash
SPAWN_TERMINAL_COMMAND="xterm -title \"$1\" -e"
CONF_PATH="$HOME/.config/bash-console-runner/"
CONF_TERMINAL="terminal-emulator.conf"
COMMAND_TO_RUN="$1"
# options
DISABLE_NOHUP=false
function help_text {
printf "\nMust feed one executable\n\n"
printf "Use: bash-console-runner-start \e[32m<executable>\e[0m\n"
}
function error {
printf "\e[31mERROR\e[0m: $1" >> /dev/stderr
help_text
return 1
}
function conf_detection {
# $1 command_name
if [ ! -d $CONF_PATH ]; then
mkdir $CONF_PATH
fi
if [ ! -f "$CONF_PATH$CONF_TERMINAL" ]; then
cp /etc/bash-console-runner/$CONF_TERMINAL $CONF_PATH
fi
while read CONF_LINE; do
if [ ${CONF_LINE:0:1} != "#" ]; then
break;
fi
done < "$CONF_PATH$CONF_TERMINAL"
if [ -n "$CONF_LINE" ]; then
SPAWN_TERMINAL_COMMAND=${CONF_LINE/"\$1"/$1}
fi
}
function toggle_option {
case $1 in
"-disable-nohup")
DISABLE_NOHUP=true
;;
*)
return 1
;;
esac
}
ARG_COUNT=1
for ARG in "$@"; do
if [ "${ARG:0:1}" = "-" ]; then
toggle_option $ARG
((ARG_COUNT++))
else
COMMAND_TO_RUN=$ARG
break;
fi
done
if [ $(($#-$ARG_COUNT)) -gt 0 ]; then
if command -v $COMMAND_TO_RUN > /dev/null; then
conf_detection $COMMAND_TO_RUN
if [ "$DISABLE_NOHUP" = true ]; then
$SPAWN_TERMINAL_COMMAND bash-console-runner ${@:ARG_COUNT}
else
nohup $SPAWN_TERMINAL_COMMAND bash-console-runner $* &>/dev/null &
fi
else
error "command \e[31m$COMMAND_TO_RUN\e[0m does not exist\e[0m\n"
fi
else
error "too few arguments: you input \e[31m$#\e[0m arguments\n"
fi