コード例 #1
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)
コード例 #2
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
コード例 #3
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)
コード例 #4
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))
コード例 #5
0
ファイル: HOMELY.py プロジェクト: phodge/dotfiles
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)
コード例 #6
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)