mirror of
https://github.com/DictXiong/dotfiles.git
synced 2026-11-06 03:58:16 +08:00
Compare commits
26 Commits
v1.3
...
7e33f92e51
| Author | SHA1 | Date | |
|---|---|---|---|
| 7e33f92e51 | |||
| 3e425f45e0 | |||
| e9e8a5fede | |||
| 74bffde6cf | |||
| b170d06d9a | |||
| cb70dc7cdc | |||
| 9cf6d65692 | |||
| a7074fc940 | |||
| 4e3ce4f9d9 | |||
| ed98a56e05 | |||
| e79b092054 | |||
| f45f7e415c | |||
| 9f1bc8f0fb | |||
| ee44717891 | |||
| d283671f25 | |||
| bdef3b52d1 | |||
| c86cc85e24 | |||
| 426e97c10e | |||
| e1f0ec0ebc | |||
| 8dbb310e02 | |||
| 8865dee1e9 | |||
| 65d690f47c | |||
| ecf652ad7b | |||
| 86670306af | |||
| 891bbcacff | |||
| 055d44886b |
6
.github/workflows/gitee_sync.yml
vendored
6
.github/workflows/gitee_sync.yml
vendored
@@ -1,15 +1,13 @@
|
||||
name: sync repos to gitee
|
||||
on:
|
||||
push: ~
|
||||
schedule:
|
||||
- cron: 10 4 * * *
|
||||
workflow_dispatch: ~
|
||||
jobs:
|
||||
dotfiles:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: DictXiong/dotfiles
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
uses: Yikun/hub-mirror-action@v1.5
|
||||
with:
|
||||
src: github/DictXiong
|
||||
dst: gitee/dictxiong
|
||||
|
||||
32
.github/workflows/gitee_sync_dependencies.yml
vendored
32
.github/workflows/gitee_sync_dependencies.yml
vendored
@@ -5,10 +5,10 @@ on:
|
||||
workflow_dispatch: ~
|
||||
jobs:
|
||||
ohmyzsh:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: ohmyzsh repo
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
uses: Yikun/hub-mirror-action@v1.5
|
||||
with:
|
||||
src: github/ohmyzsh
|
||||
dst: gitee/dictxiong
|
||||
@@ -22,10 +22,10 @@ jobs:
|
||||
static_list: "ohmyzsh"
|
||||
timeout: '600s'
|
||||
zsh-users:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: zsh-users repos
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
uses: Yikun/hub-mirror-action@v1.5
|
||||
with:
|
||||
src: github/zsh-users
|
||||
dst: gitee/dictxiong
|
||||
@@ -39,10 +39,10 @@ jobs:
|
||||
static_list: "antigen,zsh-syntax-highlighting,zsh-autosuggestions,zsh-completions"
|
||||
timeout: '600s'
|
||||
zdharma-continuum:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: zdharma-continuum repos
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
uses: Yikun/hub-mirror-action@v1.5
|
||||
with:
|
||||
src: github/zdharma-continuum
|
||||
dst: gitee/dictxiong
|
||||
@@ -56,10 +56,10 @@ jobs:
|
||||
static_list: "fast-syntax-highlighting"
|
||||
timeout: '600s'
|
||||
tmux-mem-cpu-load:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: thewtex/tmux-mem-cpu-load
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
uses: Yikun/hub-mirror-action@v1.5
|
||||
with:
|
||||
src: github/thewtex
|
||||
dst: gitee/dictxiong
|
||||
@@ -73,10 +73,10 @@ jobs:
|
||||
static_list: "tmux-mem-cpu-load"
|
||||
timeout: '600s'
|
||||
tmux-plugins:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: tmux-plugins
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
uses: Yikun/hub-mirror-action@v1.5
|
||||
with:
|
||||
src: github/tmux-plugins
|
||||
dst: gitee/dictxiong
|
||||
@@ -90,10 +90,10 @@ jobs:
|
||||
static_list: "tpm,tmux-resurrect,tmux-yank"
|
||||
timeout: '600s'
|
||||
vundle-vim:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: VundleVim/Vundle-vim
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
uses: Yikun/hub-mirror-action@v1.5
|
||||
with:
|
||||
src: github/VundleVim
|
||||
dst: gitee/dictxiong
|
||||
@@ -107,10 +107,10 @@ jobs:
|
||||
static_list: "Vundle.vim"
|
||||
timeout: '600s'
|
||||
onedark-vim:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: joshdick/onedark-vim
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
uses: Yikun/hub-mirror-action@v1.5
|
||||
with:
|
||||
src: github/joshdick
|
||||
dst: gitee/dictxiong
|
||||
@@ -124,10 +124,10 @@ jobs:
|
||||
static_list: "onedark.vim"
|
||||
timeout: '600s'
|
||||
fzf:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: junegunn/fzf
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
uses: Yikun/hub-mirror-action@v1.5
|
||||
with:
|
||||
src: github/junegunn
|
||||
dst: gitee/dictxiong
|
||||
|
||||
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@@ -46,7 +46,7 @@ jobs:
|
||||
|
||||
test-macos:
|
||||
name: test on macos
|
||||
runs-on: macos-12
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- name: checkout repo
|
||||
uses: actions/checkout@v4
|
||||
@@ -91,7 +91,7 @@ jobs:
|
||||
steps:
|
||||
- name: remove dependencies
|
||||
run: |
|
||||
sudo apt-get -y remove curl vim python3
|
||||
sudo apt-get -y remove curl vim
|
||||
|
||||
- name: checkout repo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
@@ -2,27 +2,22 @@
|
||||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGakUcSuNhuH7tk+Nj9gDfRtxYfGPL9yb8toQ/EpSJAM openpgp:0xD9271B01
|
||||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEJ4FeeBwPcUe25JsZQ7xDmGtFVeO1TQ9332IPjFY0Xm openpgp:0x8774BF70
|
||||
|
||||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCUN7IXF4nlFcVfgHesgik3LIAiXlVMYJPm3yD13EVarQx5jqdBgk8Dwgkgf4rPO6MFpvIpinOyEO8zOS6HHQrCLZUv5yTFaDkUuB7eQ0EmpicGbmk9bHqj1HkOZxaobkpEfQUmFKYvkp4EexVw66sO0qfXvjHZ4H6yCAJLK5aUnKfgrE8tODzP82sU/mpJjW+Pq3uanNq754gaHwhxCIXG143/zp8qzBAeKe38xVqqDq9fTkG4hvzFvkRdS88i6l1z++0P3n0HGdOjtSg7P7fO7+7ZyPYr0gO5vB720Om/zxqPrGd9cicWi4P+aVKa+0ujWH/pqufWG6uCjKWHnBs7 sk0/piv/9a
|
||||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGV/6cLUGA5YWVI6uPhIBOBZvlNBlZLkehHQN0Gxnc+B ltp0/ubuntu
|
||||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAkkF0Qc1YhhgmgZcujjfyn3liCxAAJSGlEme0eD6s908zm95mGd64fQJSoYVaFt5y9wrQLdWX16c+gvRyNaQdPfs5jxaP+G8Vr6PkkE79hwauEOQOTbr+q3bQJmfLe56cMV7oHrKVFffkJQTvp1mcK4+CYytsxJP5v0m5TDyv4op6VcZ2m0gdrFEBV3DMMgsqF6/tSPkqbTTj9fMMSOFzXPq7qEQWgYmxT+M0iQdgEiG7Z+INkofM56tBmQ7jSeO65/FTytB6ZMiI23NGmTmYvHPyxSDWXL0X7tX42S0/A7QhxZHN0GUD0NGaSExLfgTawRLhARVHbUXC9iu5aCAr sk1/piv/9a
|
||||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILqRfdez8IAOf6m9Ysi3uSNKEG0Xi6GPuhA6R2fci2yB ltp0/windows
|
||||
sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIA71ukY9nzzeAGp9WYstPYiIwexzIANlPwMQ68QNQwqxAAAABHNzaDo= sk1/fido2
|
||||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFO4k0tJ+Bfu95Uavg/5P3EXMKNcq+bMqaTqzkvRZ7ji ltp1/ubuntu
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMyZILj+GxTUhdCgz2w1TxQ+aTcggnOJIb84qA4u271S ltp0
|
||||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN8g34WHLEix6Qt0J/ClYbZeb9wh+p1IOcZkz/vNbZrv ltp1/windows
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGZFTyR+R86fUpZBDkDR9yYzJpmeNsIv2CMHTh6EuEeq pc0
|
||||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBN24pvN1RMN+iSZyHPdyExA1Rvt8pdr3e6ih6iX+KrQ ltp2
|
||||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGZFTyR+R86fUpZBDkDR9yYzJpmeNsIv2CMHTh6EuEeq pc0/windows
|
||||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHLYgVj+NPino6sOmahULN7SbAMaVAgzqPfDjz2S8zDv pc1/windows
|
||||
|
||||
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNvHya5i3GNniGww9Yx5ikos4Z5jevu8zz8hCQi05++SgejFPnbw9UjbHFjODK2M+ZHuhRF5mdf996r4/BxWyP8= pad0/sep
|
||||
|
||||
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBC5gu+U4picxVvCNYjLlmxGLpJl7svj3LklO7jSpwqdrNxlE+/xkx07PJx76AbA77dDM1Dxmm/VOvVQCKTRLTgk= ip14/sep
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHLYgVj+NPino6sOmahULN7SbAMaVAgzqPfDjz2S8zDv pc1
|
||||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIF52mPmbLEriZ+DfmrMHFtvg2kiO2JpRpitvs7PbJowh home0
|
||||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKhS4voo3K/Dvzqckr0bouO1WkCI5XxswstHWnuuyKBz ltp1-bd
|
||||
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNvHya5i3GNniGww9Yx5ikos4Z5jevu8zz8hCQi05++SgejFPnbw9UjbHFjODK2M+ZHuhRF5mdf996r4/BxWyP8= pad0/sep
|
||||
|
||||
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMXu7UND6N1EKcbeSeAj2CwzGA3sM5/bRtLwoY0euWdR4vzB0nwcwd6nct5JCEyozjujJfMt8d7oCzhSt1w/1cU= ip17/sep
|
||||
|
||||
12
.tmux.conf2
12
.tmux.conf2
@@ -1,4 +1,5 @@
|
||||
set -g prefix ^a
|
||||
bind ^a send-prefix
|
||||
set -g mouse on
|
||||
set -g set-clipboard on
|
||||
set -g default-terminal "xterm-256color"
|
||||
@@ -24,8 +25,19 @@ bind - split-window -v -c "#{pane_current_path}"
|
||||
bind | split-window -h -c "#{pane_current_path}"
|
||||
|
||||
# other key bindings
|
||||
## prefix r: reload conf
|
||||
bind r source-file ~/.tmux.conf \; display-message "tmux.conf reloaded"
|
||||
## prefix m: toggle mouse mode
|
||||
bind m run 'old=$(tmux show -gv mouse); new="off"; if [ "$old" = "off" ]; then new="on"; fi; tmux set -g mouse $new && tmux display-message toggle\ mouse\ mode\ $new'
|
||||
## prefix C-x: pane sync
|
||||
bind C-x set-window-option synchronize-panes\; display-message "synchronize-panes is now #{?pane_synchronized,on,off}"
|
||||
## prevent jumping to end after mouse selection
|
||||
bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-selection -x
|
||||
## F12: passthru
|
||||
bind -T root F12 set prefix None \; set key-table off \; set status-bg red \; refresh-client -S
|
||||
bind -T off F12 set -u prefix \; set -u key-table \; set -u status-bg \; refresh-client -S
|
||||
## ESC: exit copy mode
|
||||
bind -T copy-mode-vi Escape send-keys -X cancel
|
||||
|
||||
# styles
|
||||
# status bar
|
||||
|
||||
@@ -39,8 +39,7 @@ case $DFS_UPDATE_CHANNEL in
|
||||
esac
|
||||
if [[ ${#DFS_COMMIT} != 40 ]]; then
|
||||
fmt_error "invalid commit id"
|
||||
apost_beacon "dfs.invalid-commit"
|
||||
apost_log "ERROR" "$THIS_FILE" "invalid commit id: ${DFS_COMMIT}"
|
||||
apost_beacon "dfs.invalid-commit" "invalid commit id: ${DFS_COMMIT}"
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
3
.vimrc2
3
.vimrc2
@@ -10,8 +10,8 @@ filetype plugin indent on
|
||||
" end vundle
|
||||
colorscheme onedark
|
||||
|
||||
syntax on
|
||||
set cursorline
|
||||
set syntax=on
|
||||
set autoindent
|
||||
set smartindent
|
||||
set expandtab "spaces instead of tabs
|
||||
@@ -32,6 +32,7 @@ hi User3 ctermfg=15 ctermbg=2
|
||||
au InsertEnter * hi User3 ctermfg=15 ctermbg=5
|
||||
au InsertLeave * hi User3 ctermfg=15 ctermbg=2
|
||||
set statusline=%3*\ %{mode()}\ %*[%n][%F](%{\"\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\"+\":\"\").\"\"},%{&ff},%Y)%2*%r%1*%m%*%<%=\'0x%B\'\ [Line:%l/%L,Col:%c][%p%%]
|
||||
nnoremap <silent> <C-n> :let [&nu, &rnu] = [!&rnu, &nu+&rnu==1]<cr>
|
||||
|
||||
" When editing a file, always jump to the last known cursor position.
|
||||
" Don't do it when the position is invalid, when inside an event handler
|
||||
|
||||
41
.zshrc2
41
.zshrc2
@@ -9,11 +9,13 @@ else
|
||||
fi
|
||||
export DOTFILES=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
export PATH="$PATH:$DOTFILES/scripts"
|
||||
fpath=($DOTFILES/functions $fpath)
|
||||
export EDITOR='vim'
|
||||
# env for apps
|
||||
export PYTHONIOENCODING='UTF-8'
|
||||
export GPG_TTY=$(tty)
|
||||
export LESS_TERMCAP_md=$'\E[01;33m'
|
||||
export VIRTUAL_ENV_DISABLE_PROMPT=1
|
||||
# env for dfs
|
||||
if [[ -f ~/.config/dotfiles/env ]]; then set -a; source ~/.config/dotfiles/env; set +a; fi
|
||||
export DFS_OS_TYPE="$("$DOTFILES/tools/common.sh" get_os_type)"
|
||||
@@ -68,6 +70,7 @@ ANTIGEN_PLUGINS+=(
|
||||
"fzf"
|
||||
"git"
|
||||
"magic-enter"
|
||||
"man"
|
||||
"per-directory-history"
|
||||
"pip"
|
||||
"podman"
|
||||
@@ -77,7 +80,7 @@ ANTIGEN_PLUGINS+=(
|
||||
"systemd"
|
||||
"timer"
|
||||
"tmux"
|
||||
"ufw"
|
||||
"web-search"
|
||||
"z"
|
||||
)
|
||||
for i in ${ANTIGEN_PLUGINS[*]}; do
|
||||
@@ -111,25 +114,46 @@ fi
|
||||
alias "pls"='sudo $(fc -ln -1)'
|
||||
alias "se"='sudo -sE'
|
||||
alias "sl"='sudo zsh -l'
|
||||
alias "cps"='rsync -avh --info=progress2'
|
||||
alias "mvs"='rsync -avh --info=progress2 --remove-source-files'
|
||||
if [[ "$DFS_OS_TYPE" == "linux" ]]; then alias "ping"='ping -n'; alias "ping6"='ping6 -n'; fi
|
||||
if [[ "$DFS_OS_TYPE" == "msys" ]]; then alias "tmux"='script -qO /dev/null -c "tmux -u"'; fi
|
||||
alias "pbd"='ping baidu.com'
|
||||
alias "p114"='ping 114.114.114.114'
|
||||
alias "p666"='ping6 2001:da8::666'
|
||||
alias "p666"='ping6 240c::6666'
|
||||
alias "cbd"='curl http://www.baidu.com'
|
||||
alias "cbds"='curl https://www.baidu.com'
|
||||
alias "gdebug"='git add -A; git commit --allow-empty -m "bug fix ($(date))"'
|
||||
alias "ls"='ls --color=tty'
|
||||
alias "l"='ls -lAGh --time-style="+%y-%m-%d %H:%M"'
|
||||
alias "ls"='ls --color=tty --time-style="+%y-%m-%d %H:%M"'
|
||||
alias "l"='ls -lAGh'
|
||||
alias "jc"='journalctl'
|
||||
alias "jce"='jc -e'
|
||||
alias "jceu"='jc -eu'
|
||||
alias "jcf"='jc -f'
|
||||
alias "jcfu"='jc -fu'
|
||||
gbes() { git for-each-ref --sort=-committerdate refs/heads refs/remotes --format="%(authordate:format:%y-%m-%d.%a %H:%M %z)|%(color:red)%(objectname:short)|%(color:yellow)%(refname:short)%(color:reset)|%(color:reset)%(authorname): %(color:green)%(subject)" --color=always | column -ts"|" | less -FX }
|
||||
sagt() { eval "$($DOTFILES/tools/sagent.sh $@)" }
|
||||
alias "sc"='systemctl'
|
||||
alias "t"='tmux'
|
||||
gbes() { git for-each-ref --sort=-committerdate refs/heads refs/remotes --format="%(authordate:format:%y-%m-%d.%a %H:%M %z)|%(color:red)%(objectname:short)|%(color:yellow)%(refname:short)%(color:reset)|%(color:reset)%(authorname): %(color:green)%(subject)" --color=always | column -ts"|" | less -FX ; }
|
||||
sagt() { eval "$($DOTFILES/tools/sagent.sh $@)" ; }
|
||||
## nixos
|
||||
use() { nix --experimental-features nix-command --extra-experimental-features flakes shell "${(*)@/#%(#b)([^#]#)/nixpkgs#$match}" ; }
|
||||
bnd() {
|
||||
if [[ -n "$1" && -d "./hosts/$1" ]]; then
|
||||
nixos-rebuild --flake .#$1 build || return $?
|
||||
nix-diff /opt/NixOS-Config/results/hosts/$1 ./result --color=always | less
|
||||
else
|
||||
echo host $1 does not exist
|
||||
fi
|
||||
}
|
||||
nor() {
|
||||
test -n "$1" || { echo fatal: no verb given; return 1; }
|
||||
nixos-rebuild "$1" --flake .${2:+#}$2
|
||||
}
|
||||
alias 'nors'='nor switch'
|
||||
alias 'norbt'='nor boot'
|
||||
alias 'nort'='nor test'
|
||||
alias 'norb'='nor build'
|
||||
alias 'nordb'='nor dry-build'
|
||||
alias 'norda'='nor dry-activate'
|
||||
|
||||
|
||||
# key bindings
|
||||
bindkey "^b" beginning-of-line # ctrl+b
|
||||
@@ -185,7 +209,6 @@ dfs()
|
||||
"$DOTFILES/install.sh" -i
|
||||
echo 'Done. Please open a new shell to see the changes.'
|
||||
;;
|
||||
log ) "$DOTFILES/tools/common.sh" "post_log" "INFO" "dfs" "$2" ;;
|
||||
beacon ) "$DOTFILES/tools/common.sh" "post_beacon" "$2" "$3" ;;
|
||||
* ) echo "unknown command \"$1\". available: update, force-update, version, reset, cd, log" ;;
|
||||
esac
|
||||
|
||||
99
functions/_beam
Normal file
99
functions/_beam
Normal file
@@ -0,0 +1,99 @@
|
||||
#compdef beam
|
||||
|
||||
# =============================================================================
|
||||
# Beam-Go Zsh Completion Script
|
||||
# =============================================================================
|
||||
|
||||
_beam() {
|
||||
local context state state_descr line
|
||||
typeset -A opt_args
|
||||
|
||||
_arguments -C \
|
||||
'1: :_beam_commands' \
|
||||
'*:: :->args'
|
||||
|
||||
case $state in
|
||||
(args)
|
||||
case $line[1] in
|
||||
(serve) _beam_serve ;;
|
||||
(add) _beam_add ;;
|
||||
(list) _beam_list ;;
|
||||
(del) _beam_del ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# --- Subcommand Definitions ---
|
||||
|
||||
(( $+functions[_beam_commands] )) ||
|
||||
_beam_commands() {
|
||||
local -a commands
|
||||
commands=(
|
||||
'serve:Start the beam server daemon'
|
||||
'add:Share a file or directory'
|
||||
'list:List active shares'
|
||||
'del:Delete a share by path or code'
|
||||
)
|
||||
_describe -t commands 'beam command' commands
|
||||
}
|
||||
|
||||
_beam_serve() {
|
||||
_arguments \
|
||||
'(-d --database)'{-d,--database}'=[Database directory (Required)]:directory:_path_files -/' \
|
||||
'(-p --port)'{-p,--port}'=[Port to listen on (default :8280)]:port:' \
|
||||
'(-s --socket)'{-s,--socket}'=[Socket path]:socket path:_files' \
|
||||
'--subpath=[Enable subpath sharing]'
|
||||
}
|
||||
|
||||
_beam_add() {
|
||||
_arguments \
|
||||
'(-d --days)'{-d,--days}'=[Expiration days (default 7)]:days:' \
|
||||
'(-s --socket)'{-s,--socket}'=[Socket path]:socket path:_files' \
|
||||
'1:file to share:_files'
|
||||
}
|
||||
|
||||
_beam_list() {
|
||||
_arguments \
|
||||
'(-s --socket)'{-s,--socket}'=[Socket path]:socket path:_files'
|
||||
}
|
||||
|
||||
_beam_del() {
|
||||
_arguments \
|
||||
'(-s --socket)'{-s,--socket}'=[Socket path]:socket path:_files' \
|
||||
'(-c --code)'{-c,--code}'=[Share code]:share code:_beam_active_codes' \
|
||||
'1:shared path:_files'
|
||||
}
|
||||
|
||||
# --- Helpers ---
|
||||
|
||||
# 动态获取当前的 Share Code
|
||||
# 它会尝试读取用户当前输入的 -s 参数,去连接正确的 socket
|
||||
_beam_active_codes() {
|
||||
local socket_path=""
|
||||
|
||||
# 从 Zsh 解析的参数中提取 socket 路径
|
||||
if [[ -n ${opt_args[-s]} ]]; then
|
||||
socket_path=${opt_args[-s]}
|
||||
elif [[ -n ${opt_args[--socket]} ]]; then
|
||||
socket_path=${opt_args[--socket]}
|
||||
fi
|
||||
|
||||
# 构造查询命令
|
||||
local cmd_args=()
|
||||
cmd_args+=("list")
|
||||
[[ -n $socket_path ]] && cmd_args+=("-s" "$socket_path")
|
||||
|
||||
# 调用 beam list,跳过前两行表头,提取 Code($1) 和 Path($3)
|
||||
# 2>/dev/null 防止服务未启动时报错打印到终端
|
||||
local -a shares
|
||||
shares=("${(@f)$(beam "${cmd_args[@]}" 2>/dev/null | awk 'NR>2 {print $1":"$2" "$3" "$4}')}")
|
||||
|
||||
if [[ ${#shares} -gt 0 ]]; then
|
||||
_describe -t shares 'active share' shares
|
||||
else
|
||||
_message 'no active shares or server not running'
|
||||
fi
|
||||
}
|
||||
|
||||
_beam "$@"
|
||||
35
functions/_beaml
Normal file
35
functions/_beaml
Normal file
@@ -0,0 +1,35 @@
|
||||
#compdef beaml
|
||||
|
||||
_beaml() {
|
||||
local context state line
|
||||
typeset -A opt_args
|
||||
|
||||
_arguments -C \
|
||||
'1: :->cmds' \
|
||||
'2: :->args'
|
||||
|
||||
case $state in
|
||||
cmds)
|
||||
local commands; commands=(
|
||||
'add:Add a new item'
|
||||
'del:Delete an item'
|
||||
'list:List all items'
|
||||
)
|
||||
_describe -t commands 'beaml commands' commands
|
||||
;;
|
||||
args)
|
||||
case $line[1] in
|
||||
add)
|
||||
_files
|
||||
;;
|
||||
del)
|
||||
local -a items
|
||||
items=( /pss/lite/*(N:t) )
|
||||
_describe -t items 'item to delete' items
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_beaml "$@"
|
||||
3
functions/_nixos_config_hosts
Normal file
3
functions/_nixos_config_hosts
Normal file
@@ -0,0 +1,3 @@
|
||||
#compdef bnd nor
|
||||
|
||||
compadd -- /root/NixOS-Config/hosts/*(/:t)
|
||||
3
functions/_sagt
Normal file
3
functions/_sagt
Normal file
@@ -0,0 +1,3 @@
|
||||
#compdef sagt
|
||||
|
||||
compadd -- kill ls op piv reset
|
||||
3
functions/_use
Normal file
3
functions/_use
Normal file
@@ -0,0 +1,3 @@
|
||||
#compdef use
|
||||
|
||||
compadd -- $(nix eval --impure --expr 'builtins.attrNames ( (import <nixpkgs>) {} )' 2>/dev/null | tr '[]"' ' ')
|
||||
@@ -1,27 +1,49 @@
|
||||
#!/bin/false
|
||||
|
||||
# remotes
|
||||
j.remote() {
|
||||
remote=ssh.beardic.cn
|
||||
RET_PORT=${RET_PORT:-24022}
|
||||
RET_USERNAME=${RET_USERNAME:-root}
|
||||
RET_TRUST_SERVER=1
|
||||
# batches
|
||||
nasps.batch() {
|
||||
remotes+=(
|
||||
g1.nasp
|
||||
g2.nasp
|
||||
g3.nasp
|
||||
g4.nasp
|
||||
g5.nasp
|
||||
g6.nasp
|
||||
g7.nasp
|
||||
g8.nasp
|
||||
g9.nasp
|
||||
g10.nasp
|
||||
g11.nasp
|
||||
g12.nasp
|
||||
g13.nasp
|
||||
g14.nasp
|
||||
dictxiong@g15.nasp
|
||||
dictxiong@g16.nasp
|
||||
g17.nasp
|
||||
)
|
||||
}
|
||||
|
||||
# remotes
|
||||
nasp.remote() {
|
||||
remote=nasp.fit
|
||||
remote=jump.nasp.fit
|
||||
RET_PORT=${RET_PORT:-36022}
|
||||
RET_USERNAME=${RET_USERNAME:-ssh}
|
||||
RET_USERNAME=${RET_USERNAME:-root}
|
||||
RET_TRUST_SERVER=1
|
||||
}
|
||||
|
||||
# domains
|
||||
.domain() {
|
||||
RET_USERNAME=${RET_USERNAME:-root}
|
||||
RET_PORT=${RET_PORT:-12022}
|
||||
RET_HOSTNAME=${remote%.}
|
||||
}
|
||||
|
||||
i.domain() {
|
||||
RET_HOSTNAME=$host.ibd.ink
|
||||
dxng.domain() {
|
||||
if [[ "$host" =~ ^sed([0-9]{1,2})$ ]]; then
|
||||
RET_HOSTNAME=192.168.98.$((100+BASH_REMATCH[1]))
|
||||
else
|
||||
RET_HOSTNAME=$host.dxng.net
|
||||
fi
|
||||
RET_PORT=${RET_PORT:-12022}
|
||||
RET_USERNAME=${RET_USERNAME:-root}
|
||||
RET_TRUST_SERVER=1
|
||||
@@ -34,23 +56,14 @@ i.domain() {
|
||||
RET_TRUST_SERVER=1
|
||||
}
|
||||
|
||||
x.domain() {
|
||||
RET_HOSTNAME=ssh.beardic.cn
|
||||
local tmp=$(sha256sum <<< "$host" | tr -cd "[:digit:]")
|
||||
tmp=${tmp:0:4}
|
||||
RET_PORT=$((10#$tmp+36000))
|
||||
RET_USERNAME=root
|
||||
RET_TRUST_SERVER=1
|
||||
}
|
||||
|
||||
nasp.domain() {
|
||||
RET_HOSTNAME=$host
|
||||
RET_PORT=${RET_PORT:-12022}
|
||||
RET_USERNAME=${RET_USERNAME:-dictxiong}
|
||||
RET_JUMP_SERVER="ssh@nasp.fit:36022"
|
||||
RET_USERNAME=${RET_USERNAME:-root}
|
||||
RET_JUMP_SERVER="ssh@jump.nasp.fit:36022"
|
||||
RET_TRUST_SERVER=1
|
||||
}
|
||||
|
||||
default.domain() {
|
||||
i.domain
|
||||
dxng.domain
|
||||
}
|
||||
|
||||
328
scripts/riot
328
scripts/riot
@@ -4,7 +4,7 @@ THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
source "$THIS_DIR/../tools/common.sh"
|
||||
RIOT_TRUST_CLIENT=${RIOT_TRUST_CLIENT:-${DFS_TRUST:-0}}
|
||||
RIOT_TRUST_SERVER=${RIOT_TRUST_SERVER:-0}
|
||||
RIOT_EXTRA_OPTIONS=""
|
||||
EXTRA_SSH_OPTIONS=()
|
||||
|
||||
# config
|
||||
RIOT_CONFIG_FILES=(
|
||||
@@ -20,14 +20,14 @@ done
|
||||
|
||||
# check if port number valid
|
||||
check_port() {
|
||||
( echo $1 | grep -qxE "[1-9][0-9]{0,4}" ) || return 1
|
||||
test $1 -lt 65536 -a $1 -gt 0 || return 1
|
||||
[[ "$1" =~ ^[1-9][0-9]{0,4}$ ]] || return 1
|
||||
[[ $1 < 65536 && $1 > 0 ]] || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
# check if username valid
|
||||
check_username() {
|
||||
( echo $1 | grep -qxE "^[a-z][-a-z0-9_]*\$" ) || return 1
|
||||
[[ "$1" =~ ^[a-z][-a-z0-9_]*$ ]] || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -42,18 +42,28 @@ get_server_meta() {
|
||||
RET_JUMP_SERVER="" # optional
|
||||
# body
|
||||
local remote="$1"
|
||||
# if in the form user@...
|
||||
# extract username from user@...
|
||||
if [[ "$remote" == *@* ]]; then
|
||||
RET_USERNAME=${remote%%@*}
|
||||
remote=${remote#*@}
|
||||
check_username $RET_USERNAME || fmt_warning \"$RET_USERNAME\" is not a valid unix username
|
||||
fi
|
||||
# if in the form ...:22
|
||||
if [[ "$remote" == "["*"]":* || ( "$remote" != "["*"]" && "$remote" == *:* ) ]]; then
|
||||
# extract port from ...:port
|
||||
if [[
|
||||
"$remote" =~ ^[^:]+:[1-9][0-9]*$ # contains only one colon
|
||||
|| "$remote" =~ ^\[.+\]:[1-9][0-9]*$ # in the form of [host]:port
|
||||
|| "$remote" =~ :::[1-9][0-9]*$ # in the form of :::port
|
||||
|| "$remote" =~ ^([0-9a-f]{1,4}:){7}[0-9a-f]{1,4}:[1-9][0-9]*$ # full ipv6 address with port
|
||||
|| "$remote" =~ ^[0-9a-f:]+%.+:[1-9][0-9]*$ # ipv6 address with scope and port
|
||||
]]; then
|
||||
RET_PORT=${remote##*:}
|
||||
remote=${remote%:*}
|
||||
check_port $RET_PORT || fmt_fatal invalid port number \"$RET_PORT\"
|
||||
fi
|
||||
# remove square brackets
|
||||
if [[ "$remote" =~ ^\[.*\]$ ]]; then
|
||||
remote=${remote:1:-1}
|
||||
fi
|
||||
# presets -- match remote
|
||||
local remote_func="$remote.remote"
|
||||
if is_function "$remote_func"; then
|
||||
@@ -63,8 +73,8 @@ get_server_meta() {
|
||||
RET_HOSTNAME=${remote}
|
||||
local domain=${remote##*.}
|
||||
local host=${remote%.*}
|
||||
# if there's no dot
|
||||
if [[ "$host" == "$domain" && "$host" != "["*"]" ]]; then
|
||||
# if it contains no dot and is not ipv6
|
||||
if [[ "$remote" != *.* && "$remote" != *:* ]]; then
|
||||
domain="default"
|
||||
fi
|
||||
local domain_func="$domain.domain"
|
||||
@@ -83,12 +93,15 @@ parse_remote() {
|
||||
TRUST_SERVER=1
|
||||
PORT="" # optional
|
||||
USERNAME="" # optional
|
||||
SSH_OPTIONS="" # optional
|
||||
SSH_OPTIONS=("-o" "ServerAliveInterval=60")
|
||||
if [[ -t 1 ]]; then
|
||||
SSH_OPTIONS+=("-o" "RequestTTY=yes")
|
||||
fi
|
||||
if [[ "$RIOT_TRUST_CLIENT" == "1" ]]; then
|
||||
SSH_OPTIONS='-o PermitLocalCommand=yes'
|
||||
SSH_OPTIONS+=("-o" "PermitLocalCommand=yes")
|
||||
if [[ "$(get_os_type)" != "msys" ]]; then
|
||||
test "$DFS_DRY_RUN" = "1" || mkdir -p ~/.ssh/master-socket
|
||||
SSH_OPTIONS="$SSH_OPTIONS -o ControlMaster=auto -o ControlPath=~/.ssh/master-socket/%C"
|
||||
SSH_OPTIONS+=("-o" "ControlMaster=auto" "-o" "ControlPersist=5s" "-o" "ControlPath=~/.ssh/master-socket/%C")
|
||||
fi
|
||||
fi
|
||||
# handle input
|
||||
@@ -115,18 +128,41 @@ parse_remote() {
|
||||
done
|
||||
# construct cmd
|
||||
if [[ "$RIOT_TRUST_SERVER" == "1" || "$TRUST_SERVER" == "1" ]]; then
|
||||
SSH_OPTIONS="$SSH_OPTIONS -o ForwardX11=yes -o ForwardAgent=yes"
|
||||
SSH_OPTIONS+=("-o" "ForwardX11=yes" "-o" "ForwardAgent=yes")
|
||||
fi
|
||||
if [[ -n "$jump_servers" ]]; then
|
||||
SSH_OPTIONS="$SSH_OPTIONS -o ProxyJump=$jump_servers"
|
||||
SSH_OPTIONS+=("-o" "ProxyJump=$jump_servers")
|
||||
fi
|
||||
}
|
||||
|
||||
print_cmd() {
|
||||
local output=""
|
||||
for s in "${CMD[@]}"; do
|
||||
if [[ "$s" =~ [\ \\\'\"] ]]; then # needs to be escaped
|
||||
s="${s@Q}"
|
||||
fi
|
||||
output+="$s "
|
||||
done
|
||||
fmt_note "--> ${output% }"
|
||||
}
|
||||
|
||||
eval_or_echo() {
|
||||
local DO=""
|
||||
tmux_win=${tmux_win:-0}
|
||||
if [[ "$DFS_DRY_RUN" == "1" ]]; then
|
||||
echo $@
|
||||
DO=echo
|
||||
fi
|
||||
if [[ "$USE_TMUX" == "1" ]]; then
|
||||
if [[ -z "$TMUX_SESS" ]]; then
|
||||
TMUX_SESS=riot-$(date +%s)
|
||||
$DO tmux new-session -d -s $TMUX_SESS bash -l
|
||||
else
|
||||
tmux_win=$((tmux_win+1))
|
||||
$DO tmux new-window -t $TMUX_SESS:$tmux_win -d bash -l
|
||||
fi
|
||||
$DO tmux send-keys -t $TMUX_SESS:$tmux_win $(printf '%s Space ' "${CMD[@]}") Enter
|
||||
else
|
||||
eval $@
|
||||
$DO "${CMD[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -138,44 +174,83 @@ prepare_ssh_cmd() {
|
||||
else
|
||||
local port_param='-p'
|
||||
fi
|
||||
echo "$ssh_bin ${PORT:+$port_param} $PORT $SSH_OPTIONS $RIOT_EXTRA_OPTIONS $SCP_SRC $USERNAME${USERNAME:+@}$SERVER $SCP_DST ${@:2}"
|
||||
CMD=(
|
||||
"$ssh_bin"
|
||||
"${PORT:+$port_param}" "$PORT"
|
||||
"${SSH_OPTIONS[@]}"
|
||||
"${EXTRA_SSH_OPTIONS[@]}"
|
||||
"$SCP_SRC"
|
||||
"$USERNAME${USERNAME:+@}$SERVER"
|
||||
"$SCP_DST"
|
||||
"${@:2}"
|
||||
)
|
||||
for i in ${!CMD[@]}; do if [[ -z "${CMD[i]}" ]]; then unset CMD[i]; fi; done
|
||||
}
|
||||
|
||||
# ssh
|
||||
run_ssh()
|
||||
{
|
||||
local cmd="$(prepare_ssh_cmd $@)"
|
||||
fmt_note "-->" $cmd
|
||||
eval_or_echo $cmd
|
||||
prepare_ssh_cmd "$@"
|
||||
print_cmd
|
||||
eval_or_echo
|
||||
}
|
||||
|
||||
# sshl
|
||||
run_sshl()
|
||||
{
|
||||
local arg="$1"
|
||||
if [[ "$arg" != *":"* ]]; then
|
||||
# treat as a port number
|
||||
arg=localhost:$arg
|
||||
local arg left right localsock access
|
||||
local res="${1//[^:]}"
|
||||
local lorr="-L"
|
||||
if [[ "${FUNCNAME[1]}" == "run_sshr" ]]; then
|
||||
lorr="-R"
|
||||
fi
|
||||
local port=$(get_free_port)
|
||||
if [[ ${#res} -eq 2 ]]; then
|
||||
arg="$1"
|
||||
elif [[ ${#res} -eq 0 ]]; then
|
||||
if [[ "$lorr" == "-R" ]]; then
|
||||
arg="$1"
|
||||
else
|
||||
arg="$(get_free_port):localhost:$1"
|
||||
fi
|
||||
else
|
||||
left=${1%%:*}
|
||||
right=${1##*:}
|
||||
if check_port "$left"; then
|
||||
arg="$1"
|
||||
elif check_port "$right"; then
|
||||
arg="$(get_free_port):$1"
|
||||
else
|
||||
arg="$1"
|
||||
localsock=1
|
||||
fi
|
||||
fi
|
||||
if [[ "$localsock" == "1" ]]; then
|
||||
access="unix://${arg%%:*}"
|
||||
else
|
||||
access="localhost:${arg%%:*}"
|
||||
fi
|
||||
SSH_OPTIONS+=("-NC" "$lorr" "$arg")
|
||||
prepare_ssh_cmd ssh
|
||||
print_cmd
|
||||
fmt_note " > please access $access"
|
||||
eval_or_echo
|
||||
}
|
||||
|
||||
SSH_OPTIONS="$SSH_OPTIONS -NC -L $port:$arg"
|
||||
local cmd="$(prepare_ssh_cmd ssh)"
|
||||
fmt_note "-->" $cmd
|
||||
fmt_note " > please access localhost:$port"
|
||||
eval_or_echo $cmd
|
||||
# sshr
|
||||
run_sshr()
|
||||
{
|
||||
run_sshl "$1"
|
||||
}
|
||||
|
||||
# sshd
|
||||
run_sshd()
|
||||
{
|
||||
local port=$(get_free_port)
|
||||
|
||||
SSH_OPTIONS="$SSH_OPTIONS -NC -D $port"
|
||||
local cmd="$(prepare_ssh_cmd ssh)"
|
||||
fmt_note "-->" $cmd
|
||||
local port=${1:-$(get_free_port)}
|
||||
SSH_OPTIONS+=("-NC" "-D" "$port")
|
||||
prepare_ssh_cmd ssh
|
||||
print_cmd
|
||||
fmt_note " > please access localhost:$port"
|
||||
eval_or_echo $cmd
|
||||
eval_or_echo
|
||||
}
|
||||
|
||||
# scp
|
||||
@@ -189,77 +264,180 @@ run_scp() {
|
||||
dst_is_remote=0
|
||||
fi
|
||||
if [[ "$dst_is_remote" == "1" ]]; then
|
||||
SCP_SRC=\""$src"\"
|
||||
SERVER="$SERVER":\""$dst"\"
|
||||
SCP_SRC="$src"
|
||||
SERVER="$SERVER":"$dst"
|
||||
else
|
||||
SERVER="$SERVER":\""$src"\"
|
||||
SCP_DST=\""$dst"\"
|
||||
SERVER="$SERVER":"$src"
|
||||
SCP_DST="$dst"
|
||||
fi
|
||||
SSH_OPTIONS="$SSH_OPTIONS -r"
|
||||
local cmd="$(prepare_ssh_cmd scp)"
|
||||
fmt_note "-->" $cmd
|
||||
eval_or_echo $cmd
|
||||
SSH_OPTIONS+=("-r")
|
||||
prepare_ssh_cmd scp
|
||||
print_cmd
|
||||
eval_or_echo
|
||||
}
|
||||
|
||||
# ping
|
||||
run_ping() {
|
||||
CMD=(ping)
|
||||
if [[ "$1" == "ping4" ]]; then
|
||||
CMD+=(-4)
|
||||
elif [[ "$1" == "ping6" ]]; then
|
||||
CMD+=(-6)
|
||||
fi
|
||||
CMD+=(-c 4 "$SERVER")
|
||||
print_cmd
|
||||
eval_or_echo
|
||||
}
|
||||
|
||||
# remove host keys
|
||||
remove_hostkey() {
|
||||
local key
|
||||
if [[ -z "$PORT" || "$PORT" == "22" ]]; then
|
||||
key=$SERVER
|
||||
else
|
||||
key="[$SERVER]:$PORT"
|
||||
fi
|
||||
ssh-keygen -R "$key"
|
||||
}
|
||||
|
||||
# main
|
||||
print_help()
|
||||
{
|
||||
fmt_info "usage: $0 <service> [command] [options]"
|
||||
echo "available commands: ssh (default), sshl (ssh -L), zssh, sftp"
|
||||
fmt_info "usage: $0 [-Ddhlqt] [--dry-run] [--dev] [--help] [--lite] [--quite] [--trust] [--tmux] [--password] [[-o ssh-option]...] remote [command] [--] [command-args]"
|
||||
cat <<EOF
|
||||
available commands:
|
||||
- ssh [ssh-command-args] (default)
|
||||
- tmux [ssh-command-args] (run ssh in multiple tmux windows)
|
||||
- git [git-command-args] (run git on remote machine)
|
||||
- sshl [local-port:remote-host:]remote-port (ssh -L)
|
||||
- sshd [local-port] (ssh -D)
|
||||
- zssh [ssh-command-args]
|
||||
- sftp
|
||||
- scp source destination
|
||||
- rm (remove host keys)
|
||||
- ping/ping4/ping6 (ping the remote servers)
|
||||
EOF
|
||||
}
|
||||
|
||||
router() {
|
||||
if [[ -z "$1" || "$1" == "-h" || "$1" == "--help" ]]; then
|
||||
print_help
|
||||
exit
|
||||
fi
|
||||
|
||||
while [[ "$1" == -* ]]; do
|
||||
RIOT_EXTRA_OPTIONS="$RIOT_EXTRA_OPTIONS $1"
|
||||
if [[ "$1" == "-o" ]]; then
|
||||
RIOT_EXTRA_OPTIONS="$RIOT_EXTRA_OPTIONS $2"
|
||||
shift
|
||||
fi
|
||||
local positional=()
|
||||
while [[ $# > 0 ]]; do
|
||||
case "$1" in
|
||||
-h|--help )
|
||||
print_help
|
||||
exit 0
|
||||
;;
|
||||
-t|--trust )
|
||||
RIOT_TRUST_SERVER=1
|
||||
;;
|
||||
--tmux )
|
||||
USE_TMUX=1
|
||||
;;
|
||||
--password )
|
||||
EXTRA_SSH_OPTIONS+=("-o" "PasswordAuthentication=yes" "-o" "PubkeyAuthentication=no")
|
||||
;;
|
||||
-o )
|
||||
EXTRA_SSH_OPTIONS+=("-o" "$2")
|
||||
shift
|
||||
;;
|
||||
-4 )
|
||||
EXTRA_SSH_OPTIONS+=("-4")
|
||||
;;
|
||||
-6 )
|
||||
EXTRA_SSH_OPTIONS+=("-6")
|
||||
;;
|
||||
-v )
|
||||
EXTRA_SSH_OPTIONS+=("-v")
|
||||
;;
|
||||
-- )
|
||||
shift
|
||||
positional+=("$@")
|
||||
break
|
||||
;;
|
||||
-* )
|
||||
fmt_fatal "unknown option: '$1'. if this option is for the remote command, add '--' before."
|
||||
;;
|
||||
* )
|
||||
positional+=("$1")
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
IFS=',' read -ra remotes <<< "$1"
|
||||
for remote in "${remotes[@]}"; do
|
||||
if [[ -z "$remote" ]]; then
|
||||
IFS=',' read -ra remotes <<< "${positional[0]}"
|
||||
for i in ${!remotes[@]}; do if [[ -z "${remotes[i]}" ]]; then unset remotes[i]; fi; done
|
||||
if [[ "${#positional[@]}" == "0" || "${#remotes[@]}" == "0" ]]; then
|
||||
print_help
|
||||
exit 1
|
||||
fi
|
||||
for i in ${!remotes[@]}; do
|
||||
remote="${remotes[i]}"
|
||||
local batch_func="${remote}.batch"
|
||||
if is_function "$batch_func"; then
|
||||
"$batch_func"
|
||||
continue
|
||||
fi
|
||||
parse_remote "$remote"
|
||||
case $2 in
|
||||
ssh|"" )
|
||||
run_ssh ssh "${@:3}"
|
||||
case "${positional[1]}" in
|
||||
ssh|tmux|"" )
|
||||
[[ "${positional[1]}" == tmux ]] && USE_TMUX=1
|
||||
run_ssh ssh "${positional[@]:2}"
|
||||
;;
|
||||
ping|ping6 )
|
||||
run_ssh ssh "${@:2}"
|
||||
git )
|
||||
if printf '%s\0' "${positional[@]:2}" | grep -Fxqz -- '-C'; then
|
||||
run_ssh ssh git "${positional[@]:2}"
|
||||
else
|
||||
run_ssh ssh git -C "$(pwd)" "${positional[@]:2}"
|
||||
fi
|
||||
;;
|
||||
ping|ping4|ping6 )
|
||||
test "${#positional[@]}" -eq 2 || fmt_fatal "ping requires no arguments"
|
||||
run_ping "${positional[1]}"
|
||||
;;
|
||||
zssh )
|
||||
run_ssh zssh
|
||||
run_ssh zssh "${positional[@]:2}"
|
||||
;;
|
||||
sftp )
|
||||
run_ssh sftp
|
||||
run_ssh sftp "${positional[@]:2}"
|
||||
;;
|
||||
sshl )
|
||||
test -n "$3" || fmt_fatal "no target address provided"
|
||||
run_sshl "$3"
|
||||
test -n "${positional[2]}" || fmt_fatal "no target address provided"
|
||||
test "${#positional[@]}" -eq 3 || fmt_fatal "sshl requires exactly one argument"
|
||||
run_sshl "${positional[2]}"
|
||||
;;
|
||||
sshr )
|
||||
test -n "${positional[2]}" || fmt_fatal "no target address provided"
|
||||
test "${#positional[@]}" -eq 3 || fmt_fatal "sshr requires exactly one argument"
|
||||
run_sshr "${positional[2]}"
|
||||
;;
|
||||
sshd )
|
||||
run_sshd
|
||||
test "${#positional[@]}" -le 3 || fmt_fatal "sshd requires one or no arguments"
|
||||
if [[ "${#positional[@]}" -eq 3 ]]; then
|
||||
check_port "${positional[2]}" || fmt_fatal "invalid port number: ${positional[2]}"
|
||||
run_sshd "${positional[2]}"
|
||||
else
|
||||
run_sshd
|
||||
fi
|
||||
;;
|
||||
scp )
|
||||
test -n "$3" || fmt_fatal "no source path specified"
|
||||
test -n "$4" || fmt_fatal "no destination path specified"
|
||||
run_scp "$3" "$4"
|
||||
test "${#positional[@]}" -eq 4 || fmt_fatal "scp requires exactly two arguments: source and destination"
|
||||
test -n "${positional[2]}" || fmt_fatal "no source path specified"
|
||||
test -n "${positional[3]}" || fmt_fatal "no destination path specified"
|
||||
run_scp "${positional[2]}" "${positional[3]}"
|
||||
;;
|
||||
rm )
|
||||
test "${#positional[@]}" -eq 2 || fmt_fatal "rm requires no arguments"
|
||||
remove_hostkey
|
||||
;;
|
||||
* )
|
||||
print_help
|
||||
fmt_fatal "unknown command: $2"
|
||||
fmt_fatal "unknown command: ${positional[1]}"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -n "$TMUX_SESS" && "$DFS_DRY_RUN" != "1" ]]; then
|
||||
tmux attach-session -t $TMUX_SESS
|
||||
fi
|
||||
}
|
||||
|
||||
router "${GOT_OPTS[@]}"
|
||||
|
||||
31
scripts/sne
Executable file
31
scripts/sne
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ "$#" -eq 0 ]; then
|
||||
echo "usage: sne <filename or regex pattern>"
|
||||
echo "example: sne config.yaml"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SEARCH_PATTERN="$1"
|
||||
files=()
|
||||
while IFS= read -r -d $'\0' file; do
|
||||
files+=("$file")
|
||||
done < <(fd "$SEARCH_PATTERN" --type f --print0)
|
||||
file_count=${#files[@]}
|
||||
if [ "$file_count" -eq 0 ]; then
|
||||
echo "no file match '$SEARCH_PATTERN'"
|
||||
exit 0
|
||||
fi
|
||||
echo "🔎 found $file_count files:"
|
||||
for file in "${files[@]}"; do
|
||||
echo " 📄 $file"
|
||||
done
|
||||
echo "----------------------------------------"
|
||||
|
||||
read -r -p "edit? [Y/n] " response
|
||||
response=${response:-Y}
|
||||
if [[ "$response" =~ ^[Yy]$ ]]; then
|
||||
vim "${files[@]}"
|
||||
else
|
||||
echo "❌ aborted"
|
||||
fi
|
||||
@@ -13,7 +13,10 @@ if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
|
||||
ARG=""
|
||||
GOT_OPTS=()
|
||||
while [[ $# > 0 || -n "$ARG" ]]; do
|
||||
if [[ -z "$ARG" ]]; then ARG=$1; shift; fi
|
||||
if [[ -z "$ARG" ]]; then
|
||||
if [[ "$1" == "--" ]]; then GOT_OPTS+=("$@"); break; fi
|
||||
ARG="$1"; shift;
|
||||
fi
|
||||
case $ARG in
|
||||
-q*|--quite ) export DFS_QUIET=1 ;;
|
||||
-l*|--lite ) export DFS_LITE=1 ;;
|
||||
@@ -162,19 +165,6 @@ ask_for_Yn()
|
||||
fi
|
||||
}
|
||||
|
||||
post_log()
|
||||
{
|
||||
if [[ $# != 3 || -z "$1" || -z "$2" || -z "$3" ]]; then
|
||||
fmt_fatal "usage: post_log <level> <section> <content>"
|
||||
fi
|
||||
"${DOTFILES}/tools/frigg-client.sh" "log" "[$1][$2] $3"
|
||||
}
|
||||
|
||||
apost_log()
|
||||
{
|
||||
post_log "$@" 1>/dev/null &
|
||||
}
|
||||
|
||||
post_beacon()
|
||||
{
|
||||
if [[ $# < 1 || -z "$1" ]]; then
|
||||
|
||||
@@ -25,6 +25,7 @@ elif [[ -f /etc/hostname ]]; then
|
||||
else
|
||||
fmt_fatal "unable to get hostname"
|
||||
fi
|
||||
hostname=$(echo $hostname | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
init_uuid()
|
||||
{
|
||||
@@ -63,8 +64,8 @@ handle_resp()
|
||||
|
||||
post_beacon()
|
||||
{
|
||||
local beacon_type=$1
|
||||
local meta=$2
|
||||
local beacon_type="$1"
|
||||
local meta="$2"
|
||||
if [[ -n "$CI" && "$beacon_type" != "gh.ci" && "$beacon_type" != "dfs.invalid-commit" && "$beacon_type" != "dfs.dirty" ]]; then
|
||||
return
|
||||
fi
|
||||
@@ -75,17 +76,6 @@ post_beacon()
|
||||
handle_resp "$resp"
|
||||
}
|
||||
|
||||
post_log()
|
||||
{
|
||||
local log_content=$1
|
||||
if [[ -z "$log_content" ]]; then
|
||||
fmt_fatal "log content is required"
|
||||
fi
|
||||
init_uuid
|
||||
resp=$(curl $DFS_CURL_OPTIONS -sSL -X POST -H "Content-Type: text/plain" -d "$log_content" "https://api.beardic.cn/post-log?hostname=$hostname&uuid=$uuid")
|
||||
handle_resp "$resp"
|
||||
}
|
||||
|
||||
update_dns()
|
||||
{
|
||||
if [[ -z "$DFS_DDNS_IP4$DFS_DDNS_IP6" ]]; then
|
||||
@@ -109,7 +99,7 @@ update_dns()
|
||||
elif [[ "$DFS_DDNS_IP4" == "http"* ]]; then
|
||||
ip4=$(curl $DFS_CURL_OPTIONS -sSL "$DFS_DDNS_IP4")
|
||||
else
|
||||
ip4=$(ip a show $DFS_DDNS_IP4 | grep inet | grep global | awk '/inet / {print $2}' | awk -F'[/]' '{print $1}')
|
||||
ip4=$(ip -4 --brief addr show $DFS_DDNS_IP4 scope global primary | awk '{split($3,a,"/");print a[1]}' | head -n 1)
|
||||
fi
|
||||
if [[ -n "$DFS_DDNS_IP4" && -z "$ip4" ]]; then
|
||||
fmt_fatal "failed getting ip4 address"
|
||||
@@ -125,7 +115,7 @@ update_dns()
|
||||
elif [[ "$DFS_DDNS_IP6" == "http"* ]]; then
|
||||
ip6=$(curl $DFS_CURL_OPTIONS -sSL "$DFS_DDNS_IP6")
|
||||
else
|
||||
ip6=$(ip a show $DFS_DDNS_IP6 | grep inet6 | grep global | awk '/inet6 / {print $2}' | awk -F'[/]' '{print $1}')
|
||||
ip6=$(ip -6 --brief addr show $DFS_DDNS_IP6 scope global primary | awk '{split($3,a,"/");print a[1]}' | head -n 1)
|
||||
fi
|
||||
if [[ -n "$DFS_DDNS_IP6" && -z "$ip6" ]]; then
|
||||
fmt_fatal "failed getting ip6 address"
|
||||
@@ -138,7 +128,7 @@ update_dns()
|
||||
|
||||
print_help()
|
||||
{
|
||||
fmt_info "usage: $0 <beacon|log|ddns> [beacon_type|log_content]"
|
||||
fmt_info "usage: $0 <beacon|ddns> [beacon_type] [beacon_meta]"
|
||||
}
|
||||
|
||||
router()
|
||||
@@ -150,9 +140,6 @@ router()
|
||||
beacon)
|
||||
post_beacon "$2" "$3"
|
||||
;;
|
||||
log)
|
||||
post_log "$2"
|
||||
;;
|
||||
ddns)
|
||||
update_dns
|
||||
;;
|
||||
|
||||
9
tools/sagent-op.sh
Executable file
9
tools/sagent-op.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
op=$(command -v op || command -v op.exe || true)
|
||||
if [[ ! -x $op ]]; then
|
||||
echo "1password cli not found" > /dev/stderr
|
||||
exit -1
|
||||
fi
|
||||
"$op" read "op://Personal/id25519-passphrase/$(hostname)"
|
||||
@@ -47,6 +47,12 @@ add_piv()
|
||||
list
|
||||
}
|
||||
|
||||
add_id25519_with_op()
|
||||
{
|
||||
SSH_ASKPASS_REQUIRE=force SSH_ASKPASS="$THIS_DIR/sagent-op.sh" timeout 60s ssh-add ~/.ssh/id_ed25519 || fmt_fatal "timed out when adding the key. probably the passphrase is wrong or 1password-cli is not working"
|
||||
list
|
||||
}
|
||||
|
||||
list()
|
||||
{
|
||||
echo echo "available keys:"
|
||||
@@ -61,7 +67,8 @@ reset()
|
||||
|
||||
all()
|
||||
{
|
||||
local agent_file="/tmp/piv-agent-$(whoami)"
|
||||
test -d ~/.ssh || mkdir ~/.ssh
|
||||
local agent_file=~/.ssh/agent-$(whoami)
|
||||
if [[ -f $agent_file ]]; then
|
||||
source $agent_file > /dev/null
|
||||
else
|
||||
@@ -95,6 +102,9 @@ route()
|
||||
piv)
|
||||
add_piv
|
||||
;;
|
||||
op)
|
||||
add_id25519_with_op
|
||||
;;
|
||||
reset)
|
||||
reset
|
||||
;;
|
||||
|
||||
@@ -27,7 +27,6 @@ fi
|
||||
|
||||
# check scripts and functions
|
||||
dfs version
|
||||
dfs log 1
|
||||
dfs beacon gh.ci $GITHUB_SHA
|
||||
z ~
|
||||
test ~ -ef "$(pwd)"
|
||||
@@ -41,15 +40,16 @@ test $(echo n | tools/common.sh ask_for_yN "test") = "0"
|
||||
test $(echo | tools/common.sh ask_for_yN "test") = "0"
|
||||
test $(echo | tools/common.sh ask_for_Yn "test") = "1"
|
||||
test $(DFS_QUIET=1 tools/common.sh ask_for_Yn "test") = "1"
|
||||
test "$(DFS_TRUST=1 riot time@is.impt:2222/yes@you-r.right/you@are.really.recht./ibd./try@it,another@host scp /tmp/ ./tmp -D 2>/dev/null)" = 'scp -P 12022 -o PermitLocalCommand=yes -o ControlMaster=auto -o ControlPath=~/.ssh/master-socket/%C -o ProxyJump=time@is.impt:2222,yes@you-r.right,you@are.really.recht.,root@ibd. -r try@it.ibd.ink:"/tmp/" "./tmp"
|
||||
scp -P 12022 -o PermitLocalCommand=yes -o ControlMaster=auto -o ControlPath=~/.ssh/master-socket/%C -o ForwardX11=yes -o ForwardAgent=yes -r another@host.ibd.ink:"/tmp/" "./tmp"'
|
||||
test "$(DFS_TRUST=1 riot time@is.impt:2222/yes@you-r.right/you@are.really.recht./ibd./try@it,another@host scp /tmp/ ./tmp -D 2>/dev/null)" = 'scp -P 12022 -o ServerAliveInterval=60 -o PermitLocalCommand=yes -o ControlMaster=auto -o ControlPersist=5s -o ControlPath=~/.ssh/master-socket/%C -o ProxyJump=time@is.impt:2222,yes@you-r.right:12022,you@are.really.recht:12022,root@ibd:12022 -r try@it.dxng.net:/tmp/ ./tmp
|
||||
scp -P 12022 -o ServerAliveInterval=60 -o PermitLocalCommand=yes -o ControlMaster=auto -o ControlPersist=5s -o ControlPath=~/.ssh/master-socket/%C -o ForwardX11=yes -o ForwardAgent=yes -r another@host.dxng.net:/tmp/ ./tmp'
|
||||
test "$(riot you@example.com:55 -tD ssh --password -- ping -c 1 2>/dev/null)" = 'ssh -p 55 -o ServerAliveInterval=60 -o ForwardX11=yes -o ForwardAgent=yes -o PasswordAuthentication=yes -o PubkeyAuthentication=no you@example.com ping -c 1'
|
||||
|
||||
# check alias
|
||||
alias p114
|
||||
alias cbds
|
||||
which riot
|
||||
sagt
|
||||
test -f "/tmp/piv-agent-$(whoami)"
|
||||
test -f ~/.ssh/agent-$(whoami)
|
||||
gbes || which gbes
|
||||
|
||||
# check update
|
||||
|
||||
@@ -4,7 +4,7 @@ declare -A INSTALL_COMMANDS
|
||||
INSTALL_COMMANDS=(\
|
||||
[git]="apt update && apt install git" \
|
||||
[fzf]="git clone --depth 1 https://gitee.com/dictxiong/fzf.git ~/.fzf && ~/.fzf/install" \
|
||||
[acme.sh]="curl https://get.acme.sh | sh -s email=${EMAIL:-me@beardic.cn}" \
|
||||
[acme.sh]="curl https://get.acme.sh | sh -s email=${EMAIL:-acme@dxng.net}" \
|
||||
[oh-my-zsh]='sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"' \
|
||||
[oh-my-tuna]='wget https://tuna.moe/oh-my-tuna/oh-my-tuna.py && sudo python oh-my-tuna.py --global' \
|
||||
[v2fly]="bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) #--remove" \
|
||||
|
||||
Reference in New Issue
Block a user