Artix Linux Forum

Artix Linux => System => Topic started by: kiblaster on 27 January 2023, 21:55:54

Title: Local path ingnored [SOLVED]
Post by: kiblaster on 27 January 2023, 21:55:54
Here on Artix I don't see a ~/.profile so I guess it is not sourced.
I put in ~/.bash_profile and in ~/.bashrc the paths:
Code: [Select]
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi
That works when I open a terminal but not for sxhkd or dmenu.

In what file should I put them?
Title: Re: Local path ingnored
Post by: ####### on 28 January 2023, 01:37:59
Adding your home path like that is a big security hole, because unprivileged processes can put a pseudo command which will overwrite the system one, so say you think you run "ls" but you might run "ls" in your .local/bin which was put there by malware - unlikely, but anyway, it should go after the other existing paths. If you want your own scripts to be globally available on the system, you can use /usr/local/bin which requires superuser permissions to write to. Also things from there can be links to anywhere, including your home dir if you wanted, although more likely you would install your own system wide things in /opt. But for the precise answer to your question if you really wanted to do it like that - I don't know exactly, perhaps someone else does!
Title: Re: Local path ingnored
Post by: jspaces on 28 January 2023, 02:40:41
Please check out Environment variables (https://wiki.archlinux.org/title/Environment_variables).

Quote
In this example, we will create a function to add several directories (e.g. ~/bin and ~/scripts) to PATH for the respective user. To do this, just put this in your preferred global environment variable configuration file (/etc/profile or /etc/bash.bashrc)
Code: [Select]
set_path(){

    # Check if user id is 1000 or higher
    [ "$(id -u)" -ge 1000 ] || return

    for i in "$@";
    do
        # Check if the directory exists
        [ -d "$i" ] || continue

        # Check if it is not already in your $PATH.
        echo "$PATH" | grep -Eq "(^|:)$i(:|$)" && continue

        # Then append it to $PATH and export it
        export PATH="${PATH}:$i"
    done
}

set_path ~/bin ~/scripts
You would have to modify the paths to your specifications.

Quote
/etc/profile initializes variables for login shells only. It does, however, run scripts (e.g. those in /etc/profile.d/) and can be used by all Bourne shell compatible shells.
Or you could create a custom profile script in /etc/profile.d/<script>.sh.
Title: Re: Local path ingnored
Post by: kiblaster on 28 January 2023, 22:01:04
I created a custom profile script in /etc/profile.d/<script>.sh, it works for sxhkd but not for dmenu.

So maybe is it something specific to dmenu?
Or from the Arch wiki:
Quote
Note: The dbus daemon and the user instance of systemd do not inherit any of the environment variables set in places like ~/.bashrc etc. This means that, for example, dbus activated programs like GNOME Files will not use them by default. See systemd/User#Environment variables.

Also /etc/profile doesn't affect it.
I am using "dmenu_run".
Title: Re: Local path ingnored
Post by: jspaces on 29 January 2023, 00:26:50
Arch dmenu wiki entry (https://wiki.archlinux.org/title/Dmenu)
Quote
4.3 Environment variables
Environment variables needed for applications should be added to /etc/environment.

Superuser site page does have some other possibilities: dmenu doesn't set environment variable as per my .bash_profile when running Emacs (https://superuser.com/questions/506186/dmenu-doesnt-set-environment-variable-as-per-my-bash-profile-when-running-emac).
First suggestion was to use ".xsessions".
The second try ".xinitrc".


Title: Re: Local path ingnored
Post by: kiblaster on 29 January 2023, 21:12:15
dmenu needs /etc/enviroment or ~/.xsession.

I am using a dm to start the GUI, ~/.xinitrc is ignored.
Only nodm uses it since it is some kind of wrapper for startx.

sxkbd needs /etc/profile.d/script, I guess /etc/profile is fine too.

So I am using /etc/enviroment and /etc/profile.d/script, those should work on wayland too.