Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some Changes, Mainly quoting paths may be of interest? #8

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 50 additions & 3 deletions sshget
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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