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...
Related
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.
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
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).
I am learning a little bit of bash in Linux and I just can't understand why this doesn't work. It is a simple IF statement and a read command to keep the window opened. What happens is that when I execute the .sh file the terminal's window opens for a second and closes back. I can't see any message or check whether there's any error or why it doesn't work. If I remove the IF block then I can see the message and the window remains opened. This is the code inside my file
count=99
if [ $count -eq 100 ]; then
echo "Count is 100"
else
echo "Count is not 100"
fi
read -p "Press enter to continue" nothing
I tried many other ways of using the IF structure but seems like none works
Use the dos2unix utility to convert the text file created on Windows to the correct format for Linux. See this wikipedia page for more details.
Install if necessary:
$ sudo apt-get install dos2unix
<snip>
Setting up dos2unix (5.3.1-1) ...
$
Run it on your script:
$ dos2unix if.sh
dos2unix: converting file if.sh to Unix format ...
$
Your script is completely correct. atleast its okai in my linux mint
Because you (lovely) people are always so curious about posters' original intents, here's mine:
If I'm on a Mac and have a GUI (as opposed to, say, being on an ssh session), I want to set my $EDITOR to mate_wait. (And go with vim otherwise.)
And, you have an answer for that. I do too. It even works. Here. Sometimes.
So I want you to fiercely scrutinize it:
Skip intro
I can tell that I'm on a Mac by checking:
[ `uname` = 'Darwin' ]
And I think I can sort of tell that I have a GUI by checking:
[ "$TERM_PROGRAM" = 'Apple_Terminal' ]
# or
[ "$DISPLAY" ]
Now, it's theoretically possible that I have an Aqua-less OpenDarwin setup running X11. It's also possible that I'm running fully lickable Mac GUI, yet using another terminal application.
And then there's the mind-bending possibility that I'm running xterm within Apple's X11 running on top of the OS X GUI. In which case I'd still want mate_wait as $EDITOR.
For OCD's sake, I'd like my checks to be as precise as possible.
So, please, un-reckless-fy my code.
I'll take a stab at this, mind you it's probably incomplete.
Condition 1: Am I local
[ -z "$SSH_CLIENT" ]
Condition 2: Am I remote
[ -n "$SSH_CLIENT" ]
Condition 3: Do I have the lickable mac GUI
[ -n "`ps -fe | grep '[W]indowServer'`" ]
So putting these together:
if [ -z "$SSH_CLIENT" -a -n "`ps -fe | grep '[W]indowServer'`" ]; then
EDITOR="matew"
else
EDITOR=vim
fi
You will need a script called 'matew' that simply does:
#!/bin/sh
exec mate -w "$*"
as EDITOR is only expected to be a direct command, and won't work if it's 'mate -w' (at least on snow leopard).
You can ask launchctl what is managing the current session.
if [ "$(launchctl managername)" == Aqua ]; then
EDITOR="matew";
else
EDITOR="vim";
fi;