Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mgunyho/vim-things
Browse files Browse the repository at this point in the history
  • Loading branch information
mgunyho committed Nov 4, 2019
2 parents 5224e36 + 02c6998 commit ecd530f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
10 changes: 10 additions & 0 deletions templates/argparse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--silent", action = "store_true")
parser.add_argument("--repeat", type=int, default = 1)
args = parser.parse_args()

for i in range(args.repeat):
if not args.silent:
print("i:", i)
53 changes: 53 additions & 0 deletions templates/shell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import subprocess, sys, shlex, threading

def shell(cmd, silent = False):
# run shell command string (like 'ls -l') and return a dict containing the stdout and stderr as lists and the return code
# the option 'silent' suppresses printing output to stdout during execution

#{{{
proc = subprocess.Popen(shlex.split(cmd),
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
universal_newlines = True
)

# print output of command while also storing it in lists, separate threads for stdout and stderr
# based on https://stackoverflow.com/a/4985080
def tee(fd_in, fd_out, target_list):
# print fd_in to fd_out and also collect it into a list
for line in iter(fd_in):
if not silent:
fd_out.write(line)
target_list.append(line)

stdout = []
stderr = []

t_stdout = threading.Thread(target=tee, args = (proc.stdout, sys.stdout, stdout))
t_stderr = threading.Thread(target=tee, args = (proc.stderr, sys.stderr, stderr))
t_stdout.start()
t_stderr.start()

proc.wait()

t_stdout.join()
t_stderr.join()

#}}}

ret = {
"stdout": stdout,
"stderr": stderr,
"exit_status": proc.returncode
}

return ret

res = shell("ls -l")
print(res["stdout"])
print(res["stderr"])
print(res["exit_status"])

# vim: set fdm=marker :
5 changes: 3 additions & 2 deletions vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ set wildmenu
set foldopen-=search " do not open folds if there's a match inside them
set cursorline " highglight the line on which the cursor is atm.
set lazyredraw " redraw screen only when macro has finished, increases execution speed
set nojoinspaces " don't produce two spaces on 'J' when a line ends with a period
set autochdir " automatically set working directory to path of open file.
" actually cd to the current file (the above is only applied upon changing file)
cd %:p:h

" turn off rnu when in insert mode
au FocusLost * :set nornu
au FocusLost * :set nornu
au FocusGained * :set rnu "TODO: fix the delay on this...
autocmd InsertEnter * :set nornu
autocmd InsertLeave * :set rnu
autocmd InsertLeave * :set rnu


""""""""""""
Expand Down

0 comments on commit ecd530f

Please sign in to comment.