petobens / trueline

Fast and extensible bash powerline prompt with true color and fancy icon support
MIT License
385 stars 36 forks source link

bash: v: command not found #2

Closed Phate6660 closed 5 years ago

Phate6660 commented 5 years ago

Everything still works perfectly fine, however this error pops up whenever I open my terminal.

On the plus side, it only happens once. It's still pretty annoying to see it whenever I open my terminal though.

I took a quick look through the script, and couldn't find a mention of a program called 'v'. I also ran it through shellcheck and couldn't find any errors.

petobens commented 5 years ago

That's pretty weird. Can you post the full error? I'll try to reproduce it then.

Phate6660 commented 5 years ago

That is the full error, as long as I use the example settings you provided in the readme. When I use the default settings, I get this error:

bash: v: command not found
bash: [[: 0     0: syntax error in expression (error token is "0")
bash: [[: 0     0: syntax error in expression (error token is "0")
petobens commented 5 years ago

What's your bash version?

So you don't get the error with the example settings (in the readme) but do get the error with the default settings?

Phate6660 commented 5 years ago

My current bash version is 4.4.23(1)-release.

I get errors with both, I just get less errors with the example settings.

bash: v: command not found is in both, however the defaults give me these extra errors.

bash: [[: 0     0: syntax error in expression (error token is "0")
bash: [[: 0     0: syntax error in expression (error token is "0")
petobens commented 5 years ago

I've tried this with the following Dockerfile:

FROM bash:4.4.23
RUN apk update && apk add wget
RUN wget https://raw.githubusercontent.com/petobens/trueline/master/trueline.sh -P /

and I'm still unable to reproduce:

Screenshot_2019-06-19_13:30:46

Mmm can you try i) updating bash and see if the problem persists? and ii) share your .bashrc and .bash_profile files?

Phate6660 commented 5 years ago

I'll have to download updated source code for it then. I'm currently running Gentoo and this is the latest version they have for it in the repos.

Here is my .bashrc:

# /etc/skel/.bashrc
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output.  So make sure this doesn't display
# anything or bad things will happen !

# Test for an interactive shell.  There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
if [[ $- != *i* ]] ; then
    # Shell is non-interactive.  Be done now!
    return
fi

### Options for trueline
declare -A TRUELINE_COLORS=(
    [black]='36;39;46'
    [default]='36;39;46'
    [white]='208;208;208'
    [green]='152;195;121'
)

declare -a TRUELINE_SEGMENTS=(
    'user,black,white'
    'working_dir,white,black'
    'exit_status,black,white'
)

declare -A TRUELINE_SYMBOLS=(
    [segment_separator]=''
    [working_dir_folder]='...'
    [working_dir_separator]='/'
    [working_dir_home]='~'
)

TRUELINE_SHOW_VIMODE=false

_trueline_time_segment() {
    local prompt_time="\t"
    if [[ -n $prompt_time ]]; then
        local fg_color="$1"
        local bg_color="$2"
        local segment="$(_trueline_separator)"
        segment+="$(_trueline_content "$fg_color" "$bg_color" 1 " $prompt_time ")"
        PS1+="$segment"
        _last_color=$bg_color
    fi
}

### Autostart

# Enable mcfly, a history viewer/editor/executor written in Rust.
source ~/bin/mcfly.bash

# Enable completion.
source /etc/bash/bashrc.d/bash_completion.sh

# Alias thefuck to fuck.
eval $(thefuck --alias)

# Source trueline.
source ~/bin/trueline

### Environmental Variables

# General
# export PS1="[\W]->  "
export PATH="$HOME/.cargo/bin:$HOME/scripts:$HOME/bin:$HOME/.config/guix/current/bin:$PATH"
export EDITOR="nano"
export HISTCONTROL="$HISTCONTROL erasedups:ignoreboth"

# fff
export FFF_FAV1=/run/media/valley
export FFF_FAV2=/home/ff
export FFF_FAV3=~/downloads
export FFF_FAV4=~/downloads/github
export FFF_FAV5=~/projects
export FFF_FAV6=
export FFF_FAV7=
export FFF_FAV8=
export FFF_FAV9=

### Functions

wttr() {
    # change [REDACTED] to your default location
    local request="wttr.in/${1-[REDACTED]?u}"
    [ "$COLUMNS" -lt 125 ] && request+='?n'
    curl -H "Accept-Language: ${LANG%_*}" --compressed "$request"
}

hmm () {
    artists="$(echo "$(mpc list Artist | sed '/^\s*$/d' | wc -l) artists.")"
    albums="$(echo "$(mpc list Album | sed '/^\s*$/d' | wc -l) albums.")"
    songs="$(echo "$(mpc list Title | sed '/^\s*$/d' | wc -l) songs.")"
    size="$(echo Which uses up "$(du -hs ~/Music | cut -c 1-4)"B of storage.)"
    amount="$(echo "Also, you have played $(w3m -dump https://libre.fm/user/phate6660/stats | grep Total | sed "s/[^0-9]//g") complete songs.")"
    echo -e "\nYou have:\n---------\n$artists\n$albums\n$songs\n\n$size\n$amount\n"
}

f() {
    fff "$@"
    cd "$(cat "${XDG_CACHE_HOME:=${HOME}/.cache}/fff/.fff_d")"
}

title() { echo -e '\033]2;'$1'\007'; }

### Aliases

# General
alias ls="exa -lFha"
alias cat="bat"
alias fetch="rsfetch --no-wm-de -huMp portage"
alias mkdir='mkdir -pv'
alias myip="curl --silent https://ipecho.net/plain; echo"
alias ss="ss -ntlp"
alias du="diskus"

# Process-related.
alias ps="ps auxf"
alias psg="ps aux | grep -v grep | grep -i -e VSZ -e"
alias htop="htop -t"
alias vtop="htop -u valley"

# Mount music directories.
alias umus="sudo mount --bind '/run/media/valley/Music and Pics/Music' ~/Music/Music"
alias umus2="sudo mount --bind '/run/media/valley/music-2/Music' ~/Music/Music-2"
alias umus3="sudo mount --bind '/run/media/valley/Anime and Music/Music' ~/Music/Music-3"
alias umus4="sudo mount --bind '/run/media/valley/BD-Rips/Music' ~/Music/Music-4"

# Player, lyrics, and scrobbler log.
alias mus-rwb='ncmpcpp -c ~/.ncmpcpp/config-rwb'
alias lyrics='ncmpcpp -c ~/.ncmpcpp/config-lyrics'
alias scriblog='clear; tail -f ~/.mpdscribble/mpdscribble.log'

# YouTube
alias ytdl='youtube-dl'
alias yt="youtube-viewer"

# ProtonVPN
alias pvre="sudo pvpn -d; sudo pvpn -f; sudo pvpn --status; read -p 'Press [ENTER] to continue.'; speedtest --secure --no-upload"
alias pvstat="sudo pvpn --status"
alias speed="speedtest --secure --no-upload"

# Gentoo
alias merge="sudo emerge -atv"
alias searchfor="emerge --search"
alias rem="sudo emerge -av --depclean"
alias frem="sudo emerge -av --unmerge"
alias clean="sudo emerge -Da --depclean; sudo revdep-rebuild -i"

Here is my .bash_profile:

# /etc/skel/.bash_profile

# This file is sourced by bash for login shells.  The following line
# runs your .bashrc and is recommended by the bash info pages.
if [[ -f ~/.bashrc ]] ; then
    . ~/.bashrc
fi

The errors only appear when sourcing trueline.

petobens commented 5 years ago

Can you try the following:

  1. Commenting this two lines from your bashrc:
    
    # Enable mcfly, a history viewer/editor/executor written in Rust.
    # source ~/bin/mcfly.bash

Enable completion.

source /etc/bash/bashrc.d/bash_completion.sh


and see if the problem persists
2. Put a `echo "foo"` somewhere in the trueline file and then source it again until you can identify which is the problematic line (that would greatly help me to reproduce your error)
Phate6660 commented 5 years ago

Just commented those out, errors still present.

I'll work on identifying the line now.

Edit: I just found something interesting.

I appended "echo foo" to the last line of trueline like this:

PROMPT_COMMAND=_trueline_prompt_command && echo foo

And look where foo is output when opening a terminal.

bash: v: command not found
foo
bash: [[: 0     0: syntax error in expression (error token is "0")
bash: [[: 0     0: syntax error in expression (error token is "0")

Which means that the syntax errors happen after the end of the script?

Phate6660 commented 5 years ago

Also, I found out why the error bash: v: command not found appears. There's a "v" on line 316.

petobens commented 5 years ago

Apparently so. Can you:

  1. Run echo $P1 and echo $PROMPT_COMMAND and report the output
  2. Try running simply bash --rcfile ~/test_bashrc where test_bashrc only has the source truline.sh line? And see if the errors continue
petobens commented 5 years ago

Also, I found out why the error bash: v: command not found appears. There's a "v" on line 316.

Where exactly? I cannot see it here https://github.com/petobens/trueline/blob/1ad7a16284450f6178ad40ca387298fa8daab0c4/trueline.sh#L316

Phate6660 commented 5 years ago

Where exactly? I cannot see it here

I just looked through that too. For some reason mine had a "v", but yours doesn't. Which is really weird, considering that all I did was download the file and remove the extension.

Run echo $P1 and echo $PROMPT_COMMAND and report the output

P1:


bash: [[: 0     0: syntax error in expression (error token is "0")
bash: [[: 0     0: syntax error in expression (error token is "0")

PROMPT_COMMAND:

_trueline_prompt_command
bash: [[: 0     0: syntax error in expression (error token is "0")
bash: [[: 0     0: syntax error in expression (error token is "0")

Try running simply bash --rcfile ~/test_bashrc where test_bashrc only has the source truline.sh line? And see if the errors continue

bash: [[: 0     0: syntax error in expression (error token is "0")
bash: [[: 0     0: syntax error in expression (error token is "0")

The errors do continue.

petobens commented 5 years ago

I just looked through that too. For some reason mine had a "v", but yours doesn't. Which is really weird, considering that all I did was download the file and remove the extension.

So the v thing is sorted out now right?

P1

Sorry I meant echo $PS1

Phate6660 commented 5 years ago

So the v thing is sorted out now right?

Yep.

Sorry I meant echo $PS1

\[\033[38;2;36;39;46;48;2;208;208;208;1m\] valley \[\033[0m\]\[\033[38;2;208;208;208;48;2;59;64;72;1m\]\[\033[0m\]\[\033[38;2;171;178;191;48;2;59;64;72;2m\]  master \[\033[0m\]\[\033[38;2;224;108;117;48;2;59;64;72;2m\]✚ 12 \[\033[0m\]\[\033[38;2;198;120;221;48;2;59;64;72;2m\] 0 0  0 0 \[\033[0m\]\[\033[38;2;59;64;72;48;2;40;44;52;1m\]\[\033[0m\]\[\033[38;2;130;137;151;48;2;40;44;52;2m\] \[\033[1m\] \[\033[0m\]\[\033[38;2;40;44;52;48;2;36;39;46;1m\]\[\033[0m\]
bash: [[: 0     0: syntax error in expression (error token is "0")
bash: [[: 0     0: syntax error in expression (error token is "0")
petobens commented 5 years ago

Mmm; can you try removing the if conditions in lines 265 and 294 and see if the errors go away? I think it might be that...

Phate6660 commented 5 years ago

I still get the same errors, but now everything in the prompt turns invisible except for the actual text.

This is how the prompt looks (the "|" signifies location of cursor, it's not part of the prompt):

 valley    master  12  0        0  0    0  .   |
petobens commented 5 years ago

If you run the following foo.sh file with bash foo.sh:

if [[ "${#TRUELINE_COLORS[@]}" -eq 0 ]]; then
    declare -A TRUELINE_COLORS=(
        [black]='36;39;46'
    )
fi
echo "${TRUELINE_COLORS[@]}"

do you still get errors? If you do, then try running bar.sh:

declare -A TRUELINE_COLORS=(
    [black]='36;39;46'
)
echo "${TRUELINE_COLORS[@]}"
Phate6660 commented 5 years ago

foo.sh:

36;39;46
bash: [[: 0     0: syntax error in expression (error token is "0")
bash: [[: 0     0: syntax error in expression (error token is "0")

bar.sh

36;39;46
bash: [[: 0     0: syntax error in expression (error token is "0")
bash: [[: 0     0: syntax error in expression (error token is "0")
petobens commented 5 years ago

So even when running bash foo.sh where foo only has a line echo "foo" you get this error? That's strange and I don't see clearly how it's releated to trueline...

Phate6660 commented 5 years ago

So even when running bash foo.sh where foo only has a line echo "foo" you get this error?

I thought you said to put:

if [[ "${#TRUELINE_COLORS[@]}" -eq 0 ]]; then
    declare -A TRUELINE_COLORS=(
        [black]='36;39;46'
    )
fi
echo "${TRUELINE_COLORS[@]}"

in foo.sh?

That's strange and I don't see clearly how it's releated to trueline...

This only happens when trueline is sourced.

petobens commented 5 years ago

This only happens when trueline is sourced.

Can you try to bisect the problem yourself since I cannot reproduce it? I.e

  1. only use a .bashrc with the source trueline.sh line and start bash with bash --rcfile path_to_that_minimial_bashrc.
  2. Try next commenting/deleting functions in the trueline.sh file and see if the error still pops out (i.e by resourcing the file or by opening a new bash shell)
Phate6660 commented 5 years ago

only use a .bashrc with the source trueline.sh line and start bash with bash --rcfile path_to_that_minimial_bashrc.

I've already done that.

Try next commenting/deleting functions in the trueline.sh file and see if the error still pops out (i.e by resourcing the file or by opening a new bash shell)

I'll work on doing that.

petobens commented 5 years ago

Since the original issue (in the title) is now fixed I'm going to close this one now to keep the issue tracker ordered. If you find a consistent way to reproduce your second problem please open a new issue. Thanks!