Skip to content
Create a gist now

Instantly share code, notes, and snippets.

shell function for choosing from vi(m) background jobs the preferred job or start a new vim process
function vi() {
local job_id
job_id=$(jobs|sed -rn "s/\[([0-9])\] *([-+]?) *([Ss]topped|[Ss]uspended).*vim?.*/\1 \2/p"|awk "{if(\$2==\"+\"){id=\$1;exit}else if(\$2==\"-\"){id=\$1;m=\$2}else if(m!=\"-\"){id=\$1}}END{print id}")
if [ ${job_id} ]; then
fg %${job_id}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.