Browse Source

Merge 647d75b30c into 81f7f77d33

pull/8/merge
throwawy903090909 1 year ago
parent
commit
3546e1bc1f
No account linked to committer's email address
1 changed files with 50 additions and 3 deletions
  1. 50
    3
      sshget

+ 50
- 3
sshget View File

@@ -1,4 +1,20 @@
#!/usr/bin/env bash
##Modified version of
#https://github.com/DanielFGray/fzf-scripts
#https://github.com/junegunn/fzf/issues/876 FZF delim change example using keybind script.
#Ref https://github.com/junegunn/fzf/commit/131aa5dd15788875e796bbd2f2bfdf644584284a for the fzf keybinding with two commands (run the subsscript + accept output)
# This was included in my zsh conf, takes a remote path as input and starts ssh get on that path, fills results into buffer.
# sshget (){
# # BUFFER=""\
# a="$(/path/to/sshget $BUFFER)"
# zle -R;
# BUFFER="$a";
# zle end-of-line
# }
# zle -N sshget
# bindkey "^]" sshget
##So the idea is host:/remote/folder/ + hotkey -> select files or multiple files -> check the resulting output and run.


declare -r esc=$'\033'
declare -r c_reset="${esc}[0m"
@@ -60,13 +76,44 @@ for a; do
done

for s in "${!domains[@]}"; do
ssh "${domains[$s]}" "find ${paths[$s]}" | sed -r "s|^|${domains[$s]}:|" >> "$fifo" &
#Orig -- prob b/c find is everywhere
# ssh "${domains[$s]}" "find ${paths[$s]}" | sed -r "s|^|${domains[$s]}:|" >> "$fifo" &
#Attempt /w ripgrep,
# ssh "${domains[$s]}" "rg --files ${paths[$s]}" | sed -r "s|^|${domains[$s]}:|" >> "$fifo" &
#Using FD (https://github.com/sharkdp/fd)
ssh "${domains[$s]}" "fd . ${paths[$s]} --exclude .git" | sed -r "s|^|${domains[$s]}:|" >> "$fifo" &
#Using FD limiting to DIRS
# ssh "${domains[$s]}" "fd . ${paths[$s]} --type d" | sed -r "s|^|${domains[$s]}:|" >> "$fifo" &
# Added a bunch of sed find and replaces for special characters, super ugly as both a way of getting to the goal but also implimentation (can combine sed)
# ssh "${domains[$s]}" "fd . ${paths[$s]} --exclude .git -x echo \"{}\"" | sed -r "s|^|${domains[$s]}:|" | sed -r 's| |\\ |g' | sed -r 's|\(|\\(|g' | sed -r 's|\)|\\)|g' | sed -r 's|\[|\\[|g' | sed -r 's|\]|\\]|g' | sed -r 's|\;|\\;|g' >> "$fifo" &
done

mapfile -t files < <(fzf -e --inline-info +s --multi --cycle --bind='Ctrl-A:toggle-all,`:jump' < "$fifo")
# ####### Way:1 Results in double quotes around each path
# mapfile -t files < <(fzf -e --inline-info +s --multi --cycle --bind "ENTER:execute-multi(python -c 'import sys; print \",\".join(sys.argv[1:])' {})+accept" < "$fifo")
# if (( ${#files[@]} )); then
# IFS=",";
# d=''
# for c in ${files[@]}
# do
# d+=" \"$c\""
# done
# CURSOR="rsync --protect-args -auvzP -e ssh $d ."
# echo $CURSOR
# fi

####### Way:2 results in single quotes around each path (probably uses shell instead of python, but works)
mapfile -t files < <(fzf -e --inline-info +s --multi --cycle --bind "ENTER:execute-multi(echo \"{}\")+accept" < "$fifo")
if (( ${#files[@]} )); then
rsync --protect-args -auvzP -e ssh "${files[@]}" .
CURSOR="rsync --protect-args -auzP --append-verify --inplace -e ssh $files ."
echo $CURSOR
fi

# ####### Way:3 Results single quotes this is just a mental bridge between 1 and 2
#
# mapfile -t files < <(fzf -e --inline-info +s --multi --cycle --bind "enter:execute-multi(python -c 'import sys; print \" \".join(sys.argv[1:])' \"{}\")+accept" < "$fifo")
# if (( ${#files[@]} )); then
# CURSOR="rsync --protect-args -auvzP -e ssh $files ."
# echo $CURSOR
# fi

cleanup

Loading…
Cancel
Save