我正在弄乱我的 bash 设置,我决定将其移至版本控制,我做了一些更改,并将.bashrc
和.bash_profile
移至我的 dotfiles 存储库。这似乎导致了一个相当不寻常的错误,似乎我的源文件正在运行,但视觉变化仅在输入某些内容后才适用,例如
这是在打开终端后
如果我输入任何内容,它就会按预期工作
我的bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return ;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
我的.bash_profile
source ~/.bashrc
if [ -e ~/.bash_aliases ]; then
source ~/.bash_aliases >/dev/null 2>&1
fi
大部分逻辑都在.bash_aliases
# Enable for debugging purposes, it logs every command ran in the terminal
# set -x
unalias -a
set -o vi
echo "Welcome to $(hostname)!"
# The theme we'll be using
. $HOME/.bash_theme
# Set up GOPATH and GIT_EDITOR
export CLUTTER_BACKEND=wayland
export XDG_SESSION_TYPE=wayland
export QT_QPA_PLATFORM=wayland-egl
export QT_WAYLAND_FORCE_DPI=physical
export QT_WAYLAND_DISABLE_WINDOWDECORATION=1
export XDG_CURRENT_DESKTOP=sway
export XDG_SESSION_DESKTOP=sway
export SDL_VIDEODRIVER=wayland
export _JAVA_AWT_WM_NONREPARENTING=1
export MOZ_ENABLE_WAYLAND=1
export MOZ_WEBRENDER=1
# Set up PATH
export PATH="$HOME/.amplify/bin:$PATH"
export PATH=/usr/local/bin:$PATH
export PATH=$HOME/.local/.npm-global/bin:$HOME/.local/bin:$HOME/.local/n/bin/:$HOME/.local/go/bin:$HOME/go/bin:$HOME/bin:$HOME/bin:$HOME/scripts:$PATH
export PATH=$PATH:$HOME/scripts
export PATH="/usr/local/bin:$PATH"
export GOPATH="$HOME/go"
PATH="$GOPATH/bin:$PATH"
. "$HOME/.cargo/env"
bind 'set show-mode-in-prompt on'
bind 'set vi-ins-mode-string "\1\e[1;32m\2+\1\e[0m\2 "'
bind 'set vi-cmd-mode-string "\1\e[1;32m\2:\1\e[0m\2 "'
# Set NVM_DIR and source the nvm and bash_completion scripts
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# Set up XDG_CONFIG_HOME and VIM
export XDG_CONFIG_HOME=$HOME/.config
# Source personal environment and files
PERSONAL=$XDG_CONFIG_HOME/personal/bash
for i in $(find -L $PERSONAL -type f); do
. $i
done
COMMON=$XDG_CONFIG_HOME/common
for i in $(find -L $COMMON -type f); do
. $i
done
# Set VISUAL and EDITOR
export EDITOR="nvim"
export GIT_EDITOR=$EDITOR
export menu="albert"
export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig/
bind 'set bell-style none'
# Temp fix for atuin https://github.com/atuinsh/atuin/issues/1012
eval "$(atuin init bash --disable-up-arrow)"
_atuin_fix_echo() {
stty echo
stty sane
}
if [[ -n "${BLE_VERSION-}" ]]; then
blehook PRECMD-+=_atuin_fix_echo
else
precmd_functions+=(_atuin_fix_echo)
fi
# end atuin
if [[ -f ~/.ssh/id_ed25519.github ]]; then
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_ed25519.github
fi
# Have to install bash-preexec as well
[[ -e ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh
source ~/.config/broot/launcher/bash/br
source ~/.config/wezterm/wezterm.sh
eval "$(zoxide init bash)"
eval "$(starship init bash)"
[[ -e ~/.config/personal/bash/alias_personal ]] && \. ~/.config/personal/bash/alias_personal
[ "$(tty)" = "/dev/tty1" ] && exec sway
我经常通过 SSH 进入我的机器,所以这是我采用的设置,我很确定它远非最佳实践,但在我今天所做的更改之前,它运行得相对良好。不幸的是,我没有对 bashrc 和配置文件进行版本控制,所以我不知道到底是什么导致了这个问题。我目前的知识并不能让我知道罪魁祸首是什么,这太奇怪了。
我在 Ubuntu 22.04,Wayland 上,确切的点文件可以是找到这里。 我在用starship.rs
作为我的提示。昨天一切都运行良好,在我进行更改之前,(更改很少,我认为我没有添加任何内容,只是删除了一些评论,我肯定删除了一些我认为不重要的东西)
如果我在不移除输出的情况下获取来源,例如
if [ -e ~/.bash_aliases ]; then
source ~/.bash_aliases #>/dev/null 2>&1
fi
我得到以下输出
Welcome to nikola-B450M-DS3H!
它来自初始化我的提示和所有内容的文件,这意味着它的来源正确,但由于某种原因,它没有在终端的初始打开时应用。奇怪的是,如果我在末尾添加reset
或以期解决问题,它仍然会存在,但如果我手动输入 clear 或 reset,它就会起作用。所以我完全迷茫了clear
.bash_profile