还原集成的终端会话,其中最后一个工作目录在git bash上

发布于 2025-01-20 12:42:12 字数 694 浏览 0 评论 0原文

通常当我们退出终端并重新打开它时,它会恢复我们的终端和选项卡,这是一个很好的功能,但是它也可以恢复我们最后的cwd吗?我认为应该可以,但我无法让它在我的终端上运行。

会话不保存我最后的工作目录 输入图片描述这里

它说会话内容恢复

之前的目录是.../shop/shop-next,但恢复后只是。 ../shop

我希望它是相同的与之前一样 (.../shop/shop-next) 恢复后

相关设置为:

在此处输入图像描述在设置“持久会话恢复过程”时,它说它应该恢复CWD 取决于它是否受支持终端

我不知道 git bash 是否支持此功能,所以这是我的问题:

  1. 有没有办法完成它?(不使用扩展
  2. 什么终端/配置文件/bash 支持此功能。

usually when we exit the terminal and re open it, it will restore our terminal and tabs, its good a feature, but can it restore our last cwd too? i think it supposed to, but i cant get it working on my terminal.

the session doesnt save my last working directory
enter image description here

it said session contents restored

the directory before that is .../shop/shop-next, but after restored its just .../shop

i want it to be the same as before (.../shop/shop-next) after restored

the setting related is :

enter image description hereon setting "persistent session revive process", it said that it supposed to restore the CWD depends on whether it supported by the terminal

i dont know if git bash is support this feature, so here is my question:

  1. is there a way to get it done?(without using extension)
  2. what terminal/profile/bash support this feature.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心的位置 2025-01-27 12:42:12

(对不起,当您使用标签时,这可能对您不起作用,但可能会带给您一些想法。)

我使用了一些技巧,我正在将更改目录的路径写入文件,并且在会话负载上使用了此保存的路径。

因此,如果我们谈论Windows(或类似于Mingw64)或 *Nix Systems的Git Bash,我在.bashrc文件中使用了此代码:

# == Use changed/default directory on load ==

# Remember changed directory
DEFAULT_DIR=~
cd() { builtin cd ${@} && keep_last_dir; }
keep_last_dir() { pwd > ~/.bashrc.last_dir; }

if [ -z "${BASHRC_INIT}" ]; then
  export BASHRC_INIT=1
  readonly BASHRC_INIT
  change_dir=${DEFAULT_DIR}
  if [[ ${HOME} != $(pwd) ]] && [[ -f ~/.bashrc.last_dir ]]; then
    change_dir=$(cat ~/.bashrc.last_dir)
  fi
  # go to default/prev directory
  [ -d ${change_dir} ] && cd ${change_dir}
fi
# == == == == == == == == == == == == == == ==

您可以更改此行:default_dir =〜

in First on打开它总是会将您返回到最后一个目录位置。

(Sorry, this might not work for you, as you use tabs, but probably would bring you some ideas to improve.)

I used some trick, I was writing path of changed directory into a file, and used this saved path on session load.

So, if we are talking about Git Bash for Windows (or any similar to MINGW64) or *nix systems, I used this code in .bashrc file:

# == Use changed/default directory on load ==

# Remember changed directory
DEFAULT_DIR=~
cd() { builtin cd ${@} && keep_last_dir; }
keep_last_dir() { pwd > ~/.bashrc.last_dir; }

if [ -z "${BASHRC_INIT}" ]; then
  export BASHRC_INIT=1
  readonly BASHRC_INIT
  change_dir=${DEFAULT_DIR}
  if [[ ${HOME} != $(pwd) ]] && [[ -f ~/.bashrc.last_dir ]]; then
    change_dir=$(cat ~/.bashrc.last_dir)
  fi
  # go to default/prev directory
  [ -d ${change_dir} ] && cd ${change_dir}
fi
# == == == == == == == == == == == == == == ==

You may change this line: DEFAULT_DIR=~

On first open it always would return you to last directory location.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文