Skip to content

Commit ecd530f

Browse files
committed
Merge branch 'master' of https://github.com/mgunyho/vim-things
2 parents 5224e36 + 02c6998 commit ecd530f

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

templates/argparse.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import argparse
2+
3+
parser = argparse.ArgumentParser()
4+
parser.add_argument("--silent", action = "store_true")
5+
parser.add_argument("--repeat", type=int, default = 1)
6+
args = parser.parse_args()
7+
8+
for i in range(args.repeat):
9+
if not args.silent:
10+
print("i:", i)

templates/shell.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/python3
2+
# -*- coding: utf-8 -*-
3+
import subprocess, sys, shlex, threading
4+
5+
def shell(cmd, silent = False):
6+
# run shell command string (like 'ls -l') and return a dict containing the stdout and stderr as lists and the return code
7+
# the option 'silent' suppresses printing output to stdout during execution
8+
9+
#{{{
10+
proc = subprocess.Popen(shlex.split(cmd),
11+
stdout = subprocess.PIPE,
12+
stderr = subprocess.PIPE,
13+
universal_newlines = True
14+
)
15+
16+
# print output of command while also storing it in lists, separate threads for stdout and stderr
17+
# based on https://stackoverflow.com/a/4985080
18+
def tee(fd_in, fd_out, target_list):
19+
# print fd_in to fd_out and also collect it into a list
20+
for line in iter(fd_in):
21+
if not silent:
22+
fd_out.write(line)
23+
target_list.append(line)
24+
25+
stdout = []
26+
stderr = []
27+
28+
t_stdout = threading.Thread(target=tee, args = (proc.stdout, sys.stdout, stdout))
29+
t_stderr = threading.Thread(target=tee, args = (proc.stderr, sys.stderr, stderr))
30+
t_stdout.start()
31+
t_stderr.start()
32+
33+
proc.wait()
34+
35+
t_stdout.join()
36+
t_stderr.join()
37+
38+
#}}}
39+
40+
ret = {
41+
"stdout": stdout,
42+
"stderr": stderr,
43+
"exit_status": proc.returncode
44+
}
45+
46+
return ret
47+
48+
res = shell("ls -l")
49+
print(res["stdout"])
50+
print(res["stderr"])
51+
print(res["exit_status"])
52+
53+
# vim: set fdm=marker :

vimrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ set wildmenu
2626
set foldopen-=search " do not open folds if there's a match inside them
2727
set cursorline " highglight the line on which the cursor is atm.
2828
set lazyredraw " redraw screen only when macro has finished, increases execution speed
29+
set nojoinspaces " don't produce two spaces on 'J' when a line ends with a period
2930
set autochdir " automatically set working directory to path of open file.
3031
" actually cd to the current file (the above is only applied upon changing file)
3132
cd %:p:h
3233

3334
" turn off rnu when in insert mode
34-
au FocusLost * :set nornu
35+
au FocusLost * :set nornu
3536
au FocusGained * :set rnu "TODO: fix the delay on this...
3637
autocmd InsertEnter * :set nornu
37-
autocmd InsertLeave * :set rnu
38+
autocmd InsertLeave * :set rnu
3839

3940

4041
""""""""""""

0 commit comments

Comments
 (0)