Skip to content

Instantly share code, notes, and snippets.

@ichizok
Last active January 21, 2022 09:49
Show Gist options
  • Select an option

  • Save ichizok/8d2883119428857b110f3dbb13a3b291 to your computer and use it in GitHub Desktop.

Select an option

Save ichizok/8d2883119428857b110f3dbb13a3b291 to your computer and use it in GitHub Desktop.
fill pid for given command
#!/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