Compare commits
51 Commits
osc-52-pas
...
d12bc6f756
| Author | SHA1 | Date | |
|---|---|---|---|
| d12bc6f756 | |||
| e269e6ff8d | |||
| b4ce10f1bd | |||
| 1bdaa8ac08 | |||
| 47082002f9 | |||
| ba9eba596f | |||
| 0efb635f02 | |||
| f50db402af | |||
| bc3fcea5dd | |||
| 29b232527a | |||
| eae2e82bdb | |||
| 0951c445f4 | |||
| b9373430b0 | |||
| 6280d90bd9 | |||
| 3accfe0bec | |||
| a9fb5104ac | |||
| 6678fe0aaf | |||
| 1ca9e4f6ae | |||
| 7aa78e94d1 | |||
| 42260925a0 | |||
| a6d97c1eac | |||
| 1bf5d10b74 | |||
| edf37ebf07 | |||
| 18bcb6ccde | |||
| 8a9e66db32 | |||
| 1e60a5ddd5 | |||
| 4b0425b2d4 | |||
| 5c62ff219c | |||
| 1121b9a193 | |||
| 0c4cd8880b | |||
| e30f86800d | |||
| ad5dc95e4d | |||
| d226ac7097 | |||
| e7750cb0a9 | |||
|
|
efbfa23241 | ||
| b95b365276 | |||
| 501353a534 | |||
| 02abb0960c | |||
| a81465daad | |||
| 5a33d2b5ac | |||
| c691d335c0 | |||
| 715014ed3d | |||
| efcea9e8a5 | |||
| ea61bde858 | |||
| a96aa50fbe | |||
| c61c86e979 | |||
| 8790bc0c4e | |||
| b349befbf4 | |||
| 74f2dd7dae | |||
| a362ab0e04 | |||
| a422ab1125 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
# Ignore all plugin files in subdirectories
|
# Ignore all plugin files in subdirectories
|
||||||
*/
|
zsh-*/
|
||||||
|
local
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ _autoenv() {
|
|||||||
edit:'edit .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'
|
deinit:'remove .enter and .exit scripts in current directory'
|
||||||
reload:'reload the current environment'
|
reload:'reload the current environment'
|
||||||
|
add=local:'add .local/bin to PATH'
|
||||||
add=py:'add Python virtualenv to the autoenv'
|
add=py:'add Python virtualenv to the autoenv'
|
||||||
)
|
)
|
||||||
_describe -t commands command commands && ret=0 ;;
|
_describe -t commands command commands && ret=0 ;;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ commands:
|
|||||||
edit edit .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
|
deinit remove .enter and .exit scripts in current directory
|
||||||
reload reload the current environment
|
reload reload the current environment
|
||||||
|
add=local add .local/bin to PATH
|
||||||
add=py add Python virtualenv to the autoenv"
|
add=py add Python virtualenv to the autoenv"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@@ -45,11 +46,9 @@ commands:
|
|||||||
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
|
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
|
||||||
echo '.enter or .exit not found'; return 1
|
echo '.enter or .exit not found'; return 1
|
||||||
fi
|
fi
|
||||||
# If vim exists, edit enter and exit scripts.
|
|
||||||
if which vim &> /dev/null; then
|
|
||||||
# Exit the autoenv before editing.
|
# Exit the autoenv before editing.
|
||||||
_autoenv_exit $PWD
|
_autoenv_exit $PWD
|
||||||
if vim -p $PWD/.enter $PWD/.exit; then
|
if $EDITOR -p $PWD/.enter $PWD/.exit; then
|
||||||
# If enter script exists, authorize it.
|
# If enter script exists, authorize it.
|
||||||
[ -f $PWD/.enter ] && _autoenv_authorized $PWD/.enter yes
|
[ -f $PWD/.enter ] && _autoenv_authorized $PWD/.enter yes
|
||||||
# If exit script exists, authorize it.
|
# If exit script exists, authorize it.
|
||||||
@@ -57,9 +56,6 @@ commands:
|
|||||||
fi
|
fi
|
||||||
# Enter the autoenv.
|
# Enter the autoenv.
|
||||||
_autoenv_enter $PWD
|
_autoenv_enter $PWD
|
||||||
else
|
|
||||||
echo 'vim not found'; return 1
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
deinit) # Remove .enter and .exit scripts in current directory.
|
deinit) # Remove .enter and .exit scripts in current directory.
|
||||||
@@ -92,13 +88,34 @@ commands:
|
|||||||
_autoenv_enter $PWD
|
_autoenv_enter $PWD
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
add=local) # Add .local/bin to PATH
|
||||||
|
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
|
||||||
|
echo '.enter or .exit not found'; return 1
|
||||||
|
fi
|
||||||
|
_autoenv_exit $PWD
|
||||||
|
# Create .local/bin if not present
|
||||||
|
if ! [ -d $PWD/.local/bin ]; then
|
||||||
|
mkdir -p $PWD/.local/bin
|
||||||
|
fi
|
||||||
|
# On enter: store PATH and insert .local/bin
|
||||||
|
echo 'OLDPATH=$PATH' >> .enter
|
||||||
|
echo 'PATH=$PWD/.local/bin:$PATH' >> .enter
|
||||||
|
# On exit: reset PATH
|
||||||
|
echo 'PATH=$OLDPATH' >> .exit
|
||||||
|
echo 'unset OLDPATH' >> .exit
|
||||||
|
# Authorize modified autoenv
|
||||||
|
_autoenv_authorized $PWD/.enter yes
|
||||||
|
_autoenv_authorized $PWD/.exit yes
|
||||||
|
_autoenv_enter $PWD
|
||||||
|
;;
|
||||||
|
|
||||||
add=py) # Add Python virtualenv to the sandbox
|
add=py) # Add Python virtualenv to the sandbox
|
||||||
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
|
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
|
||||||
echo '.enter or .exit not found'; return 1
|
echo '.enter or .exit not found'; return 1
|
||||||
fi
|
fi
|
||||||
_autoenv_exit $PWD
|
_autoenv_exit $PWD
|
||||||
virtualenv .local
|
virtualenv -p `command -v python` .local
|
||||||
echo 'source .local/bin/activate' >> .enter
|
echo 'source ${0:a:h}/.local/bin/activate' >> .enter
|
||||||
echo 'deactivate' >> .exit
|
echo 'deactivate' >> .exit
|
||||||
_autoenv_authorized $PWD/.enter yes
|
_autoenv_authorized $PWD/.enter yes
|
||||||
_autoenv_authorized $PWD/.exit yes
|
_autoenv_authorized $PWD/.exit yes
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#compdef build-dir
|
#compdef build-dir
|
||||||
|
|
||||||
_arguments \
|
_arguments \
|
||||||
'(-h --help)'{-h,--help}'[]' \
|
'(-h --help)'{-h,--help}'[show this help message and exit]' \
|
||||||
|
'(-s --show)'{-s,--show}'[show the current build directory]' \
|
||||||
'--build[invoke a build after selection]' \
|
'--build[invoke a build after selection]' \
|
||||||
'1:directory:_files'
|
'1:directory:_files'
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ alias build="build-dir --build"
|
|||||||
# Detect installed debugger and set the `debug` alias to debug a program with
|
# Detect installed debugger and set the `debug` alias to debug a program with
|
||||||
# command line arguments.
|
# command line arguments.
|
||||||
if [ `uname` = Linux ]; then
|
if [ `uname` = Linux ]; then
|
||||||
if [[ "`vim --version|head -1|cut -c 19-21`" =~ "^8\.[123456789]$" ]]; then
|
|
||||||
autoload -U regexp-replace
|
autoload -U regexp-replace
|
||||||
function vimdebug() {
|
function vimdebug() {
|
||||||
# For each item in $* replace * and \* and then replace \ with \\
|
# For each item in $* replace * and \* and then replace \ with \\
|
||||||
@@ -16,24 +15,23 @@ if [ `uname` = Linux ]; then
|
|||||||
regexp-replace arg '\*' '\\*'
|
regexp-replace arg '\*' '\\*'
|
||||||
args+=($arg)
|
args+=($arg)
|
||||||
done
|
done
|
||||||
vim "+packadd termdebug" "+TermdebugCommand $args"
|
nvim "+packadd termdebug" "+TermdebugCommand $args"
|
||||||
}
|
}
|
||||||
alias debug='vimdebug'
|
if command -v nvim &> /dev/null; then
|
||||||
elif which cgdb &> /dev/null; then
|
alias debug=vimdebug
|
||||||
alias debug='cgdb --args'
|
elif command -v gdb &> /dev/null; then
|
||||||
elif which gdb &> /dev/null; then
|
|
||||||
alias debug='gdb --args'
|
alias debug='gdb --args'
|
||||||
fi
|
fi
|
||||||
elif [ `uname` = Darwin ]; then
|
elif [ `uname` = Darwin ]; then
|
||||||
which lldb &> /dev/null && \
|
command -v lldb &> /dev/null && \
|
||||||
alias debug='lldb --'
|
alias debug='lldb --'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Interactively choose a `~build` directory for `build` to build.
|
# Interactively choose a `~build` directory for `build` to build.
|
||||||
build-dir() {
|
build-dir() {
|
||||||
local usage='usage: build-dir [-h] [--build] [<directory>]'
|
local usage='usage: build-dir [-h] [--build] [<directory>]'
|
||||||
local -a help do_build
|
local -a help show do_build
|
||||||
zparseopts -D h=help -help=help -build=do_build
|
zparseopts -D h=help -help=help s=show -show=show -build=do_build
|
||||||
if [[ -n $help ]]; then
|
if [[ -n $help ]]; then
|
||||||
cat << EOF
|
cat << EOF
|
||||||
$usage
|
$usage
|
||||||
@@ -45,12 +43,22 @@ positional arguments:
|
|||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
-s, --show show the current build directory
|
||||||
--build invoke a build after selection
|
--build invoke a build after selection
|
||||||
EOF
|
EOF
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
error() { echo "\e[31merror:\e[0m $1" }
|
error() { echo "\e[31merror:\e[0m $1" }
|
||||||
warning() { echo "\e[33mwarning:\e[0m $1" }
|
warning() { echo "\e[33mwarning:\e[0m $1" }
|
||||||
|
if [[ -n $show ]]; then
|
||||||
|
if [[ ! -n $build_dir ]]; then
|
||||||
|
error "build directory not set"
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
echo "$build_dir"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
local local_build_dir
|
local local_build_dir
|
||||||
if [[ ${#*} -gt 1 ]]; then
|
if [[ ${#*} -gt 1 ]]; then
|
||||||
echo $usage
|
echo $usage
|
||||||
@@ -76,7 +84,23 @@ EOF
|
|||||||
integer index=0
|
integer index=0
|
||||||
if [[ ${#local_build_dirs} -eq 0 ]]; then
|
if [[ ${#local_build_dirs} -eq 0 ]]; then
|
||||||
error "no build directories found"; return 1
|
error "no build directories found"; return 1
|
||||||
|
elif [[ ${#local_build_dirs} -eq 1 ]]; then
|
||||||
|
local_build_dir=${local_build_dirs[1]}
|
||||||
elif [[ ${#local_build_dirs} -gt 1 ]]; then
|
elif [[ ${#local_build_dirs} -gt 1 ]]; then
|
||||||
|
if command -v fzf &> /dev/null; then
|
||||||
|
# Use fzf to select a build directory
|
||||||
|
local max=$(( $( tput lines ) / 2 ))
|
||||||
|
local best=$(( ${#local_build_dirs} + 3 ))
|
||||||
|
local_build_dir=$(
|
||||||
|
printf '%s\n' "${local_build_dirs[@]}" |
|
||||||
|
fzf --layout=reverse --tac --info=hidden --border=rounded \
|
||||||
|
--height=$(( $best < $max ? $best : $max ))
|
||||||
|
)
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Fallback to zcurses selector when fzf is not available
|
||||||
zmodload zsh/curses && {
|
zmodload zsh/curses && {
|
||||||
# Get the size of the terminal
|
# Get the size of the terminal
|
||||||
local size=`stty size`
|
local size=`stty size`
|
||||||
@@ -130,14 +154,16 @@ EOF
|
|||||||
zcurses delwin build-dir
|
zcurses delwin build-dir
|
||||||
zcurses end
|
zcurses end
|
||||||
}
|
}
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# On success setup the build directory for use
|
# On success setup the build directory for use
|
||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
# Set the build directory from selection if empty
|
# Set the build directory from selection if empty
|
||||||
[[ -z $local_build_dir ]] && \
|
[[ -z $local_build_dir ]] && \
|
||||||
local_build_dir=${local_build_dirs[$index+1]}
|
local_build_dir=${local_build_dirs[$index+1]}
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# If `build.ninja` exists in alias `ninja`, return.
|
# If `build.ninja` exists in alias `ninja`, return.
|
||||||
local build
|
local build
|
||||||
@@ -168,7 +194,6 @@ EOF
|
|||||||
if [[ -n $do_build ]]; then
|
if [[ -n $do_build ]]; then
|
||||||
eval build
|
eval build
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Build then run a target residing in `~build/bin`.
|
# Build then run a target residing in `~build/bin`.
|
||||||
|
|||||||
28
git-prompt.c
28
git-prompt.c
@@ -23,10 +23,10 @@
|
|||||||
|
|
||||||
typedef struct process {
|
typedef struct process {
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
FILE* out;
|
FILE *out;
|
||||||
} process_t;
|
} process_t;
|
||||||
|
|
||||||
process_t process_open(char* command) {
|
process_t process_open(char *command) {
|
||||||
int fds[2];
|
int fds[2];
|
||||||
check(pipe(fds));
|
check(pipe(fds));
|
||||||
int pid = fork();
|
int pid = fork();
|
||||||
@@ -35,7 +35,7 @@ process_t process_open(char* command) {
|
|||||||
close(fds[0]);
|
close(fds[0]);
|
||||||
dup2(fds[1], STDOUT_FILENO);
|
dup2(fds[1], STDOUT_FILENO);
|
||||||
dup2(STDOUT_FILENO, STDERR_FILENO);
|
dup2(STDOUT_FILENO, STDERR_FILENO);
|
||||||
char* argv[] = {"sh", "-c", command, NULL};
|
char *argv[] = {"sh", "-c", command, NULL};
|
||||||
exit(execvp(argv[0], argv));
|
exit(execvp(argv[0], argv));
|
||||||
} else { // parent process
|
} else { // parent process
|
||||||
close(fds[1]);
|
close(fds[1]);
|
||||||
@@ -54,9 +54,11 @@ int process_close(process_t process) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* trim(char* str) {
|
char *trim(char *str) {
|
||||||
char* end;
|
char *end;
|
||||||
while (isspace((unsigned char)*str)) str++;
|
while (isspace((unsigned char)*str)) {
|
||||||
|
str++;
|
||||||
|
}
|
||||||
if (*str == 0) {
|
if (*str == 0) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@@ -68,17 +70,17 @@ char* trim(char* str) {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* append(char* buffer, int count, ...) {
|
char *append(char *buffer, int count, ...) {
|
||||||
va_list list;
|
va_list list;
|
||||||
va_start(list, count);
|
va_start(list, count);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
strcat(buffer, va_arg(list, char*));
|
strcat(buffer, va_arg(list, char *));
|
||||||
}
|
}
|
||||||
va_end(list);
|
va_end(list);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* inttostr(char* buffer, int value) {
|
char *inttostr(char *buffer, int value) {
|
||||||
sprintf(buffer, "%d", value);
|
sprintf(buffer, "%d", value);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
@@ -102,7 +104,7 @@ int main() {
|
|||||||
check(process_close(process));
|
check(process_close(process));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
char* branch = trim(branch_buf);
|
char *branch = trim(branch_buf);
|
||||||
char prompt[1024] = {};
|
char prompt[1024] = {};
|
||||||
append(prompt, 3, " %{%F{66}%}", branch, "%{%f%}");
|
append(prompt, 3, " %{%F{66}%}", branch, "%{%f%}");
|
||||||
|
|
||||||
@@ -113,7 +115,7 @@ int main() {
|
|||||||
char remote_buf[256] = {};
|
char remote_buf[256] = {};
|
||||||
fread(remote_buf, 1, sizeof(remote_buf), process.out);
|
fread(remote_buf, 1, sizeof(remote_buf), process.out);
|
||||||
if (process_close(process) == 0) {
|
if (process_close(process) == 0) {
|
||||||
char* remote = trim(remote_buf);
|
char *remote = trim(remote_buf);
|
||||||
// get the number of commits ahead of the remote
|
// get the number of commits ahead of the remote
|
||||||
memset(command, 0, sizeof(command));
|
memset(command, 0, sizeof(command));
|
||||||
process = process_open(append(command, 5,
|
process = process_open(append(command, 5,
|
||||||
@@ -121,7 +123,7 @@ int main() {
|
|||||||
remote, "/", branch, "...HEAD --count"));
|
remote, "/", branch, "...HEAD --count"));
|
||||||
char count[32] = {};
|
char count[32] = {};
|
||||||
fread(count, 1, sizeof(count), process.out);
|
fread(count, 1, sizeof(count), process.out);
|
||||||
if(process_close(process) == 0 && strcmp("0", trim(count))) {
|
if (process_close(process) == 0 && strcmp("0", trim(count))) {
|
||||||
append(prompt, 2, "↑", trim(count));
|
append(prompt, 2, "↑", trim(count));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +134,7 @@ int main() {
|
|||||||
remote, "/", branch, "...HEAD --count"));
|
remote, "/", branch, "...HEAD --count"));
|
||||||
memset(count, 0, sizeof(count));
|
memset(count, 0, sizeof(count));
|
||||||
fread(count, 1, sizeof(count), process.out);
|
fread(count, 1, sizeof(count), process.out);
|
||||||
if(process_close(process) == 0 && strcmp("0", trim(count))) {
|
if (process_close(process) == 0 && strcmp("0", trim(count))) {
|
||||||
append(prompt, 2, "↓", trim(count));
|
append(prompt, 2, "↓", trim(count));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
91
install.zsh
Executable file
91
install.zsh
Executable file
@@ -0,0 +1,91 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
error() {
|
||||||
|
echo "error: $*"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
directories=(
|
||||||
|
~/.cache/zsh
|
||||||
|
~/.local/bin
|
||||||
|
~/.local/share/zsh/plugins
|
||||||
|
~/.local/share/zsh/site-functions
|
||||||
|
)
|
||||||
|
|
||||||
|
for directory in $directories; do
|
||||||
|
mkdir -p $directory
|
||||||
|
done
|
||||||
|
|
||||||
|
plugins=(
|
||||||
|
zsh-users/zsh-autosuggestions
|
||||||
|
zsh-users/zsh-history-substring-search
|
||||||
|
zsh-users/zsh-syntax-highlighting
|
||||||
|
zsh-users/zsh-completions
|
||||||
|
)
|
||||||
|
|
||||||
|
for plugin in $plugins; do
|
||||||
|
plugin_name=${plugin/*\//}
|
||||||
|
plugin_directory=~/.local/share/zsh/plugins/$plugin_name
|
||||||
|
if [ -d $plugin_directory ]; then
|
||||||
|
if ! git -C $plugin_directory diff-index --quiet HEAD --; then
|
||||||
|
error $plugin_directory contains unstaged changes
|
||||||
|
fi
|
||||||
|
pull=`git -C $plugin_directory pull`
|
||||||
|
if [ "$pull" != "Already up-to-date." ]; then
|
||||||
|
echo changed pulled $plugin_directory
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
git clone https://github.com/$plugin.git $plugin_directory > /dev/null
|
||||||
|
echo changed cloned $plugin_directory
|
||||||
|
fi
|
||||||
|
old_plugin_directory=~/.config/zsh/$plugin_name
|
||||||
|
if [ -d $old_plugin_directory ]; then
|
||||||
|
rm -rf $old_plugin_directory
|
||||||
|
echo changed removed $old_plugin_directory
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
declare -A symlinks
|
||||||
|
symlinks=(
|
||||||
|
~/.config/zsh/zlogin ~/.zlogin
|
||||||
|
~/.config/zsh/zlogout ~/.zlogout
|
||||||
|
~/.config/zsh/zprofile ~/.zprofile
|
||||||
|
~/.config/zsh/zshenv ~/.zshenv
|
||||||
|
~/.config/zsh/zshrc ~/.zshrc
|
||||||
|
~/.config/zsh/prompt_fresh_setup
|
||||||
|
~/.local/share/zsh/site-functions/prompt_fresh_setup
|
||||||
|
~/.config/zsh/cmake-uninstall ~/.local/bin/cmake-uninstall
|
||||||
|
~/.config/zsh/$ ~/.local/bin/$
|
||||||
|
~/.config/zsh/url/url ~/.local/bin/url
|
||||||
|
)
|
||||||
|
|
||||||
|
for completion in ~/.config/zsh/**/_*; do
|
||||||
|
filename=`basename $completion`
|
||||||
|
symlinks[$completion]=~/.local/share/zsh/site-functions/$filename
|
||||||
|
done
|
||||||
|
|
||||||
|
completions=( ~/.local/share/zsh/plugins/zsh-completions/src/* )
|
||||||
|
for completion in $completions; do
|
||||||
|
filename=`basename $completion`
|
||||||
|
name=${filename:1}
|
||||||
|
if command -v $name > /dev/null; then
|
||||||
|
symlinks[$completion]=~/.local/share/zsh/site-functions/$filename
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
for source in ${(k)symlinks}; do
|
||||||
|
dest=$symlinks[$source]
|
||||||
|
if [ -L $dest ]; then
|
||||||
|
target=`readlink $dest`
|
||||||
|
if [ "$target" != "$source" ]; then
|
||||||
|
rm $dest
|
||||||
|
ln -s $source $dest
|
||||||
|
echo changed replace incorrect symlink $dest
|
||||||
|
fi
|
||||||
|
elif [ -f $dest ]; then
|
||||||
|
error symlink failed $dest exists but is a regular file
|
||||||
|
else
|
||||||
|
ln -s $source $dest
|
||||||
|
echo changed created symlink $dest
|
||||||
|
fi
|
||||||
|
done
|
||||||
@@ -2,7 +2,7 @@ layout() {
|
|||||||
if [[ "$1" == "" ]]; then
|
if [[ "$1" == "" ]]; then
|
||||||
echo "usage: layout <layout> [name]"
|
echo "usage: layout <layout> [name]"
|
||||||
else
|
else
|
||||||
tmux source-file ~/.local/share/tmux/layouts/$1
|
~/.local/share/tmux/layouts/$1
|
||||||
if [[ "$2" != "" ]]; then
|
if [[ "$2" != "" ]]; then
|
||||||
tmux rename-window $2
|
tmux rename-window $2
|
||||||
fi
|
fi
|
||||||
|
|||||||
22
list-commands-with-available-completions.zsh
Executable file
22
list-commands-with-available-completions.zsh
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
# Loop over available completions and add existing commands to array.
|
||||||
|
local -a completions
|
||||||
|
completions=(~/.config/zsh/zsh-completions/src/*)
|
||||||
|
local -a command_list
|
||||||
|
for completion in $completions; do
|
||||||
|
local filename=$(basename $completion)
|
||||||
|
local name=${filename:1}
|
||||||
|
if command -v $name &> /dev/null; then
|
||||||
|
command_list+=($name)
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Print JSON array of commands Ansible can consume.
|
||||||
|
echo '['
|
||||||
|
local length=${#command_list[@]}
|
||||||
|
for (( i = 1; i < $length; i++ )); do
|
||||||
|
echo " \"${command_list[$i]}\","
|
||||||
|
done
|
||||||
|
echo " \"${command_list[-1]}\""
|
||||||
|
echo ']'
|
||||||
6
ls-iommu.sh
Executable file
6
ls-iommu.sh
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
for d in /sys/kernel/iommu_groups/*/devices/*; do
|
||||||
|
n=${d#*/iommu_groups/*}; n=${n%%/*}
|
||||||
|
printf '%s ' "$n"
|
||||||
|
lspci -nns "${d##*/}"
|
||||||
|
done
|
||||||
@@ -49,8 +49,8 @@ prompt_fresh_setup() {
|
|||||||
local userhost="$userhost@`hostname`"
|
local userhost="$userhost@`hostname`"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PS1="«$user» "
|
PS1="$user "
|
||||||
PS2="«${(l:${#userhost}:: :)}» "
|
PS2="${(l:${#userhost}:: :)} "
|
||||||
|
|
||||||
prompt_opts=(percent sp subst)
|
prompt_opts=(percent sp subst)
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ fresh_line_one() {
|
|||||||
# Construct the time and directory portions of the prompt
|
# Construct the time and directory portions of the prompt
|
||||||
local time_stamp="%{%F{244}%}%D{%H:%M:%S}%{%f%}"
|
local time_stamp="%{%F{244}%}%D{%H:%M:%S}%{%f%}"
|
||||||
[[ -n $SANDBOX_HOME ]] && \
|
[[ -n $SANDBOX_HOME ]] && \
|
||||||
local directory="%{%F{3}%}$SANDBOX_NAME${PWD#$SANDBOX_HOME}%{%f%}" || \
|
local directory="%{%F{220}%}$SANDBOX_NAME${PWD#$SANDBOX_HOME}%{%f%}" || \
|
||||||
local directory="%{%F{37}%}%~%{%f%}"
|
local directory="%{%F{37}%}%~%{%f%}"
|
||||||
|
|
||||||
# Check we are in a git repository
|
# Check we are in a git repository
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ usage: sandbox [-h] {create,rename,destroy,enable,disable,list} ..
|
|||||||
if [ "$git" = true ]; then
|
if [ "$git" = true ]; then
|
||||||
local repo=$arg
|
local repo=$arg
|
||||||
git=false
|
git=false
|
||||||
elif [[ -n "$name" ]]; then
|
elif [[ -z "$name" ]]; then
|
||||||
error "invalid argument $arg\n$usage" && return 1
|
error "invalid argument $arg\n$usage" && return 1
|
||||||
else
|
else
|
||||||
local name=$arg
|
local name=$arg
|
||||||
@@ -44,14 +44,11 @@ usage: sandbox [-h] {create,rename,destroy,enable,disable,list} ..
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
unset git
|
unset git
|
||||||
|
|
||||||
[[ -z "$name" ]] && \
|
[[ -z "$name" ]] && \
|
||||||
error "missing argument <name>\n$usage" && return 1
|
error "missing argument <name>\n$usage" && return 1
|
||||||
|
|
||||||
local sandbox=$SANDBOX_ROOT/$name
|
local sandbox=$SANDBOX_ROOT/$name
|
||||||
[[ -d "$sandbox" ]] && \
|
[[ -d "$sandbox" ]] && \
|
||||||
error "sandbox already exists $name" && return 1
|
error "sandbox already exists $name" && return 1
|
||||||
|
|
||||||
if [[ -n "$repo" ]]; then
|
if [[ -n "$repo" ]]; then
|
||||||
mkdir -p $SANDBOX_ROOT &> /dev/null
|
mkdir -p $SANDBOX_ROOT &> /dev/null
|
||||||
git clone $repo $sandbox
|
git clone $repo $sandbox
|
||||||
@@ -61,55 +58,49 @@ usage: sandbox [-h] {create,rename,destroy,enable,disable,list} ..
|
|||||||
cd $sandbox
|
cd $sandbox
|
||||||
git init &> /dev/null
|
git init &> /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "SANDBOX_HOME=\$(dirname -- "\$0:a")" >> $sandbox/.enter
|
echo "SANDBOX_HOME=\$(dirname -- "\$0:a")" >> $sandbox/.enter
|
||||||
echo "SANDBOX_NAME=$name" >> $sandbox/.enter
|
echo "SANDBOX_NAME=$name" >> $sandbox/.enter
|
||||||
_autoenv_authorized $sandbox/.enter yes
|
_autoenv_authorized $sandbox/.enter yes
|
||||||
|
|
||||||
echo "unset SANDBOX_NAME" >> $sandbox/.exit
|
echo "unset SANDBOX_NAME" >> $sandbox/.exit
|
||||||
echo "unset SANDBOX_HOME" >> $sandbox/.exit
|
echo "unset SANDBOX_HOME" >> $sandbox/.exit
|
||||||
_autoenv_authorized $sandbox/.exit yes
|
_autoenv_authorized $sandbox/.exit yes
|
||||||
|
|
||||||
_autoenv_enter $sandbox
|
_autoenv_enter $sandbox
|
||||||
;;
|
;;
|
||||||
|
|
||||||
rename)
|
rename)
|
||||||
local old_name=$1 new_name=$2
|
local old_name=$1 new_name=$2
|
||||||
[[ -z "$old_name" ]] && \
|
[[ -z "$old_name" ]] && \
|
||||||
error "missing argument <old-name>\n$usage" && return 1
|
error "missing argument <old-name>\n$usage" && return 1
|
||||||
[[ -z "$new_name" ]] && \
|
[[ -z "$new_name" ]] && \
|
||||||
error "missing argument <new-name>\n$usage" && return 1
|
error "missing argument <new-name>\n$usage" && return 1
|
||||||
|
|
||||||
local old=$SANDBOX_ROOT/$old_name new=$SANDBOX_ROOT/$new_name
|
local old=$SANDBOX_ROOT/$old_name new=$SANDBOX_ROOT/$new_name
|
||||||
[[ ! -d "$old" ]] && \
|
[[ ! -d "$old" ]] && \
|
||||||
error "sandbox does not exist $old_name" && return 1
|
error "sandbox does not exist $old_name" && return 1
|
||||||
[[ -d "$new" ]] && \
|
[[ -d "$new" ]] && \
|
||||||
error "sandbox already exists $new_name" && return 1
|
error "sandbox already exists $new_name" && return 1
|
||||||
|
|
||||||
[[ "$PWD" = "$old"* ]] && _autoenv_exit $PWD
|
[[ "$PWD" = "$old"* ]] && _autoenv_exit $PWD
|
||||||
|
|
||||||
mv $old $new
|
mv $old $new
|
||||||
sed -i "s/$old_name/$new_name/g" $new/.enter
|
sed -i "s/$old_name/$new_name/g" $new/.enter
|
||||||
_autoenv_authorized $new/.enter yes
|
_autoenv_authorized $new/.enter yes
|
||||||
_autoenv_authorized $new/.exit yes
|
_autoenv_authorized $new/.exit yes
|
||||||
|
|
||||||
[[ "$PWD" = "$old"* ]] && cd $new
|
[[ "$PWD" = "$old"* ]] && cd $new
|
||||||
;;
|
;;
|
||||||
|
|
||||||
destroy)
|
destroy)
|
||||||
local name=$1
|
local name=$1
|
||||||
[[ -z "$name" ]] && \
|
[[ -z "$name" ]] && \
|
||||||
error "missing argument <name>\n$usage" && return 1
|
error "missing argument <name>\n$usage" && return 1
|
||||||
|
|
||||||
local sandbox=$SANDBOX_ROOT/$name
|
local sandbox=$SANDBOX_ROOT/$name
|
||||||
[[ ! -d $sandbox ]] && \
|
[[ ! -d $sandbox ]] && \
|
||||||
error "sandbox does not exist $name" && return 1
|
error "sandbox does not exist $name" && return 1
|
||||||
|
|
||||||
[[ "$PWD" = "$sandbox"* ]] && cd ~
|
[[ "$PWD" = "$sandbox"* ]] && cd ~
|
||||||
|
|
||||||
rm -rf $sandbox
|
rm -rf $sandbox
|
||||||
;;
|
;;
|
||||||
|
|
||||||
list)
|
list)
|
||||||
ls -1 $SANDBOX_ROOT | less -F -K -R -X
|
ls -1 $SANDBOX_ROOT | less -F -K -R -X
|
||||||
;;
|
;;
|
||||||
|
|
||||||
enable)
|
enable)
|
||||||
local name=$1
|
local name=$1
|
||||||
[[ -z "$name" ]] && \
|
[[ -z "$name" ]] && \
|
||||||
@@ -118,16 +109,19 @@ usage: sandbox [-h] {create,rename,destroy,enable,disable,list} ..
|
|||||||
local sandbox=$SANDBOX_ROOT/$name
|
local sandbox=$SANDBOX_ROOT/$name
|
||||||
[[ ! -d $sandbox ]] && \
|
[[ ! -d $sandbox ]] && \
|
||||||
error "sandbox does not exist $name" && return 1
|
error "sandbox does not exist $name" && return 1
|
||||||
|
|
||||||
export SANDBOX_RETURN=$PWD
|
export SANDBOX_RETURN=$PWD
|
||||||
cd $sandbox
|
cd $sandbox
|
||||||
;;
|
;;
|
||||||
|
|
||||||
disable)
|
disable)
|
||||||
[[ -z "$SANDBOX_RETURN" ]] && \
|
[[ -z "$SANDBOX_RETURN" ]] && \
|
||||||
error "sandbox is not currently active" && return 1
|
error "sandbox is not currently active" && return 1
|
||||||
|
|
||||||
cd $SANDBOX_RETURN
|
cd $SANDBOX_RETURN
|
||||||
unset SANDBOX_RETURN
|
unset SANDBOX_RETURN
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
error "invalid sandbox command: $cmd" && return 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|||||||
91
tasks.yaml
91
tasks.yaml
@@ -1,91 +0,0 @@
|
|||||||
---
|
|
||||||
- name: zsh install packages
|
|
||||||
become: '{{package_become}}'
|
|
||||||
package:
|
|
||||||
name: zsh
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: zsh install Debian packages
|
|
||||||
when: ansible_os_family == "Debian"
|
|
||||||
become: true
|
|
||||||
apt:
|
|
||||||
name:
|
|
||||||
- zsh-doc
|
|
||||||
- pinentry-curses
|
|
||||||
- unzip
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: zsh clone plugin repos
|
|
||||||
git:
|
|
||||||
repo: '{{item.repo}}'
|
|
||||||
dest: '{{item.dest}}'
|
|
||||||
with_items:
|
|
||||||
- repo: https://github.com/zsh-users/zsh-autosuggestions.git
|
|
||||||
dest: ~/.config/zsh/zsh-autosuggestions
|
|
||||||
- repo: https://github.com/zsh-users/zsh-history-substring-search.git
|
|
||||||
dest: ~/.config/zsh/zsh-history-substring-search
|
|
||||||
- repo: https://github.com/zsh-users/zsh-syntax-highlighting.git
|
|
||||||
dest: ~/.config/zsh/zsh-syntax-highlighting
|
|
||||||
- repo: https://github.com/zsh-users/zsh-completions.git
|
|
||||||
dest: ~/.config/zsh/zsh-completions
|
|
||||||
- repo: https://github.com/junegunn/fzf.git
|
|
||||||
dest: ~/.config/zsh/fzf
|
|
||||||
|
|
||||||
- name: zsh install fzf binaries
|
|
||||||
command:
|
|
||||||
cmd: ~/.config/zsh/fzf/install --bin
|
|
||||||
creates: ~/.config/zsh/fzf/bin/fzf
|
|
||||||
|
|
||||||
- name: zsh create directories
|
|
||||||
file:
|
|
||||||
state: directory
|
|
||||||
dest: '{{item}}'
|
|
||||||
with_items:
|
|
||||||
- ~/.local/bin
|
|
||||||
- ~/.local/share/zsh/site-functions
|
|
||||||
|
|
||||||
- name: zsh create symbolic links
|
|
||||||
file:
|
|
||||||
state: link
|
|
||||||
src: '{{item.src}}'
|
|
||||||
dest: '{{item.dest}}'
|
|
||||||
with_items:
|
|
||||||
- src: ~/.config/zsh/zlogin
|
|
||||||
dest: ~/.zlogin
|
|
||||||
- src: ~/.config/zsh/zlogout
|
|
||||||
dest: ~/.zlogout
|
|
||||||
- src: ~/.config/zsh/zprofile
|
|
||||||
dest: ~/.zprofile
|
|
||||||
- src: ~/.config/zsh/zshenv
|
|
||||||
dest: ~/.zshenv
|
|
||||||
- src: ~/.config/zsh/zshrc
|
|
||||||
dest: ~/.zshrc
|
|
||||||
- src: ~/.config/zsh/prompt_fresh_setup
|
|
||||||
dest: ~/.local/share/zsh/site-functions/prompt_fresh_setup
|
|
||||||
- src: ~/.config/zsh/build/_build-dir
|
|
||||||
dest: ~/.local/share/zsh/site-functions/_build-dir
|
|
||||||
- src: ~/.config/zsh/sandbox/_sandbox
|
|
||||||
dest: ~/.local/share/zsh/site-functions/_sandbox
|
|
||||||
- src: ~/.config/zsh/layout/_layout
|
|
||||||
dest: ~/.local/share/zsh/site-functions/_layout
|
|
||||||
- src: ~/.config/zsh/notes/_note
|
|
||||||
dest: ~/.local/share/zsh/site-functions/_note
|
|
||||||
- src: ~/.config/zsh/fzf/bin/fzf
|
|
||||||
dest: ~/.local/bin/fzf
|
|
||||||
- src: ~/.config/zsh/fzf/bin/fzf-tmux
|
|
||||||
dest: ~/.local/bin/fzf-tmux
|
|
||||||
- src: ~/.config/zsh/cmake-uninstall
|
|
||||||
dest: ~/.local/bin/cmake-uninstall
|
|
||||||
- src: ~/.config/zsh/$
|
|
||||||
dest: ~/.local/bin/$
|
|
||||||
|
|
||||||
- name: zsh get absolute path
|
|
||||||
shell: command -v zsh
|
|
||||||
register: zsh
|
|
||||||
changed_when: false
|
|
||||||
|
|
||||||
- name: zsh set default shell
|
|
||||||
user:
|
|
||||||
name: '{{lookup("env", "USER")}}'
|
|
||||||
shell: '{{zsh.stdout}}'
|
|
||||||
become: true
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#!/usr/bin/env zsh
|
|
||||||
|
|
||||||
# Check if third party completions are present.
|
|
||||||
local zsh_completions=~/.config/zsh/zsh-completions
|
|
||||||
[ ! -d $zsh_completions ] && return 0
|
|
||||||
|
|
||||||
# Loop over all completions.
|
|
||||||
for completion in $zsh_completions/src/_*; do
|
|
||||||
local name=`basename $completion`
|
|
||||||
local symlink=~/.local/share/zsh/site-functions/$name
|
|
||||||
# Remove existing completion file if it exists.
|
|
||||||
[ -f $symlink ] && rm $symlink
|
|
||||||
# Check if the command exists on the PATH.
|
|
||||||
if which ${name:1} &> /dev/null; then
|
|
||||||
# Symlink the completion for the existing command.
|
|
||||||
[ `uname` = Darwin ] && \
|
|
||||||
ln -s $completion $symlink || ln -sr $completion $symlink
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
22
url/_url
Normal file
22
url/_url
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#compdef url
|
||||||
|
|
||||||
|
_url() {
|
||||||
|
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=(
|
||||||
|
encode:'encode unencoded text'
|
||||||
|
decode:'decode encoded text'
|
||||||
|
)
|
||||||
|
_describe -t commands command commands && ret=0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
27
url/url
Executable file
27
url/url
Executable file
@@ -0,0 +1,27 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
"""URL encode or decode text."""
|
||||||
|
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
from urllib import parse
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
cli = ArgumentParser(description=__doc__)
|
||||||
|
cli.add_argument('command',
|
||||||
|
choices=['encode', 'decode'],
|
||||||
|
help='type of processing to perform on text')
|
||||||
|
cli.add_argument('text',
|
||||||
|
nargs='?',
|
||||||
|
help='optional text read from stdin when omitted')
|
||||||
|
args = cli.parse_args()
|
||||||
|
print({
|
||||||
|
'encode': parse.quote_plus,
|
||||||
|
'decode': parse.unquote_plus,
|
||||||
|
}[args.command](args.text if args.text else input()))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
exit(130)
|
||||||
@@ -26,18 +26,60 @@ fi
|
|||||||
|
|
||||||
# Passthrough an escape sequences tmux doesn't know about.
|
# Passthrough an escape sequences tmux doesn't know about.
|
||||||
tmux-dcs-passthrough() {
|
tmux-dcs-passthrough() {
|
||||||
|
local escape_sequence=$1
|
||||||
if [ -n "$TMUX" ]; then
|
if [ -n "$TMUX" ]; then
|
||||||
printf "\x1bPtmux;\x1b$1\x1b\\"
|
# Replace single \x1b or \033 with two, this is required for tmux to
|
||||||
|
# properly pass-through the escape sequence.
|
||||||
|
escape_sequence=${escape_sequence//\\x1b/\\x1b\\x1b}
|
||||||
|
escape_sequence=${escape_sequence//\\033/\\x1b\\x1b}
|
||||||
|
printf '\x1bPtmux;\x1b'"$escape_sequence"'\x1b\\'
|
||||||
else
|
else
|
||||||
printf "$1"
|
printf "$escape_sequence"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# OSC 9 - Post a notification - supported by iTerm2, maybe others?
|
# OSC 9 - Post a notification - supported by iTerm2, kitty, WezTerm, others?
|
||||||
notify() {
|
notify() {
|
||||||
tmux-dcs-passthrough "\x1b]9;$*\x7"
|
tmux-dcs-passthrough '\x1b]9;'"$*"'\x7'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Send a desktop notification when long running commands complete.
|
||||||
|
notify_command_threshold=60
|
||||||
|
notify_ignore_list=(
|
||||||
|
cmatrix gh git glab man nvim ssh sudo sudoedit tmux vi vim
|
||||||
|
)
|
||||||
|
|
||||||
|
notify-ignore() {
|
||||||
|
for ignore in $notify_ignore_list; do
|
||||||
|
if [[ "$1" = "$ignore"* ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
notify-preexec() {
|
||||||
|
if notify-ignore $1; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
notify_command_start=`date +%s`
|
||||||
|
notify_command=$1
|
||||||
|
}
|
||||||
|
add-zsh-hook preexec notify-preexec
|
||||||
|
|
||||||
|
notify-precmd() {
|
||||||
|
if ! [[ -z $notify_command_start ]]; then
|
||||||
|
local notify_command_end=`date +%s`
|
||||||
|
local notify_command_time=$(($notify_command_end - $notify_command_start))
|
||||||
|
if [[ $notify_command_time -gt $notify_command_threshold ]]; then
|
||||||
|
notify "completed: $notify_command"
|
||||||
|
fi
|
||||||
|
unset notify_command
|
||||||
|
unset notify_command_start
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
add-zsh-hook precmd notify-precmd
|
||||||
|
|
||||||
# Detect the type and extract an archive file.
|
# Detect the type and extract an archive file.
|
||||||
extract() {
|
extract() {
|
||||||
if [ -f $1 ]; then
|
if [ -f $1 ]; then
|
||||||
@@ -102,3 +144,7 @@ if which docker-machine &> /dev/null; then
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
ls-iommu() {
|
||||||
|
$HOME/.config/zsh/ls-iommu.sh | sort -n
|
||||||
|
}
|
||||||
|
|||||||
52
zshenv
52
zshenv
@@ -22,10 +22,17 @@ INFOPATH=$HOME/.local/share/info:$INFOPATH
|
|||||||
|
|
||||||
# Add ccache compiler aliases to PATH and use XDG base dir paths
|
# Add ccache compiler aliases to PATH and use XDG base dir paths
|
||||||
if [ `uname` = Darwin ]; then
|
if [ `uname` = Darwin ]; then
|
||||||
[ -d /usr/local/opt/python/libexec/bin ] && \
|
if [ `uname -m` = arm64 ]; then
|
||||||
PATH=/usr/local/opt/python/libexec/bin:$PATH
|
homebrew_root=/opt/homebrew
|
||||||
[ -f /usr/local/bin/ccache ] && \
|
[ -d /opt/homebrew/bin ] && \
|
||||||
PATH=/usr/local/opt/ccache/libexec:$PATH
|
PATH=$homebrew_root/bin:$PATH
|
||||||
|
else
|
||||||
|
homebrew_root=/usr/local
|
||||||
|
fi
|
||||||
|
[ -d $homebrew_root/opt/python/libexec/bin ] && \
|
||||||
|
PATH=$homebrew_root/opt/python/libexec/bin:$PATH
|
||||||
|
[ -f $homebrew_root/bin/ccache ] && \
|
||||||
|
PATH=$homebrew_root/opt/ccache/libexec:$PATH
|
||||||
elif [ -f /usr/bin/ccache ]; then
|
elif [ -f /usr/bin/ccache ]; then
|
||||||
if [ -d /usr/lib/ccache/bin ]; then
|
if [ -d /usr/lib/ccache/bin ]; then
|
||||||
PATH=/usr/lib/ccache/bin:$PATH
|
PATH=/usr/lib/ccache/bin:$PATH
|
||||||
@@ -37,8 +44,9 @@ export CCACHE_CONFIGPATH=$HOME/.config/ccache
|
|||||||
export CCACHE_DIR=$HOME/.cache/ccache
|
export CCACHE_DIR=$HOME/.cache/ccache
|
||||||
|
|
||||||
# Add default CMake generator
|
# Add default CMake generator
|
||||||
which ninja &> /dev/null && \
|
command -v ninja &> /dev/null && \
|
||||||
export CMAKE_GENERATOR=Ninja
|
export CMAKE_GENERATOR=Ninja
|
||||||
|
export CMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||||
|
|
||||||
# Remove duplicates from environment variables
|
# Remove duplicates from environment variables
|
||||||
typeset -U fpath
|
typeset -U fpath
|
||||||
@@ -47,8 +55,20 @@ typeset -U MANPATH; export MANPATH
|
|||||||
typeset -U INFOPATH; export INFOPATH
|
typeset -U INFOPATH; export INFOPATH
|
||||||
|
|
||||||
# Set default editor.
|
# Set default editor.
|
||||||
which vim &> /dev/null && \
|
if command -v nvim &> /dev/null; then
|
||||||
export EDITOR=`which vim`
|
export EDITOR=`command -v nvim`
|
||||||
|
elif command -v vim &> /dev/null; then
|
||||||
|
export EDITOR=`command -v vim`
|
||||||
|
fi
|
||||||
|
export GIT_EDITOR=$EDITOR
|
||||||
|
|
||||||
|
if command -v fzf &> /dev/null; then
|
||||||
|
export FZF_DEFAULT_OPTS='--no-bold
|
||||||
|
--color=fg:#c5c9c5,fg+:#c5c9c5,bg:#000000,bg+:#393836
|
||||||
|
--color=hl:#8ea4a2,hl+:#8ea4a2,info:#afaf87,marker:#C8C093
|
||||||
|
--color=prompt:#C8C093,spinner:#8992a7,pointer:#FF9E3B,header:#87afaf
|
||||||
|
--color=gutter:#000000,border:#54546D,label:#aeaeae,query:#c5c9c5'
|
||||||
|
fi
|
||||||
|
|
||||||
# Use ~/.local for pip installs on macOS
|
# Use ~/.local for pip installs on macOS
|
||||||
[ "`uname`" = "Darwin" ] && export PYTHONUSERBASE=$HOME/.local
|
[ "`uname`" = "Darwin" ] && export PYTHONUSERBASE=$HOME/.local
|
||||||
@@ -77,26 +97,26 @@ export PYLINTHOME=~/.local/share/pylint
|
|||||||
export VIRTUAL_ENV_DISABLE_PROMPT=1
|
export VIRTUAL_ENV_DISABLE_PROMPT=1
|
||||||
|
|
||||||
# If pinentry-curses exists, use it for lastpass-cli
|
# If pinentry-curses exists, use it for lastpass-cli
|
||||||
which pinentry-curses &> /dev/null && \
|
command -v pinentry-curses &> /dev/null && \
|
||||||
export LPASS_PINENTRY=pinentry-curses
|
export LPASS_PINENTRY=pinentry-curses
|
||||||
|
|
||||||
# Teach these some XDG Base Directory Spec manners
|
# Teach these some XDG Base Directory Spec manners
|
||||||
export IPYTHONDIR=$HOME/.config/ipython
|
export IPYTHONDIR=$HOME/.config/ipython
|
||||||
which cargo &> /dev/null && \
|
command -v cargo &> /dev/null && \
|
||||||
export CARGO_HOME=$HOME/.local/share/cargo
|
export CARGO_HOME=$HOME/.local/share/cargo
|
||||||
if which ccache &> /dev/null; then
|
if command -v ccache &> /dev/null; then
|
||||||
export CCACHE_CONFIGPATH=$HOME/.config/ccache.conf
|
export CCACHE_CONFIGPATH=$HOME/.config/ccache.conf
|
||||||
export CCACHE_DIR=$HOME/.cache/ccache
|
export CCACHE_DIR=$HOME/.cache/ccache
|
||||||
fi
|
fi
|
||||||
which conan &> /dev/null && \
|
command -v conan &> /dev/null && \
|
||||||
export CONAN_USER_HOME=$HOME/.local/share/conan
|
export CONAN_USER_HOME=$HOME/.local/share/conan
|
||||||
which docker &> /dev/null && \
|
command -v docker &> /dev/null && \
|
||||||
export DOCKER_CONFIG=$HOME/.local/share/docker
|
export DOCKER_CONFIG=$HOME/.local/share/docker
|
||||||
export GTK_RC_FILES=$HOME/.config/gtk/gtkrc
|
export GTK_RC_FILES=$HOME/.config/gtk/gtkrc
|
||||||
export GTK2_RC_FILES=$HOME/.config/gtk-2.0/gtkrc
|
export GTK2_RC_FILES=$HOME/.config/gtk-2.0/gtkrc
|
||||||
which rustup &> /dev/null && \
|
|
||||||
export RUSTUP_HOME=$HOME/.local/share/rustup
|
|
||||||
export PYLINTHOME=$HOME/.cache/pylint
|
export PYLINTHOME=$HOME/.cache/pylint
|
||||||
|
command -v rustup &> /dev/null && \
|
||||||
|
export RUSTUP_HOME=$HOME/.local/share/rustup
|
||||||
|
[ -f $HOME/.config/wget/rc ] && \
|
||||||
|
export WGETRC=$HOME/.config/wget/rc
|
||||||
# TODO: terminfo
|
# TODO: terminfo
|
||||||
[ -f $HOME/.config/wgetrc ] &&
|
|
||||||
export WGETRC=$HOME/.config/wgetrc
|
|
||||||
|
|||||||
77
zshrc
77
zshrc
@@ -3,8 +3,12 @@
|
|||||||
|
|
||||||
# Load plugin scripts
|
# Load plugin scripts
|
||||||
source-plugin() {
|
source-plugin() {
|
||||||
if [ -d ~/.config/zsh/$1 ]; then
|
local shared_plugin=~/.local/share/zsh/plugins/$1/$1.plugin.zsh
|
||||||
source ~/.config/zsh/$1/$1.plugin.zsh
|
local local_plugin=~/.config/zsh/$1/$1.plugin.zsh
|
||||||
|
if [ -f $shared_plugin ]; then
|
||||||
|
source $shared_plugin
|
||||||
|
elif [ -f $local_plugin ]; then
|
||||||
|
source $local_plugin
|
||||||
else
|
else
|
||||||
echo "zsh plugin not found: $1"
|
echo "zsh plugin not found: $1"
|
||||||
fi
|
fi
|
||||||
@@ -17,9 +21,13 @@ ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(end-of-line vi-end-of-line)
|
|||||||
|
|
||||||
# Search history with a command substring
|
# Search history with a command substring
|
||||||
source-plugin zsh-history-substring-search
|
source-plugin zsh-history-substring-search
|
||||||
|
HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND=
|
||||||
|
HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND=
|
||||||
|
|
||||||
# Command syntax highlighting
|
# Command syntax highlighting
|
||||||
source-plugin zsh-syntax-highlighting
|
source-plugin zsh-syntax-highlighting
|
||||||
|
(( ${+ZSH_HIGHLIGHT_STYLES} )) || typeset -A ZSH_HIGHLIGHT_STYLES
|
||||||
|
ZSH_HIGHLIGHT_STYLES[precommand]=fg=green
|
||||||
|
|
||||||
# Build system helper commands
|
# Build system helper commands
|
||||||
source-plugin build
|
source-plugin build
|
||||||
@@ -65,10 +73,10 @@ setopt completeinword
|
|||||||
|
|
||||||
# Initialize completions
|
# Initialize completions
|
||||||
autoload -U compinit
|
autoload -U compinit
|
||||||
compinit
|
compinit -d ~/.cache/zsh/compdump
|
||||||
|
|
||||||
# Add pip to the old completion engine if present
|
# Add pip to the old completion engine if present
|
||||||
if which pip &> /dev/null; then
|
if command -v pip &> /dev/null; then
|
||||||
function _pip_completion {
|
function _pip_completion {
|
||||||
local words cword
|
local words cword
|
||||||
read -Ac words
|
read -Ac words
|
||||||
@@ -138,6 +146,22 @@ if [[ `uname` = Linux ]]; then
|
|||||||
[[ -n ${key[End]} ]] && bindkey "${key[End]}" end-of-line
|
[[ -n ${key[End]} ]] && bindkey "${key[End]}" end-of-line
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Fuzzy history search with fzf
|
||||||
|
function fzf-history-search() {
|
||||||
|
local selected
|
||||||
|
selected=$(
|
||||||
|
history | sed 's/ *[0-9]* *//' |
|
||||||
|
fzf --layout=reverse --tac --info=hidden --border=rounded --height=50%
|
||||||
|
)
|
||||||
|
if [[ -n "$selected" ]]; then
|
||||||
|
BUFFER="$selected"
|
||||||
|
zle end-of-line
|
||||||
|
fi
|
||||||
|
zle reset-prompt
|
||||||
|
}
|
||||||
|
zle -N fzf-history-search
|
||||||
|
bindkey '^R' fzf-history-search
|
||||||
|
|
||||||
# Enable changing cursor shape based on vi mode
|
# Enable changing cursor shape based on vi mode
|
||||||
if [ "$ITERM_PROFILE" != "" ] && [ "$TMUX" = "" ]; then
|
if [ "$ITERM_PROFILE" != "" ] && [ "$TMUX" = "" ]; then
|
||||||
# iTerm2 cursor shape escape sequences outside tmux
|
# iTerm2 cursor shape escape sequences outside tmux
|
||||||
@@ -170,17 +194,34 @@ if [[ ! -z "$cursor_block" && ! -z "$cursor_line" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Frequntly used directories
|
# Frequntly used directories
|
||||||
function frequent-directory() { export $1; hash -d $1 }
|
function frequent-directory() {
|
||||||
frequent-directory Projects="$HOME/Projects"
|
if [ -d "$2" ]; then
|
||||||
|
# Replace - with _ in environment variable name.
|
||||||
|
local name=${1//-/_}
|
||||||
|
local value=$2
|
||||||
|
export $name=$value
|
||||||
|
hash -d $1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
frequent-directory Desktop "$HOME/Desktop"
|
||||||
|
frequent-directory Documents "$HOME/Documents"
|
||||||
|
frequent-directory Downloads "$HOME/Downloads"
|
||||||
|
frequent-directory Projects "$HOME/Projects"
|
||||||
|
frequent-directory Sandbox "$HOME/Sandbox"
|
||||||
|
frequent-directory cache "$HOME/.cache"
|
||||||
|
frequent-directory config "$HOME/.config"
|
||||||
|
frequent-directory local "$HOME/.local"
|
||||||
|
|
||||||
# Load work related config
|
# Load work related config
|
||||||
[ -f ~/.config/work/zshrc ] && source ~/.config/work/zshrc
|
[ -f ~/.config/work/zshrc ] && source ~/.config/work/zshrc
|
||||||
|
[ -f ~/.config/private/zshrc ] && source ~/.config/private/zshrc
|
||||||
|
[ -f ~/.config/zsh/local ] && source ~/.config/zsh/local
|
||||||
|
|
||||||
# Aliases
|
# Aliases
|
||||||
alias grep='grep --color=always'
|
alias grep='grep --color=always'
|
||||||
which cmake &> /dev/null && \
|
command -v cmake &> /dev/null && \
|
||||||
alias cninja='cmake -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON'
|
alias cninja='cmake -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON'
|
||||||
which ssh &> /dev/null && \
|
command -v ssh &> /dev/null && \
|
||||||
alias ssh='TERM=xterm-256color ssh'
|
alias ssh='TERM=xterm-256color ssh'
|
||||||
alias weather="curl wttr.in"
|
alias weather="curl wttr.in"
|
||||||
alias cls="clear && printf '\e[3J'"
|
alias cls="clear && printf '\e[3J'"
|
||||||
@@ -188,15 +229,29 @@ alias cls="clear && printf '\e[3J'"
|
|||||||
case `uname` in
|
case `uname` in
|
||||||
Linux)
|
Linux)
|
||||||
alias ls='ls -F --color=auto'
|
alias ls='ls -F --color=auto'
|
||||||
if which cgdb &> /dev/null; then
|
if command -v cgdb &> /dev/null; then
|
||||||
alias debug='cgdb --args'
|
alias debug='cgdb --args'
|
||||||
elif which gdb &> /dev/null; then
|
elif command -v gdb &> /dev/null; then
|
||||||
alias debug='gdb --args'
|
alias debug='gdb --args'
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
Darwin)
|
Darwin)
|
||||||
alias ls='ls -GFh'
|
alias ls='ls -GFh'
|
||||||
which lldb &> /dev/null && \
|
command -v lldb &> /dev/null && \
|
||||||
alias debug='lldb --'
|
alias debug='lldb --'
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
command -v wol > /dev/null && \
|
||||||
|
alias wakeonlan='wol'
|
||||||
|
|
||||||
|
# Append any aliases to notify_ignore_list if they contain any ignore commands
|
||||||
|
# NOTE: Keep this at the end of ~/.zshrc so all aliases are processed
|
||||||
|
for name in ${(k)aliases}; do
|
||||||
|
cmd=${${${$(alias $name)#${name}=}#\'}#\"}
|
||||||
|
for ignore in $notify_ignore_list; do
|
||||||
|
if [[ "$cmd" = "$ignore"* ]]; then
|
||||||
|
notify_ignore_list+=( $name )
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user