Skip to content
/ x5050 Public

A macOS command-line script to set up a split layout

Notifications You must be signed in to change notification settings

junegunn/x5050

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

x5050

A macOS command-line script to set up a split layout of a terminal emulator and a web browser.

,-------------------.                               ,-----------.,-----------.
|-------------------|                               |-----------||-----------|
|                   |                               |           ||           |
| $ x5050 right     |--.         ,-.(  ).-,         |           ||           |
|                   |--|      ,-(          )-.      | $ x5050   ||  Google   |
|                   |  |  +~~(     *MAGIC*    )~~>  | $         ||           |
|                   |  |      `-(          ),-'     |           || [_______] |
`------+------------'  |          `-.( ).-'         |           ||   == ==   |
       |               |                            |           ||           |
       `---------------'                            |           ||           |
                                                    `-----------'`-----------'

Build

make

And put x5050 in a directory in $PATH.

Run

x5050 takes four optional arguments. The order of arguments doesn't matter.

  • Position: right (default), left, up, down
  • Percent size: 1 ~ 100 (default 50)
  • Browser: Tested with Chrome (default) and Safari
  • URL to open

Examples

x5050
x5050 left
x5050 down 40
x5050 https://github.com/junegunn
x5050 up Safari https://google.com

Rationale

A few years ago, I wrote vim-xmark, a minimal Markdown preview plugin for Vim. It does two things:

  1. Set up a split layout, Vim and a web browser, using AppleScript
  2. Convert Markdown document using pandoc and display it in the browser window

The implementation is simple and it still works fine, but lately I've been trying out markdown-preview.nvim which provides better preview functionality (e.g. immediate update, synchronized scroll, etc). So I extracted the split layout code from vim-xmark into x5050 so I can use it with the new plugin.

if has('mac') && executable('x5050')
  function! MKDPSplit(url)
    call system('x5050 '.shellescape(a:url))
  endfunction

  let g:mkdp_browserfunc = 'MKDPSplit'
endif

Alternatives

You can do the same thing pretty easily with Hammerspoon like so:

local screen = hs.window.focusedWindow():screen()
hs.layout.apply({
  { hs.window.focusedWindow(), nil, screen, hs.layout.left50 },
  { "Chrome", nil, screen, hs.layout.right50 }
})

License

MIT

About

A macOS command-line script to set up a split layout

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published