You are not logged in.
Pages: 1
This is the thread for silly little tricks that make your command shell more usable.
Example: abusing the PROMPT_COMMAND environment variable, which can execute a command every time you enter something into the shell. Like, for instance, with the nice one-liner I discovered through Google, and modified to my own needs:
export PROMPT_COMMAND='[[ $curdir != $PWD ]] && ls -a --color=auto -F; curdir=$PWD'
which prints the contents (with color and glyphs) of a directory as soon as you enter it, then shuts up until you enter another directory. IOW it turns a standard bash prompt into a very simple file manager.
What are yours?
Edit: the above can also be written, less elegantly but perhaps more readably,
export PROMPT_COMMAND='if [[ $curdir != $PWD ]]; then ls -a --color=auto -F; curdir=$PWD; fi'
Last edited by Gullible Jones (2013-02-01 20:13:04)
Offline
To accomplish the same thing in zsh, I just setup this function:
function chpwd { ls }
Also to have the current command in my terminal's title, I use:
case $TERM in
*xterm*|*rxvt*|(dt|k|E|a)term)
precmd() { print -Pn "\e]0;%~\a" }
preexec () { print -Pn "\e]0;$1\a" }
;;
screen*)
preexec () { print -Pn "\e\"$1\e\134" }
;;
esac
Last edited by anonymous_user (2013-02-02 02:25:23)
Offline
Thank you for the Zsh version, anonymous_user.
Offline
I liked the suggestion, but when there are too many files it is annoying.
So I changed it to:
PROMPT_COMMAND='[[ $curdir != $PWD ]] && curdir=$PWD && (($( find . -maxdepth 1 ! -iname .\* -printf "0" | wc -c )<100)) && ls --color=auto -F'
Offline
Hmm. Isn't find kind of slow for that? Or would it be slower to call ls twice?
Offline
Hmm. Isn't find kind of slow for that? Or would it be slower to call ls twice?
I tested it before chosing.
It depends on the number of files: on my system ls is faster when they there less than a few hundreds.
Other alternative to consider
{ cwdfiles=(*); ls "${cwdfiles[@]:0:100}" -d --color=auto; }
Consider also the cost of printing.
For example printing the output of "ls /usr/lib" on my console takes many seconds (and imagine from a ssh session!), hence the need to count them before printing.
Offline
Pages: 1