Say I open ~/vim.txt, push that to background, then cd to another path. When I bring that job to foreground, is there an option to switch back to old path? I noticed it says pwd, so I assume it is possible.
Switch back to path when resume job from background
bash;zsh;directory;background process;cd command
This is possible in zsh, and in fact it's easy thanks to the direct access to the job parameters provided by the zsh/parameter module. You can use a job number or any job specification (%+, %-, %foo, etc.) as a subscript in the array.zmodload zsh/parameterfgcd () {  local dir=$jobdirs[${1:-%+}]  # If the jobspec matched, then call cd. Otherwise it's probably a bad  # job spec, but call fg anyway to get the usual error message.  if [[ -n $dir ]]; then cd $dir; fi  fg $1}Bash also keeps track of the information, but I don't think it's exposed. On some systems, you can obtain the current working directory of the job's process, and switch to it. For example, on Linux, /proc/$pid/cwd is a symbolic link to that process's working directory.fgcd () { # Linux only  local pid=$(jobs -p $1)  if [[ -n $pid ]]; then cd /proc/$pid/cwd; fi  fg $1}Since it can also be useful, here's a zsh version. Unlike the function above, which switches to the job's original directory, this one switches to the current working directory of the job's process leader.fgcd () { # Linux only  local pid=${${${jobstates[${1:-%+}]}#*:*:}%\=*}  if [[ -n $pid ]]; then cd /proc/$pid/cwd; fi  fg $1}