Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
BrightXiaoHan committed Jan 14, 2025
0 parents commit cfc8203
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Lua
*.o
*.so
*.dll
luac.out

# Neovim
.netrwhist

# Logs
*.log

# System files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Editor/IDE specific
.vscode/
.idea/
*.swp
*.swo
*~

# Project specific
node_modules/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023-2024 The Trzsz SSH Authors.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# nvim-trzsz

A Neovim plugin for [trzsz](https://trzsz.github.io/) (trz / tsz) support, which is similar to rz/sz, but with more terminals support.

You can find detailed documentation [here](https://github.com/trzsz/trzsz#supported-terminals).

## Features
- Upload and download files in your ssh session.
- nvim-tree integration.
- Works with tmux sessions.
- Directory support.

Demo:


## Pre-requisites
- Make sure your terminal supports trzsz. You can check the supported terminals [here](https://github.com/trzsz/trzsz#supported-terminals).
- Make sure you are working in a ssh session. trzsz does not work in local terminals.
- Install trzsz-ssh on your local machine. You can find the installation instructions [here](https://github.com/trzsz/trzsz-ssh).

## Installation

Using [lazy.nvim](https://github.com/folke/lazy.nvim):
```lua
{
"BrightXiaohan/nvim-trzsz",
dependencies = {
{"nvim-tree/nvim-tree.lua"}
},
}
```

## Basic Usage
Map the commands to your preferred keybindings:
```lua
vim.keymap.set("n", "t", "<cmd>NvimTreeTrz<CR>", {noremap = true, silent = true})
vim.keymap.set("n", "s", "<cmd>NvimTreeTsz<CR>", {noremap = true, silent = true})
```
Here `t` is for uploading files and `s` is for downloading files.

- ssh into a remote server
- Open neovim and nvim-tree
- Navigate to the file you want to download in nvim-tree
- Press `t` to upload the file or `s` to download the file

or
- Navigate to the directory you want to upload files to in nvim-tree
- Press `s`, and the file explorer will open
- Select the files you want to upload

## License
MIT
80 changes: 80 additions & 0 deletions doc/nvim-trzsz.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
*nvim-trzsz.txt* Trzsz integration for Neovim

================================================================================
CONTENTS *nvim-trzsz-contents*

1. Introduction ........................... |nvim-trzsz-introduction|
2. Requirements ........................... |nvim-trzsz-requirements|
3. Installation .......................... |nvim-trzsz-installation|
4. Usage ................................. |nvim-trzsz-usage|
5. Configuration ......................... |nvim-trzsz-config|
6. Commands .............................. |nvim-trzsz-commands|

================================================================================
1. Introduction *nvim-trzsz-introduction*

nvim-trzsz is a Neovim plugin that integrates trzsz functionality into Neovim,
allowing for easy file transfers between local and remote systems directly from
your terminal.

================================================================================
2. Requirements *nvim-trzsz-requirements*

- Neovim >= 0.10.0
- A terminal that supports trzsz (see: https://github.com/trzsz/trzsz#supported-terminals)
- Must be used within an SSH session (does not work in local terminals)
- trzsz-ssh installed on your local machine
- nvim-tree.lua (optional, for file explorer integration)

================================================================================
3. Installation *nvim-trzsz-installation*
Using lazy.nvim: >
{
"BrightXiaohan/nvim-trzsz",
dependencies = {
{"nvim-tree/nvim-tree.lua"}
},
}
<

================================================================================
4. Usage *nvim-trzsz-usage*

The plugin provides commands for uploading and downloading files through nvim-tree
integration or direct commands:

Recommended key mappings: >
vim.keymap.set("n", "t", "<cmd>NvimTreeTrz<CR>", {noremap = true, silent = true})
vim.keymap.set("n", "s", "<cmd>NvimTreeTsz<CR>", {noremap = true, silent = true})
<

With nvim-tree:
1. Open nvim-tree
2. Navigate to the target file/directory
3. Press 't' to upload or 's' to download files

For uploading files:
- Navigate to the target directory in nvim-tree
- Press 's' to open the file explorer
- Select the files you want to upload

For downloading files:
- Navigate to the target directory in nvim-tree
- Press 't' to open the file explorer
- Select the files you want to download

================================================================================
5. Configuration *nvim-trzsz-config*

No configuration is required by default. The plugin works out of the box.

================================================================================
6. Commands *nvim-trzsz-commands*
:NvimTreeTrz *:NvimTreeTrz*
Download files from remote to local system using nvim-tree integration.

:NvimTreeTsz *:NvimTreeTsz*
Upload files from local to remote system using nvim-tree integration.

================================================================================
vim:ft=help:tw=78:ts=8:sw=4:sts=4:norl:
72 changes: 72 additions & 0 deletions lua/nvim-trzsz/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
local M = {}

-- Default configuration
M.config = {
-- Add your default configuration options here
}

function M.nvim_tree_tsz()
if vim.env.SSH_TTY == nil then
return
end
-- check if tsz command exists
if vim.fn.executable("tsz -h") == 0 then
print("tsz command not found")
return
end

local api = require "nvim-tree.api"
-- if current node is a folder, open it
local node = api.tree.get_node_under_cursor()
-- nil check
if not node then
return
end
-- get absolute path of the current node
local path = node.absolute_path
-- run tsz command
vim.cmd("!tsz -q -y -d -b " .. path)
-- refresh the tree
api.tree.reload()
end

function M.nvim_tree_trz()
if vim.env.SSH_TTY == nil then
return
end
-- check if trz command exists
if vim.fn.executable("trz -h") == 0 then
print("trz command not found")
return
end
local api = require "nvim-tree.api"
-- if current node is a folder, open it
local node = api.tree.get_node_under_cursor()
-- nil check
if not node then
return
end
-- get absolute path of the current node
local path = node.absolute_path
-- if current node is a file, get the parent directory of the file
if node.type == "file" then
path = vim.fn.fnamemodify(path, ":h")
end
-- run trz command
vim.cmd("!trz -q -y -b " .. path)
-- refresh the tree
api.tree.reload()
end

-- create user commands
vim.cmd [[
command! NvimTreeTsz lua require'nvim-trzsz'.nvim_tree_tsz()
command! NvimTreeTrz lua require'nvim-trzsz'.nvim_tree_trz()
]]

-- Setup function
function M.setup(opts)
M.config = vim.tbl_deep_extend('force', M.config, opts or {})
end

return M
6 changes: 6 additions & 0 deletions plugin/nvim-trzsz.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if vim.g.loaded_nvim_trzsz then
return
end
vim.g.loaded_nvim_trzsz = true

-- Add any vim commands or autocommands here

0 comments on commit cfc8203

Please sign in to comment.