I used to have an alias for cd
in csh, which can show the current time and directory at the beginning of the cmdline and trigger the ls
command.
The effect is like this:
[10:24] /home/cambridgelv/Desktop/cd ..
Desktop Documents Downloads Music
[10:24] /home/cambridgelv/cd Desktop
abc.doc def.jpg
[10:25] /home/cambridgelv/Desktop/
Does anybody have any idea?
CodePudding user response:
The easiest would be to hook in to the special cwdcmd
alias; this gets run every time the current directory changes.
alias cwdcmd 'printf "[%s] " `date %H:%m`'
For example, where >
is the prompt:
> sleep 1
> cd /
[14:06] > sleep 1
> cd ~
[14:06] >
You can also alias cd
with something like:
alias cd 'cd $* && printf "[%s] " `date %H:%m`'
Where $*
expand to the command arguments /dir
in cd /dir
. However, this also prints the directory in square brackets for some reason that I don't quite understand. The cwdcmd
alias is better anyway.
CodePudding user response:
Let me answer it by myself.
I thought maybe I aliased the set prompt
command into cd before, so we can do this separately.
Refer to this answer: https://stackoverflow.com/a/33037878/11768989
You can customize the prompt in any way.
Mine is look like this:
set prompt = '%{\e[35;40;1m%}[%T @%m]%{\e[0m%} %~/'
alias cd "cd \!:1; ls"