awesomeWM / awesome

awesome window manager

Home Page:https://awesomewm.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Shell environment not correct while using `awful.spawn_with_shell`?

bricebasty opened this issue · comments

Output of awesome --version:

awesome v4.3 (Too long)
• Compiled against Lua 5.4.4 (running with 0.9.2)
• D-Bus support: ✔
• execinfo support: ✔
• xcb-randr version: 1.6
• LGI version: /usr/share/lua/5.4/lgi/version.lua

How to reproduce the issue:

  • Using awful.spawn("code") or awful.spawn_with_shell("code") to spawn VSCode
  • Having rbenv installed as in documentation (through .bash_profile/.bashrc or .zshrc)
  • Having Shopify Ruby LSP extension, Solargraph, or any VSCode extension that would need rbenv (or probably any ruby version manager) installed

Originally posted by @solowdev in Shopify/ruby-lsp#1216 (comment)

Actual result:

  • Getting this error:
Automatic Ruby environment activation with rbenv failed: 
Command failed: 
rbenv exec ruby -W0 -rjson -e 'STDERR.print({env: ENV.to_h,yjit:!!defined?(RubyVM::YJIT),version:RUBY_VERSION}.to_json)'
/bin/sh: line 1: rbenv: command not found

Expected result:

  • Extensions should be working.
  • Environment/Path should be loaded from the current user profile.

Workaround found:

  • I figured out that launching the .desktop file made everything work. So I used awful.util.spawn("gtk-launch code.desktop") instead and no issues so far.

This is a minor issue but it can be annoying to deal with.

This is how shell environments are designed to work.

Bash only reads .bashrc when it's run as a interactive, non-login shell. .bash_profile is used when it's run as an interactive login shell.
Similar conditions apply for zsh and others.

The common condition is "interactive", but awful.spawn.with_shell is not an interactive session. Therefore neither of those files are used.

The bash man page explains this in detail in the INVOCATION section.

Thank you for the clarification!

Now, I get that it's supposed to work this way. However, what I still don't quite understand is that I used to never have this problem before. With the same config, same everything. Shell environment somehow was the good one. Not a major issue though.

If you were me in that situation, how would you tackle this problem in the cleanest manner possible? (if not using gtk-launch). I don't expect any answer if you don't have the time/energy for it though :)

Thanks again and have a great week.

what I still don't quite understand is that I used to never have this problem before. With the same config, same everything

Nothing has changed on AwesomeWM's side, so something else did. But it'd be hard to track down.

If you were me in that situation, how would you tackle this problem in the cleanest manner possible?

Two options:

  • Start AwesomeWM with the required environment variables. Then, everything started through it will inherit those values.
  • Create a small shell script that sets up the stuff you need, e.g. awful.spawn("run_with_rbenv.sh code")

Thanks a lot!

EDIT:

Been going with launching AwesomeWM in a shell script with environment variables.

  1. Create a shell script named start_awesome.sh in your home directory
#!/bin/sh
# Set environment variables
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

# Start AwesomeWM
exec awesome
  1. Enter this command in your terminal to open the desktop file of AwesomeWM:
    sudo nano /usr/share/xsessions/awesome.desktop

  2. Edit the desktop file of AwesomeWM like so: (change your_username on line 5)

[Desktop Entry]
Name=awesome
Comment=Highly configurable framework window manager
TryExec=awesome
Exec=/home/your_username/start_awesome.sh
Type=Application

Clean and configurable.