« first day (3709 days earlier)      last day (1244 days later) » 

1:23 AM
When I ssh to a particular server, I don't have a home directory or access to /etc/bashrc, but I need to have some functionality dumped into the shell without manually copying and pasting from a file into my stdin. Just assume I can't create any files on the server machine. I've been doing the following, but now autocomplete isn't working...
ssh_()
{
    ssh $1 "
    export PS1=\"$PS1\"
    /bin/bash -himBH"
}
and echo $- gives me hiBH and my startup message says bash: no job control in this shell
 
@AaronHall Use ssh -t
 
oh, -t I remember seeing that before...
sweet, it works, but why didn't I need to do it before, when I was doing plain vanilla ssh?
 
it doesn't allocate a pseudo-terminal by default when you provide a command
 
mkay
 
1:38 AM
same reason ssh localhost vim falls over, it's treated as a non-interactive session by SSH
and then Bash treats a session that has no TTY like that
 
Any tips for getting a command nicer than ssh_?
(ugly)
 
Probably ssh screen -R ... failing is a better example
@AaronHall command ssh -t "..."
 
I mean, any tips for improving the naming?
 
I mean call it "ssh" and branch on the host, if applicable
Actually presumably you can do this in .ssh/config
 
Host yourServer
    HostName <IP, FQDN or DNS resolvable name>
    IdentityFile ~/.ssh/<your keyfile>
    RemoteCommand /bin/bash -himBH
    RequestTTY force
    User <yourUsername>
 
1:44 AM
^^ that, plus SetEnv
In fact RemoteCommand export ... ; bash ... does work, so you don't need the server to accept environment variables
 
oh, neat.
ok, I can do this RemoteCommand for all the entries, can't I?
just put it at the end, right?
 
do Host * and then remove HostName
or yeah
 
I don't really need commands, I need to put in functions and environment variables.
SendEnv, huh?
 
SetEnv is to set variables, SendEnv is to copy values from your own environment variables
But it's common that only a specific list of environment variables are accepted by the server configuration
 
I hope PS1 is...
 
1:56 AM
Unlikely
 
I would imagine they restrict some because setting them could be a security vulnerability
 
The configuration can permit all variables, but if it doesn't then RemoteCommand is probably your only route
 
Kinda silly to prohibit it when you can workaround it with another option
 
The default is to accept no variables (except TERM)
Kinda silly for the default configuration of security software to be to permit bypassing restricted environments, though perhaps it could become restricted only when one of some other list of options was specified
For example, Debian's default sshd_config accepts only TERM, LANG, and LC_*
 
:/ well, then I need the workaround...
 
2:06 AM
The good news is that RemoteCommand just uses the entire rest of the line, so you can write any command you want there including semicolons and pipes (but you have to double any % signs, which may be relevant)
 
2:32 AM
RequestTTY yes and I think I don't need -t
$PS1 doesn't work...
hmm... now how to get my PS1 in there...?
 
2:47 AM
I'm tempted to have the config file auto-generated...
 
so emacs is like an alternative to bash, right? how important is it that i become familiar with multiple types of shells?
 
no and not very, except for the ones you'll be using for work or play.
 
ok cool thanks
and just one more if someone can complete the sentence for me TERM, LANG, and LC_* are examples of .....
 
what did you want to use emacs for?
they are environment variable names.
where LC_* uses * as a glob wildcard matching the rest of any name that matches the first three characters
 
it was used as an example of use in the man page for something called screen, that i ended up wanting to learn for the purpose of generating new windows from a bash script and sending the key strokes
eventually anyway as far as i can determine being novice screen is the best alternative for achieving this
 
3:00 AM
ok, I need to translate the %Y to %%Y in my .bashrc, in a heredoc...
echo %Y | tr % [%*2] only gives me %Y
@AdamL I think most people consider tmux to be superior to screen, but screen might be more common.
 
ah ok sweet thanks I will install and read now. Is the a way of using apt-cache search $input in a way such that it returns a list of functional alternatives instead of alphabetical matches?
just so that i can review all options i have for something instead of having to ask people and internet search
 
not that I'm aware of - duckduckgo it, I suppose.
 
ok true yes for some reason i have an allergy to internet searches
 
sed 's/%/%%/g' seems to work for me where tr did not...
 
3:17 AM
What would you expect echo abcd | tr abcd 'x[y*2]z' to do?
 
I need to double up the %'s for the config file
 
I sometimes wish tr had multi-character replacements, but it doesn't
 
sed did it though
now I have to work out the interpolation
"bad substitution"
 
