Skip to content

Commit

Permalink
Added xdg-open support
Browse files Browse the repository at this point in the history
  • Loading branch information
JamshedVesuna committed Dec 13, 2015
1 parent b51ecf2 commit 956b154
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Vim Markdown Preview
- [Browser](#browser)
- [Temp File](#temp)
- [Github Flavoured Markdown](#github)
- [Use xdg-open](#xdg)
- [Behind the Scenes](#behind-the-scenes)

Intro
Expand Down Expand Up @@ -137,6 +138,18 @@ Example: Use GitHub flavoured markdown.
let vim_markdown_preview_github=1
```

<a name='xdg'></a>
### The `vim_markdown_preview_use_xdg_open` option

If your system does not come with `see`, and you would like to use `xdg-open` to view your rendered html in the browser, set the following flag:

Default: `0`

Example: Use `xdg-open`.
```vim
let vim_markdown_preview_use_xdg_open=1
```

Behind The Scenes
-----------------

Expand Down
16 changes: 14 additions & 2 deletions plugin/vim-markdown-preview.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ if !exists("g:vim_markdown_preview_github")
let g:vim_markdown_preview_github = 0
endif

if !exists("g:vim_markdown_preview_use_xdg_open")
let g:vim_markdown_preview_use_xdg_open = 0
endif

if !exists("g:vim_markdown_preview_hotkey")
let g:vim_markdown_preview_hotkey='<C-p>'
endif
Expand Down Expand Up @@ -49,7 +53,11 @@ function! Vim_Markdown_Preview()
if OSNAME == 'unix'
let chrome_wid = system("xdotool search --name 'vim-markdown-preview.html - " . g:vim_markdown_preview_browser . "'")
if !chrome_wid
call system('see /tmp/vim-markdown-preview.html &> /dev/null &')
if g:vim_markdown_preview_use_xdg_open == 1
call system('xdg-open /tmp/vim-markdown-preview.html &> /dev/null &')
else
call system('see /tmp/vim-markdown-preview.html &> /dev/null &')
endif
else
let curr_wid = system('xdotool getwindowfocus')
call system('xdotool windowmap ' . chrome_wid)
Expand Down Expand Up @@ -98,7 +106,11 @@ function! Vim_Markdown_Preview_Local()
if OSNAME == 'unix'
let chrome_wid = system("xdotool search --name '". curr_file . ".html - " . g:vim_markdown_preview_browser . "'")
if !chrome_wid
call system('see ' . curr_file . '.html &> /dev/null &')
if g:vim_markdown_preview_use_xdg_open == 1
call system('xdg-open /tmp/vim-markdown-preview.html &> /dev/null &')
else
call system('see /tmp/vim-markdown-preview.html &> /dev/null &')
endif
else
let curr_wid = system('xdotool getwindowfocus')
call system('xdotool windowmap ' . chrome_wid)
Expand Down

0 comments on commit 956b154

Please sign in to comment.