Git Product home page Git Product logo

anyrc's Introduction

๐Ÿš anyrc

Bring your .bashrc, .zshrc, .vimrc, etc. into any remote environments, such as ssh, docker container (docker run / docker exec / kubectl exec), and another user (su).

๐Ÿ”œ Usage

Just use *rc commands instead of original commands

  • sshrc xxx instead of ssh xxx
  • surc xxx instead of su xxx
    • e.g., surc foo
  • dockerrc exec -it xxx instead of docker exec -it xxx
    • e.g., dockerrc exec -it foo_running_container bash
  • dockerrc run -it xxx instead of docker run -it xxx
    • e.g., dockerrc run -it foo_image bash
  • kubectlrc exec -it xxx instead of kubectl exec -it xxx
    • e.g., kubectlrc exec -it foo_running_pod -- zsh

Note: Incompatible subcommands (e.g., ps for dockerrc) will be passed to the original command (i.e., docker ps will be executed).

Setup/Upgrade

# If you want to install the latest version, change version to master in the url and set VERSION
# VERSION: anyrc version (default: same as install script version)
# DIR: Where to install (default: /usr/local/bin)
# FORCE: If defined, override .anyrc (default: undefined)
## default installation example
curl -sS https://raw.githubusercontent.com/amaya382/anyrc/0.1.0/install.sh | bash
## fully-customized installation example
curl -sS https://raw.githubusercontent.com/amaya382/anyrc/master/install.sh | VERSION=master DIR=~/.local/bin FORCE=1 bash

# Put your dotfiles or create symlinks of them into $HOME/.anyrc.d
ln -s /path/to/your/dotfiles/.somedotfile $HOME/.anyrc.d/.somedotfile

See example as well.

More options

  • ANYRC_DANYRC: Path to .anyrc. Default is in home dir or curr dir
  • ANYRC_DANYRCD: Path to .anyrc.d. Default is in home dir or curr dir
  • ANYRC_SSH_CMD: ssh command, i.e., you can use autossh instead
  • ANYRC_DOCKER_WO_TAR: If set, will work w/o tar on dockerrc
  • ANYRC_K8S_WO_TAR: If set, will work w/o tar on kubectlrc
  • ANYRC_WO_TAR: If set, will work w/o tar on any remote environment
# sshrc will use autossh internally
ANYRC_SSH_CMD=autossh sshrc user@host

Customize

Config files

  • .anyrc: Pre-configured for zsh, bash, tmux, git, and vim. If you want to support other tools, edit me.
  • .anyrc.d/*: Dotfiles you want to bring into remote. Symlinks are allowed.

Available environment variables (in .anyrc and .anyrc.d/*)

  • ANYRC_ENV: Show remote environment (ssh/su/docker/k8s)
  • ANYRC_ROOT: Path to tmp dir including all anyrc-related files each connection
  • ANYRC_HOME: Path to dir for dotfiles
  • ANYRC_DANYRC: Path to .anyrc
  • ANYRC_DANYRCD: Path to .anyrc.d

Examples

See example

Completion

zsh

compdef dockerrc=docker
compdef kubectlrc=kubectl

๐Ÿ”ฑ Features

Supported remote environments

  • ssh
    • Attach w/ a login shell
  • docker run
    • Attach w/ a specified shell
  • docker exec
    • Attach w/ a specified shell
  • kubectl exec
    • Attach w/ a specified shell
  • su (work w/ sudo)
    • Attach w/ a login shell

Supported tools

  • zsh
  • bash
  • tmux
  • vim
  • git
  • etc. (can support other tools by editing .anyrc)

๐Ÿ™‡ Acknowledgement

anyrc's People

Contributors

amaya382 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

anyrc's Issues

Support ssh-agent w/ tmux correctly

Error scenario

  1. ssh-agent and ssh-add
  2. sshrc somehost
  3. tmux
  4. <you can use keys>
  5. detach tmux
  6. exit ssh
  7. sshrc somehost again
  8. attach tmux
  9. <fail to use keys>

dockerrc tty option causes errors

# ok
$ dockerrc exec container bash

# error
$ dockerrc exec -it container bash
the input device is not a TTY
the input device is not a TTY

Question about surc

Hello,

I use those kind of functions for quite some time now, because I already used it when its was Russell91/sshrc, and as a consequence and as quoted in reference, I'd like to make a surc as root for example and preserve my user's environment variables in order to keep my powerline prompt and other stuff like that working without having to install it under root for example.

It was possible with sshrc by writing a .sshrc file which must be the equivalent of your .anyrc file like the following :

**# Define surc function to keep sshrc settings when su

surc () {
[ "$1" = "-" ] && shift
local USER="$1"
if [ -z "${USER}" ]; then
USER="root"
chmod +x "${SSHHOME}" 2>/dev/null
sudo -u "${USER}" SSHHOME="${SSHHOME}" "${SSHHOME}/bashsshrc"
fi
}**

It was the method suggested at that time, so my question now is "have you got an equivalent already present somewhere that i haven"t seen, or would it be possible to integrate it according to you ?

Thank you in advance for your answer.

Interactive shell looks duplicated

# local
sshrc some-host

# remote
false # return 1
exit # exit the first shell
exit # exit the second shell and return to local

# local

There seem to be issues w/ other remote envs.

Unexpected control characters?

anyrc/dockerrc

Line 62 in 2c581c4

TMP_DIR="$(docker exec ${DOCKER_OPTS} ${DOCKER_CONTAINER} mktemp -d /tmp/anyrc.XXXXXX)"; ;;

/tmp/anyrc.xxxxxx$\r ?

TMP_DIR="$(docker exec ${DOCKER_OPTS} ${DOCKER_CONTAINER} mktemp -d /tmp/anyrc.XXXXXX) | tr -d '\r'"

POSIX shell compatibility

e.g., Enable to run the following...

dockerrc run alpine sh

and then

apk add --no-cache bash
bash # work w/ anyrc in the bash

Better bash support

Now supporting bash by function-style, not good...

def:

anyrc/example/.anyrc

Lines 7 to 9 in 0e991fa

bash() {
$(sh -c 'which bash') --rcfile "${ANYRC_HOME}/.bashrc"
}

use:

anyrc/sshrc

Line 68 in 0e991fa

&& bash --rcfile \${ANYRC_DANYRC} \

Requirements:

  • (MUST) Can configure a path to bashrc in .anyrc
  • (MUST) Work on any env transparently
  • (WANT) Don't scatter PATH

Question: Project vision

Hi,

you have a nice project working here. Thanks for your work!

I'm wondering what is your project "vision" in terms of maintenance and longevity? By this i mean, do you intend to keep it up to date for as long as you can or is it just a temporary project that can be abandoned at any time?

I ask because i used to use a similar tool called sshrc (which you actually refer to in the readme) which was suddenly abandoned and the account even removed, and this let many users with an outdated/broken tool.

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.