mirror of
https://github.com/G2-Games/welcome.sh.git
synced 2025-05-10 14:42:54 -05:00
Compare commits
149 commits
Author | SHA1 | Date | |
---|---|---|---|
4912cfa2c8 | |||
9cee7f2904 | |||
b958afb09b | |||
965477d62b | |||
e82a0cf000 | |||
|
f78aed8316 | ||
979978a7f8 | |||
54f3619274 | |||
bd27870290 | |||
741fe542f1 | |||
b905684b63 | |||
68ab6a6310 | |||
4e5b2a848e | |||
61ddc11af7 | |||
44c14ad494 | |||
a863f8ddc6 | |||
49563932e0 | |||
e072e7c7fc | |||
b7608a59d0 | |||
bd0f3f2cc0 | |||
c58f9f5224 | |||
84874298c4 | |||
56883965c5 | |||
|
24a1dd5319 | ||
cc7ec85760 | |||
74a570a107 | |||
decec76c61 | |||
bdcb586589 | |||
5dcf4a77f8 | |||
|
df8decfd6e | ||
c6c9254a9d | |||
4226a00c31 | |||
5acea7fd34 | |||
aee6ee9e67 | |||
2b801c0a57 | |||
1760701f89 | |||
5335b5a6bb | |||
ccfb158843 | |||
df5d43dea3 | |||
05f0fd6ec8 | |||
|
5052c35831 | ||
|
affac2e291 | ||
a44b54186b | |||
ab6a2daf8d | |||
69330845b7 | |||
|
6265b2f27c | ||
|
eb10f90ce1 | ||
|
f82d1c4098 | ||
|
ac77fa236f | ||
|
544ed01199 | ||
|
d576cf98fb | ||
1b8ffa05a9 | |||
3da39bfefb | |||
3ce09125dc | |||
5d1920dfb2 | |||
|
caa1e26c0f | ||
|
ee34c250dd | ||
|
a827741e69 | ||
|
a0b7d43b4f | ||
|
355ba1aa86 | ||
|
6340d87388 | ||
|
d28195b401 | ||
|
1bdf2a6ff6 | ||
36870bc04e | |||
316cc6fda8 | |||
|
b3ab8b3b04 | ||
51159c3b39 | |||
f6aface51a | |||
666601105a | |||
bd06940b6a | |||
f26c99f2a5 | |||
c01e097140 | |||
f8d862d353 | |||
63423aa0e0 | |||
|
6286a69dcd | ||
beb2e27859 | |||
e2d183adaa | |||
512541775d | |||
942e29f0eb | |||
e1956f0df1 | |||
765a471085 | |||
5f4008459c | |||
|
b2da704a09 | ||
|
857d4d9d4e | ||
|
5c75716b5d | ||
|
7e588531de | ||
|
031b03d197 | ||
|
7ae07f7650 | ||
|
aeeac56c1f | ||
c4a0aa8899 | |||
f7f3af3828 | |||
|
79255119bf | ||
804aa8701f | |||
f2f8d567db | |||
f4477e87e1 | |||
b5060b4658 | |||
a6b5f4ded8 | |||
4c9d4bccc4 | |||
8f7fc68ea1 | |||
87e4668f99 | |||
935bc210f9 | |||
87a509c991 | |||
|
45e00f997d | ||
5215f964ae | |||
9fbcf0fb6d | |||
457788b3fe | |||
ca1a6c91ad | |||
|
4e2e76251c | ||
|
9703a47fe2 | ||
378ecc31d2 | |||
|
b1802eb490 | ||
2370c92cb0 | |||
1e0e9e37d4 | |||
|
87fea9d2f0 | ||
|
13a72920d5 | ||
9575f5e9e1 | |||
|
081e621b7c | ||
3d293d9b08 | |||
b45861ecdb | |||
200f085aa6 | |||
a165ed66b0 | |||
|
9e8367b4d0 | ||
8b577eb9e1 | |||
bb426a101c | |||
a8f761e309 | |||
66e6ca7d0e | |||
2a4724c675 | |||
|
a2d45c4ccc | ||
798025c9fa | |||
cf6634a9d5 | |||
c258c5ce2d | |||
99cd245e9c | |||
05d3f673b0 | |||
|
934ed7b0c2 | ||
|
c38b50173e | ||
|
a0426f4b45 | ||
fd252ec80e | |||
35c1b60a56 | |||
fbae8a9b72 | |||
|
25e8e24507 | ||
|
b740db5081 | ||
85aa71d731 | |||
8434db6ed7 | |||
|
14787733bb | ||
|
c812ca0906 | ||
b969c67916 | |||
|
a486bd04ef | ||
13a8de8b76 | |||
|
477862fc0e |
5 changed files with 569 additions and 146 deletions
97
README.md
97
README.md
|
@ -1,25 +1,96 @@
|
|||
# welcome-sh
|
||||

|
||||
### A nice welcome script for Bash
|
||||
This is a nice little script for your `.bashrc` that greets you on every launch, with some helpful (and customizable!) information.
|
||||
# welcome.sh
|
||||

