-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc_usb_status
More file actions
46 lines (40 loc) · 1.55 KB
/
bashrc_usb_status
File metadata and controls
46 lines (40 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
### Aggiungere in fondo al file .bashrc ###
# Definizione globale dei colori
COLOR_WHITE=$'\[\e[97m\]' # Bianco brillante (per le parentesi)
COLOR_GREEN=$'\[\e[32m\]' # Verde (per indicare montato)
COLOR_RED=$'\[\e[31m\]' # Rosso (per indicare non montato)
COLOR_GRAY=$'\[\e[90m\]' # Grigio (per indicare dispositivo assente)
COLOR_RESET=$'\[\e[0m\]'
# Funzione che controlla lo stato dei dispositivi USB e restituisce la stringa formattata
check_usb() {
USB1_DEV="/dev/sda1"
USB2_DEV="/dev/sdb1"
local status=""
# Controlla USB Storage
if [ -b "$USB1_DEV" ]; then
mount1=$(lsblk -n -o MOUNTPOINT "$USB1_DEV")
if [[ -n "$mount1" && "$mount1" =~ ^/ ]]; then
status+="${COLOR_WHITE}[${COLOR_GREEN}USB Storage: ✔${COLOR_WHITE}] "
else
status+="${COLOR_WHITE}[${COLOR_RED}USB Storage: ✖${COLOR_WHITE}] "
fi
else
status+="${COLOR_WHITE}[${COLOR_GRAY}USB Storage: ⬜${COLOR_WHITE}] "
fi
# Controlla USB Backup
if [ -b "$USB2_DEV" ]; then
mount2=$(lsblk -n -o MOUNTPOINT "$USB2_DEV")
if [[ -n "$mount2" && "$mount2" =~ ^/ ]]; then
status+="${COLOR_WHITE}[${COLOR_GREEN}USB Backup: ✔${COLOR_WHITE}]"
else
status+="${COLOR_WHITE}[${COLOR_RED}USB Backup: ✖${COLOR_WHITE}]"
fi
else
status+="${COLOR_WHITE}[${COLOR_GRAY}USB Backup: ⬜${COLOR_WHITE}]"
fi
echo -n "$status"
}
update_prompt() {
PS1=$'\[\e[34m\]\u@\h:\w '"$(check_usb)"$'\[\e[0m\]\$ '
}
PROMPT_COMMAND=update_prompt