{"id":7442,"date":"2023-12-13T20:08:30","date_gmt":"2023-12-13T20:08:30","guid":{"rendered":"https:\/\/rakhesh.com\/?p=7442"},"modified":"2023-12-13T20:08:30","modified_gmt":"2023-12-13T20:08:30","slug":"vscode-vscodium-unable-to-resolve-your-shell-environment","status":"publish","type":"post","link":"https:\/\/rakhesh.com\/linux-bsd\/vscode-vscodium-unable-to-resolve-your-shell-environment\/","title":{"rendered":"VSCode\/ VSCodium – Unable to resolve your shell environment…"},"content":{"rendered":"

(Am on a roll this week! After a long dry spell this is my 4th post in 3 days \/ 5th post this month…)<\/p>\n

Since earlier this week whenever I’d launch VSCode or VSCodium (yes I started using the latter now) I’d always get a message saying its unable to resolve my shell environment. Like here<\/a>.<\/p>\n

I tracked it down to the fact that earlier this week I had started launching tmux<\/code> by default on my desktops. Previously I would only launch it when SSHing into a machine but I figured it’s good to have it always launch on my desktops so I can easily connect to them from elsewhere. This was obviously interfering with VSCode. Interestingly, I had added the tmux<\/code> launching code in .bash_profile<\/code> so as to limit it to login sessions, but I guess VSCode launches bash as a login shell.<\/p>\n

What to do here? Inspired by this GitHub issue <\/a>I added the following line to my .bash_profile<\/code> and disabled the bit that launches tmux<\/code>.<\/p>\n

env > ~\/Downloads\/blah.txt<\/pre>\n

This dumps the environment variables that are present when the shell is launched by VSCode. Here I found a variable VSCODE_RESOLVING_ENVIRONMENT<\/code> that was set to 1. Boom, that’s my entry!<\/p>\n

Before I go further, here’s how I currently launch tmux<\/code>.<\/p>\n

# Machines where I always want to launch tmux\r\ntmux_by_default=(\r\n    \"machine1\"\r\n    \"machine2\" \r\n)\r\n\r\n# A function to join the array\r\n# https:\/\/stackoverflow.com\/questions\/1527049\/how-can-i-join-elements-of-a-bash-array-into-a-delimited-string\r\nfunction join_by { local IFS=\"$1\"; shift; echo \"$*\"; }\r\n# So join_by \"|\" \"${tmux_by_default[@]}\" will create \"machine1|machine2\" which I can then regex over :)\r\n\r\n\r\nif [[ $(hostname) =~ $(join_by \"|\" \"${tmux_by_default[@]}\") ]] || [[ ! -z \"$SSH_TTY\" ]]; then\r\n    # Check if tmux is installed, else warn that\r\n    if command -v tmux &> \/dev\/null; then\r\n\r\n        # Check if I am in a tmux session already. If I am not in one then $TMUX is empty. \r\n        if [[ -z \"$TMUX\" ]]; then\r\n            if tmux ls | grep -qv attached; then\r\n                # attach to the existing session and when it exits if the exit code is 0 then exit the shell (C-b d in tmux has exit code 0)\r\n                exec tmux at && exit\r\n            else\r\n                # create a new session and when it exits if the exit code is 0 then exit the shell (C-b d in tmux has exit code 0)\r\n                exec tmux new-session && exit\r\n            fi\r\n        fi\r\n\r\n    else\r\n        echo -e \"tmux missing!\"\r\n    fi\r\nfi<\/pre>\n

For certain machines it always launches, for the rest only if I am connecting via SSH. So I made one change:<\/p>\n

# Machines where I always want to launch tmux\r\ntmux_by_default=(\r\n    \"machine1\"\r\n    \"machine2\" \r\n)\r\n\r\n# A function to join the array\r\n# https:\/\/stackoverflow.com\/questions\/1527049\/how-can-i-join-elements-of-a-bash-array-into-a-delimited-string\r\nfunction join_by { local IFS=\"$1\"; shift; echo \"$*\"; }\r\n# So join_by \"|\" \"${tmux_by_default[@]}\" will create \"machine1|machine2\" which I can then regex over :)\r\n\r\n\r\nif ([[ $(hostname) =~ $(join_by \"|\" \"${tmux_by_default[@]}\") ]] && [[ -z \"$VSCODE_RESOLVING_ENVIRONMENT\" ]]) || ([[ ! -z \"$SSH_TTY\" ]]); then\r\n    # Check if tmux is installed, else warn that\r\n    if command -v tmux &> \/dev\/null; then\r\n\r\n        # Check if I am in a tmux session already. If I am not in one then $TMUX is empty. \r\n        if [[ -z \"$TMUX\" ]]; then\r\n            if tmux ls | grep -qv attached; then\r\n                # attach to the existing session and when it exits if the exit code is 0 then exit the shell (C-b d in tmux has exit code 0)\r\n                exec tmux at && exit\r\n            else\r\n                # create a new session and when it exits if the exit code is 0 then exit the shell (C-b d in tmux has exit code 0)\r\n                exec tmux new-session && exit\r\n            fi\r\n        fi\r\n\r\n    else\r\n        echo -e \"tmux missing!\"\r\n    fi\r\nfi<\/pre>\n

Now the section that always launches it on certain machines also checks if the VSCODE_RESOLVING_ENVIRONMENT<\/code> variable is empty and only then launches.<\/p>\n

Sweet!<\/p>\n

ps.<\/strong> I knew about VSCodium<\/a> but didn’t really look into switching to it. Then I came across this blog post <\/a>and that resonated with me so I started making the switch. I still have VSCode around coz a couple of the extensions I use only work with it, but I primarily use VSCodium otherwise. I recommend others too give it a shot. I also recommend the Night Owl<\/a> theme, it’s available on both.<\/p>\n","protected":false},"excerpt":{"rendered":"

(Am on a roll this week! After a long dry spell this is my 4th post in 3 days \/ 5th post this month…) Since earlier this week whenever I’d launch VSCode or VSCodium (yes I started using the latter now) I’d always get a message saying its unable to resolve my shell environment. Like … Continue reading VSCode\/ VSCodium – Unable to resolve your shell environment…<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[76,853],"tags":[931,1042],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/posts\/7442"}],"collection":[{"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/comments?post=7442"}],"version-history":[{"count":1,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/posts\/7442\/revisions"}],"predecessor-version":[{"id":7443,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/posts\/7442\/revisions\/7443"}],"wp:attachment":[{"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/media?parent=7442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/categories?post=7442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rakhesh.com\/wp-json\/wp\/v2\/tags?post=7442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}