ps1test: Add a PS1 tester
This commit is contained in:
parent
4263f0404a
commit
55c08e07f6
45
ps1test
Executable file
45
ps1test
Executable file
@ -0,0 +1,45 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
#
|
||||||
|
# ps1test
|
||||||
|
# Tests your bash PS1
|
||||||
|
# Copyright (C) 2020 Vintage Salt <rehashedsalt@cock.li>
|
||||||
|
#
|
||||||
|
# Distributed under terms of the MIT license.
|
||||||
|
#
|
||||||
|
|
||||||
|
main() {
|
||||||
|
. ~/.profile
|
||||||
|
. ~/.bashrc
|
||||||
|
printf "Default:\n"
|
||||||
|
printps1 # Test a default ps1
|
||||||
|
false || printps1 # Test after command failure
|
||||||
|
PWD=~/Documents printps1 # Test in a subdir of ~
|
||||||
|
PWD=/tmp printps1 # Test in a world-writeable dir
|
||||||
|
PWD=/usr/local printps1 # Test in unwriteable dir
|
||||||
|
PWD=/dir/that/doesnt/exist printps1 # Test in dir that doesn't exist
|
||||||
|
printf "\nDefault, different user:\n"
|
||||||
|
USER=notme printps1 # Test as another user
|
||||||
|
printf "\nSame user, different machine:\n"
|
||||||
|
SSH_CLIENT=notme HOSTNAME=notme printps1 # Test over fake SSH
|
||||||
|
printf "\nForeign machine, foreign user:\n"
|
||||||
|
USER=notme SSH_CLIENT=notme HOSTNAME=notme printps1 # Test both of the above
|
||||||
|
}
|
||||||
|
|
||||||
|
hostname() {
|
||||||
|
# We have this little stub here to intercept calls to hostname
|
||||||
|
echo "$HOSTNAME"
|
||||||
|
}
|
||||||
|
|
||||||
|
printps1() {
|
||||||
|
# Print the PS1, with some substitutions
|
||||||
|
"$PROMPT_COMMAND" > /dev/null 2>&1
|
||||||
|
PS1="${PS1//\\[/}"
|
||||||
|
PS1="${PS1//\\]/}"
|
||||||
|
PS1="${PS1//\\w/$PWD}"
|
||||||
|
PS1="${PS1//$HOME/\~}"
|
||||||
|
printf "\t$PS1\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
main "$@"
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user