Code Monkey home page Code Monkey logo

onestatus's Introduction

Disclaimer: This plugin has been tested with neovim so vim support is not garanteed. Feel free to open a PR if you want to contribute !

Motivation

OneStatus is an interface that helps you interact with your tmux.
One of my goal with it was to get rid of vim's redundant statusline and instead use tmux's.

Much better !

onestatus

Requirements

If you just want to quickly use the plugin :

If you want to play with the API :

  • make sure to disable the default config by setting let g:onestatus_default_layout = 0
  • create your own personal onestatus.json Have fun !

Usage

Since v0.2.0 you can very easily customize your statusline via a onestatus.json file that you put in your config folder ($HOME for vim and $HOME/.config/nvim for nvim).
If you want another path you can override g:onestatus_config_path
Here's an example of configuration file that you can copy

{
  "status-right": [
    { "fg": "#ffd167", "bg": "default", "label": "" },
    { "fg": "#218380", "bg": "#ffd167", "labelFunc": "s:getCWD" },
    { "fg": "#218380", "bg": "#ffd167", "label": "" },
    { "fg": "#fcfcfc", "bg": "#218380", "labelFunc": "s:getHead" }
  ],
  "status-left": [
    { "fg": "default", "bg": "default", "labelFunc": "s:getFileName" }
  ],
  "status-style": "s:getDefaultColor",
  "window-status-style": [
    { "fg": "#6c757d", "bg": "default", "isStyleOnly": true }
  ],
  "window-status-current-style": [
    { "fg": "#ffd167", "bg": "default", "isStyleOnly": true }
  ]
}

Which will give your current git head and the name of the focused file just like shown in the screenshot

Then you can use the full power of onestatus like in this example

if !empty($TMUX)
    au BufEnter,BufLeave,FocusGained * :OneStatus
    au VimLeave * :OneStatusClean
    set noshowmode noruler
    set laststatus=0
endif

For OneStatus you can use BufEnter and use WinEnter or some other events but I found it sufficient for my everyday use. OneStatusClean on the other end is optional and is a convinient way to clean your tmux status bar when you exit your current vim process.

The Internals

The plugin's implementation is simple, it runs tmux source 'the content of your json file', everything else is just deserialization and formatting.

Let us write an example that displays the current file extension on the left. In your onestatus.json

  "status-left": [
    { "fg": "default", "bg": "default", "labelFunc": "CurrentFileExtension" }
  ]

And make a function in your $MYVIMRC to return the file type.

fun CurrentFileExtension()
    return expand('%:e')
endfun

The labelFunc attribute takes a function name and sends its output to tmux

tmux set-option status-left -g fg=default bg=default "{the output of function}" 

The API

You must have noticed that the json file has these types of attributes

  • tmux option: an option that will be sent to tmux, you can learn more about them in man tmux
  • tmux color: can be any color format supported by tmux (ex: #ffd167)
  • onestatus' builtin function: they begin with s: like s:getFileName

and has this form

{
  option: attributes
}

In order to give a maximum amount of flexibility, attributes can either be an array of attribute of this shape:

{
  "fg": optional tmux color (will default to tmux's default),
  "bg": optional tmux color (will default to tmux's default),
  "label": the text to be displayed if your option takes a string as an argument (ex: status-left ),
  "labelFunc": you can dynamicaly display labels by using one of the functions exposed by onestatus (will take precedance over "label"),
  "isStyleOnly": a boolean that has to be set to true if your option does not display a label
}

NB1: You can also use also use a onestatus function to dynamically generate your attributes. Currently only s:getDefaultColor is supported.
NB2: You can call any global function in labelFunc. Try putting directly the name of a function of your own !

Exposed functions

labelFunc:

  • s:getCWD
  • s:getFileName
  • s:getHead

attributes:

  • s:getDefaultColor (it will make your statusline's background match with your vim's theme)

Exposed global variables

  • g:onestatus_default_layout: can be 0 or 1. Defaults to 1 Setting it to 0 prevents onestatus from applying some arbitrary layout style. Useful when you want to fully customize your statusline.
  • g:onestatus_config_path: a path string It contains the default path where onestatus will look for a onestatus.json. You can override it if you want to use a custom path.
  • g:onestatus_right_length: the max length of your right status. Defaults to 50
  • g:onestatus_left_length: the max length of your left status. Defaults to 50

For even more customization

OneStatus also provides a helper to send more straightforward commands to tmux

  call onestatus#build([
        \{'command' : 'set-option status-justify centre'},
        \{'command': 'set-option status-right-length 30'},
        \{'command': 'set-option status-left-length 50'},
        \])

TODO

  • Write a proper :h
  • Add more default templates
  • Improve default template theme integration
  • Add more builtin functions
  • Setup automated tests on develop branch

License

Distributed under the same terms as Vim itself. See the vim license.

onestatus's People

Contributors

iustin-nita avatar narajaon avatar tusqasi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

iustin-nita

onestatus's Issues

Error when calling OneStatus

Hi, I just downloaded the plugin, but when I call it, I get this error:

line    1:
E730: using List as a String
Error detected while processing function onestatus#build:
line    3:
E715: Dictionary required

I have the default onestatus.json.
Thanks

Customization example

Hi. And thank you for your plugin. It's really nice and way less popular than i would expect (but I'm pretty sure it's just because it's new)

I'm trying to understand how to customize it and i think my lacking of vimscript knowledge doesn't allow me to do it.
Here is what i have now (using tmuxinator):
image

And what i would like to achieve is these three things:

  1. remove hostname carrot from the left
  2. move all the tabs names from the middle to the left
  3. change the colors of the right to match the colors on the left

I'm not sure if 1 and 2 should be done through your plugin's config or through the tmux's config.

Cannot update config path with Lua

I'm not sure why, but I just cannot update the onestatus_config_path in my Lua configs. For example, the following does not work:

vim.g.onestatus_config_path = vim.fn.stdpath('data')

This should set the directory to .local/share/nvim where my onestatus.json is placed. Any ideas what might be the issue?

tmux configs not working as expected

Hi there, very cool plugin and just what I've been looking for. I'm running into the issue where changes I make to the onestatus.json file aren't being recognized. I assume the keys in this json file are just mapped to tmux configurations?

For example, I assume setting "status-justify": "center" maps directly to set-option -g status-justify center that I have in my .tmux.conf... is this a correct assumption? It's not super clear in the README.

Also, I don't seem to be able to access tmux "variables". For example, how would I implement the following, accessing the current tmux session name:

set-option -g status-left "#[fg=#e2e4e5,bg=#43454f] #S "

Many thanks, and keep up the great work!

Clear filename and git branch on VimLeave

Since I usually have multiple projects open in tmux at once, I'd like to not pollute my onestatus with filenames and git branches from other tmux windows if possible.

Is there a way to clear the filename and git branch in the status bar on VimLeave?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.