Skip to content

Commit 62172a7

Browse files
A Dynamic Collection of Shell Scripts with Educational Purpose
1 parent aba1aa4 commit 62172a7

4 files changed

Lines changed: 214 additions & 23 deletions

File tree

bash_profile

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# License: GPLv3
33
# Credits: Felipe Facundes
4+
45
if [[ ! $DISPLAY && ${XDG_VTNR} != 0 ]]; then
5-
if [[ "${XDG_SESSION_TYPE,,}" == tty ]]; then
6+
if [[ "${XDG_SESSION_TYPE}" = [Tt][Tt][Yy] ]]; then
67
#
78
### THEMES
89
GTK_THEME="$GTK_THEME"; export GTK_THEME
@@ -18,7 +19,7 @@ export XKB_DEFAULT_OPTIONS=grp:alt_shift_toggle
1819
#export __GL_SYNC_TO_VBLANK=0
1920

2021
export SSH_AUTH_SOCK
21-
file=~/.bash_profile
22+
file=~/.zprofile
2223
export wms_logs_dir="${HOME}/.WMs_logs_dir"
2324
wms_logs_dir_size=$(du "${wms_logs_dir}" | awk '{print $1}')
2425
scripts=~/.shell_utils/scripts
@@ -47,7 +48,7 @@ touch ~/.startx_log
4748
clear
4849

4950
local_count() {
50-
echo "${shell_color_palette[bgreen]}Exiting:${shell_color_palette[color_off]}"
51+
echo -e "${shell_color_palette[bgreen]}Exiting:${shell_color_palette[color_off]}"
5152
for i in {1..2}; do
5253
echo -n "${i}. "
5354
sleep 0.4
@@ -82,22 +83,30 @@ wm_wayland() {
8283
echo -e "${wm_wayland} log - $(date +'%d/%m/%Y - %T')\n\
8384
------------------------------------\n\n" >> "${wms_logs_dir}"/"${wm_wayland}_$(date +'%d-%m-%Y - %T')".log > /dev/null 2>&1
8485

85-
eval "${wm_wayland}" "$@" >> "${wms_logs_dir}"/"${wm_wayland}_$(date +'%d-%m-%Y - %T')".log > /dev/null 2>&1
86+
if [[ -n "$ZSH_VERSION" ]]; then
87+
local cmd=("${(@s: :)wm_wayland}")
88+
else
89+
local cmd=(${wm_wayland})
90+
fi
91+
92+
if [[ "$wm_wayland" == "Hyprland" ]]; then
93+
Exec=env WLR_RENDERER=vulkan start-hyprland "$@" >> "${wms_logs_dir}"/"${wm_wayland}_$(date +'%d-%m-%Y - %T')".log > /dev/null 2>&1
94+
else
95+
Exec=env WLR_RENDERER=vulkan "${cmd[@]}" "$@" >> "${wms_logs_dir}"/"${wm_wayland}_$(date +'%d-%m-%Y - %T')".log > /dev/null 2>&1
96+
fi
8697

8798
}
8899

89100
standard_wm() {
90101
standard_wm_conf="${HOME}/.standard_wm.conf"
91102
[[ ! -f "${standard_wm_conf}" ]] && touch "${standard_wm_conf}"
92103

93-
if [ "${wm_wayland}" ]
94-
then
104+
if [ "${wm_wayland}" ]; then
95105
echo 'protocol=1' | tee "${standard_wm_conf}" > /dev/null 2>&1
96106
echo -e "swm=${wm_wayland}" | tee -a "${standard_wm_conf}" > /dev/null 2>&1
97107
fi
98108

99-
if [ "${start_wm}" ]
100-
then
109+
if [ "${start_wm}" ]; then
101110
echo 'protocol=2' | tee "${standard_wm_conf}" > /dev/null 2>&1
102111
echo -e "swm=${start_wm}" | tee -a "${standard_wm_conf}" > /dev/null 2>&1
103112
fi
@@ -142,7 +151,7 @@ case "$option" in
142151
exit
143152
;;
144153
"2")
145-
wm_wayland='sway --unsupported-gpu'
154+
wm_wayland="sway --unsupported-gpu"
146155
standard_wm
147156
wm_wayland
148157
local_count
@@ -272,7 +281,7 @@ case "$option" in
272281
;;
273282
"3")
274283
echo -e "${shell_color_palette[bgreen]}Welcome terminal!${shell_color_palette[color_off]}\n"
275-
zsh
284+
$SHELL
276285
local_count
277286
source "${file}"
278287
;;
@@ -297,4 +306,4 @@ case "$option" in
297306
esac
298307

299308
fi
300-
fi
309+
fi

bashrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,13 @@ notifications() {
262262
[[ "$NOTIFY" == 1 ]] && notify-send "Command finished" "Status: $exit_status"
263263
}
264264

265-
PROMPT_COMMAND="notifications; $PROMPT_COMMAND; fix_bash_history"
265+
_prompt_command() {
266+
notifications
267+
"$@"
268+
fix_bash_history
269+
}
270+
271+
PROMPT_COMMAND="_prompt_command $PROMPT_COMMAND"
266272

267273
############################################################################
268274

scripts/seat-config

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#!/usr/bin/env bash
2+
# License: GPLv3
3+
# Credits: Felipe Facundes
4+
5+
: <<'DOCUMENTATION'
6+
Shell script to configure seatd for Sway on Arch Linux
7+
Verifies user is in 'seat' group and seatd service is running
8+
DOCUMENTATION
9+
10+
set -e # Exit immediately if any command fails
11+
12+
# Color codes for output formatting
13+
RED='\033[0;31m'
14+
GREEN='\033[0;32m'
15+
YELLOW='\033[1;33m'
16+
NC='\033[0m' # No Color
17+
18+
# Function to print colored status messages
19+
print_status() {
20+
echo -e "${GREEN}[INFO]${NC} $1"
21+
}
22+
23+
print_warning() {
24+
echo -e "${YELLOW}[WARN]${NC} $1"
25+
}
26+
27+
print_error() {
28+
echo -e "${RED}[ERROR]${NC} $1"
29+
}
30+
31+
# Function to check if user is in seat group
32+
check_seat_group() {
33+
print_status "Checking if user $USER is in 'seat' group..."
34+
35+
if groups "$USER" | grep -q '\bseat\b'; then
36+
print_status "User $USER is already a member of 'seat' group."
37+
return 0
38+
else
39+
print_warning "User $USER is NOT in 'seat' group."
40+
return 1
41+
fi
42+
}
43+
44+
# Function to add user to seat group
45+
add_to_seat_group() {
46+
print_status "Adding user $USER to 'seat' group..."
47+
48+
# Check if we have sudo privileges
49+
if ! sudo -v 2>/dev/null; then
50+
print_error "Need sudo privileges to add user to seat group."
51+
print_error "Please run this script with sudo or as root."
52+
exit 1
53+
fi
54+
55+
if sudo usermod -aG seat "$USER"; then
56+
print_status "Successfully added $USER to 'seat' group."
57+
print_warning "NOTE: You need to logout and login again for group changes to take effect."
58+
return 0
59+
else
60+
print_error "Failed to add user to 'seat' group."
61+
return 1
62+
fi
63+
}
64+
65+
# Function to check seatd service status
66+
check_seatd_service() {
67+
print_status "Checking seatd service status..."
68+
69+
if systemctl is-active --quiet seatd 2>/dev/null; then
70+
print_status "seatd service is already running."
71+
return 0
72+
else
73+
print_warning "seatd service is NOT running."
74+
return 1
75+
fi
76+
}
77+
78+
# Function to check if seatd service is enabled
79+
check_seatd_enabled() {
80+
if systemctl is-enabled --quiet seatd 2>/dev/null; then
81+
print_status "seatd service is already enabled."
82+
return 0
83+
else
84+
print_warning "seatd service is NOT enabled."
85+
return 1
86+
fi
87+
}
88+
89+
# Function to enable and start seatd service
90+
enable_start_seatd() {
91+
print_status "Enabling and starting seatd service..."
92+
93+
# Check if we have sudo privileges
94+
if ! sudo -v 2>/dev/null; then
95+
print_error "Need sudo privileges to manage seatd service."
96+
print_error "Please run this script with sudo or as root."
97+
exit 1
98+
fi
99+
100+
# Enable the service (starts automatically on boot)
101+
if sudo systemctl enable seatd; then
102+
print_status "Successfully enabled seatd service."
103+
else
104+
print_error "Failed to enable seatd service."
105+
return 1
106+
fi
107+
108+
# Start the service immediately
109+
if sudo systemctl start seatd; then
110+
print_status "Successfully started seatd service."
111+
return 0
112+
else
113+
print_error "Failed to start seatd service."
114+
return 1
115+
fi
116+
}
117+
118+
# Main execution
119+
main() {
120+
print_status "Starting seatd configuration check..."
121+
print_status "Current user: $USER"
122+
123+
# Check and add user to seat group if needed
124+
if ! check_seat_group; then
125+
add_to_seat_group
126+
fi
127+
128+
echo ""
129+
130+
# Check and enable/start seatd service if needed
131+
service_needs_action=false
132+
133+
if ! check_seatd_service; then
134+
service_needs_action=true
135+
fi
136+
137+
if ! check_seatd_enabled; then
138+
service_needs_action=true
139+
fi
140+
141+
if [ "$service_needs_action" = true ]; then
142+
enable_start_seatd
143+
else
144+
print_status "seatd service is already properly configured."
145+
fi
146+
147+
echo ""
148+
149+
# Summary
150+
print_status "Configuration check completed!"
151+
152+
# Final instructions
153+
if groups "$USER" | grep -q '\bseat\b' && systemctl is-active --quiet seatd 2>/dev/null; then
154+
print_status "✓ User is in 'seat' group"
155+
print_status "✓ seatd service is running"
156+
echo ""
157+
print_status "IMPORTANT: If you were just added to the 'seat' group,"
158+
print_status "you need to LOGOUT and LOGIN AGAIN for the changes to take effect."
159+
print_status "After that, Sway should be able to obtain necessary privileges."
160+
else
161+
print_warning "Some configuration might still be needed."
162+
print_warning "Check the messages above for any required actions."
163+
fi
164+
}
165+
166+
# Run main function
167+
main

