Browse Source

feat: add nvim command to sync to neto

master
Tovi Jaeschke-Rogers 1 month ago
parent
commit
18eacbf330
3 changed files with 64 additions and 1 deletions
  1. +1
    -1
      .config/nvim/.stylelua.toml
  2. +57
    -0
      .config/nvim/lua/core/commands.lua
  3. +6
    -0
      .config/zsh/.zshrc

+ 1
- 1
.config/nvim/.stylelua.toml View File

@ -4,4 +4,4 @@ indent_type = "Spaces"
indent_width = 2 indent_width = 2
quote_style = "ForceDouble" quote_style = "ForceDouble"
no_call_parentheses = false no_call_parentheses = false
collapse_simple_statement = 'Always'
collapse_simple_statement = "Always"

+ 57
- 0
.config/nvim/lua/core/commands.lua View File

@ -23,3 +23,60 @@ end, {})
vim.api.nvim_create_user_command("ClearBuffers", function() vim.api.nvim_create_user_command("ClearBuffers", function()
vim.cmd('%bd|e#|bd#') vim.cmd('%bd|e#|bd#')
end, {}) end, {})
local function load_env_file()
local env_file_path = vim.fn.getcwd() .. "/.env" -- Construct the path relative to the current working directory
local env_file = io.open(env_file_path, "r") -- Open the .env file
if not env_file then
print("Could not open .env file")
return
end
for line in env_file:lines() do
local key, value = line:match("^(%S+)=(%S+)")
if key and value then
vim.env[key] = value
end
end
env_file:close()
end
local function sync_file_to_sftp()
load_env_file()
-- Get SFTP credentials from environment variables
local sftp_user = os.getenv("SFTP_USER")
local sftp_host = os.getenv("SFTP_HOST")
local sftp_port = os.getenv("SFTP_PORT")
local sftp_password = os.getenv("SFTP_PASSWORD")
local sftp_theme_directory = os.getenv("SFTP_THEME_DIRECTORY")
local current_file = vim.fn.expand("%:p") -- Get the full path of the current file
-- Define your project root path
local project_root = vim.fn.getcwd() -- Current working directory where Neovim was launched
local relative_path = current_file:sub(#project_root + 1)
-- Construct the full remote path
local remote_path = sftp_theme_directory .. relative_path -- Append the relative path to the remote base path
-- Command to sync the file using lftp
local lftp_cmd = string.format(
"lftp -u %s,%s sftp://%s:%s -e 'put %s -o %s; bye' > /dev/null 2>&1",
sftp_user,
sftp_password,
sftp_host,
sftp_port,
current_file,
remote_path
)
-- Execute the command
os.execute(lftp_cmd)
print("File synced to SFTP server: " .. remote_path)
end
-- Map the function to a command in Neovim
vim.api.nvim_create_user_command("SyncToNeto", sync_file_to_sftp, {})

+ 6
- 0
.config/zsh/.zshrc View File

@ -112,5 +112,11 @@ if [ -f "$HOME/.cargo/env" ]; then
. "$HOME/.cargo/env" . "$HOME/.cargo/env"
fi fi
if type "pyenv" > /dev/null; then
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
fi
# Speed debugging # Speed debugging
# zprof # zprof

Loading…
Cancel
Save