mirror of
https://github.com/DictXiong/dotfiles.git
synced 2026-02-22 06:15:40 +08:00
Compare commits
No commits in common. "ee44717891add50a52167e84e862f7706cf9519b" and "426e97c10e1adefe6e1e1f5ac3f3a02af1283c1c" have entirely different histories.
ee44717891
...
426e97c10e
@ -1,99 +0,0 @@
|
||||
#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 "$@"
|
||||
@ -1,35 +0,0 @@
|
||||
#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 "$@"
|
||||
36
scripts/riot
36
scripts/riot
@ -93,10 +93,7 @@ parse_remote() {
|
||||
TRUST_SERVER=1
|
||||
PORT="" # optional
|
||||
USERNAME="" # optional
|
||||
SSH_OPTIONS=("-o" "ServerAliveInterval=60")
|
||||
if [[ -t 1 ]]; then
|
||||
SSH_OPTIONS+=("-o" "RequestTTY=yes")
|
||||
fi
|
||||
SSH_OPTIONS=("-o" "RequestTTY=yes")
|
||||
if [[ "$RIOT_TRUST_CLIENT" == "1" ]]; then
|
||||
SSH_OPTIONS+=("-o" "PermitLocalCommand=yes")
|
||||
if [[ "$(get_os_type)" != "msys" ]]; then
|
||||
@ -198,26 +195,20 @@ run_ssh()
|
||||
# sshl
|
||||
run_sshl()
|
||||
{
|
||||
local arg left right localsock access
|
||||
local res="${1//[^:]}"
|
||||
local lorr="-L"
|
||||
if [[ "${FUNCNAME[1]}" == "run_sshr" ]]; then
|
||||
lorr="-R"
|
||||
fi
|
||||
is_port() {
|
||||
if [[ "$1" =~ ^[1-9][0-9]*$ && $1 -gt 1 && $1 -lt 65535 ]]; then return 0; else return 1; fi
|
||||
}
|
||||
res="${1//[^:]}"
|
||||
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
|
||||
if is_port "$left"; then
|
||||
arg="$1"
|
||||
elif check_port "$right"; then
|
||||
elif is_port "$right"; then
|
||||
arg="$(get_free_port):$1"
|
||||
else
|
||||
arg="$1"
|
||||
@ -229,19 +220,13 @@ run_sshl()
|
||||
else
|
||||
access="localhost:${arg%%:*}"
|
||||
fi
|
||||
SSH_OPTIONS+=("-NC" "$lorr" "$arg")
|
||||
SSH_OPTIONS+=("-NC" "-L" "$arg")
|
||||
prepare_ssh_cmd ssh
|
||||
print_cmd
|
||||
fmt_note " > please access $access"
|
||||
eval_or_echo
|
||||
}
|
||||
|
||||
# sshr
|
||||
run_sshr()
|
||||
{
|
||||
run_sshl "$1"
|
||||
}
|
||||
|
||||
# sshd
|
||||
run_sshd()
|
||||
{
|
||||
@ -404,11 +389,6 @@ router() {
|
||||
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 )
|
||||
test "${#positional[@]}" -le 3 || fmt_fatal "sshd requires one or no arguments"
|
||||
if [[ "${#positional[@]}" -eq 3 ]]; then
|
||||
|
||||
@ -40,9 +40,9 @@ 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 ServerAliveInterval=60 -o PermitLocalCommand=yes -o ControlMaster=auto -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 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'
|
||||
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 RequestTTY=yes -o PermitLocalCommand=yes -o ControlMaster=auto -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 RequestTTY=yes -o PermitLocalCommand=yes -o ControlMaster=auto -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 RequestTTY=yes -o ForwardX11=yes -o ForwardAgent=yes -o PasswordAuthentication=yes -o PubkeyAuthentication=no you@example.com ping -c 1'
|
||||
|
||||
# check alias
|
||||
alias p114
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user