3:36 AM
I forgot I didn't need to escape my "s
now it works! :)
now to figure out what else I might need to cram in there... on a single line... geez...
well I glanced at the source and it looks like I could have multiple lines using the same prefix, RemoteCommand...
now my .bashrc has:
cat > ~/.ssh/config << EOF
#file edited in ~/.bashrc, do not edit ~/.ssh/config
Host host1alias
    Hostname 1_actual

Host host2alias
    Hostname 2_actual

IdentityFile ~/.ssh/id_ed25519
User myuser
IdentitiesOnly yes
RequestTTY force
VisualHostKey yes
RemoteCommand PS1="$( echo $PS1 | sed 's/%/%%/g' )" /bin/bash
EOF
 
Do you not ever connect to other hosts from this environment?
 
This is an environment where I need my stuff cleanly on my computer, for all possible servers as far as I can tell, and otherwise everything else is virtually the same.
 
3:52 AM
Just be aware that you'll never be able to use e.g. git with that configuration
(username you can override on the command line, of course - it's just the command that won't work)
 
@MichaelHomer hm... well that sucks. And you've been very helpful, thank you so much. What part will cause git to fail?
 
Every connection is going to run the same command
 
well now I need to test git...
 
So for example you can't push/pull from an SSH-based git server since it won't be able to ask to run git receive-pack
Same is true for anything else that tunnels over SSH in that way, even including things like sftp
 
I was able to run git submodule update --init --recursive and git pull successfully.
 
3:57 AM
Interesting!
 
from my client machine, not a machine I would ssh into, but it's in the same shell.
User is myuser in my system, it's probably redundant.
 
I *cannot* make git pull work, with the expected error:

> $ git pull
> Cannot execute command-line and remote command.
> fatal: Could not read from remote repository.
>
> Please make sure you have the correct access rights
> and the repository exists.
 
my shell is bash on git bash for Windows (unfortunately) because (also unfortunately) they removed cygwin.
 
It's not the shell, it's that git-over-ssh requires executing a command other than "bash" on the SSH connection
 
Maybe git is ignoring my .ssh/config?
oh, maybe I configured git weirdly...
no, I can't see anything I did to git...
 
4:06 AM
Actually, sorry, I misread your file
But host1alias doesn't have the configuration applied to it?
 
Yeah, everything unindented applies to every Host above
 
Not usually
Your ssh may be different, but the typical OpenSSH behaviour is that Host "Restricts the following declarations (up to the next Host or Match keyword) to be only for those hosts", and the indentation is for the reader
If the aliasing itself doesn't matter, you may prefer Host 1_actual 2_actual to write one block of rules for both hosts
 
OpenSSH_8.0p1, OpenSSL 1.1.1b
 
What you don't want is Host * with those options set on it, or Host 1_actual if you'll ever use 1_actual for a non-interactive purpose. In the latter case, repeating the configuration would be required to enable it for a specific alias
Does ssh host1alias echo hello work as expected?
 
it should because the command argument should override
but I don't think the command can write to STDOUT
 
4:14 AM
Then does ssh host2alias echo hello work the same way?
What I expect is that the latter says "Cannot execute command-line and remote command."
 
Yeah, I get that error
 
But I am looking at 7.9, so while it seems out of character for OpenSSH of all software to introduce a breaking configuration change...
Right
So only host2alias has any of that applied
 
But I would expect a command to override the RemoteCommand
 
Well
I don't know what to tell you.
 
if git was using the command option, it could switch to ssh myalias -o RemoteCommand=command
meaning maybe your problem was resolved with an obvious workaround in a new version of git?
 
4:25 AM
Maybe
But regardless, none of this configuration is being applied to host1alias
 
I'm logging in with my PS1, therefore I know it's working.
 
ok
If ssh host2alias echo hello fails, and ssh host1alias echo hello works, it's hard for me to imagine how they could be configured identically, but perhaps the real file is sufficiently different from the sanitised version that that is possible.
 
ooh... I switched them around and the behavior changed.
 
Shocking.
 
well... this saddens me.
but only a little.
 
4:39 AM
I donr understand why I get a bad substitution error when I run this, it all works perfectly fine from the prompt wtf
#!/bin/sh
var0="abcdefghijklmnopqrstuvwxyz"
echo "${var0:$(( RANDOM % ${#var0} )):1}"
 
"A single '*' as a pattern can be used to provide global defaults for all hosts. "
so I'll do that...
Now it's:
cat > ~/.ssh/config << EOF
#file edited in ~/.bashrc, do not edit ~/.ssh/config
Host host1alias
    Hostname 1_actual

Host host2alias
    Hostname 2_actual

