dj95 / zjstatus

A configurable statusbar plugin for zellij
MIT License
358 stars 6 forks source link

Pipe doesn't work in command #22

Closed sommerper closed 7 months ago

sommerper commented 7 months ago

Describe the bug I'm trying pipe commands to get the last dir name at the top.

To Reproduce Use the submitted layout / command.

Expected behavior The {command_pwd} command writes the last directory name.

Screenshots image

Desktop (please complete the following information):

Layout

How does the layout look like? Please copy it into a code block.

layout {

    pane size=1 borderless=true {
        plugin location="file:zjstatus.wasm" {
            // format_left  "{mode}#[fg=black,bg=blue,bold]{session}  #[fg=blue,bg=#181825]{tabs}"
            format_left  "#[fg=#6b7282,bg=#fb5262,bold]{mode}#[fg=#6b7282,bg=#4b5262,bold] wooo #[fg=#4b5262,bg=#3b4252]{tabs}"
            format_right "#[bg=#3b4252]hello {command_pwd} {command_git_branch} #[fg=#3b4252,bg=#6b7292]{datetime}"
            format_space "#[bg=#3b4252]"

            command_git_branch_command   "git rev-parse --abbrev-ref HEAD"
            command_git_branch_format    "#[fg=blue] {stdout} "
            command_git_branch_interval  "10"

            command_pwd_command   "pwd | rev | cut -f1 -d'/' - | rev"
            command_pwd_format    "#[fg=blue] {exit_code} {stdout} {stderr} "
            command_pwd_interval  "2"

            hide_frame_for_single_pane "true"

            mode_normal  "#[bg=#6b7282] "

            tab_normal              "#[fg=#3b4252,bg=#8A9CBD] #[fg=#1b2232,bg=#8A9CBD]{index}  {name} #[fg=#8A9CBD,bg=#3b4252]"
            tab_normal_fullscreen   "#[fg=#6C7086,bg=#181825] {index} {name} [] "
            tab_normal_sync         "#[fg=#6C7086,bg=#181825] {index} {name} <> "
            tab_active              "#[fg=#3b4252,bg=#d8dee9,bold] {index}  {name} #[fg=#d8dee9,bg=#3b4252]"
            tab_active_fullscreen   "#[fg=#9399B2,bg=#181825,bold] {index} {name} [] "
            tab_active_sync         "#[fg=#9399B2,bg=#181825,bold] {index} {name} <> "

            datetime          "#[fg=#3b4252,bg=#6b7292,bold] {format} "
            datetime_format   "%A, %d %b %Y %H:%M:%S"
            datetime_timezone "Europe/Berlin"
        }
    }

    pane split_direction="vertical" {
        pane
    }

    pane size=2 borderless=true {
      plugin location="zellij:status-bar"
    }
}

Additional context Thanks for such a great plugin! It's really getting better and better all the time.

sommerper commented 7 months ago

I should mention that

command_pwd_command   "pwd"
command_pwd_format    "#[fg=blue] {exit_code} {stdout} {stderr} "
command_pwd_interval  "2"

works as it writes out the complete path. Although that's not what I'm trying to achieve.

dj95 commented 7 months ago

Hi,

thanks for the kind words and the bug report. Unfortunately zjstatus currently is only able to run simpler commands. The main problem is, that it needs to split the command into an array of arguments (which is currently naively implemented by splitting at the space). This will not only prevent piping (which is only possible in a shell), but also grouping of arguments by " (e.g. bash -c "pwd | base64" won't work).

Because of this challenge I'm currently not sure how to properly fix the situation. zjstatus should recognise these kind of groups, but I'm not sure if it will suffice to just implement " and ' or if there are any other characters.

For now, the most simple solution would be to place a bash script with your command near the layout file and execute it with bash -c some.script.

Hope this solution works until it's properly fixed in zjstatus.

dj95 commented 7 months ago

With the latest release you are able to specify it with your shell. zjstatus now respects the argument grouping.

Please use a form like bash -c "pwd | base64" for utilising pipes.

sommerper commented 7 months ago

Thank you! This is so awesome!