Skip to content

Commit

Permalink
feat: add ssh support
Browse files Browse the repository at this point in the history
  • Loading branch information
Pikatsuto committed Aug 3, 2024
1 parent b506004 commit 5a23b58
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
2 changes: 2 additions & 0 deletions package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
wl-clipboard,
nil,
neovim,
sshfs,
...
}:
############
Expand Down Expand Up @@ -72,6 +73,7 @@ stdenv.mkDerivation (finalAttrs: {
wl-clipboard
nil
neovim
sshfs
]}
'';
# ----------------------------------------------------------------- #
Expand Down
59 changes: 49 additions & 10 deletions src/ide
Original file line number Diff line number Diff line change
@@ -1,25 +1,64 @@
#! /usr/bin/env bash

rm -rf ${HOME}/.config/nvim
cp -r /Applications/ide/nvim ${HOME}/.config/
sudo chown -R $(id -u):$(id -g) ${HOME}/.config/nvim
sudo chmod -R 755 ${HOME}/.config/nvim
sudo rm -rf ${HOME}/.config/nvim
cp -r \
/Applications/ide/nvim \
${HOME}/.config/
sudo chown -R $(id -u):$(id -g) \
${HOME}/.config/nvim
sudo chmod -R 755 \
${HOME}/.config/nvim

FolderIdeCommand() {
nvim -c "ToggleTerm direction=horizontal" -c "Neotree"
nvim \
-c "ToggleTerm direction=horizontal" \
-c "Neotree"
}

FileIdeCommand() {
nvim -c "ToggleTerm direction=horizontal" ${1}
nvim \
-c "ToggleTerm direction=horizontal" \
${1}
}

ideCommand="FileIdeCommand ${1}"
if [ -d "${1}" ] 2> /dev/null; then
[[ -d "${1}" && "${1}x" != *"@"* ]] &&
cd ${1}

[[ -d "${1}" || "${1}x" == "x" ]] &&
ideCommand="FolderIdeCommand"
fi
if [ "${1}x" == "x" ] 2> /dev/null; then
ideCommand="FolderIdeCommand"

if [[ "${1}x" == *"@"* ]]; then
port=22
[[ "${2}x" == "-px" && "${3}x" != "x" ]] &&
port="${3}"

dir="${HOME}/.cache/ide/$(echo ${1} | cut -d ':' -f 2)"
mkdir -p ${dir}
umount ${dir} 2> /dev/null
sshfs -p ${port} ${1} ${dir} || exit

while ! $(mountpoint -q ${dir}); do
sleep 0.5
done
cd ${dir}

workDir=$(echo ${1} | cut -d ':' -f 2)
sshLogin="$(echo ${1} | cut -d ':' -f 1)"
choiceShell="zsh 2> /dev/null || fish 2> /dev/null || bash 2> /dev/null;"
sshArgs="bash -c \\\"cd ${workDir}; clear; ${choiceShell}\\\""
sshCommand="/usr/bin/env ssh -t -p ${port} ${sshLogin} \"${sshArgs}\""
SSHIdeCommand() {
nvim \
-c "ToggleTerm direction=horizontal dir=~" \
-c "Neotree" \
-c "TermExec cmd='${sshCommand}'"
}

ideCommand="SSHIdeCommand"
fi

$ideCommand
pkill -f $(findmnt -T ${dir} \
| grep -v "TARGET" \
| cut -d " " -f 2)

0 comments on commit 5a23b58

Please sign in to comment.