|
|
- local function ToggleTabs()
- local options = { "tabstop", "softtabstop", "shiftwidth" }
-
- for _, option in ipairs(options) do
- local current_value = vim.opt[option]:get()
- vim.opt[option] = (current_value == 4) and 2 or 4
- end
- end
-
- vim.api.nvim_create_user_command("ToggleTabs", ToggleTabs, { nargs = 0 })
-
- vim.api.nvim_create_user_command("ToggleDiagnostics", function()
- if vim.g.diagnostics_enable == nil or vim.g.diagnostics_enable then
- vim.g.diagnostics_enable = false
- vim.diagnostic.enable(false)
- return
- end
-
- vim.g.diagnostics_enable = true
- vim.diagnostic.enable(true)
- end, {})
-
- vim.api.nvim_create_user_command("ClearBuffers", function()
- vim.cmd('%bd|e#|bd#')
- 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, {})
|