Host host*alias
    RemoteCommand PS1="$( echo $PS1 | sed 's/%/%%/g' ) " \
    ; ll() { ls -alF ; } \
    ; list_paths () {echo \$PATH | tr : "\n" ; } \
    ; set_terminal_name () { printf '\\033]0;%%s\\007' "\$*" ; } \
    ; export -f ll list_paths set_terminal_name \
    ; /bin/bash

Host *
    IdentityFile ~/.ssh/id_ed25519
    User myuser
now to test with git
dang... :/
ok, I'll use a more restrictive default match... - updated the above...
and it works
 
5:10 AM
nice, so you can go multiline with multilple RemoteCommand lines
now to add a couple of aliases...
no, that appears to actually not work. I need to go to sleep now I suppose...
 
5:55 AM
Looks like multiline will only be possible with escaping the endline in the heredoc
 
6:53 AM
is there a way you can color code your workspaces? like for example Debian has four workspaces as the default value, I want the 4 workspace tabs on the top horizontal panel different colors, coded by type of work that is being done in each
having multiple is a waste of time other wise really and the feature as it is is just annoying
am i asking the question properly? like I want a tab for serious comp sci study, another for making disturbing out of context remarks on social media, another for maple code and math, etc, all having a color each for the tab
 
 
4 hours later…
10:49 AM
@AaronHall You may have wanted to use a quoted here-document (cat <<'EOF' ...), or that command substitution and $PS1 would be expanded. Using a quoted here-document, you also don't need to worry about escaping every $.
I would have put th Host * section first rather than last, so it's overridable by later Host sections.
 
 
1 hour later…
12:03 PM
@Kusalananda I don’t think that’s how ~/.ssh/config works, see
4
Q: ssh config: global settings vs `Host *`

Tom HaleWhat is the difference between ssh configuration file settings: At the top (global) level In a Host * scope? Assuming there is a difference, in which cases would each be preferred?

 
@StephenKitt Ah, I got it backwards? Ok, my bad.
Thanks
 
It’s somewhat confusing, I remember being bitten by this in the past...
 
@StephenKitt Remind me where that comment of mine was. I can't seem to find it now.
 
@Kusalananda this one?
1 hour ago, by Kusalananda
I would have put th Host * section first rather than last, so it's overridable by later Host sections.
 
Oh, it was here! Ok.
Derp
 
12:07 PM
ENEEDCOFFEE
 
Indeed.
 
 
3 hours later…
2:51 PM
tmux man page is def more straight forward that what screen describes
shouldnt it be called tmuxd tho?
no wait no there prob must already be a tmuxd sorry im learning as fast as possible so i cant always say smart things. also vodka
but also why are they emphasizing it's persistence is to the extent that it will remain even if there is a ssh time out, i am just playing with it on local machines with no internet why even say ssh i feel like its to make me all nervous and internet shitty
 
screen/tmux are very, very often used as a way to connect to remote servers and not lose your work when you disconnect.
I do all of my work that way, for example. I have never used it locally.
 
you could fake it by ssh'ing to localhost, if you wanted
 
