Last active
January 21, 2022 09:49
-
-
Save ichizok/8d2883119428857b110f3dbb13a3b291 to your computer and use it in GitHub Desktop.
fill pid for given command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| if [[ $# -eq 0 ]]; then | |
| args=(echo {}) | |
| else | |
| args=("$@") | |
| fi | |
| filter=(${FILLPID_FILTER:-fzf}) | |
| if ! type "${filter[0]}" &>/dev/null; then | |
| echo >&2 "You need set a filter command to \"FILLPID_FILTER\"." | |
| exit 1 | |
| fi | |
| read pid _ < <(ps -o pid= -o tty= -o args= -U"${USER}" | "${filter[@]}") | |
| [[ ${pid} ]] || exit 1 | |
| exec "${args[@]//\{\}/${pid}}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment