Where to set $PATH for i3 (and all window managers)

Tagged: ,

  • This topic has 11 replies, 4 voices, and was last updated Nov 1-5:41 pm by Brian Masinick.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #69758
    Member
    crackulator

      I am running i3 window manager. My objective is to add a $PATH entry, which works for dmenu in i3, therefore needs to be in place before starting i3 from SLiM. I want to add this path entry to point to some scripts that I use to perform common custom tasks that I run often from dmenu or the terminal.

      Usually one adds such a command in .profile, .xsessionrc, etc. to add to the $PATH variable. However, I empirically determined that none of the following scripts are executed when launching i3 from SLiM:

      .profile
      .bashrc
      .xsession
      .xprofile
      .xinitrc
      .xsessionrc

      It does run ~/.config/i3/config, and also ~/.desktop-session/startup, but I can’t figure out how to get them to change the $PATH as seen by i3/dmenu. I believe this is because of their context, they run at a parental level that doesn’t let them set the environment variables. Or maybe I just haven’t found the right syntax, trying things like:

      PATH=/home/crackulator/scripts:$PATH
      export PATH=/home/crackulator/scripts:$PATH
      exec export PATH=/home/crackulator/scripts:$PATH
      …and so forth, as appropriate as I can tell from the context.

      In general, I’d like to add this path to all contexts and all desktops. It doesn’t need to be only for i3, that’s just my preferred desktop for this computer.

      Where and how can I insert a command to make this modification to $PATH?

      Thanks

      #69766
      Member
      ex_Koo
        Helpful
        Up
        1
        ::

        I’m not quite sure what you are trying to do.

        If you want a script to run after loading i3 you just need something like below.
        (Make Sure your scripts executable)

        exec –no-startup-id ~/.scripts/dunstesting.sh
        Or a key bind
        bindsym $mod+shift+l exec –no-startup-id ~/.config/rofi/scripts/rofi-locate

        export XDG_CONFIG_HOME=”$HOME/.scripts”

        This is my xprofile

        #!/bin/sh
        
        # sourced at boot by ~/.xinitrc and most display managers
        
        export XDG_CONFIG_HOME="$HOME/.config"
        export PATH="$HOME/.local/bin:$PATH"
        
        picom -b &
        nm-applet &
        volumeicon &
        nitrogen --restore &
        xfce4-power-manager &
        /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 &
        gnome-keyring-daemon --start --components=pkcs11 &
        ksuperkey -e 'Super_L=Alt_L|F1' &
        ksuperkey -e 'Super_R=Alt_L|F1' &
        xset dpms 600 900 1200
        xset r rate 350 60
        • This reply was modified 1 year, 6 months ago by ex_Koo.
        #69768
        Member
        crackulator
          Helpful
          Up
          0
          ::

          Thanks but that’s not it at all… I’m trying to add a custom path to the $PATH variable before (or during, but effectively before) starting i3. I don’t want the scripts to run automatically, I want to run them on command from dmenu and the terminal.

          However your answer does suggest that your .xprofile is executed at some point during the boot process, otherwise you would not get your customizations. I found that empirically, .xprofile is not executed on my system in the time between login at SLiM and i3 launch. However, it is possible that it is executed before SLiM comes up, which I didn’t test, but if that is true, it would solve my problem. I will try that…

          #69778
          Member
          crackulator
            Helpful
            Up
            0
            ::

            Well that didn’t help at all. I made an ~/.xprofile, containing this:

            echo ".xprofile" >> /tmp/fc.log
            export PATH="/home/crackulator/script:$PATH"
            

            Made sure it was executable by all. The “echo” is to report to a log file when it gets executed. I boot the computer, log in from SLiM, and i3 starts up. The $PATH is not changed, and there is no entry in /tmp/fc.log. By all appearances, .xprofile was not executed, nor /etc/xprofile.

            So that took me back to /etc/X11/xinit/xinitrc, which was basically blank, no reference to .xprofile. Fixed it according to https://wiki.archlinux.org/title/xprofile, made it executable, also made the same in ~/.xinitrc, also logging to file. Never gets executed. What the hell?

            This is a stock antix install, only thing weird is 32-bit, and I’m using i3, but I also tried Rox-Ice, same result. @Koo, why is your xprofile getting executed and mine is not?

            I guess the one good thing is that it took me back to /etc/slim.conf, and it appears that the default path is defined there. So I can probably add it there and it’ll work. But what the heck is going on here?

            • This reply was modified 1 year, 6 months ago by crackulator.
            • This reply was modified 1 year, 6 months ago by crackulator.
            #69790
            Member
            Xecure
              Helpful
              Up
              0
              ::

              I think that you need to add the path to /etc/profile for non-interactive shells that run programs/commands from the menus will get/use that PATH. The issue is that it adds it GLOBALLY to all users.

              Adding it to .bashrc and the like only adds the PATH to user launched shells (when launching a terminal, etc.).

              Maybe at some point we can ask for this option to be added to desktop-session (export environmental variables when starting the session). The /etc/profile is what has worked for me outside of hacking desktop-session.

              antiX Live system enthusiast.
              General Live Boot Parameters for antiX.

              #69799
              Member
              ex_Koo
                Helpful
                Up
                0
                ::

                ( @Koo, why is your xprofile getting executed and mine is not?)
                It is called from my xinitrc file as is i3 executed. I do not like nor use login managers that why I use xinitrc. And if I have more then one Linux system install I use tbsm which I use to login from the tty screen.

                tbsm

                #!/bin/sh
                
                # this file is run when calling startx
                
                # default arch init scripts
                if [ -d /etc/X11/xinit/xinitrc.d ]; then
                    for f in /etc/X11/xinit/xinitrc.d/?*.sh; do
                        [ -x "$f" ] && . "$f"
                    done
                fi
                
                # user init scripts and settings
                [ -r /etc/X11/xinit/.Xmodmap ] && xmodmap /etc/X11/xinit/.Xmodmap
                [ -r ~/.Xmodmap ] && xmodmap ~/.Xmodmap
                [ -r ~/.Xresources ] && xrdb -merge ~/.Xresources
                [ -r ~/.xprofile ] && . ~/.xprofile
                
                # launch the session, commands below this line will be ignored
                exec i3
                #69800
                Member
                ex_Koo
                  Helpful
                  Up
                  1
                  ::

                  I have many scripts.
                  I can’t see how you add a path to the scripts folder and get a script to run just by typing say ./dunstesting from any directory anyway. Command must be in the directory that holds the script or by typing the full path to the script.

                  ┏>>> {Sun Oct 31 02:22 AM}
                  ┗>>> koo@archlabs ~ 56 files = 1.1G ~ $ ~/.scripts/dunstesting <<< this works
                  Or
                  With a Mod key bindsym $mod+j exec –no-startup-id ~/.scripts/dunstesting <<< this works

                  And as for dmenu and running scripts have a look here.
                  using-dmenu-to-optimize-common-tasks

                  If you are going to use a window manager you need to learn to search the web, more you put in yourself the more you will learn.

                  • This reply was modified 1 year, 6 months ago by ex_Koo.
                  • This reply was modified 1 year, 6 months ago by ex_Koo.
                  #69804
                  Moderator
                  Brian Masinick
                    Helpful
                    Up
                    0
                    ::

                    Best practice, in any case, is to add a default path in either .profile, .bashrc, or the login configuration file of whatever you are running. If there is any doubt whatsoever whether it has been executed or not, you can always explicitly execute it immediately following login.

                    Beyond that, if there are any other executable paths that you want to add, but perhaps not automatically include in login, one technique that some people use is to include some kind of “add-path” script.

                    I’ve also seen many recommendations against AUTOMATICALLY including your login directory or scripts directory in the login path, so for those who are paranoid about such things, add a few scripts here and there to explicitly modifying your executable path. In which case, at login, omit anything other than the default path, and then explicitly run a simple script to add whatever PATH environment you may want to use, and another script to trim back the path (or intelligence in a single script to add or trim the path, according to arguments that you pass to the script). All of these are exercises for the reader.

                    One common default PATH on some distributions is:
                    PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

                    --
                    Brian Masinick

                    #69879
                    Member
                    crackulator
                      Helpful
                      Up
                      0
                      ::

                      If you are going to use a window manager you need to learn to search the web, more you put in yourself the more you will learn.

                      This is probably not the most asinine comment on this forum, but if there is a contest it should be considered.

                      #69880
                      Member
                      crackulator
                        Helpful
                        Up
                        0
                        ::

                        I found the answer by digging through the code.

                        Such customizations can be placed in
                        ~/.desktop-session/desktop-session.conf
                        Not sure if that is exactly intended, but it serves the purpose.

                        The files commonly used for this purpose on other systems, like .xsession, .xprofile, .xinitrc, .xsessionrc are not referenced by the toolchain in the default installation.

                        To modify the $PATH as my case, use a line such as:
                        export PATH=$HOME/script:$PATH

                        • This reply was modified 1 year, 6 months ago by crackulator.
                        • This reply was modified 1 year, 6 months ago by crackulator.
                        #69888
                        Member
                        Xecure
                          Helpful
                          Up
                          0
                          ::

                          @ crackulator

                          Thanks for posting that trick! I had a created a hack on desktop-session to export variables before starting the window manager, but this advice is much better.

                          Thanks.

                          antiX Live system enthusiast.
                          General Live Boot Parameters for antiX.

                          #69938
                          Moderator
                          Brian Masinick
                            Helpful
                            Up
                            1
                            ::

                            I found the answer by digging through the code.

                            Such customizations can be placed in
                            ~/.desktop-session/desktop-session.conf
                            Not sure if that is exactly intended, but it serves the purpose.

                            The files commonly used for this purpose on other systems, like .xsession, .xprofile, .xinitrc, .xsessionrc are not referenced by the toolchain in the default installation.

                            To modify the $PATH as my case, use a line such as:
                            export PATH=$HOME/script:$PATH

                            This makes good sense. The only thing I’d consider doing differently is that I’d probably put the script path after the primary path, but that’s personal preference; what you suggest looks fine too.

                            --
                            Brian Masinick

                          Viewing 12 posts - 1 through 12 (of 12 total)
                          • You must be logged in to reply to this topic.