How to setup zsh personal config (.dotfiles/zsh/zshrc) at every start on Raspberry Pi 400 - raspberry-pi

I am training myself on Linux with a Raspberry Pi 400 (OS: Raspbian) and I would like to setup my personal config file for apps (notably the Terminal in Zsh). I am able to setup my config onto the terminal with the following:
$ cd .dotfiles
$ ./export.sh
$ cd zsh/
$ source ./zshrc
The problem comes when I quit the terminal or if I open a new terminal or if I reboot the computer, the config is not "saved".
I am not an expert, but for changing bash to zsh and maintaining it as default shell language, I did the following:
$ nano /etc/passwd
and changed the following line from :
pi:x:1000:1000:,,,:/home/pi:/bin/bash
to:
pi:x:1000:1000:,,,:/home/pi:/bin/zsh
This move managed to get me zsh from start every time now. I am wondering if i can directly source my .zshrc with the same technique ... Or would you have any better idea?
I would like to avoid repeating the sourcing steps at every start in the terminal ...

Related

VSCode - remote SSH - can't find code executable in vscode-server directory

I'm using VSCode and the official remote-ssh extension.
I would like to be able to write code /path/to/file in an ssh terminal or in the vscode integrated terminal in a remote window in order to open a file/folder in vscode remote.
I am aware that I can use code --folder-uri=vscode-remote://ssh-remote+ADDRESS/path/to/file from the local machine's terminal, but I want to be able to run a command from within the integrated vscode terminal and any other terminal session where I've ssh'd into the remote machine)
Currently, if I run code from a remote terminal it opens up a new vscode window on the remote machine.
To achieve this goal, in the past I've used the following alias on the remote machine:
alias code="${VSCODE_GIT_ASKPASS_NODE%/*}/bin/code"
Which looks for the code executable in ~/.vscode-server/bin/<COMMIT_ID>/bin before defaulting to the local /bin/code.
I got that alias from this related stackoverflow question.
However, this doesn't seem to work right now.
Upon closer inspection, it appears that there is no code executable in the vscode-server directory.
How can I fix this?
Both machines are running MacOS and visual studio code version f80445acd5a3dadef24aa209168452a3d97cc326, if that's relevant.
I also wanted to be able to run code from the integrated terminal when running VSCode with the "remote ssh" extension. In my case, the "remote" is a Linux box (named "aorus" below), and I want to use VSCode from a laptop running macOS (named "mbp").
As for you, I used to use the VSCODE_GIT_ASKPASS_NODE trick. Recently, I had to change the alias since code (or code-insiders in my case) wasn't available in bin/ anymore. It seems it has been moved to bin/remote-cli. The correct alias (tested with vscode 1.64.2):
alias code="${VSCODE_GIT_ASKPASS_NODE%/*}/bin/remote-cli/code"
If you also want this to work from other ssh sessions (not just inside the integrated terminal), you can create a short script that I called coder (r for "remote") which I have in ~/bin on my remote ("aorus"). Note that you need to be able to reach the local machine from your remote (I do that with Tailscale). The script looks like this:
#! /bin/bash
set -ex
remotehost=$(hostname)
localhost=mbp
cmd="code"
while [ $# -gt 0 ]; do
if [ -f "$1" ]; then
cmd+=" --file-uri \"vscode-remote://ssh-remote+$remotehost$(readlink -f "$1")\""
elif [ -d "$1" ]; then
cmd+=" --folder-uri \"vscode-remote://ssh-remote+$remotehost$(readlink -f "$1")\""
else
cmd+=" $1"
fi
shift
done
exec ssh $localhost -q -t -x "exec bash -l -c '$cmd'"
On my Mac, when running VSCode connected remotely to my Linux box, I can type this in the integrated terminal to open the file main.go present on my remote Linux box:
coder main.go
The reason I have to wrap code in bash -l is due to the fact that ssh, by default, runs in a non-login shell, which means that the ~/.bashrc on my Mac isn't picked up, meaning code isn't in the PATH. The error message looks like this:
bash:1: command not found: code
Another note: there is a shorter syntax documented here:
ssh -q -t -x mbp bash -l -c "code --remote=ssh-remote+aorus main.go"
I don't use this syntax is because this method isn't able to know whether you are opening just a single file (which should be open in the most recent VSCode remote session) or a folder (which should be open as a new VSCode remote session).
Finally, if you are using VSCode Insiders, you can create a symlink so that the command code works on your local machine (in my case, on my Mac):
sudo ln -sf /usr/local/bin/code-insiders /usr/local/bin/code
As already explained by maelvls the path has been changed.
But if you use it outside integrated terminal you will got message
Command is only available in WSL or inside a Visual Studio Code terminal
To avoid this you need to export VSCODE_IPC_HOOK_CLI in your .bashrc .
Use this script in your .bashrc
export VSCODE_IPC_HOOK_CLI=`ls -t /run/user/1012/vscode-ipc-* | head -n1`
alias code="~/.vscode-server/bin/*/bin/remote-cli/code"
If you want to open your file in your current visual studio use -r option.
code -r tes.txt
Note :
I can't call VSCODE_GIT_ASKPASS_NODE so I use full path, it is working well
I don't know if VSCODE_IPC_HOOK_CLI will show in different location, just check it in your integrated terminal visual studio code
tested on remote server Centos 7
local macOS Monterey version 12.2
Visual Studio Code Version: 1.64.2 (Universal)
Commit: f80445acd5a3dadef24aa209168452a3d97cc326
extension : remote-ssh

Set global environment variables in VS Code with remote-ssh

I have the case that I need to use VS Code installed on Windows 10 and run it with the extension Remote - SSH on a RHEL 7.x.
The default RHEL 7.x runs with git 1.8.x. I have installed a newer git version but this is not in the default $PATH environment.
I have found this instructions https://code.visualstudio.com/docs/remote/wsl#_advanced-environment-setup-script which describe how to set the environment variables specifically for VS Code when usind WSL.
If you want to run additional commands or modify the environment this can be done in a setup script ~/.vscode-server/server-env-setup
This does seem to work only if you use WSL. Why does this not work with the Remote - SSH extension?
My special case is that I only want and need the git>=2 while usind VS Code. When I am connected regularly via ssh I would like and need the OS default tools and settings.
This gives me the special request that I don't want to edit the ~/.bashrc, ~/.cshrc or any other user environment files.
I would like to be able to edit the environment for VS Code only. Some kind, maybe like:
#!/bin/bash
export PATH=/opt/rh/rh-git29/root/usr/bin\:$PATH
export LD_LIBRARY_PATH=/opt/rh/httpd24/root/usr/lib64:$LD_LIBRARY_PATH
...
#!/bin/csh
setenv PATH /opt/rh/rh-git29/root/usr/bin\:$PATH
setenv LD_LIBRARY_PATH /opt/rh/httpd24/root/usr/lib64:$LD_LIBRARY_PATH
...
Is there anything I have not found yet where I can make my requests to work or would this be some kind of request to the VS Code Team?
Regards.
I think I found the solution in this issue comment and the follow-up response:
When vscode-server initially starts, it uses a login shell, sourcing .profile in your home directory.
However, any following interactive shells started through VS Code are non-login shells and thus only source .bashrc
A complication in fiddling with this is that vscode-server apparently caches the environment during its lifetimes, so changes to these dotfiles don't become visible until the server is restarted.
I have a better solution to minimize the proxy scope
export http_proxy=<proxy here>
export no_proxy=<no proxy here>
while IFS= read -r _file; do
if ! grep -s -q "export http_proxy=" "${_file}"; then
sed -i -e "/^ROOT/i export http_proxy=${http_proxy}" -e "/^ROOT/i export https_proxy=${http_proxy}" -e "/^ROOT/i export no_proxy=${no_proxy}" "${_file}"
fi
done < <(find ~/.vscode-server/bin -type f -name "server.sh")

Creating a bat file to run raspberry pi commands on windows

I am trying to set up a simple bat file to help non-tech people execute scripts by just clicking a file on desktop.
I haven't used windows in a while, and don't have a real dev environment set up on the computers they are going to be using. I installed putty, and can manually ssh into the pi's and run commands, but I can't teach that process to the employees.
I would like to create a simple bat file that runs the following commands:
ssh pi#192.168.1.xxx
<enter password>: 'xxx'
sudo reboot
Is there a way to do this?
Thank you!
Downloaded Plink #
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
I moved it, AND putty to c:/windows/system32 instead of changing PATH
This doesn't seem necessary, as the next step will automatically locate the file and change the path.
On desktop, right click and create a new shortcut.
In the shortcut path, I typed:
plink -ssh username#192.16.1.xxx -pw raspberry sudo reboot
This worked.
if you recheck the shortcut again, it should automatically change the path to execute plink

Setting up mongoDB raspberry pi

i just installed mongopi from https://github.com/RickP/mongopi and it working correctly after doing a few adjustments mainly $ sudo chown $USER /data/db. However my mongo and mongod calls arent persistent i do PATH=$PATH:/opt/mongo/bin/ &
export PATH however this does not last on next ssh session. Also how can I make mongo initialize at startup? I did all the steps from the github repo.
For the path part of the question:
To get the path working you should put it in a script that runs every time you log in. Generally there is a rc-file for you shell in your home directory. Type
echo $SHELL
to see what shell you are running. Go to your home directory:
cd
and then open the file that is called .(your shell)rc - that is, if you are running bash, open .bashrc
nano .bashrc
add the path at the end of this file:
PATH=$PATH:/opt/mongo/bin
export PATH
For the initialization part of the question:
Download and edit this script: Mongo init.d at github
You'll need to change the value of the DEAMON at line 50. I had some other troubles, but you should probably be ok if you create a configuration file (that probably could be empty) and refer to it from line 57. Also, you need to add a mongodb user that the server should run as. You can edit this on line 95, but the default is probably a good idea.
When all this editing is done, you move the file to /etc/init.d/mongodb, like so:
sudo mv init.d /etc/init.d/mongodb
and then add it to the systems start-up routine
sudo update-rc.d mongodb defaults
(This is presuming you run debian. Other distros may have other commands to do this.)
Now, see to that you are not running mongod some other place, and control the service by
sudo service mongodb start
service mongodb status
sudo service mongodb stop
... and so on. This will also run automatically on start-up and shutdown.

OpenSuse - Command for Beep Sound (System Bell)

I have a source code that runs perfectly fine on Ubuntu, it does some copumtations, and at some points it beeps like this
system("beep -f 400 -l 500");
On Ubuntu I had to do
apt-get install beep
However, I migrated to OpenSuse (not my choice) and now I get this message "sh: beep: command not found", as the command and package are obviously different.
Does anybody know hot to trigger the system beep sound and define the duration and frequency? I have been able to find only one way to change the parameters
setterm -bfreq 500 -blength 500
, but no way to actually trigger the system bell (beep). The following things don't work
echo ^G
echo -e "\a"
PS - the system Bell is enabled at
Configure Desktop -> Application and System Notifications -> System Bell
and you can actually play with this
So, I did what #fvu proposed.
However, one needs to have sudo rights, to do so, otherwise (e.g. at my work-place we don't have sudo rights) there is this output message
Could not open /dev/tty0 or /dev/vc/0 for writing open: No such file or directory
In this case, you should:
sudo chmod 4755 /usr/bin/beep
as proposed here
I noticed that on my OpenSuse 12.3 system, the bell is working in xterm or gnome-terminal, but not in konsole or xfce4-terminal.
If the same applies to your system, then maybe a work-around could be creating a shell script called "beep" which calls xterm and rings the bell:
#!/bin/sh
xterm -e "echo -e '\a'; sleep 1"