File tree Expand file tree Collapse file tree 3 files changed +66
-2
lines changed Expand file tree Collapse file tree 3 files changed +66
-2
lines changed Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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 :
Original file line number Diff line number Diff line change @@ -26,15 +26,16 @@ set wildmenu
26
26
set foldopen -= search " do not open folds if there's a match inside them
27
27
set cursorline " highglight the line on which the cursor is atm.
28
28
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
29
30
set autochdir " automatically set working directory to path of open file.
30
31
" actually cd to the current file (the above is only applied upon changing file)
31
32
cd % :p :h
32
33
33
34
" turn off rnu when in insert mode
34
- au FocusLost * :set nornu
35
+ au FocusLost * :set nornu
35
36
au FocusGained * :set rnu " TODO: fix the delay on this...
36
37
autocmd InsertEnter * :set nornu
37
- autocmd InsertLeave * :set rnu
38
+ autocmd InsertLeave * :set rnu
38
39
39
40
40
41
" """""""""""
You can’t perform that action at this time.
0 commit comments