def legacypl(): if yesno('install_legacypl', 'Create clone of legacy-pl?', want_full): mkdir('~/playground-6') legacy = InstallFromSource('ssh://[email protected]/phodge/legacy-pl.git', '~/playground-6/legacy-pl.git') legacy.select_branch('develop') run(legacy)
def nudge(): if yesno('install_nudge', 'Install nudge?', want_full): nudge = InstallFromSource('https://github.com/toomuchphp/nudge.git', '~/src/nudge.git') nudge.select_branch('master') nudge.symlink('bin/nudge', '~/bin/nudge') run(nudge)
def jerjerrod_install(): # NOTE: only install jerjerrod where we've installed powerline install_commands = [ ['pip3', 'install', '--user', '-e', '.'], ] if IS_OSX and haveexecutable('/usr/bin/pip3'): # XXX: this version of pip3 is too old to understand how to install in # ---editable mode with just a pyproject.toml, so we need to just # install it as-is install_commands.append( ['/usr/bin/pip3', 'install', '--user', '.'], ) # install from source! inst = InstallFromSource('https://github.com/phodge/jerjerrod.git', '~/src/jerjerrod.git') inst.select_branch('master') # TODO: if you uninstall jerjerrod, this won't actually reinstalll it :-( inst.compile_cmd(install_commands) run(inst) jerjerrod_addline('PROJECT', '~/src/*.git') jerjerrod_addline('PROJECT', '~/src/*.hg') jerjerrod_addline('PROJECT', HERE)
def tools(): if yesno('install_with', 'Install `with` utility?', want_full): withutil = InstallFromSource('https://github.com/mchav/with', '~/src/with.git') withutil.symlink('with', '~/bin/with') withutil.select_branch('master') run(withutil) if yesno('install_universal_ctags', 'Install Universal Ctags?', want_full): need_installpkg(apt=('autoconf', 'g++')) mkdir('~/bin') if haveexecutable('brew'): # install with homebrew execute(['brew', 'tap', 'universal-ctags/universal-ctags']) execute(['brew', 'install', '--HEAD', 'universal-ctags']) else: uc = InstallFromSource('https://github.com/universal-ctags/ctags', '~/src/universal-ctags.git') uc.select_branch('master') uc.compile_cmd([ ['./autogen.sh'], ['./configure'], ['make'], ]) uc.symlink('ctags', '~/bin/ctags') run(uc) elif allow_installing_stuff and yesno('install_ctags', 'Install `ctags`?', want_full): installpkg('ctags') if allow_installing_stuff and yesno('install_patch', 'Install patch?', want_full): installpkg('patch') if allow_installing_stuff and yesno('install_tidy', 'Install tidy cli tool?', want_full): installpkg('tidy') # on OSX we want to install gnu utils (brew install coreutils findutils) # and put /usr/local/opt/coreutils/libexec/gnubin in PATH if IS_OSX and haveexecutable('brew') and allow_installing_stuff: if yesno('brew_install_coreutils', 'Install gnu utils?', default=want_full): brew_list = set( execute(['brew', 'list'], stdout=True)[1].decode('utf-8').splitlines()) install = [ pkg for pkg in ('coreutils', 'findutils') if pkg not in brew_list ] if len(install): execute(['brew', 'install'] + install)
def install_pyenv(): if not yesno('want_pyenv', 'Git clone pyenv to ~/.pyenv?', default=None): return gitclone = InstallFromSource('https://github.com/pyenv/pyenv.git', '~/.pyenv') gitclone.select_branch('master') run(gitclone) gitclone2 = InstallFromSource('https://github.com/pyenv/pyenv-virtualenv', '~/.pyenv/plugins/pyenv-virtualenv') gitclone2.select_branch('master') run(gitclone2) # NOTE: on ubuntu you'll need to install libffi-dev if IS_UBUNTU: installpkg('libffi-dev', apt='libffi-dev') installpkg('pkgconf', apt='pkgconf')
def tmux_config(): tmux_plugins = yesno('install_tmux_plugins', 'Install TPM and use tmux plugins?', want_full) if tmux_plugins: mkdir('~/.tmux') mkdir('~/.tmux/plugins') tpm = InstallFromSource('https://github.com/tmux-plugins/tpm', '~/.tmux/plugins/tpm') tpm.select_branch('master') run(tpm) # what to put in tmux config? wildcards = {"DOTFILES": HERE, "HOME": HOME} lines = ['source ~/.tmux/keybindings.conf'] # add our dotfiles python folder to PYTHONPATH before restarting the powerline daemon #lines.append("set-environment PYTHONPATH '%(DOTFILES)s/python'") if tmux_plugins: lines.append('source "%(DOTFILES)s/tmux/plugins.conf"') # FIXME: the only way to determine if TPM installed correctly is to # press `[PREFIX]`, `I` to do a plugin install lines.append('source "%(DOTFILES)s/tmux/tmux.conf"') if wantpowerline(): wildcards["POWERLINE"] = powerline_path() lines.extend([ # always replace the daemon on startup, so that re-sourcing the # tmux conf always loads updated python modules 'source "%(POWERLINE)s/bindings/tmux/powerline.conf"', 'run-shell "powerline-daemon --replace -q"', ]) lines = [l % wildcards for l in lines] # noqa: E741 blockinfile('~/.tmux.conf', lines, '# start of automated tmux config', '# end of automated tmux config', where=WHERE_TOP)
def vim_config(): # install vim-plug into ~/.vim mkdir('~/.vim') mkdir('~/.nvim') mkdir('~/.config') mkdir('~/.config/nvim') symlink('~/.vimrc', '~/.config/nvim/init.vim') mkdir('~/.vim/autoload') download( 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', '~/.vim/autoload/plug.vim') def mkdir_r(path): assert len(path) if os.path.islink(path): raise Exception( "Cannot mkdir_r(%r): path already exists but is a symlink" % path) # if the thing already exists but isn't a dir, then we can't create it if os.path.exists(path) and not os.path.isdir(path): raise Exception( "Cannot mkdir_r(%r): path already exists but is not a dir" % path) # create the parent then our target path parent = os.path.dirname(path) if len(parent) > 5: mkdir_r(parent) mkdir(path) def _static(url, dest): dest = HOME + '/.vimstatic/' + dest mkdir_r(os.path.dirname(dest)) download(url, dest) vprefs = HOME + '/.vim/prefs.vim' nprefs = HOME + '/.nvim/prefs.vim' # chuck in a reference to our shiny new vimrc.vim (this will end up below the rtp magic block) lineinfile('~/.vimrc', 'source %s/vimrc.vim' % HERE, where=WHERE_TOP) # do we want a debugger plugin in vim? for varname, varval in get_vim_options().items(): lineinfile( '~/.vim/prefs.vim', f'let {varname} = {"1" if varval else "0"} " set by phodge\'s dotfiles' .format(varname, '1' if varval else '0'), where=WHERE_END, ) # put our magic &rtp block at the top of our vimrc blockinfile('~/.vimrc', [ ' " reset rtp', ' set runtimepath&', ' " let other scripts know they\'re allowed to modify &rtp', ' let g:allow_rtp_modify = 1', ' " grab local preferences', ' if filereadable(%r)' % vprefs, ' source %s' % vprefs, ' endif', ' if has(\'nvim\') && filereadable(%r)' % nprefs, ' source %s' % nprefs, ' endif', ], '" {{{ START OF dotfiles runtimepath magic', '" }}} END OF dotfiles runtimepath magic', where=WHERE_TOP) # if the .vimrc.preferences file doesn't exist, create it now if not os.path.exists(vprefs): with open(vprefs, 'w') as f: f.write('let g:vim_peter = 1\n') # make sure we've made a choice about clipboard option in vprefs file @whenmissing(vprefs, 'clipboard') def addclipboard(): if allowinteractive(): if yesno(None, 'Use system clipboard in vim? (clipboard=unnamed)', None): rem = "Use system clipboard" val = 'unnamed' else: rem = "Don't try and use system clipboard" val = '' with open(vprefs, 'a') as f: f.write('" %s\n' % rem) f.write("set clipboard=%s\n" % val) # put a default value about whether we want the hacky mappings for when the # terminal type isn't set correctly @whenmissing(vprefs, 'g:hackymappings') def sethackymappings(): with open(vprefs, 'a') as f: f.write('" Use hacky mappings for F-keys and keypad?\n') f.write('let g:hackymappings = 0\n') # in most cases we don't want insight_php_tests @whenmissing(vprefs, 'g:insight_php_tests') def setinsightphptests(): with open(vprefs, 'a') as f: f.write('" Do we want to use insight to check PHP code?\n') f.write('let g:insight_php_tests = []\n') # lock down &runtimepath lineinfile('~/.vimrc', 'let g:allow_rtp_modify = 0', where=WHERE_END) # if we have jerjerrod installed, add an ALWAYSFLAG entry for git repos in ~/src/plugedit if False and wantjerjerrod(): mkdir('~/.config') mkdir('~/.config/jerjerrod') lineinfile('~/.config/jerjerrod/jerjerrod.conf', 'PROJECT ~/src/plugedit/*.git ALWAYSFLAG') # icinga syntax/filetype if yesno('want_vim_icinga_stuff', 'Install vim icinga2 syntax/ftplugin?', default=False): files = ['syntax/icinga2.vim', 'ftdetect/icinga2.vim'] for name in files: url = 'https://raw.githubusercontent.com/Icinga/icinga2/master/tools/syntax/vim/{}' _static(url.format(name), name) # <est> utility hasphp = haveexecutable('php') if yesno('install_est_utility', 'Install <vim-est>?', hasphp): est = InstallFromSource('https://github.com/phodge/vim-est.git', '~/src/vim-est.git') est.select_branch('master') est.symlink('bin/est', '~/bin/est') run(est)
def git(): hooksdir = HOME + '/.githooks' mkdir(hooksdir) # symlink our pre-commit hook into ~/.githooks symlink('git/hooks/pre-commit', '~/.githooks/pre-commit') symlink('git/hooks/applypatch-msg', '~/.githooks/applypatch-msg') symlink('git/hooks/commit-msg', '~/.githooks/commit-msg') symlink('git/hooks/fsmonitor-watchman', '~/.githooks/fsmonitor-watchman') symlink('git/hooks/p4-changelist', '~/.githooks/p4-changelist') symlink('git/hooks/p4-post-changelist', '~/.githooks/p4-post-changelist') symlink('git/hooks/p4-pre-submit', '~/.githooks/p4-pre-submit') symlink('git/hooks/p4-prepare-changelist', '~/.githooks/p4-prepare-changelist') symlink('git/hooks/post-applypatch', '~/.githooks/post-applypatch') symlink('git/hooks/post-checkout', '~/.githooks/post-checkout') symlink('git/hooks/post-commit', '~/.githooks/post-commit') symlink('git/hooks/post-index-change', '~/.githooks/post-index-change') symlink('git/hooks/post-merge', '~/.githooks/post-merge') symlink('git/hooks/post-receive', '~/.githooks/post-receive') symlink('git/hooks/post-rewrite', '~/.githooks/post-rewrite') symlink('git/hooks/post-update', '~/.githooks/post-update') symlink('git/hooks/pre-applypatch', '~/.githooks/pre-applypatch') symlink('git/hooks/pre-auto-gc', '~/.githooks/pre-auto-gc') symlink('git/hooks/pre-commit', '~/.githooks/pre-commit') symlink('git/hooks/pre-merge-commit', '~/.githooks/pre-merge-commit') symlink('git/hooks/pre-push', '~/.githooks/pre-push') symlink('git/hooks/pre-rebase', '~/.githooks/pre-rebase') symlink('git/hooks/pre-receive', '~/.githooks/pre-receive') symlink('git/hooks/prepare-commit-msg', '~/.githooks/prepare-commit-msg') symlink('git/hooks/proc-receive', '~/.githooks/proc-receive') symlink('git/hooks/push-to-checkout', '~/.githooks/push-to-checkout') symlink('git/hooks/rebase', '~/.githooks/rebase') symlink('git/hooks/reference-transaction', '~/.githooks/reference-transaction') symlink('git/hooks/sendemail-validate', '~/.githooks/sendemail-validate') symlink('git/hooks/update', '~/.githooks/update') lines = [ # include our dotfiles git config from ~/.gitconfig "[include] path = %s/git/config" % HERE, # because git config files don't support ENV vars, we need to tell it where to find our hooks "[core] hooksPath = %s/.githooks" % HOME, ] blockinfile('~/.gitconfig', lines, WHERE_TOP) # put our standard ignore stuff into ~/.gitignore with open('%s/git/ignore' % HERE, 'r') as f: lines = [l.rstrip('\r\n') for l in f.readlines()] # noqa: E741 blockinfile('~/.gitignore', lines, "# exclude items from phodge/dotfiles", "# end of items from phodge/dotfiles", where=WHERE_TOP) gitwip = InstallFromSource('https://github.com/phodge/git-wip.git', '~/src/git-wip.git') gitwip.symlink('bin/git-wip', '~/bin/git-wip') gitwip.symlink('bin/git-unwip', '~/bin/git-unwip') gitwip.select_branch('master') run(gitwip)