├── LICENSE ├── README.md └── backpack /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 sineemore 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # backpack 2 | 3 | backpack is a small wrapper around ssh. 4 | 5 | It transfers contents of a local file ~/.backpack and itself to remote host, sources it and continues with normal ssh session. 6 | 7 | 8 | * works best as `alias ssh=backpack` 9 | * won't create any files on remote hosts (even temporary) 10 | * tries to fallback to normal ssh when remote shell is not bash 11 | * **self-replication** allows you to use backpack again directly from remote host, in this case backpack will keep original local file as you go deaper from host to host. 12 | 13 | Example of ~/.backpack file: 14 | 15 | ```sh 16 | PS1="\u \[\033[1;31m\]\h\[\033[0m\] \W " 17 | 18 | alias ssh=backpack 19 | alias l="ls -alah" 20 | alias juu="perl -MJSON::PP -E 'local \$/; say JSON::PP->new->pretty(1)->encode(decode_json(<>));'" 21 | 22 | human() { 23 | if [ $# -ne 0 ]; then 24 | numfmt --to=iec "$@" 25 | else 26 | cat | numfmt --to=iec "$@" 27 | fi 28 | } 29 | 30 | bind '"\e[A": history-search-backward' 31 | bind '"\e[B": history-search-forward' 32 | 33 | # I use st terminal, but probably there is no st.info 34 | TERM=xterm-256color 35 | ``` 36 | 37 | Also check similar project [sshrc](https://github.com/Russell91/sshrc). 38 | -------------------------------------------------------------------------------- /backpack: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if [ ! -t 1 -o ! $# -eq 1 -o ! -f ~/.backpack -a -z "$BACKPACK" ]; then 3 | exec ssh "$@" 4 | fi 5 | if [ -z "$BACKPACK" ]; then 6 | encode() { 7 | base64 | tr -d "\n" 8 | } 9 | RC="$(encode < ~/.backpack)" 10 | FUNCTION="$(encode </dev/null \ 38 | && eval 'decode() { printf %s "\$1" | fold -w 64 | base64 -d; }' \ 39 | && export BACKPACK="$BACKPACK" \ 40 | && eval "\$(decode "\$BACKPACK")" \ 41 | && extract_backpack 42 | [ -x "\$SHELL" ] && exec "\$SHELL" -l 43 | exec /bin/sh -i 44 | EOF 45 | )" 46 | exec ssh -t "$1" "$INIT" 47 | --------------------------------------------------------------------------------