3:54 PM
yeah, but that's like googling google
(and yes, I know it isn't, I often ssh to localhost to test ssh stuff :P)
 
I google google all the time :/
I use chrome and instead of searching for something in the address bar I will search for "google" so that I can perform my search on the actual google homepage
 
4:24 PM
I duckduckgo things now. Google was being extremely uncooperative and frustrating.
@Kusalananda I use the PS1 created in the accepted answer on this code review: codereview.stackexchange.com/q/174019/23451
It's very fast and I like the features.
It's not very human readable on echo though.
 
I'm terrified just by the title: "PS1 for Bash prompt showing last exit status, written mostly in Python"
 
4:46 PM
@AaronHall really?
terdon@tpad ~ $ echo $PS1
\[\033[01;93m\]\u@\h\[\033[01;34m\] \W\[\033[00m\] \[\033[01;34m\]$\[\033[00m\]\[\033[01;37m\] \[\033[00m\]
As opposed to that which is oh so easily readable, right? :P
Or worse, if I'm in a git repo dir:
terdon@tpad saphetor (8.4) $ echo $PS1
\[\033[01;93m\]\u@\h\[\033[01;34m\] \W\[\033[00m\] (${__git_ps1_branch_name}) \[\033[01;34m\]$\[\033[00m\]\[\033[01;37m\] \[\033[00m\]
 
\u@\h:$PWD\$
 
BORING!
 
I resemble that statement
 
I need colors. At work, I hop between various servers, especially dev/test/prod etc, and the color is essential so I don't get my terminals mixed up.
 
it's not the size of the prompt, it's what you do with it
3
 
4:49 PM
Yes dear.
 
$ printf '%q\n' "$PS1"
$'\\[\E[1m\\]{\\[\E(B\E[m\\]\\[\E[1m\E[33m\\]$?\\[\E(B\E[m\\]\\[\E[1m\\]}\\[\E(B\E[m\\]\\[\E[1m\\]:\\[\E(B\E[m\\]\\[\E[1m\E[32m\\][\\[\E(B\E[m\\]\\w\\[\E[1m\E[32m\\]]\\[\E(B\E[m\\]\\[\E[1m\\]:\\[\E(B\E[m\\]\\[\E[1m\E[32m\\][\\[\E(B\E[m\\]\\[\E[32m\\]$(TZ=UTC date \'+%FT%TZ\')\\[\E(B\E[m\\]\\[\E[1m\E[32m\\]]\\[\E(B\E[m\\]$(parse_git_branch)\\n\\[\E[1m\E[31m\\]$ \\[\E(B\E[m\\]'
 
And we have a winner! I remember you had one of those atrocities prompts with embedded newlines.
 
my prompt is huge, it's the biggest. Everyone knows it. Other prompts are weak compared to my prompt
 
Mine looks quite tame, really. It's just not readable as such
 
I am the king of extra
 
4:55 PM
This is mine:
 
[[ LINES -lt 20 ]] && exit
 
my.prompt ()
{
    local prompt=$1;
    local open="\[${TXT_GOOD}\][\[${TXT_RST}\]";
    local close="\[${TXT_GOOD}\]]\[${TXT_RST}\]";
    local col="\[${TXT_BLD}\]:\[${TXT_RST}\]";
    case $prompt in
        simple)
            export PS1="\u \W \\$ "
        ;;
        default)
            export PS1="\[${TXT_BLD}\]{\[${TXT_RST}\]\[${TXT_WARN}\]\$?\[${TXT_RST}\]\[${TXT_BLD}\]}\[${TXT_RST}\]${col}${open}\w${close}${col}${open}\[${TXT_GRN}\]\$(TZ=UTC date '+%FT%TZ')\[${TXT_RST}\]${close}\$(parse_git_branch)\n\[${TXT_FAIL}\]\$ \[${TXT_RST}\]"
 
seeing TXT_GOOD, I wanted to read TXT_BAD on the next line
 
I think I have TXT_GOOD, TXT_WARN, TXT_FAIL
terdon loves to hate my dot files too :p
$ exit
Nice try!
 
@jesse_b I believe I used the word atrocity... :P
 
5:06 PM
@terdon haters gonna hate
 
@terdon When I echo I don't see the escape codes, I see the results of hte escape codes...
 
@AaronHall echo ${PS1@Q}
 
bad substitution
 
your bash version may not support it
 
5:17 PM
@AaronHall precisely, which makes yours considerably more readable than most. I was responding to your claim that your python version wasn't readable.
 
This isn't sourced in Python
 
@jesse_b What is that supposed to do? Never seen it before. I don't get an error, just a single quoted PS1
 
You have to recreate the escape codes to recreate the PS1.
somehow they get carried through the substitution stuff though.
 
@jesse_b changelog points to version 4.4 introducing @ transformation operators in parameter expansion
@terdon "The expansion is a string that is the value of parameter quoted in a format that can be reused as input."
 
similar to printf '%q' I suppose
I have an open drive bay on my pc and today I learned that my 2 year old has been stashing things in there for months
Now I have to keep a close eye on it while my duct tape comes up to operating temperature
 
5:25 PM
a free-range 2 year old?
 
He is very free range. We keep a gate on the bottom of the stairs but he is fully capable of ripping it off if he wants
 
we need to build a better mouse trap baby jail.
 
I built the gate at the top of the stairs myself and it is significantly more skookum, I have it screwed right into the wall with two door hinges
 
@jesse_b kid just needs a nice VCR!
 
hah. I once broke the family vcr when I was a child because I wanted to watch some chocolate chip cookies on tv
 
5:38 PM
Need 24 points, my eyes are not the best...
 
zsh!
 
It is.
 
RABBLE RABBLE RABBLE
 
I might switch back to yash at some point. But I'm doing most of my shell scripting in either zsh or plain sh.
 
s/y/b/
 
5:43 PM
No, yash.
 
:-)
 
@JeffSchaller ah OK. So yes, exactly the same as my PS1 just with an extra single quote around it. I thought maybe it was supposed to interpret the escapes and display the result.
@Kusalananda that's a strange combination isn't it? Kinda like saying "I do all my driving in a Ferrari or a bicicle"
2
 
@terdon Yes, it may well sound somewhat strange. I switched my login shell to zsh originally to get to know the shell a bit better. I now feel that I know the bits of it that I would ever need to use in scripts, so I might switch back to the shell I used to run interactively before.
 
I'm offended by the comparison of zsh to a ferrari but I starred it anyway because it's funny and I thought the same thing in a much less articulate way
 
5:53 PM
maybe zsh is a Tesla, instead? If you push enough buttons and close your eyes, you'll get where you want to go, but just don't ask how it happens.
2
 
hah
 
lol
 
I just have sour grapes about zsh because I don't want to relearn a new shell
 
@JeffSchaller Yeah, zsh is a Tesla if your local car mechanic's name is Stéphane.
@jesse_b me too. I have just (reluctantly) come to accept that it's a damn good shell.
 
@jesse_b I know the feeling. From what I've seen from Stéphane, it is a nice and useful language though, so I thought I might as well try to learn a bit about it.
 
5:55 PM
natively sorting files by date is the killer feature, for me
 
I haven't used zsh, but I've seen enough of Stéphane's "Here is a 20-character command that does the same thing as the 30-line script in terdon's post" answers that I have to respect it.
 
@JeffSchaller Yes. That's useful enough to warrant calling it from your average bash scripts.
 
@Kusalananda and my bash scripts are very average :)
2
 
damn lots of zingers today
 
That's the z in zsh, right?
 
5:59 PM
demerit
 
6:20 PM
I want the Linux of cars. What car is that?
 
@AaronHall You either mean "The car of Linuxes" or "What Linux is that?", right?
Or I'm just too tired to understand.
 
"Linux is just the engine"
2
 
linux is so many different things though. Some are about reliability, some are about performance, some focus on customization, some focus on justin beiber
 
6:22 PM
> With one exception, that is: Linux, which is right next door, and which is not a business at all. It's a bunch
of RVs, yurts, tepees, and geodesic domes set up in a field and organized by consensus. The people who
live there are making tanks. These are not old-fashioned, cast-iron Soviet tanks; these are more like the
M1 tanks of the U.S. Army, made of space-age materials and jammed with sophisticated technology
from one end to the other. But they are better than Army tanks. They've been modified in such a way
 
free tanks for everyone
 
hah
highly specialized at an extremely narrow use case that most people don't actually need and overwhelmingly impractical for everything else
 
Yeah, JMG really nailed it in that answer.
 
@Kusalananda thanks for the improvement on my recent answer, btw!
(recall the "very average" comment) :)
 
6:28 PM
@JeffSchaller Mostly aesthetics, but you're welcome. And "your average" was not meant to refer to your scripts.
... but you know that.
 
:)
that's what I like about this site -- a "decent" answer becomes better and better as more people see it and use it
 
@JeffSchaller unless the user blindly reverts all edits
 
TXT_BAD :)
 
@terdon tanks a lot
 
I think I saw that on jay leno's garage
 
I did see it on jay lenos garage
 
@AaronHall good thing all those bays are covered!
 
@AaronHall :)
 
6:51 PM
At this point you should be able to build a custom car around a chassis of your choice without spending six figures.
 
7:22 PM
@terdon may I ask why you choose to not work on a machine that is not connected to a network of any type or is that inappropriate? What i am getting at is of course, here i am on the internet, but I have more than one machine, I don't understand the logic here, but it's probably because I have little understanding of what ssh is at this point i suppose
and is duckduckgo not being data mined by google anyway? duckduckgoing google is googling google i am pretty sure i remembered that for a logical non imaginary reason anyway
 
@AdamL ssh is a secure method of opening a network connection to a (usually remote) computer that allows you to operate on that computer. If you don't have a remote computer set up for that, you can loopback to your own computer just to test the protocol and usage.
An insecure method, for contrast, would be telnet.
 
 
2 hours later…
9:41 PM
cool yes i know that part about it but I am still confused by @terdon 's choice
like everything i do remotely, with no external hard drive backups, or trial and error learning on a local unconnected before updating what ever it is for my network comps, this is very strange for me i wouldn't feel comfortable
 
10:00 PM
Well the Shockley diode equation is going to put me in a bad mood for the rest of today, you can't just declare something called a "ideality factor" and not follow up as to how this is determined, or a link to empirical data see this is what annoys me with physics its just left as an exercise to the reader to work out that its just been stuffed in there as a variable to represent the part they a still unsure about, but they give it a ridiculous name and move on
 

« first day (3709 days earlier)      last day (1244 days later) »