How do you get a custom Gnu screen config to load .bash_profile and .bash_aliases? - gnu-screen

I have a custom screen configuration myscreenconfig and a .screenrc. myscreenconfig looks like this:
source .screenrc
screen 0 bash
title 'notes'
screen 1 bash
title 'bash'
[etc.]
.screenrc has these lines at the top:
altscreen on
shell -${SHELL}
My .bash_profile file sets a lot of things and then calls source $HOME/.bash_aliases.
If I start screen without any arguments, my .bash_profile gets loaded and .bash_aliases gets loaded. But if I start screen via screen -c myscreenconfig, only .bash_profile gets loaded, and not .bash_aliases. Why? How can I fix this?

What worked for me was making a symbolic link between wherever I had my bash settings and .bashrc (which I did not have):
ln -s ~/.bash_profile ~/.bashrc

I had the same problem on one of the machines I use. After reading the suggestion above about linking the two bash resource files, I realized that the following section had been put in comment in the .bash_profile file on this particular machine:
# Get the aliases and functions
# if [ -f ~/.bashrc ]; then
# . ~/.bashrc
# fi
After removing the comment signs (#) from before the if block lines, settings in .bashrc became available in screen sessions as well.

Because you are not using login shells in myscreenconfig. Use (IIRC) screen 0 -bash, or try combinations with deflogin on.

I'm use this in my .bashrc
if [ "$TERM" = "screen" ]; then
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile
fi
fi

Related

Google Colab Blender render Error: cannot read file

Trying to render a single frame
following this script "Blender_script_for_Google_Colab_using_the_GPU.ipynb"
by- https://github.com/donmahallem
Successfully mounted GDrive and installed Blender.
Executed all the cells from top to bottom, one by one.
This is the OUTPUT of final Cell
found bundled python: /content/blender2.83.12/2.83/python
Error: Cannot read file '/content/{/content/drive/MyDrive/Blender/donut.blend}': No such file or directory
<bpy_struct, CyclesPreferences at 0x7f6366c38ba8>
Device found CUDA
Activating <bpy_struct, CyclesDeviceSettings("Tesla T4")>
Activating <bpy_struct, CyclesDeviceSettings("Tesla T4")>
Blender quit```
ANSWER
It should be like this
!/content/blender2.83.12/blender -P './setgpu.py' -b -noaudio '/content/drive/MyDrive/Blender/donut.blend' -E CYCLES -o '/content/drive/MyDrive/Blender/test_mixed_####.png' -f 1 |& tee '/content/drive/MyDrive/Blender/log.txt'
NOT like this
!/content/blender2.83.12/blender -P './setgpu.py' -b -noaudio '{/content/drive/MyDrive/Blender/donut.blend}' -E CYCLES -o '{/content/drive/MyDrive/Blender/test_mixed_####.png}' -f 1 |& tee '/content/drive/MyDrive/Blender/log.txt'
In short I forgot to remove the curly brackets {} from "Blend_file_path" and "Output_path"
I believe you should use 'My Drive' rather than 'MyDrive' in your directory path.

Unable to override PS1 with direnv

I am following the direnv wiki on PS1. I have the following relevant entries in my files.
.bashrc
DEFAULT_PS1='\[$(ppwd)\]\u#\h:\w$(__git_ps1 " (%s)")'
# add some more things to DEFAULT_PS1, conditionally
DEFAULT_PS1+='> '
PS1=${CUSTOM_PS1:-$DEFAULT_PS1}
# optional bashrc file extensions
for f in ~/.bashrc_*; do test -s $f && . $f || true; done
eval "$(direnv hook bash)"
.envrc
export KUBECONFIG=~/.config/kube/homelab.yaml
export KUBE_PS1_ENABLED=on
export CUSTOM_PS1='$(kube_ps1) $ '
PATH_add scripts
I have allowed the latest version of the .envrc with direnv allow. However, when changing to the directory, the custom PS1 value is not set, although the values seems to be right
$ cd -
/home/robert/sources/oss/sling-cloud-native
direnv: loading .envrc
direnv: export +CUSTOM_PS1 +KUBE_PS1_ENABLED ~KUBECONFIG ~PATH
$ echo $PS1
\[$(ppwd)\]\u#\h:\w$(__git_ps1 " (%s)")$(kube_ps1)>
$ echo $CUSTOM_PS1
$(kube_ps1) $
I am not sure how the solution in the wiki is supposed to work, as apparently the value of PS1 is set to the DEFAULT_PS1 when the .bashrc file is loaded the first time and is not re-evaluated as part of the direnv hook.
How can I change the value of PS1 using direnv?
The direnv wiki mentions that the author had to "blacklist PS1 as an environment variable that can be changed," mainly because "The core issue is that PS1 is a local variable." So I don't think workarounds that involve using the .envrc file to indirectly modify the PS1 can work.
I had a similar issue with python virtual environments, which I realize is different to your use case, but there is an example in this blog that could be helpful.
Because links can die I reproduce it here:
add the following to ~/.bashrc (me: I tested this with ~/.zshrc and it also works)
show_virtual_env() {
if [[ -n "$VIRTUAL_ENV" && -n "$DIRENV_DIR" ]]; then
echo "($(basename $VIRTUAL_ENV))"
fi
}
export -f show_virtual_env
PS1='$(show_virtual_env)'$PS1
Then source the file again
source ~/.bashrc
The wiki also mentions adding unset PS1 to the .envrc file, which removes any error about direnv: PS1 cannot be exported... and I can confirm that also works with this scenario.
Perhaps you can do something similar; use .envrc to export the environment variables as you are doing, but remove the line export CUSTOM_PS1='$(kube_ps1) $ ' and in your ~/.bashrc make a function that checks if you have set KUBE_PS1_ENABLED and appends '$(kube_ps1) $ ' to PS1 if it is set.

Adding home-brew to PATH

I just installed Home-brew and now I'm trying to insert the home-brew directory at the top of my path environment variable by typing in two commands inside my terminal. My questions are these:
What is a path environment variable?
Are the two codes provided me correct?
echo "export Path=/usr/local/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile
After this I am to type in brew doctor. Nothing is happening as far as I can see.
Can anyone offer me some advice or direction?
I installed brew in my new Mac M1 and ask me to put /opt/homebrew/bin in the path, so the right command for this case is:
echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile
TL;DR
echo "export PATH=/usr/local/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile
is what you want.
To answer your first question; in order to run (execute) a program (executable) the shell must know exactly where it is in your filesystem in order to run it. The PATH environment variable is a list of directories that the shell uses to search for executables. When you use a command that is not built into the shell you are using the shell will search through these directories in order and will execute the first matching executable it finds.
For example when you type: mv foo bar the shell is almost certainly actually using an executable located in the /bin directory. Thus fully the command is
/bin/mv foo bar
The PATH environment variable therefore saves you some extra typing. You can see what is in your PATH currently (as you can with all environment variables) by entering:
echo $<NAME OF VARIABLE>
So in this instance:
echo $PATH
As I mentioned earlier, ordering is important. Adding /usr/local/bin to the beginning of PATH means that the shell will search there first and so if you have an executable foo in that folder it will be used in preference to any other foo executables you may have in the folders in your path. This means that any executables you install with brew will be used in preference to the system defaults.
On to your second question. What the command you have provided is trying to do is add a line to your .bash_profile and then source it. The .bash_profile is a text file stored in your home directory that is sourced (read) every time bash (your shell) starts. The mistake in the line you've provided is that only the first letter of PATH is capitalised. To your shell Path and PATH are very different things.
To fix it you want:
echo "export PATH=/usr/local/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile
To explain
echo "export PATH=/usr/local/bin:$PATH"
simply prints or echoes what follows to stdout, which in the above instance is the terminal. (stdout, stderr and stdin are very important concepts on UNIX systems but rather off topic) Running this command produces the result:
export PATH=/usr/local/bin:/opt/local/sbin:/opt/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
on my system because using $PATH within double quotes means bash will substitute it with its value. >> is then used to redirect stdout to the end of the ~/.bash_profile file. ~ is shorthand for your home directory. (NB be very careful as > will redirect to the file and overwrite it rather than appending.)
&& means run the next command is the previous is successful and
source ~/.bash_profile
simply carries out the actions contained in that file.
As per the latest documentation, you need to do this:
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/dhruv/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
Now you should be able to run brew from anywhere.
When you type in a program somewhere and click enter, it checks certain locations to see if that program exists there.
Linux brew uses locations different from the normal linux programs, so we are adding these locations to the ~/.profile file which sets the paths.
Run this in your terminal, and it will place the correct code in the .profile file, automatically.
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
Don't use .bash_profile because when you use something different from bash, like zsh, it may not work. .profile is the correct location.

Unable to see processes using ps comand when I configure terminal to auto load my .bashrc

My default login shell is bash. From a few online forums, I configured my terminal to auto load my .bashrc file whenever I open the terminal by adding:
source ~/.bashrc in .bash_profile OR
by adding the following code snippet in .profile:
if [ -n "$BASH_VERSION" ]; then
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
With either of the two, my .bashrc loads automatically, but with this I am unable to see the process status using ps command.
Note: If I disable the auto loading of my .bashrc and manually load it by typing bash, I am still able to see process status using the ps command.
Please help me out.
You can see what ps is mapped to by typing type ps. Compare before and after the source and you should be able to re-alias it what you're expecting.

Updating files after RVM install

I have installed RVM enroute to updating and running different ruby and rails. After install I received message to update shell's loading files.
1) Place the folowing line at the end of your shell's loading files
(.bashrc or .bash_profile for bash and .zshrc for zsh),
after all PATH/variable settings:
[[ -s "/Users/eric/.rvm/scripts/rvm" ]] && source "/Users/eric/.rvm/scripts/rvm" # This loads RVM into a shell session.
You only need to add this line the first time you install rvm.
I typed [[ -s "/Users/eric/.rvm/scripts/rvm" ]] && source "/Users/eric/.rvm/scripts/rvm"
and hit enter. Does this update my files? Or do I have to open some type of file and cut and paste code?
Since I did not see any notice as stated below from part 2 of the post install, I closed the shell and opened a new one. but the RVM command does not seem to work. Part 2 of the instructions post install was:
2) Ensure that there is no 'return' from inside the ~/.bashrc file,
otherwise rvm may be prevented from working properly.
This means that if you see something like:
'[ -z "$PS1" ] && return'
then you change this line to:
if [[ -n "$PS1" ]] ; then
# ... original content that was below the '&& return' line ...
fi # <= be sure to close the if at the end of the .bashrc.
# This is a good place to source rvm v v v
[[ -s "/Users/eric/.rvm/scripts/rvm" ]] && source "/Users/eric/.rvm/scripts/rvm" # This loads RVM into a shell session.
EOF - This marks the end of the .bashrc file
Be absolutely *sure* to REMOVE the '&& return'.
If you wish to DRY up your config you can 'source ~/.bashrc' at the bottom of your .bash_profile.
Placing all non-interactive (non login) items in the .bashrc,
including the 'source' line above and any environment settings.
Thanks for the help as I am very new and trying to learn RoR but so far have not been able to get past the setup in many of the tutorials I've attempted. It seems many [
1 2 are out of date with new software or I get error messages before I can even attempt to learn the code. If someone knows of a good beginner tutorial that would be great. Thanks again!
The snippet that the installer gives you need to go in a file called the bashrc. The file lives in your home directory: /Users/eric/.bashrc
You need to edit this file and add the line from rvm and then you should be good to go.
As for getting rolling with rails I'd recommend The Pragmatic Programmers book on rails. You can find their books at pragprog.com
If you're on Ubuntu, my tutorial on setting rvm will get you roll all the way up to rails installation:
http://blog.dcxn.com/2011/06/20/setting-up-rvm-on-ubuntu-11-04/