How to disable Powerlevel10k in Warp and install Starship - terminal

I just installed Warp terminal and I'm loving it.
But I want to customize the prompt with Starship and still having Powerlevel10k on my iTerm2 terminal. Does it is posible?

After a few hours I managed to install Starship on Warp and still having Powerlevel10k on iTerm (and all the others terminals ) modifying my .zshrc file as the Warp documentation says.
So at the start of the file I wrapped the Powelevel10k initialization to only activate it if the terminal is not Warp:
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ $TERM_PROGRAM != "WarpTerminal" ]]; then
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
fi
And I wrapped the Starship initialization only for Warp at the end of the file:
if [[ $TERM_PROGRAM == "WarpTerminal" ]]; then
eval "$(starship init zsh)"
fi

I would add to #Christian answer small hint in case of still missing prompt:
if [[ $TERM_PROGRAM == "iTerm.app" ]]; then
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
fi
That shell integration quite often cause a issue (e.g. https://github.com/warpdotdev/Warp/issues/1518) - the same was for me and the conditional initialisation helped to solve the problem.

Related

How to use STDOUT inside /etc/ssh/sshrc without breaking SCP

I want to call a program when any SSH user logs in that prints a welcome message. I did this by editing the /etc/ssh/sshrc file:
#!/bin/bash
ip=`echo $SSH_CONNECTION | cut -d " " -f 1`
echo $USER logged in from $ip
For simplicity, I replaced the program call with a simple echo command in the example
The problem is, I learned SCP is sensitive to any script that prints to stdout in .bashrc or, apparently, sshrc. My SCP commands failed silently. This was confirmed here: https://stackoverflow.com/a/12442753/2887850
Lots of solutions offered quick ways to check if the user is in an interactive terminal:
if [[ $- != *i* ]]; then return; fi link
Fails becase [ is not linked
case $- in *i* link
Fails because in is not recognized?
Use tty program (same as above)
tty gave me a bizarre error code when executed from sshrc
While all of those solutions could work in a normal BASH environment, none of them work in the sshrc file. I believe that is because PATH (and I suspect a few other things) aren't actually available when executing from sshrc, despite specifying BASH with a shebang. I'm not really sure why this is the case, but this link is what tipped me off to the fact that sshrc is running in a limited environment.
So the question becomes: is there a way to detect interactive terminal in the limited environment that sshrc executes in?
Use test to check $SSH_TTY (final solution in this link):
test -z $SSH_TTY || echo $USER logged in from $ip

BASH: Determine if script was called from virtual machine (Ubuntu), or the W10 bash app?

Is there a way for a shell script to determine if it is called from a terminal in a virtual machine running Ubuntu, or a W10 terminal using the bash call (installed Ubuntu app in W10)?
I am working in both environments and have a lot of useful shell scripts to make my work more efficient on the virtual machine, e.g. opening specific URLs or running sets of commands. I would like them to work on the Windows side as well. However, my scripts sets up directories which will have to be different on my Windows side.
I have installed the ubuntu app from Windows Store, which allows me to open a bash window and source the files. I could just check if ~ returns an empty string, but is there a more robust way of doing it?
I am running Windows 10, version 17763 and using Ubuntu 18.04 LTS.
E.g.
C:\.sourceThis.sh
#!/bin/bash
myDir="/home/user/stuff"
cdMySub() {
cd "$myDir/$1"
}
I can run this in a Windows terminal by
C:\> bash
USER#XXXX:/mnt/c/$ source ./.sourceThis.sh
USER#XXXX:/mnt/c/$ cdMySub someSubDirectoryName
-bash: cd: /home/user/stuff/someSubDirectoryname: No such file or directory
USER#XXXX:/mnt/c/$ #Fail!
but it does not work, since the Ubuntu file system is different to Windows.
I would like to change .sourceThis.sh to something like
...
if [[ "Something that detects virtual machine" ]] ; then
myDir="/home/user/stuff"
elif [[ "Something that detects 'bash' from Windows prompt" ]] ; then
myDir="/mnt/c/user/stuff"
fi
so that the outcome is instead
C:\> bash
USER#XXXX:/mnt/c/$ source ./.sourceThis.sh
USER#XXXX:/mnt/c/$ cdMySub someSubDirectoryName
USER#XXXX:/mnt/c/stuff/someSubDirectoryName$ #Yeay, success!
EDIT:
I cannot just check for the validity of the default directory, since the scripts create the directory if it does not exist. I want it to point to another default path instead.
I use different user names, so I could check that the output from ~ is the "Windows or VM user".
USER#XXXX:/mnt/c$ echo ~
/home/USER
Thus,
tmpHome=~
if [[ "${tmpHome##*/}" == "USER" ]] ; then
# Windows user
elif [[ "${tmpHome##*/}" == "VM" ]] ; then
# VM user
fi
works for my specific user. However, I suspect that I want to use this on different users (e.g. share it with a colleague). This demands a more robust way.
I am not too experience with Linux. I do not know how to navigate the world of users, processes and tasks, which I suspect can give the answer.
I have used this for a long time successfully:
if [[ "$(uname -r)" == *Microsoft ]]; then
do stuff
fi
You could always use an if condition checking whether the path exists, and run the script from there :
if [[ -f /home/user/stuff ]]; do
script if running on linux
else
script if running on windows
fi
Here the -f flags is a bash condition checking whether the file at specified path exists, returns true if it does. You can add other validations to check whether the file also exists when running on Windows and whatnot.
Bash provides information about the system that is running it it the MACHTYPE, HOSTTYPE, and OSTYPE built-in variables.
Example values for a physical Linux system are:
MACHTYPE=x86_64-redhat-linux-gnu
HOSTTYPE=x86_64
OSTYPE=linux-gnu
Example values for a WSL Linux system are:
MACHTYPE=x86_64-pc-linux-gnu
HOSTTYPE=x86_64
OSTYPE=linux-gnu
One possible way to check if the system is WSL Linux is:
if [[ $MACHTYPE == *-pc-* ]]; then
...
fi
#Dexirian and #Michael Hoffman suggested a method that worked!
For me uname -r returns x.x.x-17763-Microsoft from the Windows prompt and x.x.x-xx-generic on my virtual machine.
Thus,
if [[ "$(uname -r)" =~ "Microsoft" ]] ; then
myDir="/mnt/c/user/stuff"
elseif [[ "$(uname -r)" =~ "generic" ]] ; then
myDir="/home/user/stuff"
fi
works like a charm!

Troubleshooting a script for my RPI to toggle displays

So I have a Quimat LCD attached to my gpio.
included is a script which runs to switch to the display (LCD35-show), and another to switch back to the HDMI port (LCD-hdmi). This causes a reboot when done so any variable changes have to happen prior to this.
as this is for my mother who is afraid of touching command prompt, I am trying to set up a single icon to use to switch between video sources.
I am a novice at coding, most of my experience from dabbling in BASIC, and have spent a couple days searching and trying to set this up, but apparently am failing at how to search properly as I couldn't get it functioning.
What I have done so far is this:
Created text file state.txt to hold a variable stating what mode the device is in (HDMI or LCD)
My attempt was to read the variable, then use if then statement to determine which file to run, change the variable then run the file.
This is the code I ended up with.
!/bin/bash
read var < state.txt
if var == HDMI
then
echo LCD > state.txt
cd LCD-show/
sudo ./LCD35-show
else
echo HDMI > state.txt
cd LCD-show/
sudo ./LCD-hdmi
fi
I am hoping someone can show me what I did wrong, and hopefully explain what I missed in the process.
Be careful with your bash script comparisons.
Wrap strings in quotes (or some other method), so it's not a syntax error when string-vars evaluate to empty. You can use == for string comparisons in bash, but = works in bash and sh.
#! /bin/bash
EXE=`basename "$0"`
LCD_DIR="LCD-show"
STATE_FILE="state.txt"
if [ ! -d "$LCD_DIR" ]; then
echo "$EXE: $LCD_DIR does not exist"
exit 1
fi
read var < state.txt
if [ "$var" = "HDMI" ]; then
echo LCD > "$STATE_FILE"
cd "$LCD_DIR"
sudo ./LCD35-show
else
echo HDMI > "$STATE_FILE"
cd "$LCD_DIR"
sudo ./LCD-hdmi
fi
The difference between a good script and a great script is error handling.
What happens when the dir LCD-show does not exist? (for whatever reason).

Solution for using iTerm2 'shell integration' and screen (over ssh)

So when i ssh into a remote server i use 'screen -R myscreen' to prevent any running scripts/processes from being interrupted when the ssh connection disconnects, for whatever reason (bad wifi, etc).
However, when starting screen, iTerm2's shell integration doesn't work anymore.
Is there any workaround for this?
fyi the solution i found is:
instead of 'screen' use 'tmux', by executing tmux -CC to open a tmux session (and using tmux -CC attach to re-attach after a disconnection.)
This is also described here.
To make iTerm2 shell integration work in tmux, modify ~/.iterm2_shell_integration.bash and remove this part of the first line:
"$TERM" != screen
So this
if [[ "$TERM" != screen && "$ITERM_SHELL_INTEGRATION_INSTALLED" = "" && "$-" == *i* ]]; then
becomes:
if [[ "$ITERM_SHELL_INTEGRATION_INSTALLED" = "" && "$-" == *i* ]]; then
You can use triggers to replicate almost all of the features of shell integration. See the Triggers section near the bottom of this document: https://www.iterm2.com/documentation-shell-integration.html

Weird interaction between gvm, .profile and lightdm Ubuntu 14.10

Good morning everyone,
I have a strange interaction problem between gvm, my .profile and lightdm on Ubuntu 14.10.
The line that gvm puts at the end of .profile looks like this:
[[ -s "/home/clh/.gvm/bin/gvm-init.sh" ]] && source "/home/clh/.gvm/bin/gvm-init.sh"
It seems that lightdm, which I guess processes .profile upon login, doesn't like that line, for a popup during the login process states
/usr/sbin/lightdm-session: 25 /home/clh/.profile: [[ not found
To me this looks like lightdm is using sh and not bash to handle the test. It also seems like this must be a recent change because I have been using the gvm - lightdm combo for several months now and I just started noticing this in the last week or so.
Anyway, I have "fixed" this by changing my .profile so that the last line, put in by gvm, now looks like:
if [ -n "$BASH_VERSION" ]; then
[[ -s "/home/clh/.gvm/bin/gvm-init.sh" ]] && source "/home/clh/.gvm/bin/gvm-init.sh"
fi
I say "fixed" because the popup message has gone away and gvm seems to run.
But if anyone else has any better ideas, I'm all ears...

Resources