Estoy en Arch Linux, y cuando abro una nueva pestaña de terminal, siempre va a $HOME. ¿Cómo puedo hacer que cuando abra una nueva pestaña, abra el shell en el directorio en el que estaba anteriormente?
Estoy en Arch Linux, y cuando abro una nueva pestaña de terminal, siempre va a $HOME. ¿Cómo puedo hacer que cuando abra una nueva pestaña, abra el shell en el directorio en el que estaba anteriormente?
Respuestas:
Hay un error relacionado con este problema
Todo lo que necesita hacer es agregar la siguiente línea a su .bashrco .zshrc:
. /etc/profile.d/vte.sh
Al menos en Arch, el script comprueba si está ejecutando bash o zsh y se cierra si no lo está.
/etc/profile.d/vte.shanula la PROMPT_COMMANDvariable. Para solucionar este problema, puede modificar vte.shy cambiar la pieza con PROMPT_COMMAND="__vte_prompt_command"aPROMPT_COMMAND="${PROMPT_COMMAND};__vte_prompt_command"
.zshrc. Estoy usando oh-my-zsh, no estoy seguro de si eso está relacionado.
También podría publicar esta solución hacky de superusuario:
[Esto] guarda la carpeta actual en un archivo, después de cada comando (no daña demasiado la OMI) y abre un nuevo terminal en la carpeta actual guardada.
agregue lo siguiente a .zshrc [o .bashrc ]
# emulate bash PROMPT_COMMAND (only for zsh)
precmd() { eval "$PROMPT_COMMAND" }
# open new terminal in same dir
PROMPT_COMMAND='pwd > "${HOME}/.cwd"'
[[ -f "${HOME}/.cwd" ]] && cd "$(< ${HOME}/.cwd)"
Tenga en cuenta que esto también lo colocará en su último directorio utilizado al abrir una nueva ventana .
@swalog me inspiró en su comentario para eliminar todas las partes innecesarias vte.shsin modificar la solicitud ni el título del terminal. Tenga en cuenta que no uso zsh, por lo tanto, zsheliminé el código relacionado.
# Copyright © 2006 Shaun McCance <shaunm@gnome.org>
# Copyright © 2013 Peter De Wachter <pdewacht@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# 28 Sep 2019: Tukusej’s Sirs modified this by stripping down all unnecessary parts for his usage
# (src: https://unix.stackexchange.com/questions/93476/gnome-terminal-keep-track-of-directory-in-new-tab#comment219157_93477)
# Not an interactive shell?
[[ $- == *i* ]] || return 0
# Not running under vte?
[ "${VTE_VERSION:-0}" -ge 3405 ] || return 0
__vte_urlencode() (
# This is important to make sure string manipulation is handled
# byte-by-byte.
LC_ALL=C
str="$1"
while [ -n "$str" ]; do
safe="${str%%[!a-zA-Z0-9/:_\.\-\!\'\(\)~]*}"
printf "%s" "$safe"
str="${str#"$safe"}"
if [ -n "$str" ]; then
printf "%%%02X" "'$str"
str="${str#?}"
fi
done
)
__vte_prompt_command() {
local command=$(HISTTIMEFORMAT= history 1 | sed 's/^ *[0-9]\+ *//')
command="${command//;/ }"
local pwd='~'
printf "\033]7;file://%s%s\007" "${HOSTNAME:-}" "$(__vte_urlencode "${PWD}")"
}
case "$TERM" in
xterm*|vte*)
[ -n "$BASH_VERSION" ] && PROMPT_COMMAND="${PROMPT_COMMAND};__vte_prompt_command"
;;
esac
export PROMPT_COMMAND=..., si tal cosa ya existe en su.bashrc.