You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.5 KiB

11 months ago
11 months ago
11 months ago
  1. local function ToggleTabs()
  2. local options = { "tabstop", "softtabstop", "shiftwidth" }
  3. for _, option in ipairs(options) do
  4. local current_value = vim.opt[option]:get()
  5. vim.opt[option] = (current_value == 4) and 2 or 4
  6. end
  7. end
  8. vim.api.nvim_create_user_command("ToggleTabs", ToggleTabs, { nargs = 0 })
  9. vim.api.nvim_create_user_command("ToggleDiagnostics", function()
  10. if vim.g.diagnostics_enable == nil or vim.g.diagnostics_enable then
  11. vim.g.diagnostics_enable = false
  12. vim.diagnostic.enable(false)
  13. return
  14. end
  15. vim.g.diagnostics_enable = true
  16. vim.diagnostic.enable(true)
  17. end, {})
  18. vim.api.nvim_create_user_command("ClearBuffers", function()
  19. vim.cmd('%bd|e#|bd#')
  20. end, {})
  21. local function load_env_file()
  22. local env_file_path = vim.fn.getcwd() .. "/.env" -- Construct the path relative to the current working directory
  23. local env_file = io.open(env_file_path, "r") -- Open the .env file
  24. if not env_file then
  25. print("Could not open .env file")
  26. return
  27. end
  28. for line in env_file:lines() do
  29. local key, value = line:match("^(%S+)=(%S+)")
  30. if key and value then
  31. vim.env[key] = value
  32. end
  33. end
  34. env_file:close()
  35. end
  36. local function sync_file_to_sftp()
  37. load_env_file()
  38. -- Get SFTP credentials from environment variables
  39. local sftp_user = os.getenv("SFTP_USER")
  40. local sftp_host = os.getenv("SFTP_HOST")
  41. local sftp_port = os.getenv("SFTP_PORT")
  42. local sftp_password = os.getenv("SFTP_PASSWORD")
  43. local sftp_theme_directory = os.getenv("SFTP_THEME_DIRECTORY")
  44. local current_file = vim.fn.expand("%:p") -- Get the full path of the current file
  45. -- Define your project root path
  46. local project_root = vim.fn.getcwd() -- Current working directory where Neovim was launched
  47. local relative_path = current_file:sub(#project_root + 1)
  48. -- Construct the full remote path
  49. local remote_path = sftp_theme_directory .. relative_path -- Append the relative path to the remote base path
  50. -- Command to sync the file using lftp
  51. local lftp_cmd = string.format(
  52. "lftp -u %s,%s sftp://%s:%s -e 'put %s -o %s; bye' > /dev/null 2>&1",
  53. sftp_user,
  54. sftp_password,
  55. sftp_host,
  56. sftp_port,
  57. current_file,
  58. remote_path
  59. )
  60. -- Execute the command
  61. os.execute(lftp_cmd)
  62. print("File synced to SFTP server: " .. remote_path)
  63. end
  64. -- Map the function to a command in Neovim
  65. vim.api.nvim_create_user_command("SyncToNeto", sync_file_to_sftp, {})