1
0
dotfiles/.config/zsh/alias/idle.zsh

43 lines
703 B
Bash
Raw Normal View History

2021-03-21 18:25:10 +03:00
#!/bin/zsh
2021-12-07 02:46:50 +03:00
idle() {
2024-01-27 00:10:58 +03:00
[ -n "${1:?}" ] || return 1
2021-12-07 02:46:50 +03:00
local f
2022-07-19 02:41:45 +03:00
2021-12-07 02:46:50 +03:00
f=$(type "$1")
case "$f" in
2024-01-27 00:10:58 +03:00
"$1 is /"* )
z-idle-ext "$@"
;;
* )
z-idle-int "$@"
;;
2021-12-07 02:46:50 +03:00
esac
}
z-idle-ext() {
2024-01-27 00:10:58 +03:00
[ -n "${1:?}" ] || return 1
2021-03-21 18:25:10 +03:00
local -a s
2022-07-19 02:41:45 +03:00
2021-03-21 18:25:10 +03:00
s+=( $(z-alt-find 'nice -n +40') )
s+=( $(z-alt-find 'chrt -i 0' ) )
s+=( $(z-alt-find 'ionice -c 3') )
2021-12-07 02:46:50 +03:00
command ${s[@]} "$@"
}
z-idle-int() {
2024-01-27 00:10:58 +03:00
[ -n "${1:?}" ] || return 1
2021-12-07 02:46:50 +03:00
## execute in subshell
(
{
command renice -n +40 -p ${sysparams[pid]}
command chrt -i -p 0 ${sysparams[pid]}
command ionice -c 3 -p ${sysparams[pid]}
} </dev/null &>/dev/null
"$@"
)
2021-03-21 18:25:10 +03:00
}