diff --git a/.conduit.yaml b/.conduit.yaml index e5c2f6f..806089f 100644 --- a/.conduit.yaml +++ b/.conduit.yaml @@ -20,4 +20,6 @@ - https://github.com/zsh-users/zsh-autosuggestions.git - https://github.com/zsh-users/zsh-history-substring-search.git - https://github.com/zsh-users/zsh-syntax-highlighting.git +- pip: + - --user pick - message: zsh will be the default prompt after next login diff --git a/build/build-dir.py b/build/build-dir.py new file mode 100755 index 0000000..8958d63 --- /dev/null +++ b/build/build-dir.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +"""The pick_build_dir command selects a build directory + +The pick_build_dir command scans the current directory for directories starting +with ``build`` and prompts the user to select one from the list. +""" + +from __future__ import print_function + +from argparse import ArgumentParser +from os import listdir +from os.path import curdir, isdir +from sys import stderr + +from pick import Picker + + +def main(): + """Main entry point to build-dir.py script.""" + parser = ArgumentParser() + parser.add_argument('output') + parser.add_argument('--default', action='store_true') + args = parser.parse_args() + directories = [] + for directory in listdir(curdir): + if isdir(directory) and directory.startswith('build'): + directories.append(directory) + if len(directories) == 0: + print('no build directories found', file=stderr) + exit(1) + build_dirs = sorted(directories) + if args.default: + build_dir = build_dirs[0] + else: + picker = Picker(build_dirs, 'Select a build directory:') + picker.register_custom_handler(ord(''), lambda _: exit(1)) + build_dir, _ = picker.start() + with open(args.output, 'w') as output: + output.write(build_dir) + + +if __name__ == '__main__': + try: + main() + except KeyboardInterrupt: + exit(130) diff --git a/build/build.plugin.zsh b/build/build.plugin.zsh new file mode 100644 index 0000000..71a3e39 --- /dev/null +++ b/build/build.plugin.zsh @@ -0,0 +1,72 @@ +# A collection of commands to make it easier to build projects. + +# Default `build` alias to select a `build-dir` then invoke a build, using an +# alias means the configured build command's completion works out of the box. +alias build="build-dir --build" + +# Detect installed debugger and set the `debug` alias to debug a program with +# command line arguments. +if [ `uname` = Linux ]; then + if which cgdb &> /dev/null; then + alias debug='cgdb --args' + elif which gdb &> /dev/null; then + alias debug='gdb --args' + fi +elif [ `uname` = Darwin ]; then + which lldb &> /dev/null && \ + alias debug='lldb --' +fi + +# Store the path to `build-dir.py`, using `${0:a:h}` does not work in a +# function because it will result in `pwd` not this scripts directory. +_build_dir_py=${0:a:h}/build-dir.py + +# Interactively choose a `~build` directory for `build` to build. +# TODO: Support arguments: +# * [x] [-h,--help] - show this help message and exit +# * [x] [--build] - execute the build commend +# * [ ]