Last active
September 11, 2024 21:07
-
-
Save notpike/db0e27a3252f79595e20ef6143784174 to your computer and use it in GitHub Desktop.
PS1 update in Bash and logging with Date, Time, and IP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| #By: NotPike | |
| #About: Bash envirement script and logging | |
| #Usege: > Start.sh [FileName] | |
| #End process: > exit | |
| ## check for file name | |
| if [ $# -eq 0 ] | |
| then | |
| echo "File name needed" | |
| echo "Usege: > Start.sh [FileName]" | |
| echo "End process: > exit" | |
| exit 0 | |
| fi | |
| ## check if shell is bash | |
| if [[ $SHELL != *"bash" ]] | |
| then | |
| echo "Set envirement to bash and restart computer." | |
| echo "> chsh -s /usr/bin/bash" | |
| exit 0 | |
| fi | |
| ## back up ~/.bashrc | |
| cp ~/.bashrc ~/.bashrc.backup | |
| ## set PS1 | |
| ## https://bash-prompt-generator.org/ | |
| #echo 'export PS1="┌──[\d] [\t] [$(hostname -I | tr -d '[:space:]')] [\u@\H] [\w]\n└─$ "' >> ~/.bashrc | |
| echo 'export PS1="\[\e[38;5;46m\]┌──\[\e[48;5;235m\][\[\e[1m\]\d\[\e[22m\]]\[\e[49m\]-\[\e[48;5;235m\][\[\e[1m\]\t\[\e[22m\]]\[\e[49m\]-\[\e[48;5;235m\][\[\e[1m\]$(hostname -I | xargs)\[\e[22m\]]\[\e[49m\] (\[\e[38;5;45;1m\]\u@\H\[\e[0;38;5;46m\])-[\[\e[0;1m\]\w\[\e[0;38;5;46m\]]\n└─\[\e[38;5;45;1m\]\$ \[\e[0m\]"' >> ~/.bashrc | |
| ## start logging | |
| script $(date +"%m-%d-%Y_%T")_$1.log | |
| ## revert changes | |
| cp ~/.bashrc.backup ~/.bashrc && rm ~/.bashrc.backup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment