aboutsummaryrefslogtreecommitdiff
path: root/.profile
blob: 471759de134c6bb2905892c5b1069a4874183599 (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/sh

#. ~/.env

#if [ -n "$DISPLAY" ] && [ -n "$XAUTHORITY" ] && [ "$SHLVL" -eq '1' ]; then
#    /usr/bin/dunst &
#fi

# Default session to be executed
session=""

# Function to display and start the selected session
display() {
    # Default list of sessions in priority order
    default_sessions=("Hyprland" "bspwm" "sway" "i3")

    # Check conditions and set session command
    if [ "$DISPLAY" = "" ] && [ "$XDG_VTNR" -eq 1 ]; then
        if [ -f ~/.session ]; then
            session=$(cat ~/.session)
            rm ~/.session  # Remove the session file after reading
        fi

        if [ "$session" != "" ]; then
            case "$session" in
                bspwm | i3)
                    session="startx /usr/bin/$session"
                    ;;
                Hyprland | sway)
                    session="exec $session"
                    ;;
                *)
                    echo "Session $session is not supported."
                    session=""
                    ;;
            esac
        else
            # Iterate through default sessions to find a suitable one
            for wm in "${default_sessions[@]}"; do
                if command -v "$wm" >/dev/null 2>&1; then
                    case "$wm" in
                        bspwm | i3)
                            session="startx /usr/bin/$wm"
                            break
                            ;;
                        Hyprland | sway)
                            session="exec $wm"
                            break
                            ;;
                    esac
                fi
            done
        fi

        # Execute the session command if session is set
        if [ "$session" != "" ]; then
            echo "Starting session: $session"
            eval "$session"
        else
            echo "No suitable window manager found or conditions not met."
        fi
    fi
}

# Zsh
zsh() {
    if [ "$ZSH_VERSION" != "" ]; then
        # Source zsh environment if it exists
        if [ -f ~/.config/zsh/.zshenv ]; then
            . ~/.config/zsh/.zshenv
        fi
    fi
}

# GnuPG
gnupg() {
    if ! systemctl --quiet --user is-active gpg-agent.socket && command -v gpg-agent >/dev/null 2>&1; then
        echo 'Launching GPG agent...'
        eval "$(gpg-agent --daemon)"
    fi
}

# D-Bus
dbus() {
    if [ "$DBUS_SESSION_BUS_ADDRESS" = "" ]; then
        if command -v dbus-launch >/dev/null 2>&1; then
            echo 'Launching D-BUS per-session daemon...'
            eval "$(dbus-launch --sh-syntax --exit-with-session)"
            echo "D-BUS per-session daemon address: ${DBUS_SESSION_BUS_ADDRESS}"
        fi
    fi
    dbus-update-activation-environment --systemd --all
}

# Gnome Keyring Daemon
gnome_keyring() {
    if command -v gnome-keyring-daemon >/dev/null 2>&1; then
        echo 'Launching/reinitializing Gnome keyring daemon...'
        eval "$(gnome-keyring-daemon --daemonize --start --components=ssh,secrets,pkcs11)"
        echo
        export SSH_AUTH_SOCK
    fi
}

# PolKit
polkit() {
    if [ -x /usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1 ]; then
        echo 'Launching PolicyKit agent...'
        /usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1 &
    fi
}

# Main
main() {
    zsh
    gnupg
    dbus
    gnome_keyring
    polkit
    display
}

main "$@"