Compare commits
21 Commits
8fbb496b0d
...
zcurses/bu
| Author | SHA1 | Date | |
|---|---|---|---|
| 3194afc80d | |||
| 087a315289 | |||
| 9b54ebc366 | |||
| 9f9c4a11eb | |||
| 8cad5acd83 | |||
| 90b3e24789 | |||
| ada3cb7d3d | |||
| e13e70de6b | |||
| b61ebc4f7a | |||
| f7d952c628 | |||
| 65b0b7a099 | |||
| 64dcee0d78 | |||
| 128cc3c57a | |||
| 8e04758760 | |||
| 52f42a7875 | |||
| 639e1b9cee | |||
| b12dcfe243 | |||
| e9993b0874 | |||
| 40c2395f43 | |||
| 9f7367c550 | |||
| d58e543c78 |
@@ -6,18 +6,26 @@
|
|||||||
- brew:
|
- brew:
|
||||||
- zsh
|
- zsh
|
||||||
- command:
|
- command:
|
||||||
- sudo chsh $USER -s `which zsh`
|
- install: sudo chsh $USER -s `which zsh`
|
||||||
|
remove: sudo chsh $USER -s `which bash`
|
||||||
- symlink:
|
- symlink:
|
||||||
- {src: zlogin, dst: ~/.zlogin}
|
- {src: zlogin, dst: ~/.zlogin}
|
||||||
- {src: zlogout, dst: ~/.zlogout}
|
- {src: zlogout, dst: ~/.zlogout}
|
||||||
- {src: zprofile, dst: ~/.zprofile}
|
- {src: zprofile, dst: ~/.zprofile}
|
||||||
- {src: zshenv, dst: ~/.zshenv}
|
- {src: zshenv, dst: ~/.zshenv}
|
||||||
- {src: zshrc, dst: ~/.zshrc}
|
- {src: zshrc, dst: ~/.zshrc}
|
||||||
-
|
- src: prompt_fresh_setup
|
||||||
src: prompt_fresh_setup
|
|
||||||
dst: ~/.local/share/zsh/site-functions/prompt_fresh_setup
|
dst: ~/.local/share/zsh/site-functions/prompt_fresh_setup
|
||||||
|
- src: build/_build-dir
|
||||||
|
dst: ~/.local/share/zsh/site-functions/_build-dir
|
||||||
|
- src: sandbox/_sandbox
|
||||||
|
dst: ~/.local/share/zsh/site-functions/_sandbox
|
||||||
|
- src: layout/_layout
|
||||||
|
dst: ~/.local/share/zsh/site-functions/_layout
|
||||||
|
- src: notes/_note
|
||||||
|
dst: ~/.local/share/zsh/site-functions/_note
|
||||||
- repo:
|
- repo:
|
||||||
- https://github.com/zsh-users/zsh-autosuggestions.git
|
- https://github.com/zsh-users/zsh-autosuggestions.git
|
||||||
- https://github.com/zsh-users/zsh-history-substring-search.git
|
- https://github.com/zsh-users/zsh-history-substring-search.git
|
||||||
- https://github.com/zsh-users/zsh-syntax-highlighting.git
|
- https://github.com/zdharma/fast-syntax-highlighting.git
|
||||||
- message: zsh will be the default prompt after next login
|
- message: zsh will be the default prompt after next login
|
||||||
|
|||||||
24
autoenv/_autoenv
Normal file
24
autoenv/_autoenv
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#compdef autoenv
|
||||||
|
|
||||||
|
# Completion for the autoenv command.
|
||||||
|
_autoenv() {
|
||||||
|
local ret=1 context curcontext="$curcontext" state line
|
||||||
|
typeset -A opt_args
|
||||||
|
|
||||||
|
_arguments -C -w -s \
|
||||||
|
'(-h --help)'{-h,--help}'[show this help message and exit]' \
|
||||||
|
'1: :->command'
|
||||||
|
|
||||||
|
case $state in
|
||||||
|
(command)
|
||||||
|
declare -a commands
|
||||||
|
local commands=(
|
||||||
|
init:'add .enter and .exit scripts in current directory'
|
||||||
|
edit:'edit .enter and .exit scripts in current directory'
|
||||||
|
deinit:'remove .enter and .exit scripts in current directory'
|
||||||
|
)
|
||||||
|
_describe -t commands command commands && ret=0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
@@ -1,73 +1,4 @@
|
|||||||
# Automatically update the environment when the current working directory
|
# Source the autoenv implementation script.
|
||||||
# changes, this is a reimplementation of the ideas found in the repository
|
source ${0:a:h}/autoenv.zsh
|
||||||
# https://github.com/Tarrasch/zsh-autoenv stripped down to suit my specific
|
# Add the autoenv directory to fpath for completion.
|
||||||
# needs.
|
fpath+=${0:a:h}
|
||||||
|
|
||||||
# Global entered directories array.
|
|
||||||
_autoenv_entered=()
|
|
||||||
|
|
||||||
# Source an enter script and add its directory to the global entered
|
|
||||||
# directories array.
|
|
||||||
_autoenv_enter() {
|
|
||||||
local entered=$1
|
|
||||||
# If entered has already been sourced, return.
|
|
||||||
(( ${+_autoenv_entered[${_autoenv_entered[(i)$entered]}]} )) && return
|
|
||||||
# If the enter script is not authorized, return.
|
|
||||||
# TODO: _autoenv_authorized $entered/.enter || return
|
|
||||||
# Source the enter script.
|
|
||||||
source $entered/.enter
|
|
||||||
# Add the entered directory to the global entered array.
|
|
||||||
_autoenv_entered+=$entered
|
|
||||||
}
|
|
||||||
|
|
||||||
# Source an exit script and remove its directory from the global entered
|
|
||||||
# directories array.
|
|
||||||
_autoenv_exit() {
|
|
||||||
local entered=$1
|
|
||||||
# If the exit script is not authorized, return.
|
|
||||||
# TODO: _autoenv_authorized $entered/.exit || return
|
|
||||||
# Source the exit script.
|
|
||||||
source $entered/.exit
|
|
||||||
# Remove the entered directory from the global entered array.
|
|
||||||
_autoenv_entered[${_autoenv_entered[(i)$entered]}]=()
|
|
||||||
}
|
|
||||||
|
|
||||||
# Find a directory containing a .enter file by searching up the directory tree
|
|
||||||
# starting in the current directory.
|
|
||||||
_autoenv_find_enter() {
|
|
||||||
local current=$PWD
|
|
||||||
# If an enter script is found in the current directory, return it.
|
|
||||||
[ -f "$current/.enter" ] && echo $current
|
|
||||||
# Loop until an enter script or the root directory is found.
|
|
||||||
while true; do
|
|
||||||
# Walk up one directory and make the path absolute.
|
|
||||||
local next=$current/..; local next=${next:A}
|
|
||||||
# If the current directory equals the next directory, return.
|
|
||||||
[[ $current == $next ]] && return || local current=$next
|
|
||||||
# If an enter script is found in the current directory, return it.
|
|
||||||
[ -f $current/.enter ] && echo $current
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# A chpwd hook function which automatically sources enter and exit scripts to
|
|
||||||
# setup local environments for directory and its subdirectories.
|
|
||||||
_autoenv_chpwd() {
|
|
||||||
local entered
|
|
||||||
# Loop over the entered directory stack.
|
|
||||||
for entered in $_autoenv_entered; do
|
|
||||||
# If the the current directory was previously entered then exit.
|
|
||||||
# TODO: Verify what this condition expression actually does.
|
|
||||||
! [[ $PWD/ == $entered/* ]] && _autoenv_exit $entered
|
|
||||||
done
|
|
||||||
# Find the nearest enter script directory.
|
|
||||||
local enter=`_autoenv_find_enter`
|
|
||||||
# If the enter directory exists, enter it.
|
|
||||||
[ -d "$enter" ] && _autoenv_enter $enter
|
|
||||||
}
|
|
||||||
|
|
||||||
# Register the autoenv chpwd hook.
|
|
||||||
autoload -U add-zsh-hook
|
|
||||||
add-zsh-hook chpwd _autoenv_chpwd
|
|
||||||
|
|
||||||
# Ensure autoenv is activated in the current directory on first load.
|
|
||||||
_autoenv_chpwd
|
|
||||||
|
|||||||
179
autoenv/autoenv.zsh
Normal file
179
autoenv/autoenv.zsh
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
# Automatically update the environment when the current working directory
|
||||||
|
# changes, this is a reimplementation of the ideas found in the repository
|
||||||
|
# https://github.com/Tarrasch/zsh-autoenv stripped down to bare essentials.
|
||||||
|
#
|
||||||
|
# The secret sauce can be found at the bottom of this file, where the chpwd
|
||||||
|
# hook function _autoenv_chpwd is added.
|
||||||
|
|
||||||
|
# The autoenv command provides a convenient way to create, edit, and remove
|
||||||
|
# enter and exit scripts in the current directory.
|
||||||
|
autoenv() {
|
||||||
|
local cmd=$1
|
||||||
|
case "$cmd" in
|
||||||
|
-h|--help) # Display help.
|
||||||
|
echo "\
|
||||||
|
usage: autoenv [-h] {init,edit,deinit}
|
||||||
|
|
||||||
|
options:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
|
||||||
|
commands:
|
||||||
|
init add .enter and .exit scripts in current directory
|
||||||
|
edit edit .enter and .exit scripts in current directory
|
||||||
|
deinit remove .enter and .exit scripts in current directory"
|
||||||
|
;;
|
||||||
|
|
||||||
|
init) # Create enter and exit scripts in current directory.
|
||||||
|
if [ -f $PWD/.enter ] || [ -f $PWD/.exit ]; then
|
||||||
|
echo '.enter or .exit already exists'; return 1
|
||||||
|
fi
|
||||||
|
# Create then edit enter and exit scripts.
|
||||||
|
touch .enter .exit && autoenv edit
|
||||||
|
# If enter script exists, authorize it.
|
||||||
|
[ -f $PWD/.enter ] && _autoenv_authorized $PWD/.enter yes
|
||||||
|
# If exit script exists, authorize it.
|
||||||
|
[ -f $PWD/.exit ] && _autoenv_authorized $PWD/.exit yes
|
||||||
|
# Enter the new autoenv.
|
||||||
|
_autoenv_enter $PWD ;;
|
||||||
|
|
||||||
|
edit) # Edit enter and exit scripts in current directory.
|
||||||
|
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
|
||||||
|
echo '.enter or .exit not found'; return 1
|
||||||
|
fi
|
||||||
|
# If vim exists, edit enter and exit scripts.
|
||||||
|
if which vim &> /dev/null; then
|
||||||
|
vim -p $PWD/.enter $PWD/.exit
|
||||||
|
else
|
||||||
|
echo 'vim not found'; return 1
|
||||||
|
fi ;;
|
||||||
|
|
||||||
|
deinit) # Remove enter and exit scripts in current directory.
|
||||||
|
if [ -f $PWD/.enter ] || [ -f $PWD/.exit ]; then
|
||||||
|
# Prompt user to confirm removal of enter and exit scripts.
|
||||||
|
while true; do
|
||||||
|
read "answer?Are you sure [y/N]? "
|
||||||
|
case "$answer" in
|
||||||
|
y|Y|yes)
|
||||||
|
# Remove enter and exit scripts if they exist.
|
||||||
|
[ -f $PWD/.enter ] && rm $PWD/.enter
|
||||||
|
[ -f $PWD/.exit ] && rm $PWD/.exit
|
||||||
|
break ;;
|
||||||
|
*) break ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo '.enter and .exit not found'; return 1
|
||||||
|
fi ;;
|
||||||
|
|
||||||
|
*) # Invalid arguments, show help then error.
|
||||||
|
echo "invalid arguments: $@"
|
||||||
|
autoenv --help
|
||||||
|
return 1 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Global entered directories array.
|
||||||
|
_autoenv_entered=()
|
||||||
|
|
||||||
|
# Check if the given file is authorized, if not prompt the user to authorize,
|
||||||
|
# ignore, or view the file. Authorized files and their modified times are
|
||||||
|
# stored in the ~/.cache/autoenv/authorized file to make authorization
|
||||||
|
# persistent.
|
||||||
|
_autoenv_authorized() {
|
||||||
|
local file=$1 yes=$2
|
||||||
|
# If autoenv cache directory does not exist, create it.
|
||||||
|
! [ -d ~/.cache/autoenv ] && mkdir -p ~/.cache/autoenv
|
||||||
|
# If the authorized file does not exist, create it.
|
||||||
|
! [ -f ~/.cache/autoenv/authorized ] && touch ~/.cache/autoenv/authorized
|
||||||
|
# Load the authorized file into a map of authorized key value pairs.
|
||||||
|
typeset -A authorized=(`cat ~/.cache/autoenv/authorized`)
|
||||||
|
# If the file has been removed, return.
|
||||||
|
! [ -f $file ] && return 1
|
||||||
|
# If the given file has been authorized, i.e. the modified time matches that
|
||||||
|
# held in the authorized file, return.
|
||||||
|
local modified_time=`zstat +mtime $file`
|
||||||
|
[ "$authorized[$file]" = "$modified_time" ] && return
|
||||||
|
# If yes, don't prompt for user confirmation.
|
||||||
|
if [ "$yes" != "yes" ]; then
|
||||||
|
# Prompt to authorize file.
|
||||||
|
while true; do
|
||||||
|
read "answer?Authorize $file [Y/n/v]? "
|
||||||
|
case "$answer" in
|
||||||
|
y|Y|yes|'') break ;; # Authorize the file.
|
||||||
|
n|N|no) return 1 ;; # Do not authorize the file.
|
||||||
|
v|V|view) cat $file ;; # View the file.
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
# Add file to the authorized map.
|
||||||
|
authorized[$file]=$modified_time
|
||||||
|
# Store authorized map in authorized file.
|
||||||
|
echo ${(kv)authorized} > ~/.cache/autoenv/authorized
|
||||||
|
}
|
||||||
|
|
||||||
|
# Source an enter script and add its directory to the global entered
|
||||||
|
# directories array.
|
||||||
|
_autoenv_enter() {
|
||||||
|
local entered=$1
|
||||||
|
# If entered exists in the entered directories array, return.
|
||||||
|
(( ${+_autoenv_entered[${_autoenv_entered[(i)$entered]}]} )) && return
|
||||||
|
# If the enter script is not authorized, return.
|
||||||
|
_autoenv_authorized $entered/.enter || return
|
||||||
|
# Source the enter script.
|
||||||
|
source $entered/.enter
|
||||||
|
# Add the entered directory to the global entered array.
|
||||||
|
_autoenv_entered+=$entered
|
||||||
|
}
|
||||||
|
|
||||||
|
# Source an exit script and remove its directory from the global entered
|
||||||
|
# directories array.
|
||||||
|
_autoenv_exit() {
|
||||||
|
local entered=$1
|
||||||
|
# If the exit script is not authorized, return.
|
||||||
|
_autoenv_authorized $entered/.exit || return
|
||||||
|
# Source the exit script.
|
||||||
|
source $entered/.exit
|
||||||
|
# Remove the entered directory from the global entered array.
|
||||||
|
_autoenv_entered[${_autoenv_entered[(i)$entered]}]=()
|
||||||
|
}
|
||||||
|
|
||||||
|
# Find all directories containing a .enter file by searching up the directory
|
||||||
|
# tree starting in the current directory.
|
||||||
|
_autoenv_find_enter_directories() {
|
||||||
|
local current=$PWD
|
||||||
|
# If an enter script is found in the current directory, return it.
|
||||||
|
[ -f $current/.enter ] && echo $current
|
||||||
|
# Loop until an enter script or the root directory is found.
|
||||||
|
while true; do
|
||||||
|
# Go up one directory and make the path absolute.
|
||||||
|
local next=$current/..; local next=${next:A}
|
||||||
|
# If an enter script is found in the current directory, return it.
|
||||||
|
[ -f $next/.enter ] && echo $next
|
||||||
|
# If the current directory equals the next directory we are done, otherwise
|
||||||
|
# update the current directory.
|
||||||
|
[[ $current == $next ]] && return || local current=$next
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# A chpwd hook function which automatically sources enter and exit scripts to
|
||||||
|
# setup local environments for directory and its subdirectories.
|
||||||
|
_autoenv_chpwd() {
|
||||||
|
local entered
|
||||||
|
# Loop over the reversed entered directory array.
|
||||||
|
for entered in ${(aO)_autoenv_entered}; do
|
||||||
|
# If the the current directory was previously entered then exit.
|
||||||
|
! [[ $PWD/ == $entered/* ]] && _autoenv_exit $entered
|
||||||
|
done
|
||||||
|
# Find all enter script directories, store them in an array.
|
||||||
|
local enter_dirs=(`_autoenv_find_enter_directories`)
|
||||||
|
# Loop over reversed enter script directories array, so enter scripts found
|
||||||
|
# last are sourced first, then source all enter scripts.
|
||||||
|
for enter in ${(aO)enter_dirs}; do _autoenv_enter $enter; done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Register the autoenv chpwd hook.
|
||||||
|
autoload -U add-zsh-hook
|
||||||
|
add-zsh-hook chpwd _autoenv_chpwd
|
||||||
|
|
||||||
|
# Ensure autoenv is activated in the current directory on first load.
|
||||||
|
_autoenv_chpwd
|
||||||
6
build/_build-dir
Normal file
6
build/_build-dir
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#compdef build-dir
|
||||||
|
|
||||||
|
_arguments \
|
||||||
|
'(-h --help)'{-h,--help}'[]' \
|
||||||
|
'--build[invoke a build after selection]' \
|
||||||
|
'1:directory:_files'
|
||||||
46
build/build-dir.py
Executable file
46
build/build-dir.py
Executable file
@@ -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)
|
||||||
166
build/build.plugin.zsh
Normal file
166
build/build.plugin.zsh
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
# Interactively choose a `~build` directory for `build` to build.
|
||||||
|
build-dir() {
|
||||||
|
local usage='usage: build-dir [-h] [--build] [<directory>]'
|
||||||
|
local -a help do_build
|
||||||
|
zparseopts -D h=help -help=help -build=do_build
|
||||||
|
if [[ -n $help ]]; then
|
||||||
|
cat << EOF
|
||||||
|
$usage
|
||||||
|
|
||||||
|
Find and select the current build directory interactively.
|
||||||
|
|
||||||
|
positional arguments:
|
||||||
|
<directory> the build directory to select
|
||||||
|
|
||||||
|
optional arguments:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
--build invoke a build after selection
|
||||||
|
EOF
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
error() { echo "\e[31merror:\e[0m $1"; return 1 }
|
||||||
|
local build_dir
|
||||||
|
if [[ ${#*} -gt 1 ]]; then
|
||||||
|
echo $usage
|
||||||
|
error "unexpected position arguments: ${*[2,${#*}]}"
|
||||||
|
elif [[ ${#*} -eq 1 ]]; then
|
||||||
|
build_dir=${*[1]}
|
||||||
|
[[ ! -d $build_dir ]] && \
|
||||||
|
error "directory not found: $build_dir"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If <directory> was not set begin selection
|
||||||
|
if [[ -z $build_dir ]]; then
|
||||||
|
# Find build directories
|
||||||
|
local -a build_dirs
|
||||||
|
for entry in `ls -A`; do
|
||||||
|
[ -d $entry ] && [[ $entry =~ build* ]] && \
|
||||||
|
build_dirs+=${entry/\//}
|
||||||
|
done
|
||||||
|
|
||||||
|
# Interactively select a build directory if more than 1 found
|
||||||
|
integer index=0
|
||||||
|
if [[ ${#build_dirs} -eq 0 ]]; then
|
||||||
|
error "no build directories found"
|
||||||
|
elif [[ ${#build_dirs} -gt 1 ]]; then
|
||||||
|
zmodload zsh/curses && {
|
||||||
|
# Get the size of the terminal
|
||||||
|
local size=`stty size`
|
||||||
|
integer height=${size% *}
|
||||||
|
integer width=${size#* }
|
||||||
|
|
||||||
|
# Create the window and hide the cursor
|
||||||
|
zcurses init
|
||||||
|
zcurses addwin build-dir $height $width 0 0
|
||||||
|
|
||||||
|
# Hide the cursor for zcurses, trap SIGINT to ensure cleanup in
|
||||||
|
# always-list occurs below
|
||||||
|
tput civis; trap 'return 130' INT
|
||||||
|
|
||||||
|
# Enter display loop
|
||||||
|
local key keypad
|
||||||
|
while (( 1 )); do
|
||||||
|
zcurses clear build-dir
|
||||||
|
|
||||||
|
# Add the prompt text
|
||||||
|
zcurses move build-dir 1 1
|
||||||
|
zcurses string build-dir 'Select a build directory:'
|
||||||
|
|
||||||
|
# Add the selections text
|
||||||
|
for (( i = 0; i < ${#build_dirs}; i++ )); do
|
||||||
|
integer line=$i+3
|
||||||
|
zcurses move build-dir $line 1
|
||||||
|
[[ $index -eq $i ]] &&
|
||||||
|
zcurses string build-dir "* " ||
|
||||||
|
zcurses string build-dir " "
|
||||||
|
zcurses string build-dir ${build_dirs[$i+1]}
|
||||||
|
done
|
||||||
|
|
||||||
|
# Display the text the and wait for input
|
||||||
|
zcurses refresh build-dir
|
||||||
|
zcurses input build-dir key keypad
|
||||||
|
|
||||||
|
# Handle user input
|
||||||
|
case $key in
|
||||||
|
(UP|k|$'\C-P')
|
||||||
|
[[ $index -gt 0 ]] && index=$index-1 ;;
|
||||||
|
(DOWN|j|$'\C-N')
|
||||||
|
[[ $index -lt ${#build_dirs}-1 ]] && index=$index+1 ;;
|
||||||
|
(ENTER|$'\n')
|
||||||
|
break ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
} always {
|
||||||
|
# Restore the cursor and cleanup zcurses
|
||||||
|
tput cvvis; tput cnorm
|
||||||
|
zcurses delwin build-dir
|
||||||
|
zcurses end
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# On success setup the build directory for use
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
# Set the build directory from selection if empty
|
||||||
|
[[ -z $build_dir ]] && \
|
||||||
|
build_dir=${build_dirs[$index+1]}
|
||||||
|
|
||||||
|
# If `build.ninja` exists in alias `ninja`, return.
|
||||||
|
local build
|
||||||
|
[ -f $build_dir/build.ninja ] && \
|
||||||
|
build="ninja -C $build_dir"
|
||||||
|
|
||||||
|
# If `Makefile` exists in alias `make`, return.
|
||||||
|
if [ -f $build_dir/Makefile ]; then
|
||||||
|
[ `uname` = Darwin ] && \
|
||||||
|
local cpu_count=`sysctl -n hw.ncpu` ||
|
||||||
|
local cpu_count=`grep -c '^processor' /proc/cpuinfo`
|
||||||
|
build="make -j $cpu_count -C $build_dir"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If the build variable is not defined the command could not be determined
|
||||||
|
if [ -z $build ]; then
|
||||||
|
echo "\e[33mwarning:\e[0m build command detection failed: $build_dir"
|
||||||
|
# Prompt user to enter a build command
|
||||||
|
vared -p 'enter comand: ' build
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Redefine the `build` alias and update the `~build` hash directory
|
||||||
|
alias build="$build"
|
||||||
|
hash -d build=$build_dir
|
||||||
|
|
||||||
|
# If `--build` is specified then evaluate the command.
|
||||||
|
[[ -n $do_build ]] && eval build
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Build then run a target residing in `~build/bin`.
|
||||||
|
build-run() {
|
||||||
|
local target=$1; shift 1
|
||||||
|
eval build $target && ~build/bin/$target $*
|
||||||
|
}
|
||||||
|
|
||||||
|
# Build then debug a target residing in `~build/bin`.
|
||||||
|
build-debug() {
|
||||||
|
local target=$1; shift 1
|
||||||
|
eval build $target && debug ~build/bin/$target $*
|
||||||
|
}
|
||||||
76
fresh.ini
Normal file
76
fresh.ini
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
; fresh fast-syntax-highlighting theme
|
||||||
|
|
||||||
|
[base]
|
||||||
|
default = none
|
||||||
|
unknown-token = red,bold
|
||||||
|
commandseparator = none
|
||||||
|
redirection = none
|
||||||
|
here-string-tri = yellow
|
||||||
|
here-string-word = bg:blue
|
||||||
|
exec-descriptor = yellow,bold
|
||||||
|
comment = black,bold
|
||||||
|
correct-subtle = none
|
||||||
|
incorrect-subtle = red
|
||||||
|
subtle-bg = bg:blue
|
||||||
|
secondary =
|
||||||
|
|
||||||
|
[command-point]
|
||||||
|
reserved-word = yellow
|
||||||
|
alias = green
|
||||||
|
suffix-alias = green
|
||||||
|
global-alias = bg:blue
|
||||||
|
builtin = green
|
||||||
|
function = green
|
||||||
|
command = green
|
||||||
|
precommand = green
|
||||||
|
hashed-command = green
|
||||||
|
|
||||||
|
[paths]
|
||||||
|
path = none
|
||||||
|
pathseparator = none
|
||||||
|
path-to-dir = none
|
||||||
|
globbing = blue,bold
|
||||||
|
|
||||||
|
[brackets]
|
||||||
|
paired-bracket = bg:blue
|
||||||
|
bracket-level-1 = green,bold
|
||||||
|
bracket-level-2 = yellow,bold
|
||||||
|
bracket-level-3 = cyan,bold
|
||||||
|
|
||||||
|
[arguments]
|
||||||
|
single-hyphen-option = cyan
|
||||||
|
double-hyphen-option = cyan
|
||||||
|
back-quoted-argument = none
|
||||||
|
single-quoted-argument = yellow
|
||||||
|
double-quoted-argument = yellow
|
||||||
|
dollar-quoted-argument = yellow
|
||||||
|
|
||||||
|
[in-string]
|
||||||
|
; backslash in $'...'
|
||||||
|
back-dollar-quoted-argument = cyan
|
||||||
|
; backslash or $... in "..."
|
||||||
|
back-or-dollar-double-quoted-argument = cyan
|
||||||
|
|
||||||
|
[other]
|
||||||
|
variable = 113
|
||||||
|
assign = none
|
||||||
|
assign-array-bracket = green
|
||||||
|
history-expansion = blue,bold
|
||||||
|
|
||||||
|
[math]
|
||||||
|
mathvar = blue,bold
|
||||||
|
mathnum = magenta
|
||||||
|
matherr = red
|
||||||
|
|
||||||
|
[for-loop]
|
||||||
|
forvar = none
|
||||||
|
fornum = magenta
|
||||||
|
; operator
|
||||||
|
foroper = yellow
|
||||||
|
; separator
|
||||||
|
forsep = yellow,bold
|
||||||
|
|
||||||
|
[case]
|
||||||
|
case-input = green
|
||||||
|
case-parentheses = yellow
|
||||||
|
case-condition = bg:blue
|
||||||
14
layout/_layout
Normal file
14
layout/_layout
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#compdef layout
|
||||||
|
|
||||||
|
__get_layouts() {
|
||||||
|
ls -1 ~/.config/tmux/layouts 2>/dev/null | \
|
||||||
|
while read -r layout; do echo $layout; done
|
||||||
|
}
|
||||||
|
|
||||||
|
__layouts() {
|
||||||
|
local -a layouts
|
||||||
|
layouts=(${(fo)"$(__get_layouts)"})
|
||||||
|
_describe 'layout' layouts
|
||||||
|
}
|
||||||
|
|
||||||
|
_arguments ':layout:__layouts'
|
||||||
10
layout/layout.plugin.zsh
Normal file
10
layout/layout.plugin.zsh
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
layout() {
|
||||||
|
if [[ "$1" == "" ]]; then
|
||||||
|
echo "usage: layout <layout> [name]"
|
||||||
|
else
|
||||||
|
tmux source-file ~/.config/tmux/layouts/$1
|
||||||
|
if [[ "$2" != "" ]]; then
|
||||||
|
tmux rename-window $2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
13
notes/_note
Normal file
13
notes/_note
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#compdef note
|
||||||
|
|
||||||
|
__get_notes() {
|
||||||
|
ls -1 ~/Sync/Notes 2>/dev/null | while read -r note; do echo $note; done
|
||||||
|
}
|
||||||
|
|
||||||
|
__notes() {
|
||||||
|
local -a notes
|
||||||
|
notes=(${(fo)"$(__get_notes)"})
|
||||||
|
_describe 'notes' notes
|
||||||
|
}
|
||||||
|
|
||||||
|
_arguments ':notes:__notes'
|
||||||
8
notes/notes.plugin.zsh
Normal file
8
notes/notes.plugin.zsh
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# TODO: Support opening multiple notes in buffers or tabs
|
||||||
|
note() {
|
||||||
|
if [[ "$1" == "" ]]; then
|
||||||
|
echo "usage: note \"<title>\""
|
||||||
|
else
|
||||||
|
vim -c "Note $1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
49
sandbox/_sandbox
Normal file
49
sandbox/_sandbox
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#compdef sandbox
|
||||||
|
|
||||||
|
__get_sandboxes() {
|
||||||
|
/bin/ls $SANDBOX_ROOT 2> /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
__sandboxes() {
|
||||||
|
local -a sandboxes
|
||||||
|
sandboxes=(${(fo)"$(__get_sandboxes)"})
|
||||||
|
_describe 'in' sandboxes
|
||||||
|
}
|
||||||
|
|
||||||
|
_sandbox_cmds() {
|
||||||
|
local commands; commands=(
|
||||||
|
'create:Create a new sandbox'
|
||||||
|
'rename:Rename an existing sandbox'
|
||||||
|
'destroy:Destroy an existing sandbox'
|
||||||
|
'list:Show all existing sandboxes'
|
||||||
|
'enable:Enable an existing sandbox'
|
||||||
|
'disable:Disable the current sandbox'
|
||||||
|
)
|
||||||
|
_describe -t commands 'sandbox command' commands "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
_sandbox() {
|
||||||
|
local context curcontext="$curcontext" state line
|
||||||
|
typeset -A opt_args
|
||||||
|
|
||||||
|
_arguments -C \
|
||||||
|
'1: :_sandbox_cmds' \
|
||||||
|
'*::arg:->args'
|
||||||
|
|
||||||
|
case $state in
|
||||||
|
(args)
|
||||||
|
curcontext="${curcontext%:*:*}:sandbox-cmd-$words[1]:"
|
||||||
|
case $line[1] in
|
||||||
|
(create|list|disable)
|
||||||
|
;;
|
||||||
|
(enable|destroy)
|
||||||
|
_arguments -C '1:: :__sandboxes'
|
||||||
|
;;
|
||||||
|
(rename)
|
||||||
|
_arguments -C '1:: :__sandboxes'
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_sandbox "$@"
|
||||||
103
sandbox/sandbox.plugin.zsh
Normal file
103
sandbox/sandbox.plugin.zsh
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
if [[ "" == $SANDBOX_ENV_IN_FILE ]]; then
|
||||||
|
export SANDBOX_ENV_IN_FILE=$AUTOENV_IN_FILE
|
||||||
|
fi
|
||||||
|
if [[ "" == $SANDBOX_ENV_OUT_FILE ]]; then
|
||||||
|
export SANDBOX_ENV_OUT_FILE=$AUTOENV_OUT_FILE
|
||||||
|
fi
|
||||||
|
if [[ "" == $SANDBOX_ROOT ]]; then
|
||||||
|
export SANDBOX_ROOT=$HOME/Sandbox
|
||||||
|
fi
|
||||||
|
|
||||||
|
sandbox() {
|
||||||
|
local usage="usage: sandbox {create,destroy,enable,disable} [name]"
|
||||||
|
|
||||||
|
if [[ "" == $1 ]]; then
|
||||||
|
echo $usage
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
create)
|
||||||
|
if [[ "" == $2 ]]; then
|
||||||
|
echo $usage
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local sandbox=$SANDBOX_ROOT/$2
|
||||||
|
if [[ -d $sandbox ]]; then
|
||||||
|
echo "Sandbox '$2' already exists"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p $sandbox &> /dev/null
|
||||||
|
begin=$PWD
|
||||||
|
cd $sandbox
|
||||||
|
|
||||||
|
echo "SANDBOX_HOME=\$(dirname -- "\$0:a")" >> $SANDBOX_ENV_IN_FILE
|
||||||
|
echo "SANDBOX_NAME=$2" >> $SANDBOX_ENV_IN_FILE
|
||||||
|
|
||||||
|
echo "unset SANDBOX_NAME" >> $SANDBOX_ENV_OUT_FILE
|
||||||
|
echo "unset SANDBOX_HOME" >> $SANDBOX_ENV_OUT_FILE
|
||||||
|
|
||||||
|
git init &> /dev/null
|
||||||
|
|
||||||
|
cd $begin
|
||||||
|
cd $sandbox
|
||||||
|
;;
|
||||||
|
rename)
|
||||||
|
if [[ "" == $2 || "" == $3 ]]; then
|
||||||
|
echo $usage
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mv $SANDBOX_ROOT/$2 $SANDBOX_ROOT/$3
|
||||||
|
sed -i "" "s/$2/$3/g" $SANDBOX_ROOT/$3/.env
|
||||||
|
;;
|
||||||
|
destroy)
|
||||||
|
if [[ "" == $2 ]]; then
|
||||||
|
echo $usage
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local sandbox=$SANDBOX_ROOT/$2
|
||||||
|
if [[ ! -d $sandbox ]]; then
|
||||||
|
echo "Sandbox '$2' does not exist"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd -
|
||||||
|
if [[ "${SANDBOX_ROOT##$PWD}" = "${SANDBOX_ROOT}" ]]; then
|
||||||
|
cd $HOME
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf $sandbox
|
||||||
|
;;
|
||||||
|
list)
|
||||||
|
/bin/ls -1 $SANDBOX_ROOT
|
||||||
|
;;
|
||||||
|
enable)
|
||||||
|
if [[ "" == $2 ]]; then
|
||||||
|
echo $usage
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local sandbox=$SANDBOX_ROOT/$2
|
||||||
|
if [[ ! -d $sandbox ]]; then
|
||||||
|
echo "Sandbox '$2' does not exist"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
export SANDBOX_RETURN=$PWD
|
||||||
|
cd $sandbox
|
||||||
|
;;
|
||||||
|
disable)
|
||||||
|
if [[ -z $SANDBOX_RETURN ]]; then
|
||||||
|
echo "Sandbox is not currently active"
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd $SANDBOX_RETURN
|
||||||
|
unset $SANDBOX_RETURN
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
5
zshenv
5
zshenv
@@ -33,5 +33,10 @@ export LESS_TERMCAP_se=`printf "\e[0m"`
|
|||||||
export LESS_TERMCAP_us=`printf "\e[0;34m"`
|
export LESS_TERMCAP_us=`printf "\e[0;34m"`
|
||||||
export LESS_TERMCAP_ue=`printf "\e[0m"`
|
export LESS_TERMCAP_ue=`printf "\e[0m"`
|
||||||
|
|
||||||
|
# Force GoogleTest to output colors
|
||||||
|
export GTEST_COLOR=yes
|
||||||
|
# Allow completions for GoogleTest break on failure
|
||||||
|
export GTEST_BREAK_ON_FAILURE=0
|
||||||
|
|
||||||
# Disable virtualenv prompt
|
# Disable virtualenv prompt
|
||||||
VIRTUAL_ENV_DISABLE_PROMPT=1
|
VIRTUAL_ENV_DISABLE_PROMPT=1
|
||||||
|
|||||||
67
zshrc
67
zshrc
@@ -3,18 +3,40 @@
|
|||||||
|
|
||||||
# Load plugin scripts
|
# Load plugin scripts
|
||||||
source-plugin() {
|
source-plugin() {
|
||||||
[ -d ~/.config/zsh/$1 ] && \
|
if [ -d ~/.config/zsh/$1 ]; then
|
||||||
source ~/.config/zsh/$1/$1.plugin.zsh || \
|
source ~/.config/zsh/$1/$1.plugin.zsh
|
||||||
|
else
|
||||||
echo "zsh plugin not found: $1"
|
echo "zsh plugin not found: $1"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
source-plugin zsh-autosuggestions
|
|
||||||
source-plugin zsh-history-substring-search
|
|
||||||
source-plugin zsh-syntax-highlighting
|
|
||||||
source-plugin autoenv
|
|
||||||
|
|
||||||
|
# Fish like automatic suggestions from command history
|
||||||
|
source-plugin zsh-autosuggestions
|
||||||
# Disable non end-of-line autosuggest accept widgets
|
# Disable non end-of-line autosuggest accept widgets
|
||||||
ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(end-of-line vi-end-of-line)
|
ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(end-of-line vi-end-of-line)
|
||||||
|
|
||||||
|
# Search history with a command substring
|
||||||
|
source-plugin zsh-history-substring-search
|
||||||
|
|
||||||
|
# Command syntax highlighting
|
||||||
|
source-plugin fast-syntax-highlighting
|
||||||
|
fast-theme -q ~/.config/zsh/fresh.ini
|
||||||
|
|
||||||
|
# Automatically source .enter and .exit scripts on cd
|
||||||
|
source-plugin autoenv
|
||||||
|
|
||||||
|
# Build system helper commands
|
||||||
|
source-plugin build
|
||||||
|
|
||||||
|
# Project sandboxing commands
|
||||||
|
source-plugin sandbox
|
||||||
|
|
||||||
|
# Layout tmux window commands
|
||||||
|
source-plugin layout
|
||||||
|
|
||||||
|
# Note taking commands
|
||||||
|
source-plugin notes
|
||||||
|
|
||||||
# Remove duplicates from history
|
# Remove duplicates from history
|
||||||
setopt hist_ignore_all_dups
|
setopt hist_ignore_all_dups
|
||||||
setopt hist_reduce_blanks
|
setopt hist_reduce_blanks
|
||||||
@@ -39,6 +61,19 @@ unsetopt flow_control && stty -ixon
|
|||||||
autoload -U compinit
|
autoload -U compinit
|
||||||
compinit
|
compinit
|
||||||
|
|
||||||
|
# Add pip to the old completion engine if present
|
||||||
|
if which pip &> /dev/null; then
|
||||||
|
function _pip_completion {
|
||||||
|
local words cword
|
||||||
|
read -Ac words
|
||||||
|
read -cn cword
|
||||||
|
reply=( $( COMP_WORDS="$words[*]" \
|
||||||
|
COMP_CWORD=$(( cword-1 )) \
|
||||||
|
PIP_AUTO_COMPLETE=1 $words[1] ) )
|
||||||
|
}
|
||||||
|
compctl -K _pip_completion pip
|
||||||
|
fi
|
||||||
|
|
||||||
# Enable prompt themes
|
# Enable prompt themes
|
||||||
autoload -Uz promptinit
|
autoload -Uz promptinit
|
||||||
promptinit
|
promptinit
|
||||||
@@ -50,6 +85,9 @@ bindkey -v
|
|||||||
# Enable yank, change, and delete whole line with 'Y', 'cc', and 'dd'
|
# Enable yank, change, and delete whole line with 'Y', 'cc', and 'dd'
|
||||||
bindkey -M vicmd 'Y' vi-yank-whole-line
|
bindkey -M vicmd 'Y' vi-yank-whole-line
|
||||||
|
|
||||||
|
# Edit the command line in vim
|
||||||
|
bindkey -M vicmd '^F' edit-command-line
|
||||||
|
|
||||||
# Enable undo with 'u' and redo with 'U'
|
# Enable undo with 'u' and redo with 'U'
|
||||||
bindkey -M vicmd 'u' undo
|
bindkey -M vicmd 'u' undo
|
||||||
bindkey -M vicmd 'U' redo
|
bindkey -M vicmd 'U' redo
|
||||||
@@ -117,6 +155,9 @@ if [[ ! -z "$cursor_block" && ! -z "$cursor_line" ]]; then
|
|||||||
zle -N zle-line-finish
|
zle -N zle-line-finish
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Load work related config
|
||||||
|
[ -f ~/.config/work/zshrc ] && source ~/.config/work/zshrc
|
||||||
|
|
||||||
# Remove duplicates from environment variables
|
# Remove duplicates from environment variables
|
||||||
typeset -U PATH
|
typeset -U PATH
|
||||||
typeset -U MANPATH
|
typeset -U MANPATH
|
||||||
@@ -136,7 +177,7 @@ fi
|
|||||||
# Aliases
|
# Aliases
|
||||||
alias grep='grep --color=always'
|
alias grep='grep --color=always'
|
||||||
which cmake &> /dev/null && \
|
which cmake &> /dev/null && \
|
||||||
alias cninja='cmake -GNinja -DCMAKE_EXPORT_COMPILE_COMMNADS=ON'
|
alias cninja='cmake -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON'
|
||||||
which ssh &> /dev/null && \
|
which ssh &> /dev/null && \
|
||||||
alias ssh='TERM=xterm-256color ssh'
|
alias ssh='TERM=xterm-256color ssh'
|
||||||
|
|
||||||
@@ -146,10 +187,11 @@ case `uname` in
|
|||||||
alias cls="printf '\ec'" || \
|
alias cls="printf '\ec'" || \
|
||||||
alias cls="clear && printf '\e[3J'"
|
alias cls="clear && printf '\e[3J'"
|
||||||
alias ls='ls -F --color=auto'
|
alias ls='ls -F --color=auto'
|
||||||
which cgdb &> /dev/null && \
|
if which cgdb &> /dev/null; then
|
||||||
alias debug='cgdb --args' || \
|
alias debug='cgdb --args'
|
||||||
which gdb &> /dev/null && \
|
elif which gdb &> /dev/null; then
|
||||||
alias debug='gdb --args'
|
alias debug='gdb --args'
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
Darwin)
|
Darwin)
|
||||||
alias cls="clear && printf '\e[3J'"
|
alias cls="clear && printf '\e[3J'"
|
||||||
@@ -158,8 +200,3 @@ case `uname` in
|
|||||||
alias debug='lldb --'
|
alias debug='lldb --'
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ "$TMUX" != "" ]; then
|
|
||||||
alias sp='tmux split-window'
|
|
||||||
alias vs='tmux split-window -h'
|
|
||||||
fi
|
|
||||||
|
|||||||
Reference in New Issue
Block a user