Skip to content

Commit 093c935

Browse files
committed
Initial commit of automkdir plugin
0 parents  commit 093c935

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# vim-automkdir
2+
3+
Automatically call mkdir -p as necessary when writing files.
4+
5+
## Installation
6+
7+
### With [Vundle][vundle]
8+
9+
In vimrc:
10+
11+
```vim
12+
Bundle 'benizi/vim-automkdir'
13+
```
14+
15+
### With [vim-addon-manager][vam]
16+
17+
```vim
18+
:InstallAddons github:benizi/vim-automkdir
19+
```
20+
21+
## Usage
22+
23+
Open a file, even if its directory doesn't exist.
24+
25+
Save it.
26+
27+
## Full documentation
28+
29+
Within `vim` run:
30+
31+
```vim
32+
:help automkdir
33+
```
34+
35+
[vundle]: https://github.com/gmarik/vundle#readme
36+
[vam]: https://github.com/MarcWeber/vim-addon-manager

after/plugin/automkdir.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
au BufWrite * call AutomkdirCurrent()

doc/automkdir.txt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
*automkdir* Autocommand to create dirs as needed
2+
*automkdir-plugin*
3+
4+
Automkdir
5+
6+
Author: Benjamin R. Haskell - benizi
7+
8+
==============================================================================
9+
CONTENTS *automkdir-contents* {{{1
10+
11+
1. Contents..........................................|automkdir-contents|
12+
2. Use a Vim plugin manager..........................|automkdir-managers|
13+
3. Installation.......................................|automkdir-install|
14+
4. Usage................................................|automkdir-usage|
15+
5. Caveats............................................|automkdir-caveats|
16+
17+
==============================================================================
18+
PLUGIN MANAGERS *automkdir-managers* {{{1
19+
20+
If you don't already use a Vim plugin manager, install one now.
21+
22+
Vundle is easy:
23+
24+
https://github.com/gmarik/vundle#readme
25+
26+
So is vim-addon-manager (VAM):
27+
28+
https://github.com/MarcWeber/vim-addon-manager
29+
30+
==============================================================================
31+
INSTALLATION *automkdir-install* {{{1
32+
33+
To add this plugin with Vundle: >
34+
35+
Bundle 'benizi/vim-automkdir'
36+
<
37+
38+
With VAM: >
39+
40+
:InstallAddons github:benizi/vim-automkdir
41+
<
42+
43+
==============================================================================
44+
USAGE *automkdir-usage* {{{1
45+
46+
It's automatic.
47+
48+
==============================================================================
49+
CAVEATS *automkdir-caveats* {{{1
50+
51+
Requires a mkdir command that accepts the -p argument. (POSIX)

plugin/automkdir.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
fun! AutomkdirCurrent()
2+
call AutomkdirAsNeeded(expand('%:p:h'))
3+
endf
4+
5+
fun! AutomkdirAsNeeded(dir)
6+
let d = a:dir
7+
8+
" Skip files that have schemes
9+
if d =~ '^[a-z]\+:/'
10+
return
11+
endif
12+
13+
if !isdirectory(d)
14+
call system('mkdir -p '.shellescape(d))
15+
echom 'Created directory:' d
16+
end
17+
endf

0 commit comments

Comments
 (0)