1 Commits

Author SHA1 Message Date
3194afc80d Replace build-dir.py with zcurses build-dir
Update the build-dir shell function to usage zcurses instead of the
Python pick package to interactively select build directories, this
results in a more responsive user experience. Add argument parsing to
handle various use cases. Add prompt when the build command for the
selected build directory could not be detected, allowing the user to
specify the desired build command.

```
usage: build-dir [-h] [--build] [<directory>]

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
```
2018-08-24 11:04:18 +01:00
3 changed files with 13 additions and 7 deletions

View File

@@ -16,6 +16,8 @@
- {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 - src: sandbox/_sandbox
dst: ~/.local/share/zsh/site-functions/_sandbox dst: ~/.local/share/zsh/site-functions/_sandbox
- src: layout/_layout - src: layout/_layout
@@ -26,6 +28,4 @@
- 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/zdharma/fast-syntax-highlighting.git - https://github.com/zdharma/fast-syntax-highlighting.git
- pip:
- pick
- message: zsh will be the default prompt after next login - message: zsh will be the default prompt after next login

6
build/_build-dir Normal file
View File

@@ -0,0 +1,6 @@
#compdef build-dir
_arguments \
'(-h --help)'{-h,--help}'[]' \
'--build[invoke a build after selection]' \
'1:directory:_files'

View File

@@ -35,9 +35,9 @@ optional arguments:
-h, --help show this help message and exit -h, --help show this help message and exit
--build invoke a build after selection --build invoke a build after selection
EOF EOF
exit return
fi fi
error() { echo "\e[31merror:\e[0m $1"; exit 1 } error() { echo "\e[31merror:\e[0m $1"; return 1 }
local build_dir local build_dir
if [[ ${#*} -gt 1 ]]; then if [[ ${#*} -gt 1 ]]; then
echo $usage echo $usage
@@ -54,7 +54,7 @@ EOF
local -a build_dirs local -a build_dirs
for entry in `ls -A`; do for entry in `ls -A`; do
[ -d $entry ] && [[ $entry =~ build* ]] && \ [ -d $entry ] && [[ $entry =~ build* ]] && \
build_dirs+=$entry build_dirs+=${entry/\//}
done done
# Interactively select a build directory if more than 1 found # Interactively select a build directory if more than 1 found
@@ -74,7 +74,7 @@ EOF
# Hide the cursor for zcurses, trap SIGINT to ensure cleanup in # Hide the cursor for zcurses, trap SIGINT to ensure cleanup in
# always-list occurs below # always-list occurs below
tput civis; trap 'exit 130' INT tput civis; trap 'return 130' INT
# Enter display loop # Enter display loop
local key keypad local key keypad
@@ -138,7 +138,7 @@ EOF
fi fi
# If the build variable is not defined the command could not be determined # If the build variable is not defined the command could not be determined
if [ -n $build ]; then if [ -z $build ]; then
echo "\e[33mwarning:\e[0m build command detection failed: $build_dir" echo "\e[33mwarning:\e[0m build command detection failed: $build_dir"
# Prompt user to enter a build command # Prompt user to enter a build command
vared -p 'enter comand: ' build vared -p 'enter comand: ' build