├── LICENSE ├── README.md ├── anyrc ├── dockerrc ├── example ├── .anyrc ├── .anyrc.d │ ├── .bashrc │ ├── .tmux.conf │ ├── .vimrc │ └── .zshrc └── README.md ├── install.sh ├── kubectlrc ├── sshrc └── surc /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2019 amaya (Ryuichi Ito) 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

:shell: anyrc

2 | 3 | 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`). 4 | 5 | 6 | ## :soon: Usage 7 | Just use `*rc` commands instead of original commands 8 | 9 | * `sshrc xxx` instead of `ssh xxx` 10 | * e.g., `sshrc -p 10022 foo@XXX.XXX.XXX.XXX` 11 | * `surc xxx` instead of `su xxx` 12 | * e.g., `surc foo` 13 | * `dockerrc exec -it xxx` instead of `docker exec -it xxx` 14 | * e.g., `dockerrc exec -it foo_running_container bash` 15 | * `dockerrc run -it xxx` instead of `docker run -it xxx` 16 | * e.g., `dockerrc run -it foo_image bash` 17 | * `kubectlrc exec -it xxx` instead of `kubectl exec -it xxx` 18 | * e.g., `kubectlrc exec -it foo_running_pod -- zsh` 19 | 20 | **Note**: Incompatible subcommands (e.g., `ps` for `dockerrc`) will be passed to the original command (i.e., `docker ps` will be executed). 21 | 22 | 23 | ### Setup/Upgrade 24 | ```sh 25 | # If you want to install the latest version, change version to master in the url and set VERSION 26 | # VERSION: anyrc version (default: same as install script version) 27 | # DIR: Where to install (default: /usr/local/bin) 28 | # FORCE: If defined, override .anyrc (default: undefined) 29 | ## default installation example 30 | curl -sS https://raw.githubusercontent.com/amaya382/anyrc/0.1.0/install.sh | bash 31 | ## fully-customized installation example 32 | curl -sS https://raw.githubusercontent.com/amaya382/anyrc/master/install.sh | VERSION=master DIR=~/.local/bin FORCE=1 bash 33 | 34 | # Put your dotfiles or create symlinks of them into $HOME/.anyrc.d 35 | ln -s /path/to/your/dotfiles/.somedotfile $HOME/.anyrc.d/.somedotfile 36 | ``` 37 | 38 | See [example](./example) as well. 39 | 40 | 41 | ### More options 42 | * `ANYRC_DANYRC`: Path to `.anyrc`. Default is in home dir or curr dir 43 | * `ANYRC_DANYRCD`: Path to `.anyrc.d`. Default is in home dir or curr dir 44 | * `ANYRC_SSH_CMD`: `ssh` command, i.e., you can use `autossh` instead 45 | * `ANYRC_DOCKER_WO_TAR`: If set, will work w/o `tar` on `dockerrc` 46 | * `ANYRC_K8S_WO_TAR`: If set, will work w/o `tar` on `kubectlrc` 47 | * `ANYRC_WO_TAR`: If set, will work w/o `tar` on any remote environment 48 | 49 | ```sh 50 | # sshrc will use autossh internally 51 | ANYRC_SSH_CMD=autossh sshrc user@host 52 | ``` 53 | 54 | 55 | ## Customize 56 | ### Config files 57 | * `.anyrc`: Pre-configured for zsh, bash, tmux, git, and vim. If you want to support other tools, edit me. 58 | * `.anyrc.d/*`: Dotfiles you want to bring into remote. Symlinks are allowed. 59 | 60 | ### Available environment variables (in `.anyrc` and `.anyrc.d/*`) 61 | * `ANYRC_ENV`: Show remote environment (`ssh`/`su`/`docker`/`k8s`) 62 | * `ANYRC_ROOT`: Path to tmp dir including all anyrc-related files each connection 63 | * `ANYRC_HOME`: Path to dir for dotfiles 64 | * `ANYRC_DANYRC`: Path to `.anyrc` 65 | * `ANYRC_DANYRCD`: Path to `.anyrc.d` 66 | 67 | ### Examples 68 | See [example](./example) 69 | 70 | ### Completion 71 | #### zsh 72 | ```sh 73 | compdef dockerrc=docker 74 | compdef kubectlrc=kubectl 75 | ``` 76 | 77 | 78 | ## :trident: Features 79 | ### Supported remote environments 80 | * `ssh` 81 | * Attach w/ a login shell 82 | * `docker run` 83 | * Attach w/ a specified shell 84 | * `docker exec` 85 | * Attach w/ a specified shell 86 | * `kubectl exec` 87 | * Attach w/ a specified shell 88 | * `su` (work w/ `sudo`) 89 | * Attach w/ a login shell 90 | 91 | ### Supported tools 92 | * zsh 93 | * bash 94 | * tmux 95 | * vim 96 | * git 97 | * etc. (can support other tools by editing `.anyrc`) 98 | 99 | 100 | ## :bow: Acknowledgement 101 | * [Russell91/sshrc](https://github.com/Russell91/sshrc) 102 | * Using a lot of logics and codes from sshrc 103 | -------------------------------------------------------------------------------- /anyrc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Const vals 4 | DANYRC_NAME='.anyrc' 5 | DANYRCD_NAME='.anyrc.d' 6 | 7 | ANYRC_CMD='anyrc' 8 | ANYRC_CMD_SSH='sshrc' 9 | ANYRC_CMD_DOCKER='dockerrc' 10 | ANYRC_CMD_KUBECTL='kubectlrc' 11 | ANYRC_CMD_SU='surc' 12 | 13 | ANYRC_CMDS=( \ 14 | "${ANYRC_CMD_SSH}" \ 15 | "${ANYRC_CMD_DOCKER}" \ 16 | "${ANYRC_CMD_KUBECTL}" \ 17 | "${ANYRC_CMD_SU}") 18 | 19 | 20 | 21 | # Funcs 22 | set_danyrc() { 23 | # .anyrc on local 24 | if [ -z "${ANYRC_DANYRC:+_}" ]; then 25 | if [ -f "${HOME}/${DANYRC_NAME}" ]; then # Home dir 26 | ANYRC_DANYRC="${HOME}/${DANYRC_NAME}" 27 | elif [ -f "$(pwd)/${DANYRC_NAME}" ]; then # Current dir 28 | ANYRC_DANYRC="$(pwd)/${DANYRC_NAME}" 29 | else 30 | echo >&2 "${DANYRC_NAME} not found" 31 | exit 1 32 | fi 33 | fi 34 | } 35 | 36 | set_danyrcd() { 37 | # .anyrc.d on local 38 | if [ -z "${ANYRC_DANYRCD:+_}" ]; then 39 | if [ -d "${HOME}/${DANYRCD_NAME}" ]; then # Home dir 40 | ANYRC_DANYRCD="${HOME}/${DANYRCD_NAME}" 41 | elif [ -d "$(pwd)/${DANYRCD_NAME}" ]; then # Current dir 42 | ANYRC_DANYRCD="$(pwd)/${DANYRCD_NAME}" 43 | else 44 | echo >&2 "${DANYRCD_NAME} not found" 45 | exit 1 46 | fi 47 | fi 48 | 49 | DANYRCD_BASE="${ANYRC_DANYRCD##*/}" 50 | DANYRCD_DIR="${ANYRC_DANYRCD%/*}" 51 | } 52 | 53 | abs_dirname() { 54 | local CWD="$(pwd)" 55 | local path="$1" 56 | 57 | while [ -n "$path" ]; do 58 | cd "${path%/*}" 59 | local NAME="${path##*/}" 60 | path="$(readlink "${NAME}" || :)" 61 | done 62 | 63 | pwd -P 64 | cd "${CWD}" 65 | } 66 | 67 | 68 | 69 | # Main 70 | init "$@" # (Inherit from *rc) 71 | 72 | set_danyrc 73 | set_danyrcd 74 | 75 | mk_tmp_dir # (Inherit from *rc) 76 | 77 | transfer # (Inherit from *rc) 78 | 79 | connect # (Inherit from *rc) 80 | -------------------------------------------------------------------------------- /dockerrc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ANYRC_ENV='docker' 4 | 5 | init() { 6 | DOCKER_SUBCMD="$1"; shift # expect 'run' or 'exec' 7 | DOCKER_GLOBAL_OPTS='' 8 | DOCKER_RUN_OPTS='' 9 | DOCKER_EXEC_OPTS='' 10 | DOCKER_UNKNOWN_OPTS='' 11 | 12 | case "${DOCKER_SUBCMD}" in 13 | run ) 14 | while [[ -n "$1" ]]; do 15 | case "$1" in 16 | --help ) 17 | docker "${DOCKER_SUBCMD}" "$1" 18 | exit 0 ;; 19 | 20 | -D | --debug | --tls | --tlsverify ) 21 | DOCKER_GLOBAL_OPTS="${DOCKER_GLOBAL_OPTS} $1" ;; 22 | --config | -c | --context | -H | --host | -l | --log-level | --tlscacert | --tlscert | --tlskey ) 23 | DOCKER_GLOBAL_OPTS="${DOCKER_GLOBAL_OPTS} $1 $2"; shift ;; 24 | --config=* | -c=* | --context=* | -H=* | --host=* | -l=* | --log-level=* | --tlscacert=* | --tlscert=* | --tlskey=* ) 25 | DOCKER_GLOBAL_OPTS="${DOCKER_GLOBAL_OPTS} $1" ;; 26 | 27 | -d | --detach | --disable-content-trust | --init | -i | --interactive | --no-healthcheck | --oom-kill-disable | --privileged | -P | --publish-all | --read-only | --rm | --sig-proxy | -t | --tty | -it | -ti ) 28 | DOCKER_RUN_OPTS="${DOCKER_RUN_OPTS} $1" ;; 29 | --add-host | -a | --attach | --blkio-weight-device | --cap-add | --cap-drop | --cgroup-parent | --cidfile | --cpu-period | --cpu-quota | --cpu-rt-period | --cpu-rt-runtime | -c | --cpu-shares | --cpus | --cpuset-cpus | --cpuset-mems | --detach-keys | --device | --device-cgroup-rule | --device-read-bps | --device-read-iops | --device-write-bps | --device-write-iops | --dns | --dns-option | --dns-search | --domainname | --entrypoint | -e | --env | --env-file | --expose | --group-add | --health-cmd | --health-interval | --health-retries | --health-start-period | --health-timeout | -h | --hostname | --ip | --ip6 | --ipc | --isolation | --kernel-memory | -l | --label | --label-file | --link | --link-local-ip | --log-driver | --log-opt | --mac-address | -m | --memory | --memory-reservation | --memory-swap | --memory-swappiness | --mount | --name | --network | --network-alias | --oom-score-adj | --pid | --pids-limit | --platform | -p | --publish | --restart | --runtime | --security-opt | --shm-size | --stop-signal | --stop-timeout | --storage-opt | --sysctl | --tmpfs | --ulimit | -u | --user | --userns | --uts | -v | --volume | --volume-driver | --volumes-from | -w | --workdir ) 30 | DOCKER_RUN_OPTS="${DOCKER_RUN_OPTS} $1 $2"; shift ;; 31 | --add-host=* | -a=* | --attach=* | --blkio-weight-device=* | --cap-add=* | --cap-drop=* | --cgroup-parent=* | --cidfile=* | --cpu-period=* | --cpu-quota=* | --cpu-rt-period=* | --cpu-rt-runtime=* | -c=* | --cpu-shares=* | --cpus=* | --cpuset-cpus=* | --cpuset-mems=* | --detach-keys=* | --device=* | --device-cgroup-rule=* | --device-read-bps=* | --device-read-iops=* | --device-write-bps=* | --device-write-iops=* | --dns=* | --dns-option=* | --dns-search=* | --domainname=* | --entrypoint=* | -e=* | --env=* | --env-file=* | --expose=* | --group-add=* | --health-cmd=* | --health-interval=* | --health-retries=* | --health-start-period=* | --health-timeout=* | -h=* | --hostname=* | --ip=* | --ip6=* | --ipc=* | --isolation=* | --kernel-memory=* | -l=* | --label=* | --label-file=* | --link=* | --link-local-ip=* | --log-driver=* | --log-opt=* | --mac-address=* | -m=* | --memory=* | --memory-reservation=* | --memory-swap=* | --memory-swappiness=* | --mount=* | --name=* | --network=* | --network-alias=* | --oom-score-adj=* | --pid=* | --pids-limit=* | --platform=* | -p=* | --publish=* | --restart=* | --runtime=* | --security-opt=* | --shm-size=* | --stop-signal=* | --stop-timeout=* | --storage-opt=* | --sysctl=* | --tmpfs=* | --ulimit=* | -u=* | --user=* | --userns=* | --uts=* | -v=* | --volume=* | --volume-driver=* | --volumes-from=* | -w=* | --workdir ) 32 | DOCKER_RUN_OPTS="${DOCKER_RUN_OPTS} $1" ;; 33 | 34 | -* ) 35 | # handle unknown opts as solo opts 36 | DOCKER_UNKNOWN_OPTS="${DOCKER_UNKNOWN_OPTS} $1" ;; 37 | * ) 38 | if [ -z "${DOCKER_IMAGE:+_}" ]; then 39 | DOCKER_IMAGE="$1" 40 | elif [ -z "${REMOTE_SHELL:+_}" ]; then 41 | REMOTE_SHELL="$1" 42 | fi ;; 43 | esac 44 | shift 45 | done 46 | if [ -z "${DOCKER_IMAGE:+_}" ] || [ -z "${REMOTE_SHELL:+_}" ]; then 47 | exit 1 48 | fi ;; 49 | exec ) 50 | while [[ -n "$1" ]]; do 51 | case "$1" in 52 | --help ) 53 | docker "${DOCKER_SUBCMD}" "$1" 54 | exit 0 ;; 55 | 56 | -D | --debug | --tls | --tlsverify ) 57 | DOCKER_GLOBAL_OPTS="${DOCKER_GLOBAL_OPTS} $1" ;; 58 | --config | -c | --context | -H | --host | -l | --log-level | --tlscacert | --tlscert | --tlskey ) 59 | DOCKER_GLOBAL_OPTS="${DOCKER_GLOBAL_OPTS} $1 $2" 60 | shift ;; 61 | --config=* | -c=* | --context=* | -H=* | --host=* | -l=* | --log-level=* | --tlscacert=* | --tlscert=* | --tlskey=* ) 62 | DOCKER_GLOBAL_OPTS="${DOCKER_GLOBAL_OPTS} $1" ;; 63 | 64 | -d | --detach | -i | --interactive | --privileged | -t | --tty | -it | -ti ) 65 | DOCKER_EXEC_OPTS="${DOCKER_EXEC_OPTS} $1" ;; 66 | --detach-keys | -e | --env | -u | --user | -w | --workdir ) 67 | DOCKER_EXEC_OPTS="${DOCKER_EXEC_OPTS} $1 $2" 68 | shift ;; 69 | --detach-keys=* | -e=* | --env=* | -u=* | --user=* | -w=* | --workdir=* ) 70 | DOCKER_EXEC_OPTS="${DOCKER_EXEC_OPTS} $1" ;; 71 | 72 | -* ) 73 | # handle unknown opts as solo opts 74 | DOCKER_UNKNOWN_OPTS="${DOCKER_UNKNOWN_OPTS} $1" ;; 75 | * ) 76 | if [ -z "${DOCKER_CONTAINER:+_}" ]; then 77 | DOCKER_CONTAINER="$1" 78 | elif [ -z "${REMOTE_SHELL:+_}" ]; then 79 | REMOTE_SHELL="$1" 80 | fi ;; 81 | esac 82 | shift 83 | done 84 | if [ -z "${DOCKER_CONTAINER:+_}" ] || [ -z "${REMOTE_SHELL:+_}" ]; then 85 | exit 1 86 | fi ;; 87 | * ) 88 | # pass through and then exit 89 | docker "${DOCKER_SUBCMD}" $@ 90 | exit 0 ;; 91 | esac 92 | } 93 | 94 | mk_tmp_dir() { 95 | case "${DOCKER_SUBCMD}" in 96 | run ) 97 | : ;; 98 | exec ) 99 | TMP_DIR="$(docker exec ${DOCKER_GLOBAL_OPTS} ${DOCKER_CONTAINER} mktemp -d /tmp/anyrc.XXXXXX)"; ;; 100 | esac 101 | } 102 | 103 | transfer() { 104 | case "${DOCKER_SUBCMD}" in 105 | run ) 106 | : ;; 107 | exec ) 108 | # Transfer .anyrc 109 | docker cp -L ${DOCKER_GLOBAL_OPTS} "${ANYRC_DANYRC}" "${DOCKER_CONTAINER}:${TMP_DIR}/${DANYRC_NAME}" 110 | 111 | if [ ! -z "${ANYRC_DOCKER_WO_TAR:+_}" ] || [ ! -z "${ANYRC_WO_TAR:+_}" ]; then 112 | # Transfer .anyrc.d 113 | docker cp -L ${DOCKER_GLOBAL_OPTS} "${ANYRC_DANYRCD}" "${DOCKER_CONTAINER}:${TMP_DIR}/${DANYRCD_NAME}" 114 | 115 | # Transfer *rc 116 | local CMD_DIR="$(abs_dirname $0)" 117 | for cmd in "${ANYRC_CMD}" "${ANYRC_CMDS[@]}"; do 118 | if [ -f "${CMD_DIR}/${cmd}" ]; then 119 | docker cp -L ${DOCKER_GLOBAL_OPTS} "${CMD_DIR}/${cmd}" "${DOCKER_CONTAINER}:${TMP_DIR}/${cmd}" 120 | fi 121 | done 122 | else 123 | # Transfer .anyrc.d 124 | tar cz -h -C "${DANYRCD_DIR}" "${DANYRCD_BASE}" \ 125 | | docker exec -i ${DOCKER_GLOBAL_OPTS} ${DOCKER_CONTAINER} sh -c "tar xz -C ${TMP_DIR}" 126 | 127 | # Transfer *rc 128 | local CMD_DIR="$(abs_dirname $0)" 129 | local RCS=() 130 | for cmd in "${ANYRC_CMD}" "${ANYRC_CMDS[@]}"; do 131 | if [ -f "${CMD_DIR}/${cmd}" ]; then 132 | RCS=("${RCS[@]}" "${cmd}") 133 | fi 134 | done 135 | tar czf - -h -C ${CMD_DIR} "${RCS[@]}" \ 136 | | docker exec -i ${DOCKER_GLOBAL_OPTS} "${DOCKER_CONTAINER}" sh -c "tar xz -C ${TMP_DIR}" 137 | fi ;; 138 | esac 139 | } 140 | 141 | connect() { 142 | case "${DOCKER_SUBCMD}" in 143 | run ) 144 | local CMD_DIR="$(abs_dirname $0)" 145 | docker run ${DOCKER_GLOBAL_OPTS} ${DOCKER_RUN_OPTS} "${DOCKER_IMAGE}" \ 146 | "${REMOTE_SHELL}" -c " 147 | export DANYRC_NAME=\"${DANYRC_NAME}\" 148 | export DANYRCD_NAME=\"${DANYRCD_NAME}\" 149 | export ANYRC_ROOT=\"\$(mktemp -d /tmp/anyrc.XXXXXX)\" 150 | export ANYRC_DANYRC=\"\${ANYRC_ROOT}/\${DANYRC_NAME}\" 151 | export ANYRC_DANYRCD=\"\${ANYRC_ROOT}/\${DANYRCD_NAME}\" 152 | export ANYRC_HOME=\"\${ANYRC_DANYRCD}\" 153 | export PATH=\"\${ANYRC_ROOT}:\${PATH}\" 154 | trap \"rm -rf \${ANYRC_ROOT}; exit\" 0 155 | mkdir -p \${ANYRC_DANYRCD} 156 | echo '$(cat "${ANYRC_DANYRC}" | base64)' | base64 -d > \${ANYRC_DANYRC} 157 | echo '$(tar czf - -h -C ${CMD_DIR} ${ANYRC_CMD} ${ANYRC_CMDS[@]} | base64)' | base64 -d | tar mxzf - -C \${ANYRC_ROOT} 158 | echo '$(tar czf - -h -C ${DANYRCD_DIR} ${DANYRCD_BASE} | base64)' | base64 -d | tar mxzf - -C \${ANYRC_ROOT} 159 | source \"\${ANYRC_DANYRC}\" 160 | if [ \"${REMOTE_SHELL##*/}\" = 'bash' ]; then 161 | bash --rcfile \${ANYRC_DANYRC} 162 | else 163 | ${REMOTE_SHELL} 164 | fi" ;; 165 | exec ) 166 | docker exec ${DOCKER_GLOBAL_OPTS} ${DOCKER_EXEC_OPTS} "${DOCKER_CONTAINER}" \ 167 | "${REMOTE_SHELL}" -c " 168 | export DANYRC_NAME=\"${DANYRC_NAME}\" 169 | export DANYRCD_NAME=\"${DANYRCD_NAME}\" 170 | export ANYRC_ROOT=\"${TMP_DIR}\" 171 | export ANYRC_DANYRC=\"\${ANYRC_ROOT}/\${DANYRC_NAME}\" 172 | export ANYRC_DANYRCD=\"\${ANYRC_ROOT}/\${DANYRCD_NAME}\" 173 | export ANYRC_HOME=\"\${ANYRC_DANYRCD}\" 174 | export SHELL=\$(which \"${REMOTE_SHELL}\") 175 | export PATH=\"\${PATH}:\${ANYRC_ROOT}\" 176 | trap \"rm -rf \${ANYRC_ROOT}; exit\" 0 177 | source \"\${ANYRC_DANYRC}\" 178 | if [ \"${REMOTE_SHELL##*/}\" = 'bash' ]; then 179 | bash --rcfile \${ANYRC_DANYRC} 180 | else 181 | ${REMOTE_SHELL} 182 | fi" ;; 183 | esac 184 | } 185 | 186 | source anyrc 187 | -------------------------------------------------------------------------------- /example/.anyrc: -------------------------------------------------------------------------------- 1 | # This example is compatible with bash and zsh 2 | 3 | CURR_SHELL="$(readlink /proc/$$/exe)" 4 | 5 | # For before loading shell 6 | ## bash 7 | bash() { 8 | $(sh -c 'which bash') --rcfile "${ANYRC_HOME}/.bashrc" 9 | } 10 | 11 | ## zsh 12 | export ZDOTDIR="${ANYRC_HOME}" 13 | 14 | 15 | # For after loading shell 16 | ## vim 17 | export VIMINIT="let \$MYVIMRC='${ANYRC_HOME}/.vimrc' | source \${MYVIMRC}" 18 | 19 | ## tmux 20 | tmux() { 21 | local TMUX_DIR="/tmp/anyrc.tmux.$(whoami)" 22 | [ ! -d "${TMUX_DIR}" ] && rm -rf "${TMUX_DIR}" 23 | mkdir -p "${TMUX_DIR}" 24 | chmod 700 "${TMUX_DIR}" 25 | 26 | # Copy all of anyrc for inside of tmux 27 | 'cp' -rf "${ANYRC_ROOT}/." "${TMUX_DIR}" &> /dev/null 28 | 29 | # If ssh-agent is enabled, use a static path 30 | [ -n "${SSH_AUTH_SOCK}" ] && ln -sf "${SSH_AUTH_SOCK}" "${TMUX_DIR}/agent" 31 | 32 | DANYRC_NAME="${DANYRC_NAME}" \ 33 | DANYRCD_NAME="${DANYRCD_NAME}" \ 34 | ANYRC_ROOT="${TMUX_DIR}" \ 35 | ANYRC_DANYRC="${TMUX_DIR}/${DANYRC_NAME}" \ 36 | ANYRC_DANYRCD="${TMUX_DIR}/${DANYRCD_NAME}" \ 37 | ANYRC_HOME="${TMUX_DIR}/${DANYRCD_NAME}" \ 38 | VIMINIT="let \$MYVIMRC='${TMUX_DIR}/${DANYRCD_NAME}/.vimrc' | source \${MYVIMRC}" \ 39 | ZDOTDIR="${TMUX_DIR}/${DANYRCD_NAME}" \ 40 | SSH_AUTH_SOCK="${TMUX_DIR}/agent" \ 41 | PATH="${TMUX_DIR}:${PATH}" \ 42 | $(sh -c 'which tmux') -2 \ 43 | -f "${TMUX_DIR}/${DANYRCD_NAME}/.tmux.conf" \ 44 | -S "${TMUX_DIR}/tmuxserver" "$@" 45 | } 46 | 47 | ## git 48 | git() { 49 | HOME="${ANYRC_HOME}" $(sh -c 'which git') "$@" 50 | } 51 | -------------------------------------------------------------------------------- /example/.anyrc.d/.bashrc: -------------------------------------------------------------------------------- 1 | alias ll='ls -Al' 2 | PS1='\e[0;34m\]$\[\e[m\] ' 3 | 4 | source "${ANYRC_DANYRC}" 5 | -------------------------------------------------------------------------------- /example/.anyrc.d/.tmux.conf: -------------------------------------------------------------------------------- 1 | set -g status-right "#[fg=black][%Y-%m-%d(%a) %H:%M]" 2 | 3 | set -g default-command zsh 4 | -------------------------------------------------------------------------------- /example/.anyrc.d/.vimrc: -------------------------------------------------------------------------------- 1 | set number 2 | -------------------------------------------------------------------------------- /example/.anyrc.d/.zshrc: -------------------------------------------------------------------------------- 1 | alias ll='ls -Al' 2 | PROMPT='%F{red}$ %f' 3 | 4 | source ${ANYRC_DANYRC} 5 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # anyrc example 2 | ## Files you need 3 | * `.anyrc` 4 | * Nomally, you needn't care of this file 5 | * This file will be installed automatically in the anyrc installation 6 | * Pre-configured for zsh, bash, tmux, git, and vim 7 | * If you want to support other tools, edit me 8 | * `.anyrc.d/*` 9 | * Put your dotfiles here. Symlinks are allowed. 10 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -eu 2 | 3 | : ${VERSION:='0.1.0'} 4 | : ${DIR:='/usr/local/bin'} 5 | [ "$(ls -ld ${DIR} | cut -d' ' -f3)" != "${USER}" ] && SUDO='sudo' || SUDO='' 6 | echo "Installing anyrc commands into ${DIR} ..." 7 | for cmd in dockrc kuberc dockerrunrc dockerexecrc kubectlexecrc; do 8 | ${SUDO} rm "${DIR}/${cmd}" &> /dev/null # Remove old commands 9 | done 10 | for cmd in anyrc sshrc dockerrc kubectlrc surc; do 11 | ${SUDO} curl -sSL "https://github.com/amaya382/anyrc/raw/${VERSION}/${cmd}" -o "${DIR}/${cmd}" 12 | ${SUDO} chmod +x "${DIR}/${cmd}" 13 | done 14 | 15 | if [ -e "${HOME}/.anyrc" ]; then 16 | if [ ! -z "${FORCE:+_}" ]; then 17 | echo "Overriding ${HOME}/.anyrc" 18 | else 19 | SKIP_DANYRC=1 20 | echo "Skipping installing .anyrc (If you want to install default .anyrc, install again w/ FORCE=1)" 21 | fi 22 | fi 23 | 24 | if [ -z "${SKIP_DANYRC:+_}" ]; then 25 | echo "Installing ${HOME}/.anyrc ..." 26 | curl -sSL https://github.com/amaya382/anyrc/raw/${VERSION}/example/.anyrc \ 27 | -o ~/.anyrc 28 | fi 29 | echo "Creating ${HOME}/.anyrc.d ..." 30 | mkdir -p "${HOME}/.anyrc.d" 31 | 32 | cat << EOS 33 | anyrc was successfully installed! 34 | Put your dotfiles into ${HOME}/.anyrc.d . Symlinks are allowed. 35 | EOS 36 | 37 | -------------------------------------------------------------------------------- /kubectlrc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ANYRC_ENV='kubectlrc' 4 | 5 | init() { 6 | K8S_SUBCMD="$1"; shift # expect 'exec' 7 | K8S_GLOBAL_OPTS='' 8 | K8S_CONTAINER_OPTS='' 9 | K8S_EXEC_OPTS='' 10 | K8S_UNKNOWN_OPTS='' 11 | 12 | case "${K8S_SUBCMD}" in 13 | exec ) 14 | while [[ -n "$1" ]]; do 15 | case "$1" in 16 | --help ) 17 | kubectl "${K8S_SUBCMD}" "$1" 18 | exit 0 ;; 19 | 20 | --add-dir-header | --alsologtostderr | --insecure-skip-tls-verify | --logtostderr | --match-server-version | --skip-headers | --skip-log-header ) 21 | K8S_GLOBAL_OPTS="${K8S_GLOBAL_OPTS} $1" ;; 22 | --add-dir-header=* | --alsologtostderr=* | --insecure-skip-tls-verify=* | --logtostderr=* | --match-server-version=* | --skip-headers=* | --skip-log-header ) 23 | K8S_GLOBAL_OPTS="${K8S_GLOBAL_OPTS} $1" ;; 24 | --as | --as-group | --cache-dir | --certificate-authority | --client-certificate | --client-key | --cluster | --context | --kubeconfig | --log-backtrace-at | --log-dir | --log-file | --log-file-max-size | --log-flush-frequency | -n | --namespace | --password | --profile | --profile-output | --request-timeout | -s | --server | --stderrthreshold | --tls-server-name | --token | --user | --username | -v | --v | --vmodule ) 25 | K8S_GLOBAL_OPTS="${K8S_GLOBAL_OPTS} $1 $2" 26 | shift ;; 27 | --as=* | --as-group=* | --cache-dir=* | --certificate-authority=* | --client-certificate=* | --client-key=* | --cluster=* | --context=* | --kubeconfig=* | --log-backtrace-at=* | --log-dir=* | --log-file=* | --log-file-max-size=* | --log-flush-frequency=* | -n=* | --namespace=* | --password=* | --profile=* | --profile-output=* | --request-timeout=* | -s=* | --server=* | --stderrthreshold=* | --tls-server-name=* | --token=* | --user=* | --username=* | -v=* | --v=* | --vmodule ) 28 | K8S_GLOBAL_OPTS="${K8S_GLOBAL_OPTS} $1" ;; 29 | 30 | -c | --container ) 31 | K8S_CONTAINER_OPTS="${K8S_CONTAINER_OPTS} $1 $2" 32 | K8S_EXEC_OPTS="${K8S_EXEC_OPTS} $1 $2" 33 | shift ;; 34 | -c=* | --container=* ) 35 | K8S_CONTAINER_OPTS="${K8S_CONTAINER_OPTS} $1" 36 | K8S_EXEC_OPTS="${K8S_EXEC_OPTS} $1" ;; 37 | 38 | -i | -t | -it | -ti ) 39 | K8S_EXEC_OPTS="${K8S_EXEC_OPTS} $1" ;; 40 | -f | --filename | --pod-running-timeout ) 41 | K8S_EXEC_OPTS="${K8S_EXEC_OPTS} $1 $2" 42 | shift ;; 43 | -f=* | --filename=* | --pod-running-timeout=* ) 44 | K8S_EXEC_OPTS="${K8S_EXEC_OPTS} $1" ;; 45 | 46 | -- ) 47 | ;; 48 | -* ) 49 | K8S_UNKNOWN_OPTS="${K8S_UNKNOWN_OPTS} $1" ;; 50 | * ) 51 | if [ -z "${K8S_POD:+_}" ]; then 52 | K8S_POD="$1" 53 | elif [ -z ${REMOTE_SHELL:+_} ]; then 54 | REMOTE_SHELL="$1" 55 | fi ;; 56 | esac 57 | shift 58 | done 59 | if [ -z "${K8S_POD:+_}" ] || [ -z "${REMOTE_SHELL:+_}" ]; then 60 | exit 1 61 | fi ;; 62 | * ) 63 | kubectl "${K8S_SUBCMD}" $@ 64 | exit 0 ;; 65 | esac 66 | } 67 | 68 | mk_tmp_dir() { 69 | case "${K8S_SUBCMD}" in 70 | exec ) 71 | TMP_DIR="$(kubectl exec ${K8S_GLOBAL_OPTS} ${K8S_CONTAINER_OPTS} ${K8S_POD} -- mktemp -d /tmp/anyrc.XXXXXX)" ;; 72 | esac 73 | } 74 | 75 | transfer() { 76 | case "${K8S_SUBCMD}" in 77 | exec ) 78 | # Transfer .anyrc 79 | kubectl cp ${K8S_GLOBAL_OPTS} ${K8S_CONTAINER_OPTS} "$(readlink -f ${ANYRC_DANYRC})" "${K8S_POD}:${TMP_DIR}/${DANYRC_NAME}" 80 | 81 | if [ ! -z "${ANYRC_K8S_WO_TAR:+_}" ] || [ ! -z "${ANYRC_WO_TAR:+_}" ]; then 82 | # Transfer .anyrc.d 83 | kubectl cp ${K8S_GLOBAL_OPTS} ${K8S_CONTAINER_OPTS} "$(readlink -f ${ANYRC_DANYRCD})" "${K8S_POD}:${TMP_DIR}/${DANYRCD_NAME}" 84 | 85 | # Transfer *rc 86 | local CMD_DIR="$(abs_dirname $0)" 87 | for cmd in "${ANYRC_CMD}" "${ANYRC_CMDS[@]}"; do 88 | if [ -f "${CMD_DIR}/${cmd}" ]; then 89 | kubectl cp ${K8S_GLOBAL_OPTS} ${K8S_CONTAINER_OPTS} "$(readlink -f ${CMD_DIR}/${cmd})" "${K8S_POD}:${TMP_DIR}/${cmd}" 90 | fi 91 | done 92 | else 93 | # Transfer .anyrc.d 94 | tar cz -h -C "${DANYRCD_DIR}" "${DANYRCD_BASE}" \ 95 | | kubectl exec -i ${K8S_GLOBAL_OPTS} ${K8S_CONTAINER_OPTS} ${K8S_POD} -- tar xz -C "${TMP_DIR}" 96 | 97 | # Transfer *rc 98 | local CMD_DIR=$(abs_dirname $0) 99 | local RCS=() 100 | for cmd in "${ANYRC_CMD}" "${ANYRC_CMDS[@]}"; do 101 | if [ -f "${CMD_DIR}/${cmd}" ]; then 102 | RCS=("${RCS[@]}" "${cmd}") 103 | fi 104 | done 105 | tar czf - -h -C ${CMD_DIR} "${RCS[@]}" \ 106 | | kubectl exec -i ${K8S_GLOBAL_OPTS} ${K8S_CONTAINER_OPTS} "${K8S_POD}" -- tar xz -C "${TMP_DIR}" 107 | fi ;; 108 | esac 109 | } 110 | 111 | connect() { 112 | case "${K8S_SUBCMD}" in 113 | exec ) 114 | kubectl exec ${K8S_GLOBAL_OPTS} ${K8S_CONTAINER_OPTS} ${K8S_EXEC_OPTS} "${K8S_POD}" \ 115 | -- "${REMOTE_SHELL}" -c " 116 | export DANYRC_NAME=\"${DANYRC_NAME}\" 117 | export DANYRCD_NAME=\"${DANYRCD_NAME}\" 118 | export ANYRC_ROOT=\"${TMP_DIR}\" 119 | export ANYRC_DANYRC=\"\${ANYRC_ROOT}/\${DANYRC_NAME}\" 120 | export ANYRC_DANYRCD=\"\${ANYRC_ROOT}/\${DANYRCD_NAME}\" 121 | export ANYRC_HOME=\"\${ANYRC_DANYRCD}\" 122 | export SHELL=\$(which \"${REMOTE_SHELL}\") 123 | export PATH=\"\${PATH}:\${ANYRC_ROOT}\" 124 | trap \"rm -rf \${ANYRC_ROOT}; exit\" 0 125 | source \"\${ANYRC_DANYRC}\" 126 | if [ \"${REMOTE_SHELL##*/}\" = 'bash' ]; then 127 | bash --rcfile \${ANYRC_DANYRC} 128 | else 129 | ${REMOTE_SHELL} 130 | fi" ;; 131 | esac 132 | } 133 | 134 | source anyrc 135 | -------------------------------------------------------------------------------- /sshrc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ANYRC_ENV='ssh' 4 | 5 | init() { 6 | SSH_CMD="${ANYRC_SSH_CMD:-ssh}" 7 | SSH_OPTS='' 8 | while [[ -n "$1" ]]; do 9 | case "$1" in 10 | --ssh_cmd ) 11 | SSH_CMD="$2" 12 | shift ;; 13 | -b | -c | -D | -E | -e | -F | -I | -i | -J | -L | -l | -m | -O | -o | -p | -Q | -R | -S | -W | -w ) 14 | SSH_OPTS="${SSH_OPTS} $1 $2"; shift ;; 15 | -* ) 16 | SSH_OPTS="${SSH_OPTS} $1" ;; 17 | * ) 18 | if [ -z "${SSH_REMOTE:+_}" ]; then 19 | SSH_REMOTE="$1" 20 | fi; ;; 21 | esac 22 | shift 23 | done 24 | if [ -z "${SSH_REMOTE:+_}" ]; then 25 | ${SSH_CMD} ${SSH_OPTS}; exit 1; 26 | fi 27 | } 28 | 29 | mk_tmp_dir() { 30 | : 31 | } 32 | 33 | transfer() { 34 | : 35 | } 36 | 37 | connect() { 38 | local CMD_DIR="$(abs_dirname $0)" 39 | ${SSH_CMD} -t "${SSH_REMOTE}" ${SSH_OPTS} "\ 40 | export DANYRC_NAME=\"${DANYRC_NAME}\" 41 | export DANYRCD_NAME=\"${DANYRCD_NAME}\" 42 | export ANYRC_ROOT=\"\$(mktemp -d /tmp/anyrc.XXXXXX)\" 43 | export ANYRC_DANYRC=\"\${ANYRC_ROOT}/\${DANYRC_NAME}\" 44 | export ANYRC_DANYRCD=\"\${ANYRC_ROOT}/\${DANYRCD_NAME}\" 45 | export ANYRC_HOME=\"\${ANYRC_DANYRCD}\" 46 | export PATH=\"\${ANYRC_ROOT}:\${PATH}\" 47 | trap \"rm -rf \${ANYRC_ROOT}; exit\" 0 48 | mkdir -p \${ANYRC_DANYRCD} 49 | echo '"$(cat "${ANYRC_DANYRC}" | base64)"' | tr -s ' ' '\n' | base64 -d > \${ANYRC_DANYRC} 50 | echo '"$(tar czf - -h -C ${CMD_DIR} ${ANYRC_CMD} ${ANYRC_CMDS[@]} | base64)"' | tr -s ' ' $'\n' | base64 -d | tar mxzf - -C \${ANYRC_ROOT} 51 | echo '"$(tar czf - -h -C ${DANYRCD_DIR} ${DANYRCD_BASE} | base64)"' | tr -s ' ' '\n' | base64 -d | tar mxzf - -C \${ANYRC_ROOT} 52 | source \${ANYRC_DANYRC} 53 | if [ \"\${SHELL##*/}\" = 'bash' ]; then 54 | bash --rcfile \${ANYRC_DANYRC}; 55 | else 56 | \${SHELL}; 57 | fi" 58 | } 59 | 60 | source anyrc 61 | -------------------------------------------------------------------------------- /surc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ANYRC_ENV='su' 4 | 5 | init() { 6 | SU_OPTS='' 7 | while [[ -n "$1" ]]; do 8 | case $1 in 9 | -* ) 10 | SU_OPTS="${SU_OPTS} $1" ;; 11 | * ) 12 | if [ -z "${SU_USER:+_}" ]; then 13 | SU_USER="$1" 14 | fi; ;; 15 | esac 16 | shift 17 | done 18 | if [ -z "${SU_USER:+_}" ]; then 19 | exit 1 20 | fi 21 | } 22 | 23 | mk_tmp_dir() { 24 | TMP_DIR="$(mktemp -d /tmp/anyrc.XXXXXX)" 25 | } 26 | 27 | transfer() { 28 | cp "${ANYRC_DANYRC}" "${TMP_DIR}/${DANYRC_NAME}" 29 | cp -r "${ANYRC_DANYRCD}" "${TMP_DIR}/${DANYRCD_NAME}" 30 | 31 | # Transfer *rc 32 | local CMD_DIR="$(abs_dirname $0)" 33 | for cmd in "${ANYRC_CMD}" "${ANYRC_CMDS[@]}"; do 34 | if [ -f "${CMD_DIR}/${cmd}" ]; then 35 | cp "${CMD_DIR}/${cmd}" "${TMP_DIR}/${cmd}" 36 | fi 37 | done 38 | 39 | chmod -R 777 "${TMP_DIR}" 40 | } 41 | 42 | connect() { 43 | sudo -s -u "${SU_USER}" ${SU_OPTS} bash -c "\ 44 | export DANYRC_NAME=\"${DANYRC_NAME}\" && \ 45 | export DANYRCD_NAME=\"${DANYRCD_NAME}\" && \ 46 | export ANYRC_ROOT=\"${TMP_DIR}\" && \ 47 | export ANYRC_DANYRC=\"\${ANYRC_ROOT}/\${DANYRC_NAME}\" && \ 48 | export ANYRC_DANYRCD=\"\${ANYRC_ROOT}/\${DANYRCD_NAME}\" && \ 49 | export ANYRC_HOME=\"\${ANYRC_DANYRCD}\" && \ 50 | export PATH=\"\${ANYRC_ROOT}:\${PATH}\" && \ 51 | trap \"rm -rf \${ANYRC_ROOT}/*; exit\" 0 && \ 52 | mkdir -p \${ANYRC_DANYRCD} && \ 53 | source \${ANYRC_DANYRC} 54 | if [ \"\${SHELL##*/}\" = 'bash' ]; then 55 | bash --rcfile \${ANYRC_DANYRC}; 56 | else 57 | \${SHELL}; 58 | fi" 59 | rm -rf "${TMP_DIR}" # FIXME 60 | } 61 | 62 | source anyrc 63 | --------------------------------------------------------------------------------