From 26e36759b7d40f4cd762e114a445bcb75dec14d5 Mon Sep 17 00:00:00 2001 From: Ein Verne Date: Fri, 21 Jun 2019 17:42:37 +0800 Subject: [PATCH] Update README --- .zshrc | 1 + README.md | 40 +++++------ script/ssh_login | 182 +++++++++++++++++++++++++++++++++++++++++++++++ termux_init.sh | 1 + 4 files changed, 201 insertions(+), 23 deletions(-) create mode 100755 script/ssh_login diff --git a/.zshrc b/.zshrc index dda1490..e48f3b5 100644 --- a/.zshrc +++ b/.zshrc @@ -198,6 +198,7 @@ ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=6' alias tmux="TERM=screen-256color tmux -2" alias vi="vim" alias mux="TERM=screen-256color tmuxinator" +alias ls="ls -alh" alias cp="cp -i" alias df="df -sh" alias free="free -m" diff --git a/README.md b/README.md index 51b9af2..26f6531 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,24 @@ -vim, zsh, tmux 相关的配置 +dotfiles config contain vim, zsh, tmux configurations. ## Overview -使用 [antigen](https://gtk.pw/antigen) 来管理 zsh 插件 -vundle 相关配置在 vundle_vimrc 中,用 vundle 管理插件,插件列表`:PluginList`查看 +- zsh +- vim +- tmux + +With + +- [Vundle](https://github.com/VundleVim/Vundle.vim) to manage vim plugins, vundle relate configuration is under `vundle_vimrc` +- [antigen](https://gtk.pw/antigen) to manage zsh plugins +- [tpm](https://github.com/tmux-plugins/tpm) to manage tmux plugins + + +### Vim config +vundle related configuration is under `vundle_vimrc`, to show all plugins list, use `:PluginList` in vim. + +python related configurations is under `python_vimrc`. + -python 相关配置在 python_vimrc 中 ## Instruction under Linux @@ -30,25 +43,6 @@ with yum: sudo yum install ctags-etags -## Plugin - - Plugin 'VundleVim/Vundle.vim' - Plugin 'tpope/vim-fugitive' - Plugin 'godlygeek/tabular' - Plugin 'plasticboy/vim-markdown' - Plugin 'scrooloose/nerdtree' - Plugin 'davidhalter/jedi-vim' - Plugin 'ervandew/supertab' - Plugin 'Raimondi/delimitMate' - Plugin 'tomasr/molokai' - Plugin 'nathanaelkane/vim-indent-guides' - Plugin 'vim-scripts/taglist.vim' - Plugin 'WolfgangMehner/vim-plugins' - Plugin 'L9' - Plugin 'perl-support.vim' - Plugin 'christoomey/vim-tmux-navigator' - Plugin 'tpope/vim-surround' - Plugin 'git://git.wincent.com/command-t.git' ## Tmux Tmux 配置參考了 [gpakosz](https://github.com/gpakosz/.tmux) 的大部分配置。Tmux 的基础部分可以参考[这篇](http://einverne.github.io/post/2017/07/tmux-introduction.html) 文章。 diff --git a/script/ssh_login b/script/ssh_login new file mode 100755 index 0000000..a3256c5 --- /dev/null +++ b/script/ssh_login @@ -0,0 +1,182 @@ +#!/bin/bash +# Feature : 使用 except 自动模拟输入密码,登录服务器,适用于跳板机情况自动登录ssh +# 对于自己的服务器可以通过配置 ssh key 来直接免密码登录,但是对于一些 +# 跳板机,则每次都需要手动输入比较麻烦,那么可以直接使用该脚本一键登录 +# Notice : 注意系统需要安装 expect 程序 +# Original Author : Jiangxianli +# Modified : Ein Verne +# Date : 2019/06/10 +# Github : https://github.com/jiangxianli/SSHAutoLogin +# Update : Xiongwilee 2018/06/18 https://github.com/xiongwilee/SSHAutoLogin +# Update : + +#默认服务器配置项 +# "别名 服务器名称 端口号 IP地址 登录用户名 登录密码/秘钥文件Key 秘钥文件地址" +CONFIGS=( + "tencent tencent 22 118.xxxxxxxxxx ubuntu 1234" + "ds ds 22 118.xxxxxxxxxx ubuntu 1234" +) + +#读取自定义服务器配置文件(`~/.sshloginrc`)列表,合并服务器配置列表 +sshloginrc_path=~/.sshloginrc +if [ -f ${sshloginrc_path} ]; then + CONFIGS=() + while read line + do + CONFIGS+=("$line") + done < ${sshloginrc_path} +fi + +#服务器配置数 +CONFIG_LENGTH=${#CONFIGS[*]} #配置站点个数 + +if [[ $CONFIG_LENGTH -le 0 ]] ; +then + echo "未检测到服务器配置项!" + echo "请在脚本CONFIGS变量中配置或单独创建一个 ~/.sshloginrc 文件并配置" + exit ; +fi + +## +# 绿色输出 +## +function GreenEcho() { + echo -e "\033[32m ${1} \033[0m"; +} + +## +# 服务器配置菜单 +## +function ConfigList(){ + echo "- 序号 IP 别名" + for ((i=0;i<${CONFIG_LENGTH};i++)); + do + CONFIG=(${CONFIGS[$i]}) #将一维sites字符串赋值到数组 + serverNum=$(($i+1)) + echo "- [${serverNum}] ${CONFIG[3]} ${CONFIG[0]}" + done +} + +## +# 登录菜单 +## +function LoginMenu(){ + if [ ! -n $1 ]; then + AutoLogin $1 + else + echo "-------请输入登录的服务器序号或别名---------" + ConfigList + echo "请输入您选择登录的服务器序号或别名: " + fi +} + +## +# 选择登录的服务器 +## +function ChooseServer(){ + read serverNum; + + # 是否重新选择 + needChooseServer=1; + + if [ -z $serverNum ]; then + echo "请输入序号或者别名" + reChooseServer $needChooseServer; + fi + + AutoLogin $serverNum $needChooseServer; +} + +## +# 是退出还是重新选择Server +# @param $1 是否重新选择server 1: 重新选择server +## +function reChooseServer(){ + if [ "$1"x = "1"x ]; then + ChooseServer; + else + exit; + fi +} + +## +# 自动登录 +# @param $1 序号或者别名 +# @param $2 是否重新选择server 1: 重新选择server +## +function AutoLogin(){ + num=$(GetServer $1) + + if [ -z $num ]; then + echo "您输入的别名【$1】不存在,请重试" + reChooseServer $2; + fi + + CONFIG=(${CONFIGS[$num]}) + + if [ -z $CONFIG ]; then + echo "您输入的序号【$1】不存在,请重试" + reChooseServer $2; + else + echo "正在登录【${CONFIG[1]}】" + fi + + export PASSWORD=${CONFIG[5]}; + + command=" + expect { + \"*assword\" {set timeout 6000; send \$env(PASSWORD)\r; exp_continue ; sleep 3; } + \"*passphrase\" {set timeout 6000; send \$env(PASSWORD)\n\r; exp_continue ; sleep 3; } + \"yes/no\" {send \"yes\n\"; exp_continue;} + \"Last*\" { send_user \"\n成功登录【${CONFIG[1]}】\n\";} + } + interact + "; + pem=${CONFIG[6]} + if [ -n "$pem" ] ;then + expect -c " + spawn ssh -p ${CONFIG[2]} -i ${CONFIG[6]} ${CONFIG[4]}@${CONFIG[3]} + ${command} + " + else + expect -c " + spawn ssh -p ${CONFIG[2]} ${CONFIG[4]}@${CONFIG[3]} + ${command} + " + fi + GreenEcho "您已退出【${CONFIG[1]}】" + exit; + +} + +## +# 通过输入定位选择那个服务器配置 +## +function GetServer(){ + # 判断输入是否为数字 + if [ "$1" -gt 0 ] 2>/dev/null ;then + echo $(($1-1)) + else + for key in ${!CONFIGS[*]} ; do + item=(${CONFIGS[$key]}) + if [ ${item[0]} == $1 ]; then + echo $key + break; + fi + done + fi +} + +## +# 程序入口 +## +if [ 1 == $# ]; then + if [ 'list' == $1 ]; then + ConfigList + else + AutoLogin $1 + fi +else + LoginMenu + ChooseServer +fi diff --git a/termux_init.sh b/termux_init.sh index 9e58f27..f96f93c 100644 --- a/termux_init.sh +++ b/termux_init.sh @@ -2,6 +2,7 @@ # https://github.com/4679/oh-my-termux pkg install -y libcurl wget curl openssh vim git zsh unrar unzip less +pkg install -y tsu neofetch clear if [ -d "$HOME/.termux" ]; then