>>2
although you'd need to be careful, since this would change the directory in the shell script, not the parent shell, so when the script exited, you'd be back at where you were in the parent shell. It's tricky.
>>8 alias cd ~ = 'cd ~ && echo "what"' Am I just dumb, or isn't it a bad idea to alias something to itself? Wouldn't the output of that aliased command be ``cd ~ what cd ~ what cd ~ what cd ~ what cd ~ what''... etc
Reminds me of something similar:
(save as what.bat)
@echo off
:start
echo what
what.bat
goto start
also I am high as fuck
smoke weed everyday, it makes thinking more difficult
If using zsh: function cd () {
if ! test "$@"; then
$HOME || return $?
else
$@ || return $?
fi
if test "$PWD" = "$HOME"; then
echo 'Welcome home, oniichan!'
fi
}
>>9
That should be start what.bat to create a new process/window. Without start, the batch file never resumes and goto start is never reached. A common bug in batch files is to forget start or call, so the original batch file never resumes. The default behavior without call is to pop the entire chain of batch files from the call stack. Why did Microsoft decide that you need call for batch files instead of having them behave like any other executable? Because changing the default behavior would break compatibility with QDOS. Even in the early 1980s Microsoft and Intel products were full of kludges for backwards compatibility.
>>13
bash version: cd () {
if ! test "$@"; then
pushd $HOME > /dev/null || return $?
else
pushd $@ > /dev/null || return $?
fi
if test "$PWD" = "$HOME"; then
echo 'Welcome home!'
fi
}
Name:
Anonymous2012-02-08 7:33
>>1
You can start with something like export PS1='$(if [ $PWD == $HOME ]; then echo "Welcome home, oniichan! "; fi)\$ '
It works in bash and changes your prompt every time you are in your home directory.
As for echoing a welcome message only when $PWD changes to your $HOME, I don't know, for one thing there's a shitload of things that can change your $PWD, also it would be all kinds of annoying if it fucked up scripts accidentally.
Name:
Anonymous2012-02-08 7:36
~/bin/cd: #!/bin/sh
cd "$@"
if [ $PWD = $HOME ]
then
echo "Welcome home, weeaboo!"
fi
You can use persistent state in your PS1 "script". Apparently, it's impossible to store it in environment variables, but you can always store it in a temp file. So you can see if $PWD has changed between two invocations of PS1. And you can output \n or two after the welcome message, to make it appear separate from the prompt.
>>19
That'll just close your shell.
Better also put exec $SHELL on the bottom of your ~/bin/cd.
Note that is horribly inefficient, makes your shell restart every time and parse its configuration files (and print any fortunes or whatever) every time you cd. >>13 is a way better solution.
>>17 that would suck because 1) there are other ways to change current directory, like pushd/popd, 2) you don't want scripts that might change a directory to pollute their stdout with bullshit (I guess you can check if stdout is a tty).
But on the other hand, as I understand a buggy incomplete solution that does one thing only sometimes and does it badly is exactly what UNIX Way is about, so in this respect your approach is fine.
Name:
Anonymous2012-02-08 9:21
OK, I kind of did it.
Put this in your .bashrc:
export WELCOMEPWD=`mktemp -t`
export PS1='$(~/bin/welcome.sh)'$PS1
Put this in ~/bin/welcome.sh:
#!/bin/sh
if [ -n "$WELCOMEPWD" -a -f "$WELCOMEPWD" ] ; then
if [ "$PWD" != "`cat "$WELCOMEPWD"`" ] ; then
if [ "$PWD" = "$HOME" ]; then
echo -e "Welcome home, oniichan!\n\n "
fi
echo "$PWD" > "$WELCOMEPWD"
fi
fi
The problem is that fucking space, because otherwise fucking bash strips trailing newlines from anything that executes inside $() or ``, and this can't be disabled. So you have to put the beginning of your prompt in the script/command.