Skip to content

Commit aca4c68

Browse files
committed
Adding documentation for prompt forwarding
1 parent 40e9a99 commit aca4c68

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Table of contents
3131
- [`Sign` car](#sign-car)
3232
- [`Status` car](#status-car)
3333
- [`Time` car](#time-car)
34+
- [Prompt forwarding via SSH](#prompt-forwarding-via-ssh)
3435
- [Author](#author)
3536
- [License](#license)
3637

@@ -1225,6 +1226,39 @@ Car that displays current date and time.
12251226
Custom separator string for this car.
12261227

12271228

1229+
Prompt forwarding via SSH
1230+
-------------------------
1231+
1232+
It's possible to use GBT to generate prompt string and forward it to remote
1233+
server via SSH so we can have GBT-like prompt also in the remote shell. The
1234+
main limitation is that the text of the cars can only be dynamic if only prompt
1235+
[escape sequences](http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html)
1236+
recognized by the remote shell are used.
1237+
1238+
As most of the remote servers have Bash as their default shell, we need to
1239+
create Bash-compatible `PS1` string.
1240+
1241+
```shell
1242+
# Create file which we will use to configure the output of locally executed GBT
1243+
# as the `PS1` for the remote server. Notice that we are using Bash escape
1244+
# sequences as the text content of the cars (e.g. \u for the user name).
1245+
cat <<END > ~/.gbt.ssh
1246+
export GBT_CARS='Os, Time, Hostname, Dir, Sign'
1247+
export GBT_CAR_OS_NAME='cloud'
1248+
export GBT_CAR_TIME_FORMAT=' \t '
1249+
export GBT_CAR_HOSTNAME_USER_TEXT='\u'
1250+
export GBT_CAR_HOSTNAME_HOST_TEXT='\h'
1251+
export GBT_CAR_DIR_DIR_TEXT='\W'
1252+
export GBT_CAR_SIGN_SYMBOL_FORMAT='\\\$'
1253+
export GBT_SHELL='_bash'
1254+
END
1255+
# Then we can tell SSH to execute remote command which consists of locally
1256+
# generated GBT output, which is written into a file on the remote server, and
1257+
# the Bash command which loads that generated file as its RC file:
1258+
ssh $@ -t "echo \"PS1='$(source ~/.gbt.ssh; gbt)'\" > ~/.myprompt; bash --rcfile ~/.myprompt -i"
1259+
```
1260+
1261+
12281262
Author
12291263
------
12301264

0 commit comments

Comments
 (0)