info-taskspooler: add script

master
Shane Donohoe 2019-05-02 12:22:01 +01:00 committed by x70b1
parent a65cbbcee6
commit 309b154233
2 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,39 @@
# Script: info-taskspooler
Show queued/running count for one or more task spooler servers.
![info-taskspooler](screenshots/1.png)
## Dependencies
- `task-spooler`
## Configuration
No arguments required, by default the script will output the count of the default task-spooler server.
If desired, arguments can be passed to show custom task-spooler servers by using the TS_SOCKET variable. These custom servers will need to use a socket filename format like /tmp/ts-socket.SOCK_NAME or the script will be unable to find the server. Arguments are passed as name,sock_name with sock_name being optional, e.g. `default yt,youtube p,podcast`.
## Module
```ini
[module/{ name }]
type = custom/script
exec = ~/polybar-scripts/info-task-spooler/info-task-spooler.sh
format-prefix = "tsp "
interval = 5
...
```
or
```ini
[module/{ name }]
type = custom/script
exec = ~/polybar-scripts/info-task-spooler/info-task-spooler.sh default yt,youtube p,podcast
interval = 5
...
```

View File

@ -0,0 +1,27 @@
#!/usr/bin/env sh
# USAGE:
# No arguments: prints the job running/queued job count of the default tsp server
# Arguments: name,sock_name - one or more arguments, e.g. tsp yt,youtube p,podcasts
# sock_name is optional, will default to default tsp socket
# custom socket names will be generated as /tmp/ts-socket.SOCK_NAME, your TS_SOCKET will need to match
get_tsp_count() {
sock=/tmp/socket-ts.${1:-$(id -u)}
tsp_count=$(TS_SOCKET=$sock tsp|grep -E -c 'running|queued')
echo "${tsp_count:-0}"
}
# without argument, just show count of default socket
if [ $# -lt 1 ]; then
get_tsp_count
else
for t in "$@"; do
IFS=, read -r name sock_name <<- EOF
${t}
EOF
echo "${name} $(get_tsp_count "${sock_name}")"
done|sed 'N;s/\n/ /'
fi