Example #1
0
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)
Example #2
0
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)
Example #3
0
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)
Example #4
0
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)
Example #5
0
def tmux_install():
    if yesno('own_tmux', 'Compile tmux from source?', None):
        need_installpkg(
            apt=('libevent-dev', 'ncurses-dev'),
            brew=('automake', 'libevent'),
        )
        tmux = InstallFromSource('https://github.com/tmux/tmux.git',
                                 '~/src/tmux.git')
        tmux.select_tag('2.7')
        tmux.compile_cmd([
            # distclean will always fail if there's nothing to clean
            ['bash', '-c', 'make distclean || :'],
            ['sh', 'autogen.sh'],
            ['./configure'],
            ['make'],
        ])
        tmux.symlink('tmux', '~/bin/tmux')
        tmux.symlink('tmux.1', '~/man/man1/tmux.1')
        run(tmux)
    else:
        try:
            # install tmux using brew or apt-get ...
            installpkg('tmux')
        except Exception:
            print("-" * 50)
            print(
                "Compiling `tmux` failed - do you need to install automake or gcc?"
            )  # noqa
            print("-" * 50)
            raise
Example #6
0
def zsh_config():
    lineinfile('~/.zshrc', 'source $HOME/.shellrc', where=WHERE_TOP)
    install_completions('~/.zshrc')
    lineinfile('~/.zshrc', 'shell_init_done  # this line must be last', where=WHERE_END)
    antigen = InstallFromSource('https://github.com/zsh-users/antigen.git',
                                '~/src/antigen.git')
    antigen.select_tag('v2.2.3')
    run(antigen)
Example #7
0
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')
Example #8
0
def fzf_install():
    if not yesno('install_fzf', 'Install fzf?', want_full):
        return

    if haveexecutable('brew') and allow_installing_stuff:
        installpkg('fzf')
        brewpath = execute(['brew', '--prefix'],
                           stdout=True)[1].decode('utf-8').strip()
        if brewpath == '/opt/homebrew':
            # brew puts the fzf files into versioned folders, so all we can do
            # is glob and sort (which isn't perfect because it would need to be
            # a semver-compatible sort) and pick the first one
            fzf_path = execute(
                [
                    'bash', '-c',
                    f'echo {brewpath}/Cellar/fzf/* | sort -r | head -n 1'
                ],
                stdout=True,
            )[1].decode('utf-8').strip()
        else:
            # this is how it was on my old mac
            fzf_path = brewpath + '/opt/fzf'
    else:
        # do it the long way
        import os.path
        fzf_repo = os.path.expanduser('~/src/fzf.git')
        fzf_install = InstallFromSource('https://github.com/junegunn/fzf.git',
                                        fzf_repo)
        fzf_install.select_tag('0.17.3')
        fzf_install.compile_cmd([
            ['./install', '--bin'],
        ])
        fzf_install.symlink('bin/fzf', '~/bin/fzf')
        run(fzf_install)
        execute(['./install', '--bin'], cwd=fzf_repo, stdout='TTY')
        fzf_path = fzf_repo

    lineinfile('~/.bashrc', 'source {}/shell/completion.bash'.format(fzf_path))
    lineinfile('~/.bashrc',
               'source {}/shell/key-bindings.bash'.format(fzf_path))
    if wantzsh():
        lineinfile('~/.zshrc',
                   'source {}/shell/completion.zsh'.format(fzf_path))
        lineinfile('~/.zshrc',
                   'source {}/shell/key-bindings.zsh'.format(fzf_path))
Example #9
0
def nvim_install():
    if install_nvim_via_apt():
        installpkg('neovim')
        installpkg('python-neovim')
        return

    if (allow_installing_stuff and haveexecutable('brew')
            and yesno('install_nvim_package', 'Install nvim from apt/brew?')):
        installpkg('neovim')
        return

    the_hard_way = yesno('compile_nvim',
                         'Compile/install nvim from source?',
                         recommended=allow_installing_stuff)
    if not the_hard_way:
        raise Exception('No way to install neovim')

    need_installpkg(
        apt=(
            'libtool',
            'libtool-bin',
            'autoconf',
            'automake',
            'cmake',
            'g++',
            'pkg-config',
            'unzip',
            'gettext',
        ),
        yum=('cmake', 'gcc-c++', 'unzip'),
        brew=('cmake', 'libtool', 'gettext'),
    )
    n = InstallFromSource('https://github.com/neovim/neovim.git',
                          '~/src/neovim.git')
    n.select_tag(NVIM_TAG)
    n.compile_cmd([
        ['make', 'distclean'],
        ['make'],
        ['sudo', 'make', 'install'],
    ])
    run(n)
Example #10
0
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)
Example #11
0
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)
Example #12
0
def vim_install():
    # TODO: prompt to install a better version of vim?
    # - yum install vim-enhanced
    if not yesno('compile_vim', 'Compile vim from source?', want_full):
        return

    local = HOME + '/src/vim.git'

    mkdir('~/.config')
    flagsfile = HOME + '/.config/vim-configure-flags'
    written = False
    if not os.path.exists(flagsfile):
        written = True
        # pull down git source code right now so that we can see what the configure flags are
        if not os.path.exists(local):
            execute(['git', 'clone', 'https://github.com/vim/vim.git', local])
        out = execute([local + '/configure', '--help'], stdout=True,
                      cwd=local)[1]
        with open(flagsfile, 'w') as f:
            f.write('# put configure flags here\n')
            f.write('--with-features=huge\n')
            f.write('--enable-pythoninterp=yes\n')
            f.write('--enable-python3interp=yes\n')
            f.write('\n')
            f.write('\n')
            for line in out.decode('utf-8').split('\n'):
                f.write('# ')
                f.write(line)
                f.write('\n')
    if yesno(None, 'Edit %s now?' % flagsfile, written, noprompt=False):
        execute(['vim', flagsfile], stdout="TTY")

    # install required libraries first
    need_installpkg(
        apt=(
            'libtool',
            'libtool-bin',
            'autoconf',
            'automake',
            'cmake',
            'g++',
            'pkg-config',
            'unzip',
            'ncurses-dev',
        ),
        brew=(
            'cmake',
            'libtool',
        ),
    )
    inst = InstallFromSource('https://github.com/vim/vim.git', '~/src/vim.git')
    inst.select_tag(VIM_TAG)
    configure = ['./configure']
    with open(flagsfile) as f:
        for line in f:
            if not line.startswith('#'):
                configure.append(line.rstrip())
    inst.compile_cmd([
        ['make', 'distclean'],
        configure,
        ['make'],
        ['sudo', 'make', 'install'],
    ])
    run(inst)
Example #13
0
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)