def _zsh_environment(self): template = self.temp_env.get_template(wpath('zsh/zshrc.template')) with open(hpath('.zshrc'), 'w') as zshrc: zshrc.write( template.render(platform=sys.platform, extra_paths=self._get_extra_paths())) # sh.cp(wpath('zsh/zshrc'), hpath('.zshrc'), **SHARG) if os.path.isdir(hpath('.oh-my-zsh')): sh.zsh(hpath('.oh-my-zsh/tools/upgrade.sh'), **SHARG) else: install_script = 'https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh' sh.zsh('-c', '$(wget {} -O -)'.format(install_script), **SHARG) sh.cp(wpath('zsh/mytheme.zsh-theme'), hpath('.oh-my-zsh/themes/mytheme.zsh-theme'), **SHARG) # zsh-autosuggestions zsh_autosuggestions_path = hpath( '.oh-my-zsh/custom/plugins/zsh-autosuggestions') if os.path.isdir(zsh_autosuggestions_path): os.chdir(zsh_autosuggestions_path) sh.git('pull', **SHARG) os.chdir(working_dir) else: sh.git('clone', 'https://github.com/zsh-users/zsh-autosuggestions', zsh_autosuggestions_path, **SHARG)
def setup_zsh(): prezto = join(HOME, '.zprezto') if not os.path.isdir(prezto): sh.git('clone', '--recursive', 'https://github.com/sorin-ionescu/prezto.git', prezto) sh.zsh('-c', 'setopt EXTENDED_GLOB; for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do ln -sf "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"; done') lnk(join(DIR, 'zsh', 'prompt_krx_setup'), join(prezto, 'modules', 'prompt', 'functions')) shutil.rmtree(join(prezto, 'runcoms')) lnk(join(DIR, 'zsh', 'runcoms'), join(prezto, 'runcoms'))
def setup_zsh(): prezto = join(HOME, '.zprezto') if not os.path.isdir(prezto): sh.git('clone', '--recursive', 'https://github.com/sorin-ionescu/prezto.git', prezto) sh.zsh( '-c', 'setopt EXTENDED_GLOB; for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"; done' ) lnk(join(DIR, 'zsh', 'prompt_krx_setup'), join(prezto, 'modules', 'prompt', 'functions')) shutil.rmtree(join(prezto, 'runcoms')) lnk(join(DIR, 'zsh', 'runcoms'), join(prezto, 'runcoms'))
def start(self): sh.rm('-rf', wpath('bin/tp'), **SHARG) sh.ln('-s', wpath('bin/command.py'), wpath('bin/tp'), **SHARG) rows, columns = os.popen('stty size', 'r').read().split() terminal_width = int(columns) for module in [ 'zsh', 'vim', 'git', 'ssh', 'tmux', 'python', 'clang', 'dircolors' ]: print('{0:-^{1}}'.format(' {} environment '.format(module).upper(), terminal_width)) getattr(self, '_{}_environment'.format(module))() sh.zsh(hpath('.zshrc'), **SHARG)
def xxd_diff(old, new): ''' just for fun ''' # xxd -p for pure hexdump # -p must pass in before file name shell = check_shell() # support : bash, zsh # not support : dash cmd = 'diff <(xxd -p {}) <(xxd -p {})'.format(old, new) if shell['bash']: return sh.bash('-c', cmd, _ok_code=[0, 1]) elif shell['zsh']: return sh.zsh('-c', cmd, _ok_code=[0, 1]) else: tmp_old = '/var/tmp/old_hex' tmp_new = '/var/tmp/new_hex' sh.xxd('-p', old, _out=tmp_old) sh.xxd('-p', new, _out=tmp_new) patch = sh.diff(old, new, _iter=True, _ok_code=[0, 1]) sh.rm('-f', tmp_old) sh.rm('-f', tmp_new) return patch
def _vim_environment(self): sh.mkdir('-p', hpath('.vim/colors'), **SHARG) sh.cp(wpath('vim/molokai.vim'), hpath('.vim/colors/molokai.vim'), **SHARG) sh.cp(wpath('vim/solarized.vim'), hpath('.vim/colors/solarized.vim'), **SHARG) sh.rsync('-rzvaP', wpath('vim/UltiSnips'), hpath('.vim'), **SHARG) vundle_dir = hpath('.vim/bundle/Vundle.vim') if os.path.isdir(vundle_dir): os.chdir(vundle_dir) sh.git('pull', **SHARG) os.chdir(working_dir) else: sh.git('clone', 'https://github.com/VundleVim/Vundle.vim.git', vundle_dir, **SHARG) template = self.temp_env.get_template(wpath('vim/vimrc.template')) with open(hpath('.vimrc'), 'w') as vimrc: vimrc.write(template.render(python_path=self.python_path)) # sh.cp(wpath('vim/vimrc'), hpath('.vimrc'), **SHARG) sh.vim('+PluginInstall', '+qall', **SHARG) ycm_dir = hpath('.vim/bundle/YouCompleteMe') if not os.path.isdir(ycm_dir): sh.git('clone', 'https://github.com/Valloric/YouCompleteMe.git', ycm_dir, **SHARG) if not os.path.isfile( hpath( '.vim/bundle/YouCompleteMe/third_party/ycmd/ycm_core.so')): os.chdir(ycm_dir) sh.git('submodule', 'update', '--init', '--recursive', **SHARG) sh.zsh('install.sh', '--clang-completer', **SHARG) os.chdir(working_dir)
else: top.append((past[key] * 100, "[ drp ] {}".format(s))) #print(top[-1]) top = [s for d, s in sorted(top, key=lambda d: abs(d[0]))] print("\n".join(top[-toplen:])) trends(toplen=10, seconds=60*60*24*365, pertext="past year") trends(toplen=10, seconds=60*60*24*30, pertext="past month") trends(toplen=10, seconds=60*60*24*7, pertext="past week") from fuzzywuzzy import fuzz import sh print("\ntop 10 - common typos") all_commands = set() for line in sh.zsh("-i", c="alias"): all_commands.add(line.split("=", 1)[0]) for path in os.getenv("PATH").split(":"): if os.path.isdir(path): all_commands.update(os.listdir(path)) else: print("[WARNING] in path but not folder:", path) top = [] for key, value in by_base.items(): if len(value) < 2 or any([key.startswith(v) for v in ["/", "./", "~/"]]): continue if key not in all_commands: for k2, v2 in by_base.items(): if key == k2: continue
top.append((past[key] * 100, "[ drp ] {}".format(s))) #print(top[-1]) top = [s for d, s in sorted(top, key=lambda d: abs(d[0]))] print("\n".join(top[-toplen:])) trends(toplen=10, seconds=60 * 60 * 24 * 365, pertext="past year") trends(toplen=10, seconds=60 * 60 * 24 * 30, pertext="past month") trends(toplen=10, seconds=60 * 60 * 24 * 7, pertext="past week") from fuzzywuzzy import fuzz import sh print("\ntop 10 - common typos") all_commands = set() for line in sh.zsh("-i", c="alias"): all_commands.add(line.split("=", 1)[0]) for path in os.getenv("PATH").split(":"): if os.path.isdir(path): all_commands.update(os.listdir(path)) else: print("[WARNING] in path but not folder:", path) top = [] for key, value in by_base.items(): if len(value) < 2 or any([key.startswith(v) for v in ["/", "./", "~/"]]): continue if key not in all_commands: for k2, v2 in by_base.items(): if key == k2: continue