aboutsummaryrefslogtreecommitdiff
path: root/vim/autoload/xdg.vim
blob: ab756f73acf45a3b1f0a60fc85b6440a3c0ff582 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function! xdg#CacheDir(name) abort
  let name = a:name
  let home = exists('$XDG_CACHE_HOME')
        \ ? $XDG_CACHE_HOME
        \ : '~/.cache'
  return join([home, name], '/')
endfunction

function! xdg#ConfigDirs(name) abort
  let name = a:name
  let home = exists('$XDG_CONFIG_HOME')
        \ ? $XDG_CONFIG_HOME
        \ : '~/.config'
  let dirs = exists('$XDG_CONFIG_DIRS')
        \ ? split($XDG_CONFIG_DIRS, ':')
        \ : []
  return map(
        \ insert(dirs, home)
        \,'join([v:val, name], "/")'
        \)
endfunction

function! xdg#DataDirs(name) abort
  let name = a:name
  let home = exists('$XDG_DATA_HOME')
        \ ? $XDG_DATA_HOME
        \ : '~/.local/share'
  let dirs = exists('$XDG_DATA_DIRS')
        \ ? split($XDG_DATA_DIRS, ':')
        \ : []
  return map(
        \ insert(dirs, home)
        \,'join([v:val, name], "/")'
        \)
endfunction