S
S
Sergo Zar2022-03-26 19:36:37
bash
Sergo Zar, 2022-03-26 19:36:37

Two problems with .bashrc?

I tried to customize .bashrc but after that two problems appeared:

1. When you return one of the previous commands with the arrows or through ctrl + p, you cannot move the cursor to the left of more than a few characters (in the case of a video, you cannot go to the left of "pacman -Sy"), and if you execute this command, then only the part to the right of these characters will be executed.
2. If you try to erase some characters, the command will be duplicated up, as shown in the video.

How to fix it?

(everything that I changed / added below the comments "colors" and "what I changed")

.bashrc
#
# ~/.bashrc
#

 && return

colors() {
  local fgc bgc seq0 vals

  printf "Color escapes are %s\n" '\e[${value};...;${value}m'
  printf "Values 30..37 are \e[33mforeground colors\e[m\n"
  printf "Values 40..47 are \e[43mbackground colors\e[m\n"
  printf "Value  1 gives a  \e[1mbold-faced look\e[m\n\n"

  # foreground colors
  for fgc in {30..37}; do
    # background colors
    for bgc in {40..47}; do
      fgc=${fgc#37} # white
      bgc=${bgc#40} # black

      vals="${fgc:+$fgc;}${bgc}"
      vals=${vals%%;}

      seq0="${vals:+\e[${vals}m}"
      printf "  %-9s" "${seq0:-(default)}"
      printf " ${seq0}TEXT\e[m"
      printf " \e[${vals:+${vals+$vals;}}1mBOLD\e[m"
    done
    echo; echo
  done
}

[ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion

# Change the window title of X terminals
case ${TERM} in
  xterm*|rxvt*|Eterm*|aterm|kterm|gnome*|interix|konsole*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\007"'
    ;;
  screen*)
    PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\033\\"'
    ;;
esac

use_color=true

# Set colorful PS1 only on colorful terminals.
# dircolors --print-database uses its own built-in database
# instead of using /etc/DIR_COLORS.  Try to use the external file
# first to take advantage of user additions.  Use internal bash
# globbing instead of external grep binary.
safe_term=${TERM//[^[:alnum:]]/?}   # sanitize TERM
match_lhs=""
 && match_lhs="${match_lhs}$(<~/.dir_colors)"
 && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
 \
  && type -P dircolors >/dev/null \
  && match_lhs=$(dircolors --print-database)
 && use_color=true


# цвета
cls="\033[00m" 
f_2="\[\033[38;5;10m\]" # green bg
b_2="\[\033[48;5;10m\]" # green fg
f_1="\[\033[38;5;0m\]" # black bg
b_1="\[\033[48;5;0m\]" # black fg
text1="\[\033[38;5;14m\]" # cyan
text2="\[\033[38;5;210m\]" # orange
text3="\[\033[38;5;13m\]" # purple 1
text4="\[\033[38;5;3m\]" # purple 2
text5="\[\033[38;5;11m\]" # yellow
text6="\[\033[38;5;6m\]" # blue light

if ${use_color} ; then
  # Enable colors for ls, etc.  Prefer ~/.dir_colors #64489
  if type -P dircolors >/dev/null ; then
    if  ; then
      eval $(dircolors -b ~/.dir_colors)
    elif  ; then
      eval $(dircolors -b /etc/DIR_COLORS)
    fi
  fi 

  if  ; then
    PS1='\[\033[01;31m\][\h\[\033[01;36m\] \W\[\033[01;31m\]]\$\[\033[00m\] \a\d \t\n  '
  else
    # PS1='\[\033[01;32m\][\[email protected]\h\[\033[01;37m\] \W\[\033[01;32m\]]\$\[\033[00m\] \a\d \t\n  '
    # то что менял
    PS1="$b_2 $b_1$f_2$cls$text1$b_1\w $cls$f_1$cls\n$b_2 $b_1$f_2$cls$b_1$text2\$$cls$b_1$text3$back1 \u$text4\H$text5\d$text6\t  $cls$f_1$cls\n$b_2 $b_1$f_2$cls$f_1$cls "
  fi

  alias ls='ls --color=auto'
  alias grep='grep --colour=auto'
  alias egrep='egrep --colour=auto'
  alias fgrep='fgrep --colour=auto'
else
  if  ; then
    # show [email protected] when we don't have colors
    PS1='\[email protected]\h \W \$ '
  else
    PS1='\[email protected]\h \w \$ '
  fi
fi

unset use_color safe_term match_lhs sh

#alias cp="cp -i"                          # confirm before overwriting something
#alias df='df -h'                          # human-readable sizes
#alias free='free -m'                      # show sizes in MB
#alias np='nano -w PKGBUILD'
#alias more=less

####my alias
alias p3=python3
alias c=clear
#pacman 
alias pacS='sudo pacman -Ss'
alias pacI='sudo pacman -Sv'
#yay
alias yayS='yay -Ss'
alias yayI='yay -Sv'



xhost +local:root > /dev/null 2>&1

# Bash won't get SIGWINCH if another process is in the foreground.
# Enable checkwinsize so that bash will check the terminal size when
# it regains control.  #65623
# http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
shopt -s checkwinsize

shopt -s expand_aliases

# export QT_SELECT=4

# Enable history appending instead of overwriting.  #139609
shopt -s histappend
#######

#shopt -s cdspell
PROMPT_COMMAND='history -a'
export HISTCONTROL="ignoredups"

#######
# # ex - archive extractor
# # usage: ex <file>
ex ()
{
  if [ -f $1 ] ; then
    case $1 in
      *.tar.bz2)   tar xjf $1   ;;
      *.tar.gz)    tar xzf $1   ;;
      *.bz2)       bunzip2 $1   ;;
      *.rar)       unrar x $1     ;;
      *.gz)        gunzip $1    ;;
      *.tar)       tar xf $1    ;;
      *.tbz2)      tar xjf $1   ;;
      *.tgz)       tar xzf $1   ;;
      *.zip)       unzip $1     ;;
      *.Z)         uncompress $1;;
      *.7z)        7z x $1      ;;
      *)           echo "'$1' cannot be extracted via ex()" ;;
    esac
  else
    echo "'$1' is not a valid file"
  fi
}

Recording what the problem looks like https://youtu.be/6_1dYmVWMlo

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2022-03-26
@Sergomen

usual recommendation. do not do a lot of things at once, but try to customize several lines,
roll back the config to the default one and add a few lines or change something one by one. see what happens.
at some step the problem will reappear and it will be clear what's what.
this is a universal answer, I can’t give a specific answer here, but this method will be more useful than just pointing to the line where the problem is

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question