List only hidden files, not use . option

Hi

I have a prompt like this:

PS1='\[\e[1;33m\]\u@\h \[\e[1;34m\]\w $(es=$?; [[ $es -ne 0 ]] && echo "\[\e[1;31m\]" || echo "\[\e[1;32m\]")[$(ls | wc -l):$(($(ls -ad .* | wc -l)-2))]\$\[\e[0m\]'

It works like it should, but have a bug.

Problem is the counting of hidden files

$(($(ls -ad .* | wc -l)-2))
echo $(($(ls -ad .* | wc -l)-2))

The . seems to create the problem when I cut and past to the screen.
It works correct, but gives extra/wrong character displayed on my screen.

Simple test
echo $PS1 in my home folder gives:

\[\e[1;33m\]\u@\h \[\e[1;34m\]\w $(es=$?; [[ $es -ne 0 ]] && echo "\[\e[1;31m\]" || echo "\[\e[1;32m\]")[$(ls | wc -l):$(($(ls -ad . .. .aptitude .bash_history .bashrc .cache .nano_history .ncftp .profile .selected_editor .ssh .subversion | wc -l)-2))]\$\[\e[0m\]

The extra is in red

Is there another way to get correct hidden files, that does not create this mess?

I use "ls -A" to see hidden files not . or .. as well as visible files. If you want to see only hidden, You can say "ls .??*z" as long as there are no short names, or "ls -A | grep '^\.' ". With "A", no need to subtract 2. You can "grep -c '^\.' " to get count.

1 Like

Thanks allot.
Getting rid of the ls -ad .* , did fix it.

PS1='\[\e[1;33m\]\u@\h \[\e[1;34m\]\w $(es=$?; [[ $es -ne 0 ]] && echo "\[\e[1;31m\]" || echo "\[\e[1;32m\]")[$(ls | wc -l):$(ls -A|grep "^\."|wc -l)]\$\[\e[0m\]'

grep ...|wc -l

grep -c ...

1 Like