Add parameters to every function and make the handling more generic
This commit is contained in:
parent
a0f2b61734
commit
6a0e2fd7d1
1 changed files with 32 additions and 23 deletions
55
ts-control
55
ts-control
|
@ -10,15 +10,8 @@ back
|
||||||
message
|
message
|
||||||
message-user"
|
message-user"
|
||||||
|
|
||||||
action="$1"
|
|
||||||
if [ -n "$1" ]; then
|
|
||||||
shift
|
|
||||||
else
|
|
||||||
action=$(echo "$actions" | $DMENU)
|
|
||||||
fi
|
|
||||||
|
|
||||||
_ts_control_get_entity() {
|
_ts_control_get_entity() {
|
||||||
entity=$(teamspeak-query-lib "$1s" | $DMENU)
|
entity=$(_ts_control_single_or_dmenu "$(teamspeak-query-lib "$1s")" "$2")
|
||||||
if [ -z "$entity" ]; then
|
if [ -z "$entity" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -26,39 +19,59 @@ _ts_control_get_entity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_ts_control_get_message() {
|
_ts_control_get_message() {
|
||||||
message=$(printf "\n" | $DMENU -p "message")
|
if [ -n "$1" ];
|
||||||
|
then
|
||||||
|
message="$1"
|
||||||
|
else
|
||||||
|
message=$(printf "\n" | $DMENU -p "message")
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$message" ]; then
|
if [ -z "$message" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$message"
|
echo "$message"
|
||||||
}
|
}
|
||||||
|
|
||||||
_ts_control_move_self() {
|
_ts_control_move_self() {
|
||||||
channel=$(_ts_control_get_entity channel)
|
channel=$(_ts_control_get_entity channel "$1" "$2")
|
||||||
teamspeak-query-lib move --strict-channel "$channel"
|
teamspeak-query-lib move --strict-channel "$channel"
|
||||||
}
|
}
|
||||||
|
|
||||||
_ts_control_fetch() {
|
_ts_control_fetch() {
|
||||||
target=$(_ts_control_get_entity "$1")
|
target=$(_ts_control_get_entity "$1" "$2")
|
||||||
teamspeak-query-lib fetch "--strict-$1" "--$1" "$target"
|
teamspeak-query-lib fetch "--strict-$1" "--$1" "$target"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ts_control_single_or_dmenu() {
|
||||||
|
options=$(echo "$1" | grep "$2")
|
||||||
|
count=$(echo "$options" | wc -l)
|
||||||
|
if [ "$count" -eq 1 ]; then
|
||||||
|
echo "$options"
|
||||||
|
else
|
||||||
|
echo "$options" | $DMENU
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add '$' to $1 to add 'End of line' to the regex for grep
|
||||||
|
action=$(_ts_control_single_or_dmenu "$actions" "$1$")
|
||||||
|
|
||||||
case $action in
|
case $action in
|
||||||
"quick")
|
"quick")
|
||||||
action=$($DMENU < "$XDG_CONFIG_HOME/ts-control-quick")
|
action=$($DMENU < "$XDG_CONFIG_HOME/ts-control-quick")
|
||||||
if [ -z "$action" ]; then
|
if [ -z "$action" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
eval "teamspeak-query-lib $action"
|
eval "$0 $action"
|
||||||
;;
|
;;
|
||||||
"move")
|
"move")
|
||||||
_ts_control_move_self
|
_ts_control_move_self "$2"
|
||||||
;;
|
;;
|
||||||
"fetch-client")
|
"fetch-client")
|
||||||
_ts_control_fetch client
|
_ts_control_fetch client "$2"
|
||||||
;;
|
;;
|
||||||
"fetch-channel")
|
"fetch-channel")
|
||||||
_ts_control_fetch channel
|
_ts_control_fetch channel "$2"
|
||||||
;;
|
;;
|
||||||
"not away")
|
"not away")
|
||||||
teamspeak-query-lib move "Not Away From Keyboard"
|
teamspeak-query-lib move "Not Away From Keyboard"
|
||||||
|
@ -72,20 +85,16 @@ case $action in
|
||||||
;;
|
;;
|
||||||
"back")
|
"back")
|
||||||
teamspeak-query-lib update --back
|
teamspeak-query-lib update --back
|
||||||
if [ -n "$1" ]; then
|
_ts_control_move_self "$2"
|
||||||
teamspeak-query-lib move "$1"
|
|
||||||
else
|
|
||||||
_ts_control_move_self "$1"
|
|
||||||
fi
|
|
||||||
teamspeak-query-lib update --microphone=true --speakers=true
|
teamspeak-query-lib update --microphone=true --speakers=true
|
||||||
;;
|
;;
|
||||||
"message")
|
"message")
|
||||||
message=$(_ts_control_get_message)
|
message=$(_ts_control_get_message "$2")
|
||||||
teamspeak-query-lib message "$message"
|
teamspeak-query-lib message "$message"
|
||||||
;;
|
;;
|
||||||
"message-user")
|
"message-user")
|
||||||
message=$(_ts_control_get_message)
|
user=$(_ts_control_get_entity client "$2")
|
||||||
user=$(_ts_control_get_entity client)
|
message=$(_ts_control_get_message "$3")
|
||||||
teamspeak-query-lib message --strict-client --client "$user" "$message"
|
teamspeak-query-lib message --strict-client --client "$user" "$message"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in a new issue