So I routinely push applications to background and switch among them. I realized that fg doesn't have a tab complete defined.
So I thought I can put together a tab complete for fg quickly with the suggestions coming from the jobs command. I didn't check if something like this exists online already, cause this seemed like a fun project to build. Here's my code so far:
job(){
readarray COMPREPLY < <(jobs -l)
for i in "${!COMPREPLY[@]}"; do
printf -v pad %*s -$COLUMNS "${COMPREPLY[i]}"
COMPREPLY[i]="%"${pad//[][]}
done
}
The problem is that at the end of each suggestion there's a stray linefeed character(^j) showing up eg:
%1 53967 Stopped vim^J
%2 54257 Stopped python^J
%3 54499 Stopped (signal) nano^J
%4- 42270 Stopped vim ~/.bashrc^J
%5+ 47434 Stopped vim ~/.bashrc^J
readarray
toreadarray -t
. – Aug 12 '18 at 06:24