How can I serve a directory from its absolute path #12

Closed
opened 2024-07-12 22:21:51 +00:00 by statquant · 11 comments
statquant commented 2024-07-12 22:21:51 +00:00

Hello,
I must be missing something obvious but I cannot manage to serve a given directory.
I tried passing --open= and/or --watch= in args but that's not working, that makes sense because on the command line it's not working either

My config is the following

 local config = function()                                                                           
   require('lazy').setup({})                                                                         
   require('live-server').setup({                                                                                        
     args = { '--port=0', '--browser=firefox', '--htpasswd=/home/statquant/.live_server_pwd.txt', '/home/statquant/Work' }
   })                                                                                                
 end                                                                                                 
                                                                                                     
 return {                                                                                            
   'barrett-ruth/live-server.nvim',                                                                  
   laxy = false,                                                                                     
   -- build = 'pnpm add -g live-server',                                                             
   cmd = { 'LiveServerStart', 'LiveServerStop' },                                                    
   config = config,                                                                                  
   enabled = true,                                                                                   
 }                                                                                                   

Say I want to serve /home/statquant, how should I proceed ?

Hello, I must be missing something obvious but I cannot manage to serve a given directory. I tried passing `--open=` and/or `--watch=` in `args` but that's not working, that makes sense because on the command line it's not working either My config is the following ``` local config = function() require('lazy').setup({}) require('live-server').setup({ args = { '--port=0', '--browser=firefox', '--htpasswd=/home/statquant/.live_server_pwd.txt', '/home/statquant/Work' } }) end return { 'barrett-ruth/live-server.nvim', laxy = false, -- build = 'pnpm add -g live-server', cmd = { 'LiveServerStart', 'LiveServerStop' }, config = config, enabled = true, } ``` Say I want to serve `/home/statquant`, how should I proceed ?
barrettruth commented 2024-07-13 17:41:44 +00:00

@statquant I can add an optional directory argument to LiveServer<cmd>. How does that sound?

@statquant I can add an optional directory argument to `LiveServer<cmd>`. How does that sound?
statquant commented 2024-07-13 17:45:06 +00:00

That would be grand!

That would be grand!
barrettruth commented 2024-07-14 00:08:25 +00:00
[done](https://github.com/barrett-ruth/live-server.nvim/commit/da3496d878d9d92b54f4efc1b95792064913650b)
statquant commented 2024-07-14 17:30:24 +00:00

Hello,
I had issues with relative paths and path that did not exist
I added the following which solved it for me, just FYI

local function file_exists(name)                                
  local f = io.open(name, "r")                                  
  if f ~= nil then io.close(f) return true else return false end
end  

M.start = function(dir)                                     
    -- resolve the directory                                
    dir = vim.fn.fnamemodify(dir, ':p')                     
    -- return if dir does not exist                         
    local exists = file_exists(dir)                         
    if not exists then                                      
        log('the provided directory does not exist', 'INFO')
        return                                              
    end                                                     
    local running = is_running(dir)                         
    ... rest the same
Hello, I had issues with relative paths and path that did not exist I added the following which solved it for me, just FYI ``` local function file_exists(name) local f = io.open(name, "r") if f ~= nil then io.close(f) return true else return false end end M.start = function(dir) -- resolve the directory dir = vim.fn.fnamemodify(dir, ':p') -- return if dir does not exist local exists = file_exists(dir) if not exists then log('the provided directory does not exist', 'INFO') return end local running = is_running(dir) ... rest the same ```
barrettruth commented 2024-07-14 17:51:29 +00:00
  1. if you provide a file that does not exist then, well, I could add that for a graceful way to handle errors. Still a user error
  2. I dont understand the relative path - you should provide the directory and it will be expanded by vim.fn.expand. if you need to modify the path, then you are probably not providing the correct root directory to serve files from. Can you give me an example?
1. if you provide a file that does not exist then, well, I could add that for a graceful way to handle errors. Still a user error 2. I dont understand the relative path - you should provide the *directory* and it will be expanded by `vim.fn.expand`. if you need to modify the path, then you are probably not providing the correct root directory to serve files from. Can you give me an example?
statquant commented 2024-07-14 18:27:31 +00:00
  1. totally user error
  2. i tried to provide LiveServerStart ../.. which seemed to froze neovim
    I am not in front of a computer, I'll test it again I might have made a mistake
1. totally user error 2. i tried to provide LiveServerStart ../.. which seemed to froze neovim I am not in front of a computer, I'll test it again I might have made a mistake
barrettruth commented 2024-07-14 18:41:29 +00:00

please repo. sometimes nvim freezes on wrong path - that could definitely be an error

please repo. sometimes nvim freezes on wrong path - that could definitely be an error
barrettruth commented 2024-07-15 00:56:58 +00:00

resolved. feel free to open. relative paths now resolve correctly.

[resolved](https://github.com/barrett-ruth/live-server.nvim/commit/fde21e3dc4f0349dfe2bd527d1562df5dcf497aa). feel free to open. relative paths now resolve correctly.
statquant commented 2024-07-21 14:00:50 +00:00

Thanks, it works perfect for me now.
Many thanks for your very fast turnover !

PS:
Can I suggest 2 things

  • add an option to find a random free port (0 is not guaranteed to work is it ?)
  • add a LiveServerInfo function to get list of live-servers opened ?
Thanks, it works perfect for me now. Many thanks for your very fast turnover ! PS: Can I suggest 2 things - add an option to find a random free port (0 is not guaranteed to work is it ?) - add a LiveServerInfo function to get list of live-servers opened ?
barrettruth commented 2024-07-21 15:02:26 +00:00

I don't currently have time to add such features. Willing to review any prs or offer help, though - should be simpel.

I don't currently have time to add such features. Willing to review any prs or offer help, though - should be simpel.
statquant commented 2024-07-21 16:15:23 +00:00

Will PR ince done.
Thanks and regards

On Sun, 21 Jul 2024 at 16:02, Barrett Ruth @.***> wrote:

I don't currently have time to add such features. Willing to review any
prs or offer help, though - should be simpel.


Reply to this email directly, view it on GitHub
https://github.com/barrett-ruth/live-server.nvim/issues/12#issuecomment-2241640740,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AA3R6OIIPPHMQDOUW2HLVCDZNPERRAVCNFSM6AAAAABKZVCU7WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBRGY2DANZUGA
.
You are receiving this because you were mentioned.Message ID:
@.***>

Will PR ince done. Thanks and regards On Sun, 21 Jul 2024 at 16:02, Barrett Ruth ***@***.***> wrote: > I don't currently have time to add such features. Willing to review any > prs or offer help, though - should be simpel. > > — > Reply to this email directly, view it on GitHub > <https://github.com/barrett-ruth/live-server.nvim/issues/12#issuecomment-2241640740>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AA3R6OIIPPHMQDOUW2HLVCDZNPERRAVCNFSM6AAAAABKZVCU7WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBRGY2DANZUGA> > . > You are receiving this because you were mentioned.Message ID: > ***@***.***> >
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
barrettruth/live-server.nvim#12
No description provided.