zprofile

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#!/bin/zsh
1+
#!/usr/bin/env zsh
22
# License: GPLv3
33
# Credits: Felipe Facundes
4+
45
if [[ ! $DISPLAY && ${XDG_VTNR} != 0 ]]; then
56
if [[ "${XDG_SESSION_TYPE}" = [Tt][Tt][Yy] ]]; then
67
#
@@ -47,7 +48,7 @@ touch ~/.startx_log
4748
clear
4849

4950
local_count() {
50-
echo "${shell_color_palette[bgreen]}Exiting:${shell_color_palette[color_off]}"
51+
echo -e "${shell_color_palette[bgreen]}Exiting:${shell_color_palette[color_off]}"
5152
for i in {1..2}; do
5253
echo -n "${i}. "
5354
sleep 0.4
@@ -82,22 +83,30 @@ wm_wayland() {
8283
echo -e "${wm_wayland} log - $(date +'%d/%m/%Y - %T')\n\
8384
------------------------------------\n\n" >> "${wms_logs_dir}"/"${wm_wayland}_$(date +'%d-%m-%Y - %T')".log > /dev/null 2>&1
8485

85-
eval "${wm_wayland}" "$@" >> "${wms_logs_dir}"/"${wm_wayland}_$(date +'%d-%m-%Y - %T')".log > /dev/null 2>&1
86+
if [[ -n "$ZSH_VERSION" ]]; then
87+
local cmd=("${(@s: :)wm_wayland}")
88+
else
89+
local cmd=(${wm_wayland})
90+
fi
91+
92+
if [[ "$wm_wayland" == "Hyprland" ]]; then
93+
Exec=env WLR_RENDERER=vulkan start-hyprland "$@" >> "${wms_logs_dir}"/"${wm_wayland}_$(date +'%d-%m-%Y - %T')".log > /dev/null 2>&1
94+
else
95+
Exec=env WLR_RENDERER=vulkan "${cmd[@]}" "$@" >> "${wms_logs_dir}"/"${wm_wayland}_$(date +'%d-%m-%Y - %T')".log > /dev/null 2>&1
96+
fi
8697

8798
}
8899

89100
standard_wm() {
90101
standard_wm_conf="${HOME}/.standard_wm.conf"
91102
[[ ! -f "${standard_wm_conf}" ]] && touch "${standard_wm_conf}"
92103

93-
if [ "${wm_wayland}" ]
94-
then
104+
if [ "${wm_wayland}" ]; then
95105
echo 'protocol=1' | tee "${standard_wm_conf}" > /dev/null 2>&1
96106
echo -e "swm=${wm_wayland}" | tee -a "${standard_wm_conf}" > /dev/null 2>&1
97107
fi
98108

99-
if [ "${start_wm}" ]
100-
then
109+
if [ "${start_wm}" ]; then
101110
echo 'protocol=2' | tee "${standard_wm_conf}" > /dev/null 2>&1
102111
echo -e "swm=${start_wm}" | tee -a "${standard_wm_conf}" > /dev/null 2>&1
103112
fi
@@ -142,7 +151,7 @@ case "$option" in
142151
exit
143152
;;
144153
"2")
145-
wm_wayland='sway --unsupported-gpu'
154+
wm_wayland="sway --unsupported-gpu"
146155
standard_wm
147156
wm_wayland
148157
local_count
@@ -272,7 +281,7 @@ case "$option" in
272281
;;
273282
"3")
274283
echo -e "${shell_color_palette[bgreen]}Welcome terminal!${shell_color_palette[color_off]}\n"
275-
zsh
284+
$SHELL
276285
local_count
277286
source "${file}"
278287
;;
@@ -297,4 +306,4 @@ case "$option" in
297306
esac
298307

299308
fi
300-
fi
309+
fi

0 commit comments

Comments
 (0)