Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script works in terminal emulator, but not as i3 keybind

Tags:

I have a lock screen script (via i3lock) that runs correctly in a terminal window, but not when used as a keybind in i3 config.

The script is pretty straightforward:

# Take screenshot
scrot /tmp/screenshot.png

# Pixelate and add central logo
magick /tmp/screenshot.png -scale 10% -scale 1000% -gravity center /home/user/bin/archlogo.png -composite /tmp/lock.png

# Lock using pixelated image & logo
i3lock -e -f -c 000000 -i /tmp/lock.png

The script is saved to ~/bin/lock and executable. The directory has also been identified in my ~/.bash_profile.

There is no error message, only brief flash of the terminal cursor.

The relevant lines in ~/.config/i3/config:

# lock screen
bindsym $mod+l exec lock

(the default keybind for $mod+l was deleted and i3 was restarted).

like image 644
Soundscape Avatar asked Jun 21 '18 12:06

Soundscape


1 Answers

~/.bash_profile is a configuration file for bash and as such is only loaded when bash starts (as an interactive login shell or when it is expclicitly sourced by other bash configuration files, e.g. ~/.bashrc). i3 itself does not load anything from ~/.bash_profile and neither does X.org. So unless you start your X session from a bash shell (for example with startx from the console) any changes to PATH will not have been loaded and i3 will not know about ~/bin being added to PATH.

If you want to modify PATH for i3 itself, then ~/.bash_profile is not the right place. Unfortunately for X sessions the "right place" very much depends on how you start it (e.g. from the console with start or with some desktop manager like lightdm or kdm).

You could add a setting for PATH to ~/.pam_environment, which - at least on Arch - should prepend the given value to the system default setting of PATH. For example, if you put the follwing in your ~/.pam_environment

PATH=/home/soundscape/bin

and the default value is

/usr/local/sbin:/usr/local/bin:/usr/bin

you will end up with

/home/soundscape/bin:/usr/local/sbin:/usr/local/bin:/usr/bin

Of course, this value might be further modified by any settings in ~/.bash_profile or similar files when you start bash.

Note: ~/.pam_environment does not support any parameter expansion, so adding something like

PATH=${PATH}:${HOME}/bin

will not work.

like image 70
Adaephon Avatar answered Sep 28 '22 19:09

Adaephon