|
||||
|
||||
My goal with this script is to keep it simple, just a single line that gives useful information when you start the terminal.
|
||||
### A nice welcome script for Bash and Zsh
|
||||
This is a nice little script for your `.bashrc` or `.zshrc` that greets you on every launch, with some helpful (and customizable!) information.
|
||||
|
||||
My goal with this script is to keep it simple, just a single line that gives useful information when you start a terminal session.
|
||||
|
||||
#### Features:
|
||||
- Relatively fast
|
||||
- <span title="Please let me know of other things to support!">Works across many distros (update checking support)</span>
|
||||
- Clean and simple
|
||||
- Customizable
|
||||
- Easy to install and update
|
||||
|
||||
#### Requirements:
|
||||
- Terminal with 24-bit true color support
|
||||
- Can check with `printf "\x1b[38;2;255;100;0mTRUECOLOR\x1b[0m\n"`, will return `TRUECOLOR` in Brown if supported<br>
|
||||
<sup>Source: [https://github.com/termstandard/colors](https://github.com/termstandard/colors)</sup>
|
||||
- [List of supported terminal emulators](https://github.com/termstandard/colors#truecolor-support-in-output-devices)
|
||||
- A modern version of Bash or Zsh (eg. the `/bin/sh` shell in Ubuntu does **not** work)
|
||||
<hr>
|
||||
|
||||
### Installing:
|
||||
#### Via Curl
|
||||
Run `bash -c "$(curl https://raw.githubusercontent.com/G2-Games/welcome-sh/main/install.sh)"` to install it.
|
||||
#### Automatic Installation via Curl
|
||||
<sub>Bash:</sub>
|
||||
```
|
||||
bash -c "$(curl -s https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh)"
|
||||
```
|
||||
<sub>Zsh:</sub>
|
||||
```
|
||||
zsh -c "$(curl -s https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh)"
|
||||
```
|
||||
|
||||
Run it again to uninstall.
|
||||
It installs to `~/.welcome/welcome.sh`, and adds a line to the bottom of `~/.bashrc` or `~/.zshrc`
|
||||
|
||||
#### Manual Installation
|
||||
To use it, download `welcome.sh` and place it in your home directory. Then add `/home/$USER/welcome.sh` to your `.bashrc`
|
||||
To install it manually, download the latest `welcome.sh` from <a href="https://github.com/G2-Games/welcome.sh/releases/latest">releases</a> and place it in your home directory. Then add `bash ~/welcome.sh` to your `.bashrc`. It works without the config file, but you can also add that to your home directory for easier manual updates.
|
||||
|
||||
### Updating:
|
||||
WIP
|
||||
Run the script again to check for an update. If you have an older version it will prompt you. You can update **from** any version **to** any newer version. The proper files will be downloaded as necessary.
|
||||
|
||||
Currently you can update by uninstalling and reinstalling, but this wipes all settings. I am working on making a better way to do this.
|
||||
<hr>
|
||||
|
||||
### Configs:
|
||||
To configure settings, open `~/.welcome/config.cfg` in your text editor of choice. There, you'll find a few settings:
|
||||
|
||||
```bash
|
||||
#==================SETUP=================#
|
||||
# Select which parts you want active by #
|
||||
# commenting them out. For example, on a #
|
||||
# desktop, disabling the battery message #
|
||||
# is a good idea. You can also re-order #
|
||||
# them to change how they display! #
|
||||
#========================================#
|
||||
|
||||
greetings=("Welcome" "Greetings" "Hello" "Hi") # Add your own greetings!
|
||||
randgreeting="off" #< Turn the random greetings on (eg. "Hello <user>, Hi <user>")
|
||||
twelvehour="on" #< Switch between 12 and 24 hour time (eg. 8:00 PM vs 20:00)
|
||||
rechargenotif="off" #< Notify that you should recharge if below 15%
|
||||
updatecheck="on" #< Check for all updates, slows startup a bit
|
||||
flatpakupd="off" #< Check for flatpak updates, this slows startup down A LOT
|
||||
goodgreeting="on" #< Display greetings like "Good afternoon," else "It's afternoon"
|
||||
displaydate="off" #< Unused so far
|
||||
|
||||
#=========COLORS=======#
|
||||
NCOL='\e[0m'
|
||||
BOLD='\e[1m'
|
||||
ITAL='\e[3m'
|
||||
UNDR='\e[4m'
|
||||
BLNK='\e[5m'
|
||||
|
||||
# Battery level colors
|
||||
CRIT='\e[31m'
|
||||
LOW='\e[33m'
|
||||
NORM='\e[32m'
|
||||
FULL='\e[3;4;92m'
|
||||
|
||||
TIME='\e[38;2;224;146;252;1m' # Clock color
|
||||
DATE='\e[38;2;50;168;82;1m' # Future "Date" item color
|
||||
USRC=$(randcolor) # Username color
|
||||
|
||||
# Greeting colors
|
||||
NIGH='\e[38;2;200;107;209m'
|
||||
MORN='\e[38;2;255;164;74m'
|
||||
AFTN='\e[38;2;250;245;110m'
|
||||
EVEN='\e[38;2;171;54;3m'
|
||||
|
||||
cfgversion=2
|
||||
```
|
||||
<hr>
|
||||
|
||||
### TODO:
|
||||
- [x] Add easier way to install and update
|
||||
- [ ] Fix issues across other distros
|
||||
- [ ] Add features?
|
||||
- [ ] Add new features? (Please suggest!)
|
||||
- [ ] Improve MacOS functionality
|
||||
|
|
25
cleanup.sh
Normal file
25
cleanup.sh
Normal file
|
@ -0,0 +1,25 @@
|
|||
#!/bin/bash
|
||||
version=1
|
||||
|
||||
echo "Ensuring welcome.sh is installed in the new location..."
|
||||
|
||||
# Check if welcome.sh is installed in the old location
|
||||
if [[ -f ~/.welcome ]]\
|
||||
|| [[ -f ~/.welcome/welcome.sh ]]\
|
||||
|| [[ -f ~/.welcome/config.cfg ]];
|
||||
then
|
||||
# Modify the files with proper paths
|
||||
sed "${i}d" "$zshrc" > file.tmp && mv file.tmp "$zshrc"
|
||||
|
||||
# Create the directories in the proper spots
|
||||
mkdir -p ~/.config/welcome.sh/
|
||||
mkdir -p ~/.local/bin/
|
||||
|
||||
# Move the welcome files to the proper folders
|
||||
mv ~/.welcome/config.cfg ~/.config/welcome.sh/config.cfg
|
||||
mv ~/.welcome/welcome.sh ~/.local/bin/welcome.sh
|
||||
|
||||
echo "welcome.sh is now installed in the new location!"
|
||||
else
|
||||
echo "welcome.sh is already installed properly!"
|
||||
fi
|
41
config.cfg
Normal file
41
config.cfg
Normal file
|
@ -0,0 +1,41 @@
|
|||
#==================SETUP=================#
|
||||
# Select which parts you want active by #
|
||||
# commenting them out. For example, on a #
|
||||
# desktop, disabling the battery message #
|
||||
# is a good idea. You can also re-order #
|
||||
# them to change how they display! #
|
||||
#========================================#
|
||||
|
||||
greetings=("Welcome" "Greetings" "Hello" "Hi") # Add your own greetings!
|
||||
randgreeting="off" #< Turn the random greetings on (eg. "Hello <user>, Hi <user>")
|
||||
twelvehour="on" #< Switch between 12 and 24 hour time (eg. 8:00 PM vs 20:00)
|
||||
rechargenotif="off" #< Notify that you should recharge if below 15%
|
||||
updatecheck="on" #< Check for all updates, slows startup a bit
|
||||
flatpakupd="off" #< Check for flatpak updates, this slows startup down A LOT
|
||||
goodgreeting="on" #< Display greetings like "Good afternoon," else "It's afternoon"
|
||||
displaydate="off" #< Unused so far
|
||||
|
||||
#=========COLORS=======#
|
||||
NCOL='\e[0m'
|
||||
BOLD='\e[1m'
|
||||
ITAL='\e[3m'
|
||||
UNDR='\e[4m'
|
||||
BLNK='\e[5m'
|
||||
|
||||
# Battery level colors
|
||||
CRIT='\e[31m'
|
||||
LOW='\e[33m'
|
||||
NORM='\e[32m'
|
||||
FULL='\e[3;4;92m'
|
||||
|
||||
TIME='\e[38;2;224;146;252;1m' # Clock color
|
||||
DATE='\e[38;2;50;168;82;1m' # Future "Date" item color
|
||||
USRC=$(randcolor) # Username color
|
||||
|
||||
# Greeting colors
|
||||
NIGH='\e[38;2;200;107;209m'
|
||||
MORN='\e[38;2;255;164;74m'
|
||||
AFTN='\e[38;2;250;245;110m'
|
||||
EVEN='\e[38;2;171;54;3m'
|
||||
|
||||
cfgversion=2
|
226
install.sh
226
install.sh
|
@ -1,35 +1,207 @@
|
|||
#!/bin/bash
|
||||
version=0.1
|
||||
bashrc="/home/$USER/.bashrc"
|
||||
originaldir=$PWD
|
||||
getVersion () {
|
||||
local ver
|
||||
ver=$(grep version ~/.welcome/welcome.sh 2> /dev/null | sed 's/.*=//')
|
||||
|
||||
if ! grep -q 'bash /home/$USER/.welcome/welcome.sh' $bashrc;
|
||||
then
|
||||
if [ -z "$ver" ]; then
|
||||
echo -e "\bUnknown"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "$ver"
|
||||
}
|
||||
|
||||
# Universal read command for bash and zsh
|
||||
univRead () {
|
||||
echo -en "$1"
|
||||
echo -en "\n[\e[36mY/n\e[0m]"
|
||||
if [[ "$environment" = "bash" ]]; then
|
||||
read -p " " -r
|
||||
elif [[ "$environment" = "zsh" ]]; then
|
||||
read -q "REPLY? " -r
|
||||
fi
|
||||
echo
|
||||
}
|
||||
|
||||
uninstall () {
|
||||
# Check if the user actually wishes to uninstall the script
|
||||
univRead "Do you want to \e[31muninstall \e[35mwelcome.sh\e[0m?"
|
||||
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
tput rc el ed
|
||||
echo -e "\e[31mUninstall cancelled.\e[0m"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
tput rc el ed
|
||||
echo "Goodbye. Uninstalling..."
|
||||
tput sc
|
||||
echo "Welcome! Installing..."
|
||||
cd /home/$USER
|
||||
mkdir -p /home/$USER/.welcome
|
||||
curl -q https://raw.githubusercontent.com/G2-Games/welcome-sh/main/welcome.sh --output /home/$USER/.welcome/welcome.sh
|
||||
chmod +x /home/$USER/.welcome/welcome.sh
|
||||
echo 'bash /home/$USER/.welcome/welcome.sh' >> $bashrc
|
||||
rm ~/.welcome/welcome.sh 2> /dev/null
|
||||
rm ~/.welcome/install.sh 2> /dev/null
|
||||
rm ~/.welcome/config.cfg 2> /dev/null
|
||||
rm ~/.welcome/config_old.cfg 2> /dev/null
|
||||
rm -r ~/.welcome
|
||||
|
||||
#remove all lines that match the string
|
||||
lines=$(grep -sn 'bash ~/.welcome/welcome.sh' "$bashrc" | sed -e 's/:.*//g' && grep -sn 'bash /home/$USER/.welcome/welcome.sh' "$bashrc" | sed -e 's/:.*//g')
|
||||
lines=$(printf '%s\n' "$lines" | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g')
|
||||
for i in $lines; do
|
||||
sed "${i}d" "$bashrc" > file.tmp && mv file.tmp "$bashrc"
|
||||
done
|
||||
|
||||
lines=$(grep -sn 'zsh ~/.welcome/welcome.sh' "$zshrc" | sed -e 's/:.*//g' && grep -sn 'zsh /home/$USER/.welcome/welcome.sh' "$zshrc" | sed -e 's/:.*//g')
|
||||
lines=$(printf '%s\n' "$lines" | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g')
|
||||
for i in $lines; do
|
||||
sed "${i}d" "$zshrc" > file.tmp && mv file.tmp "$zshrc"
|
||||
done
|
||||
|
||||
tput rc && tput el && tput ed
|
||||
echo -e "\e[36mUninstalled! \e[0m"
|
||||
}
|
||||
|
||||
update () {
|
||||
tput rc el ed
|
||||
echo "Updating..."
|
||||
tput sc
|
||||
mkdir -p ~/.welcome
|
||||
rm ~/.welcome/welcome.sh 2> /dev/null
|
||||
rm ~/.welcome/install.sh 2> /dev/null
|
||||
|
||||
curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/welcome.sh --output ~/.welcome/welcome.sh
|
||||
curl -SL https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh --output ~/.welcome/install.sh
|
||||
if [[ $vernum -ge 100 ]] && [[ $overcfg -gt 0 ]]; then
|
||||
echo "Backing up: config.cfg >> config_old.cfg"
|
||||
mv ~/.welcome/config.cfg ~/.welcome/config_old.cfg
|
||||
curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/config.cfg --output ~/.welcome/config.cfg
|
||||
fi
|
||||
|
||||
# Check for older versions and replace bashrc lines
|
||||
lines=$(grep -sn 'bash ~/.welcome/welcome.sh' "$bashrc" | sed -e 's/:.*//g' && grep -sn 'bash /home/$USER/.welcome/welcome.sh' "$bashrc" | sed -e 's/:.*//g') # Find target line number
|
||||
lines=$(printf '%s\n' "$lines" | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g') # Format the line number properly (macos doesn't have Cut)
|
||||
for i in $lines; do
|
||||
sed "${i}d" "$bashrc" > file.tmp && mv file.tmp "$bashrc"
|
||||
done
|
||||
echo 'bash ~/.welcome/welcome.sh' >> "$bashrc"
|
||||
|
||||
lines=$(grep -sn 'zsh ~/.welcome/welcome.sh' "$zshrc" | sed -e 's/:.*//g' && grep -sn 'zsh /home/$USER/.welcome/welcome.sh' "$zshrc" | sed -e 's/:.*//g')
|
||||
lines=$(printf '%s\n' "$lines" | sed '1!G;h;$!d' | sed ':a;N;$!ba;s/\n/ /g')
|
||||
for i in $lines; do
|
||||
sed "${i}d" "$zshrc" > file.tmp && mv file.tmp "$zshrc"
|
||||
done
|
||||
echo 'zsh ~/.welcome/welcome.sh' >> "$zshrc"
|
||||
|
||||
tput rc el ed
|
||||
echo -e "\e[32mUpdated to v$version! \e[0m"
|
||||
}
|
||||
|
||||
tput sc
|
||||
if [[ -z "$1" ]] && [[ $1 != "auto" ]]; then
|
||||
echo "Checking for latest release..."
|
||||
fi
|
||||
|
||||
if ! [[ $(command -v curl) ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
latestver=$(curl -Ls https://github.com/G2-Games/welcome.sh/releases/latest/download/welcome.sh | grep version | cut -d= -f2)
|
||||
oldver=$(grep version ~/.welcome/welcome.sh 2> /dev/null | cut -d= -f2 | sed 's/[.][.]*//g') && if [[ -z "$oldver" ]]; then oldver=0; fi
|
||||
|
||||
version="${1:-$latestver}"
|
||||
|
||||
if [[ $1 == "auto" ]] && [[ ${latestver//./} -le $oldver ]]; then
|
||||
exit 0
|
||||
elif [[ $1 == "auto" ]]; then
|
||||
version=$latestver
|
||||
fi
|
||||
|
||||
vernum=${version//./}
|
||||
bashrc=~/.bashrc
|
||||
zshrc=~/.zshrc
|
||||
originaldir=$PWD
|
||||
environment=$(ps -o args= -p $$ | grep -Em 1 -o '\w{0,5}sh' | head -1)
|
||||
|
||||
# Check if the environment is bash or zsh
|
||||
if [[ "$environment" != "bash" ]] && [[ "$environment" != "zsh" ]]; then
|
||||
tput rc
|
||||
printf "\e[31;5mERROR:\e[0m \e[31;3mThis script can only be installed in Bash or Zsh.\e[0m\n"
|
||||
printf "\e[32mYou appear to be using %s, which is not a valid shell for\n\
|
||||
this script!\e[0m Please use \e[3mBash \e[0mor \e[3mZsh.\e[0m\n" "${environment}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if already installed
|
||||
if ! grep -qs 'bash ~/.welcome/welcome.sh' $bashrc &&
|
||||
! grep -qs 'zsh ~/.welcome/welcome.sh' $zshrc &&
|
||||
! grep -qs 'bash /home/$USER/.welcome/welcome.sh' $bashrc &&
|
||||
! grep -qs 'zsh /home/$USER/.welcome/welcome.sh' $zshrc;
|
||||
then
|
||||
#==== Execute if first time installing...====#
|
||||
tput rc
|
||||
echo "Welcome! Installing v$version in $environment..."
|
||||
tput sc
|
||||
|
||||
cd ~/ || exit 1
|
||||
mkdir -p ~/.welcome
|
||||
curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/welcome.sh --output ~/.welcome/welcome.sh
|
||||
curl -SL https://raw.githubusercontent.com/G2-Games/welcome.sh/main/install.sh --output ~/.welcome/install.sh
|
||||
|
||||
if [[ $vernum -ge 100 ]]; then
|
||||
curl -SL https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/config.cfg --output ~/.welcome/config.cfg
|
||||
fi
|
||||
chmod +x ~/.welcome/welcome.sh
|
||||
|
||||
if [[ "$environment" = "bash" ]]; then
|
||||
echo "Installing to bashrc"
|
||||
echo 'bash ~/.welcome/welcome.sh' >> $bashrc
|
||||
elif [[ "$environment" = "zsh" ]]; then
|
||||
echo "Installing to zshrc"
|
||||
echo 'zsh ~/.welcome/welcome.sh' >> $zshrc
|
||||
fi
|
||||
|
||||
cd "$originaldir" || exit 1
|
||||
tput rc el ed
|
||||
echo -e "\e[36mInstalled! \e[0m"
|
||||
cd "$originaldir"
|
||||
else
|
||||
tput sc
|
||||
echo -e "\e[35mwelcome.sh\e[0m already installed!"
|
||||
echo -en "\e[31mDo you want to uninstall welcome.sh?\e[0m\n\e[36mY/n\e[0m"
|
||||
read -p " " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]
|
||||
then
|
||||
rm /home/$USER/.welcome/welcome.sh
|
||||
rmdir /home/$USER/.welcome
|
||||
sed -i 's#bash /home/$USER/.welcome/welcome.sh##g' $bashrc
|
||||
tput rc el ed
|
||||
echo -e "\e[36mUninstalled! \e[0m"
|
||||
#==== Execute if already installed...====#
|
||||
|
||||
tput rc sc el ed
|
||||
mkdir -p ~/.welcome
|
||||
if ! [[ $1 == "auto" ]]; then
|
||||
echo -e "\e[35mwelcome.sh\e[0m already installed!"
|
||||
else
|
||||
tput rc el ed
|
||||
echo -e "\e[32mCancelled. \e[0m"
|
||||
echo -e "\e[32mUpdate available for \e[35mwelcome.sh!\e[0m"
|
||||
fi
|
||||
|
||||
if [[ $vernum -gt $oldver ]]; then
|
||||
# Pull the new configuration version from github
|
||||
newCfgVer=$(curl -Ls https://github.com/G2-Games/welcome.sh/releases/download/v"${version}"/config.cfg | grep version | cut -d= -f2)
|
||||
|
||||
univRead "Do you want to \e[36mupdate \e[35mwelcome.sh\e[0m? (\e[36mv$(getVersion)\e[0m => \e[32mv$version\e[0m)"
|
||||
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
tput rc sc el ed
|
||||
echo -e "\e[31mUpdate cancelled.\e[0m"
|
||||
update=0
|
||||
else
|
||||
update=1
|
||||
fi
|
||||
|
||||
if [[ $newCfgVer -gt $(grep version ~/.welcome/config.cfg 2> /dev/null | cut -d= -f2) ]]; then
|
||||
univRead "Newer \e[36mconfig\e[0m version available. Do you want to \e[31moverwrite\e[0m your \e[36mconfig\e[0m? \nA backup will be created in the \e[36m.welcome\e[0m folder."
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
overcfg=1
|
||||
fi
|
||||
elif [[ $oldver -lt 100 ]]; then
|
||||
overcfg=1
|
||||
else
|
||||
overcfg=0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ update -gt 0 ]]; then
|
||||
update
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if ! [[ $1 == "auto" ]]; then
|
||||
uninstall
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
|
326
welcome.sh
326
welcome.sh
|
@ -1,46 +1,71 @@
|
|||
#!/bin/bash
|
||||
export LC_NUMERIC="en_US.UTF-8" &> /dev/null #Fix for locales that use , instead of . as a decimal delimiter
|
||||
|
||||
#====Customization=====#
|
||||
# Set colors for ease of use
|
||||
NCOL='\e[0m'
|
||||
CRIT='\e[31m'
|
||||
LOW='\e[33m'
|
||||
NORM='\e[32m'
|
||||
FULL='\e[3;4;92m'
|
||||
BOLD='\e[1m'
|
||||
ITAL='\e[3m'
|
||||
UNDR='\e[4m'
|
||||
BLNK='\e[5m'
|
||||
USRC='\e[1;32m'
|
||||
|
||||
NIGH='\e[0;35m'
|
||||
MORN='\e[0;33m'
|
||||
AFTN='\e[0;93m'
|
||||
EVEN='\e[0;91m'
|
||||
# Define "global" variables
|
||||
environment=$(ps -o args= -p $$ | grep -Em 1 -o '\w{0,5}sh' | head -1)
|
||||
version=1.1.2
|
||||
|
||||
#========Welcome=======#
|
||||
welcome () {
|
||||
msg="Welcome" # Default
|
||||
greetingsLength=${#greetings[@]}
|
||||
greetingsNumber=$((RANDOM % greetingsLength))
|
||||
|
||||
if command -v whoami &>/dev/null ; then
|
||||
usr=$(whoami)
|
||||
elif command -v id &>/dev/null; then
|
||||
usr=$(id -u -n)
|
||||
else
|
||||
usr=$USER
|
||||
fi
|
||||
|
||||
if [ "$randgreeting" = "on" ]; then
|
||||
msg=${greetings[@]:$greetingsNumber:1}
|
||||
fi
|
||||
|
||||
# Print the welcome message
|
||||
echo -en "Welcome, ${USRC}$USER${NCOL}. "
|
||||
echo -en "$msg, ${USRC}${BOLD}$usr${NCOL}. "
|
||||
}
|
||||
|
||||
#=========Time=========#
|
||||
clock () {
|
||||
bksp=""
|
||||
# Set the current hour and minute
|
||||
if [ "$twelvehour" = "on" ]; then
|
||||
if [[ "$(date +%_I)" -lt 10 ]]; then
|
||||
hour="\b$(date +%_I)"
|
||||
else
|
||||
hour="$(date +%_I)"
|
||||
fi
|
||||
ampm=$(date +%p)
|
||||
else
|
||||
hour=$(date +%H)
|
||||
bksp="\b \b" # This is a hack to fix some spacing issues with AM and PM with different lengths of time
|
||||
fi
|
||||
minute=$(date +%M)
|
||||
|
||||
# Print the time
|
||||
echo -en "The time is ${TIME}$hour${BLNK}:${NCOL}${TIME}$minute $bksp${ampm}${NCOL}. "
|
||||
}
|
||||
|
||||
#=======Greeting=======#
|
||||
greeting () {
|
||||
# Set the hour
|
||||
hr=$(date +%H)
|
||||
hour=$(date +%H)
|
||||
greet="It's"
|
||||
|
||||
if [ $hr -le 11 ] && [ $hr -gt 6 ];
|
||||
then
|
||||
echo -en "It's ${MORN}morning${NCOL}. "
|
||||
elif [ $hr -eq 12 ];
|
||||
then
|
||||
if [ "$goodgreeting" = "on" ]; then
|
||||
greet="Good"
|
||||
fi
|
||||
|
||||
# Change color and greeting depending on the segment of day
|
||||
if [ "$hour" -le 11 ] && [ "$hour" -gt 6 ]; then
|
||||
echo -en "$greet ${MORN}morning${NCOL}. "
|
||||
elif [ "$hour" -eq 12 ]; then
|
||||
echo -en "It's ${AFTN}noon${NCOL}. "
|
||||
elif [ $hr -le 16 ] && [ $hr -gt 12 ];
|
||||
then
|
||||
echo -en "It's ${AFTN}afternoon${NCOL}. "
|
||||
elif [ $hr -le 19 ] && [ $hr -gt 16 ];
|
||||
then
|
||||
echo -en "It's ${EVEN}evening${NCOL}. "
|
||||
elif [ "$hour" -le 17 ] && [ "$hour" -gt 12 ]; then
|
||||
echo -en "$greet ${AFTN}afternoon${NCOL}. "
|
||||
elif [ "$hour" -le 19 ] && [ "$hour" -gt 17 ]; then
|
||||
echo -en "$greet ${EVEN}evening${NCOL}. "
|
||||
else
|
||||
echo -en "It's ${NIGH}night${NCOL}. "
|
||||
fi
|
||||
|
@ -52,29 +77,28 @@ battery () {
|
|||
# Set a default to prevent errors
|
||||
batlvl=0
|
||||
|
||||
if [ -a /sys/class/power_supply/BAT0/capacity ];
|
||||
then
|
||||
# Check the two usually used battery locations
|
||||
if [[ -a "/sys/class/power_supply/BAT0/capacity" ]]; then
|
||||
batlvl=$(cat /sys/class/power_supply/BAT0/capacity)
|
||||
elif [ -a /sys/class/power_supply/BAT1/capacity ];
|
||||
then
|
||||
elif [[ -a "/sys/class/power_supply/BAT1/capacity" ]]; then
|
||||
batlvl=$(cat /sys/class/power_supply/BAT1/capacity)
|
||||
elif command -v pmset &> /dev/null;then
|
||||
batlvl=$(pmset -g batt | grep -Eo "\d+%" | cut -d% -f1)
|
||||
else
|
||||
batlvl=-1
|
||||
fi
|
||||
|
||||
# Change color depending on level
|
||||
if [ $batlvl -eq 100 ];
|
||||
then
|
||||
if [[ $batlvl -ge 100 ]]; then
|
||||
echo -en "The battery is ${FULL}fully charged${NCOL}. "
|
||||
else
|
||||
elif [[ $batlvl -gt 0 ]]; then
|
||||
echo -en "The battery level is "
|
||||
if [ $batlvl -le 15 ];
|
||||
then
|
||||
if [[ $batlvl -le 15 ]]; then
|
||||
echo -en "${CRIT}$batlvl%${NCOL}. "
|
||||
if [ $rechargenotif == "on" ];
|
||||
then
|
||||
if [[ "$rechargenotif" = "on" ]]; then
|
||||
echo -en "- ${NORM}You should probably recharge${NCOL}. "
|
||||
fi
|
||||
elif [ $batlvl -le 30 ];
|
||||
then
|
||||
elif [ $batlvl -le 30 ]; then
|
||||
echo -en "${LOW}$batlvl%${NCOL}. "
|
||||
else
|
||||
echo -en "${NORM}$batlvl%${NCOL}. "
|
||||
|
@ -82,88 +106,178 @@ battery () {
|
|||
fi
|
||||
}
|
||||
|
||||
#=========Time=========#
|
||||
clock () {
|
||||
# Set the current hour and minute
|
||||
hour=$(date +%I)
|
||||
minute=$(date +%M)
|
||||
|
||||
# Print the time
|
||||
echo -en "The time is ${BOLD}$hour${BLNK}:${NCOL}${BOLD}$minute${NCOL}. "
|
||||
}
|
||||
|
||||
#========Updates=======#
|
||||
updates () {
|
||||
# Set defaults to prevent errors
|
||||
debian=0
|
||||
arch=0
|
||||
fedora=0
|
||||
brew=0
|
||||
flatpak=0
|
||||
chk=0
|
||||
updates=0
|
||||
|
||||
# Check for updates from different places...
|
||||
# Check for updates from different places... wonder if there's a better way
|
||||
updchk () {
|
||||
# Check for APT (Debian based)
|
||||
if command -v apt-get &> /dev/null; then
|
||||
debian=$(apt-get -s dist-upgrade -V | grep -c '=>')
|
||||
fi
|
||||
|
||||
# Check for APT
|
||||
if command -v apt &> /dev/null;
|
||||
then
|
||||
debian=$(apt-get -s dist-upgrade -V | grep '=>' | awk '{print$1}' | wc -l)
|
||||
# Check for Arch things
|
||||
if command -v checkupdates &> /dev/null; then
|
||||
arch=$(checkupdates 2> /dev/null | wc -l)
|
||||
elif command -v yay &> /dev/null; then
|
||||
arch=$(yay -Qu 2> /dev/null | wc -l)
|
||||
elif command -v paru &> /dev/null; then
|
||||
arch=$(paru -Quq 2> /dev/null | wc -l)
|
||||
elif command -v pacman &> /dev/null; then
|
||||
arch=$(pacman -Qu 2> /dev/null | wc -l)
|
||||
fi
|
||||
|
||||
# Check for Fedora things
|
||||
if command -v dnf &> /dev/null; then
|
||||
fedora=$(dnf list updates 2> /dev/null | wc -l)
|
||||
fedora=$((fedora-1))
|
||||
elif command -v yum &> /dev/null; then
|
||||
fedora=$(yum list updates 2> /dev/null | wc -l)
|
||||
fedora=$((fedora-1))
|
||||
fi
|
||||
|
||||
# Check for OpenSUSE things
|
||||
if command -v zypper &> /dev/null; then
|
||||
suse=$(zypper list-updates 2> /dev/null | wc -l)
|
||||
suse=$((suse-4))
|
||||
fi
|
||||
|
||||
# Check for Brew updates
|
||||
if command -v brew &> /dev/null; then
|
||||
brew=$(brew outdated 2> /dev/null | wc -l)
|
||||
fi
|
||||
|
||||
# Check for Flatpak
|
||||
if command -v flatpak &> /dev/null && [ "$flatpakupd" = "on" ]; then
|
||||
flatpak=$(flatpak remote-ls --updates 2> /dev/null | wc -l)
|
||||
fi
|
||||
|
||||
# Add all update counts together
|
||||
updates=$((debian + arch + fedora + suse + flatpak + brew))
|
||||
echo $updates >| ~/.welcome/updates
|
||||
pkill -P "${pid}" sleep # When update checking is finished, kill the sleep function running under this bash process
|
||||
sleep 5
|
||||
if [[ -a ~/.welcome/updates ]]; then
|
||||
rm ~/.welcome/updates
|
||||
fi
|
||||
}
|
||||
|
||||
pid=$$ # Grab the PID of the process
|
||||
updchk & # Check for updates Asynchronously
|
||||
|
||||
set +e # Allow nonzero exit status for killing sleep
|
||||
exec 3>&2 # These exec commands simply supress the output of the "kill" command
|
||||
exec 2> /dev/null
|
||||
sleep 5
|
||||
chk=$?
|
||||
exec 2>&3 # And then re-enable it
|
||||
exec 3>&-
|
||||
set -e # Return to disallowing nonzero exit status
|
||||
|
||||
if [[ -a ~/.welcome/updates ]]; then
|
||||
updates=$(cat ~/.welcome/updates)
|
||||
rm ~/.welcome/updates
|
||||
fi
|
||||
|
||||
# Check for different Arch things
|
||||
if command -v yay &> /dev/null;
|
||||
then
|
||||
arch=$(yay -Qu 2> /dev/null | wc -l)
|
||||
elif command -v paru &> /dev/null;
|
||||
then
|
||||
arch=$(paru -Quq 2> /dev/null | wc -l)
|
||||
elif command -v pacman &> /dev/null;
|
||||
then
|
||||
arch=$(pacman -Qu 2> /dev/null | wc -l)
|
||||
fi
|
||||
|
||||
# Check for Fedora things
|
||||
if command -v dnf &> /dev/null;
|
||||
then
|
||||
fedora=$(dnf list updates 2> /dev/null | wc -l)
|
||||
fedora=$((fedora-1))
|
||||
elif command -v yum &> /dev/null;
|
||||
then
|
||||
fedora=$(yum list updates 2> /dev/null | wc -l)
|
||||
fedora=$((fedora-1))
|
||||
fi
|
||||
|
||||
# Check for Flatpak
|
||||
if command -v flatpak &> /dev/null && [ $flatpakupd == "on" ];
|
||||
then
|
||||
flatpak=$(flatpak remote-ls --updates 2> /dev/null | wc -l)
|
||||
fi
|
||||
|
||||
|
||||
# Add all update counts together
|
||||
updates=$(($debian + $arch + fedora + $flatpak))
|
||||
|
||||
# Check the update amounts and print them out
|
||||
if [ $updates -eq 1 ];
|
||||
then
|
||||
echo -en "You have ${NORM}1${NCOL} pending update. "
|
||||
elif [ $updates -eq 0 ];
|
||||
then
|
||||
echo -en "You have no pending updates. "
|
||||
if [ $chk -lt 1 ]; then
|
||||
echo -en "Update check timed out. "
|
||||
else
|
||||
echo -en "You have ~${NORM}$updates${NCOL} pending updates. "
|
||||
if [ "${updates}" -eq 0 ]; then
|
||||
echo -en "You have no pending updates. "
|
||||
elif [ "${updates}" -eq 1 ]; then
|
||||
echo -en "You have ${NORM}1${NCOL} pending update. "
|
||||
else
|
||||
echo -en "You have ~${NORM}$updates${NCOL} pending updates. "
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
#=========SETUP========#
|
||||
# Select which parts you want active by commenting them out
|
||||
# For example, on a desktop, disabling the battery message is a good idea
|
||||
# You can also re order them to change how they display!
|
||||
#=====Random Color=====#
|
||||
randcolor() {
|
||||
# For random colors; this will only generate colors with sufficient #
|
||||
# perceptual luma to be readable on a dark background... you may have #
|
||||
# to modify it for a light one #
|
||||
cluma=0
|
||||
loops=0
|
||||
while [ "$(printf %.0f $cluma)" -le 100 ] && [ $loops -le 10 ]; do
|
||||
cr=$((0 + RANDOM % 255))
|
||||
crl=$(echo "$cr 0.299" | awk '{print $1 * $2}')
|
||||
cg=$((0 + RANDOM % 255))
|
||||
cgl=$(echo "$cg 0.587" | awk '{print $1 * $2}')
|
||||
cb=$((0 + RANDOM % 255))
|
||||
cbl=$(echo "$cb 0.114" | awk '{print $1 * $2}')
|
||||
cluma=$(echo "$crl $cgl $cbl" | awk '{print $1 + $2 + $3}')
|
||||
loops=$((loops+1))
|
||||
done
|
||||
echo "\e[38;2;${cr};${cg};${cb}m"
|
||||
}
|
||||
|
||||
flatpakupd="off" # Check for flatpak updates, this slows startup down A LOT
|
||||
rechargenotif="off" # Notify that you should recharge if below 15%
|
||||
#=========COLORS=======#
|
||||
NCOL='\e[0m'
|
||||
BOLD='\e[1m'
|
||||
ITAL='\e[3m'
|
||||
UNDR='\e[4m'
|
||||
BLNK='\e[5m'
|
||||
|
||||
# Battery level colors
|
||||
CRIT='\e[31m'
|
||||
LOW='\e[33m'
|
||||
NORM='\e[32m'
|
||||
FULL='\e[3;4;92m'
|
||||
|
||||
TIME='\e[38;2;224;146;252;1m' # Clock color
|
||||
DATE='\e[38;2;50;168;82;1m'
|
||||
USRC=$(randcolor) # <-----------Username color
|
||||
|
||||
# Greeting colors
|
||||
NIGH='\e[38;2;200;107;209m'
|
||||
MORN='\e[38;2;255;164;74m'
|
||||
AFTN='\e[38;2;250;245;110m'
|
||||
EVEN='\e[38;2;171;54;3m'
|
||||
|
||||
greetings=("Welcome" "Greetings" "Hello" "Hi") # Add your own greetings!
|
||||
randgreeting="off" #< Turn the random greetings on (eg. "Hello <user>, Hi <user>")
|
||||
twelvehour="on" #< Switch between 12 and 24 hour time (eg. 8:00 PM vs 20:00)
|
||||
rechargenotif="off" #< Notify that you should recharge if below 15%
|
||||
updatecheck="on" #< Check for general updates
|
||||
flatpakupd="off" #< Check for flatpak updates, this slows startup down A LOT
|
||||
goodgreeting="on" #< Display greetings like "Good afternoon," else "It's afternoon"
|
||||
|
||||
# ALL the stuff above this line and below the colors line is in the config, changing it here will do nothing only if the config doesn't exist!
|
||||
|
||||
source ~/.welcome/config.cfg
|
||||
|
||||
welcome
|
||||
greeting
|
||||
clock
|
||||
battery
|
||||
updates #< This makes startup slower
|
||||
if [ "$updatecheck" = "on" ]; then
|
||||
updates
|
||||
fi
|
||||
echo # Properly line break at the end
|
||||
|
||||
set +e
|
||||
|
||||
date=$(date +%s)
|
||||
lastdate=$(cat ~/.welcome/udm 2>/dev/null)
|
||||
|
||||
if [[ $((date - lastdate)) -ge 86400 ]]; then
|
||||
if [[ "$environment" = "bash" ]]; then
|
||||
bash ~/.welcome/install.sh auto
|
||||
elif [[ "$environment" = "zsh" ]]; then
|
||||
zsh ~/.welcome/install.sh auto
|
||||
fi
|
||||
date +%s >| ~/.welcome/udm 2>/dev/null
|
||||
elif ! [[ -f ~/.welcome/udm ]]; then
|
||||
touch ~/.welcome/udm
|
||||
date +%s >| ~/.welcome/udm 2>/dev/null
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue