ohmyzsh
This commit is contained in:
@ -54,7 +54,9 @@ export FZF_CS_PREVIEW_COMMAND="python third_party/py/pygments/google/google_pygm
|
||||
export FZF_CS_PREVIEW_HIGHLIGHT="\x1b[38;2;248;248;248m\x1b[48;2;81;85;89m"
|
||||
|
||||
source ~/fzf-at-google.zsh
|
||||
|
||||
# source /google/src/cloud/cnieves/gms-codelab/google3/java/com/google/android/gmscore/g3doc/quickstart/gmscore.sh
|
||||
source ~/g3path.zsh
|
||||
source /etc/bash_completion.d/hgd
|
||||
|
||||
export HGSHORT_CMDS="ls cat head tail mv cp rm chmod g4 diff merge patch meld trim less more"
|
||||
alias hgd='source /google/src/head/depot/google3/experimental/fig_contrib/hgshort/hgd.sh'
|
||||
export ACID_STARTUP_SCRIPT_PATH=~/acid_startup.sh
|
||||
|
1
zsh/.oh-my-zsh/cache/.gcert_expiration
vendored
Normal file
1
zsh/.oh-my-zsh/cache/.gcert_expiration
vendored
Normal file
@ -0,0 +1 @@
|
||||
0
|
0
zsh/.oh-my-zsh/cache/.gitkeep
vendored
Normal file
0
zsh/.oh-my-zsh/cache/.gitkeep
vendored
Normal file
1
zsh/.oh-my-zsh/cache/.zsh-update
vendored
Normal file
1
zsh/.oh-my-zsh/cache/.zsh-update
vendored
Normal file
@ -0,0 +1 @@
|
||||
LAST_EPOCH=19199
|
1
zsh/.oh-my-zsh/cache/BLAZE_build_options
vendored
Normal file
1
zsh/.oh-my-zsh/cache/BLAZE_build_options
vendored
Normal file
File diff suppressed because one or more lines are too long
4
zsh/.oh-my-zsh/cache/BLAZE_commands
vendored
Normal file
4
zsh/.oh-my-zsh/cache/BLAZE_commands
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
_blaze_cmd_list=( ${(Q)"${(z)$(<<\EO:_blaze_cmd_list
|
||||
'analyze-profile' 'aquery' 'build' 'canonicalize-flags' 'clean' 'coverage' 'cquery' 'dump' 'help' 'info' 'javahotswap' 'mobile-install' 'mpm' 'print_action' 'query' 'run' 'shutdown' 'test' 'version'
|
||||
EO:_blaze_cmd_list
|
||||
)}"} )
|
1
zsh/.oh-my-zsh/cache/BLAZE_run_options
vendored
Normal file
1
zsh/.oh-my-zsh/cache/BLAZE_run_options
vendored
Normal file
File diff suppressed because one or more lines are too long
1
zsh/.oh-my-zsh/cache/BLAZE_startup_options_options
vendored
Normal file
1
zsh/.oh-my-zsh/cache/BLAZE_startup_options_options
vendored
Normal file
@ -0,0 +1 @@
|
||||
_blaze_startup_options_options='--noautodetect_server_javabase|--autodetect_server_javabase|--nobatch|--batch|--nobatch_cpu_scheduling|--batch_cpu_scheduling|--blazerc=:string: |--noblock_for_lock|--block_for_lock|--noclient_debug|--client_debug|--connect_timeout_secs=:integer: |--noexoblaze|--exoblaze|--noexpand_configs_in_place|--expand_configs_in_place|--noexperimental_use_g1_gc|--experimental_use_g1_gc|--failure_detail_out=:path:_files|--noidle_server_tasks|--idle_server_tasks|--noignore_all_rc_files|--ignore_all_rc_files|--io_nice_level=:integer: |--local_startup_timeout_secs=:integer: |--macos_qos_class=:string: |--nomaster_blazerc|--master_blazerc|--max_idle_secs=:integer: |--output_base=:path:_files|--output_user_root=:path:_files|--nopreemptible|--preemptible|--server_jvm_out=:path:_files|--noshutdown_on_low_sys_mem|--shutdown_on_low_sys_mem|--nounlimit_coredumps|--unlimit_coredumps|--nowatchfs|--watchfs|--nowindows_enable_symlinks|--windows_enable_symlinks|--objfs_source_symlink_forest=:string: |--noverifiable|--verifiable|--noupload_query_output_to_objfs|--upload_query_output_to_objfs|--noremote_logging_executed_actions_local_only|--remote_logging_executed_actions_local_only|--google_auth_scopes=:string: |--google_credentials=:string: |--nogoogle_default_credentials|--google_default_credentials|--grpc_keepalive_time=:string: |--grpc_keepalive_timeout=:string: |--host_jvm_args=:string: |--host_jvm_debug|--host_jvm_profile=:string: |--objfs=:string: |--objfs_loas=:string: |--objfs_port=:integer: |--objfs_root=:path:_files|--objfs_rpc_layer=:string: |--objfs_upload_service_rpc_layer=:string: |--objfs_upload_service_stubby_failure_detection_delay=:string: |--noremote_logging|--remote_logging|--remote_logging_executed_actions_percentage=:string: |--server_javabase=:string: |--status_port=:integer: |--tls_certificate=:string: |--tls_client_certificate=:string: |--tls_client_key=:string: '
|
1
zsh/.oh-my-zsh/cache/BLAZE_test_options
vendored
Normal file
1
zsh/.oh-my-zsh/cache/BLAZE_test_options
vendored
Normal file
File diff suppressed because one or more lines are too long
4
zsh/.oh-my-zsh/cache/DEBS_avail
vendored
Normal file
4
zsh/.oh-my-zsh/cache/DEBS_avail
vendored
Normal file
File diff suppressed because one or more lines are too long
3
zsh/.oh-my-zsh/cache/grep-alias
vendored
Normal file
3
zsh/.oh-my-zsh/cache/grep-alias
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
alias grep='grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}'
|
||||
alias egrep='egrep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}'
|
||||
alias fgrep='fgrep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}'
|
10
zsh/.oh-my-zsh/custom/example.zsh
Normal file
10
zsh/.oh-my-zsh/custom/example.zsh
Normal file
@ -0,0 +1,10 @@
|
||||
# You can put files here to add functionality separated per file, which
|
||||
# will be ignored by git.
|
||||
# Files on the custom/ directory will be automatically loaded by the init
|
||||
# script, in alphabetical order.
|
||||
|
||||
# For example: add yourself some shortcuts to projects you often work on.
|
||||
#
|
||||
# brainstormr=~/Projects/development/planetargon/brainstormr
|
||||
# cd $brainstormr
|
||||
#
|
2
zsh/.oh-my-zsh/custom/plugins/example/example.plugin.zsh
Normal file
2
zsh/.oh-my-zsh/custom/plugins/example/example.plugin.zsh
Normal file
@ -0,0 +1,2 @@
|
||||
# Add your own custom plugins in the custom/plugins directory. Plugins placed
|
||||
# here will override ones with the same name in the main plugins directory.
|
82
zsh/.oh-my-zsh/custom/plugins/gcert/README.md
Executable file
82
zsh/.oh-my-zsh/custom/plugins/gcert/README.md
Executable file
@ -0,0 +1,82 @@
|
||||
# Prompt command to track GCert expiration
|
||||
|
||||
## Basics
|
||||
|
||||
This provides a function, useful in `$PROMPT`, for showing the time left until
|
||||
certificate expiration. It monitors your command history, grepping for when you
|
||||
run `gcert`, and updates the file `.gcert_expiration`[^directory] with the
|
||||
expiration time when you do. Then it displays the time remaining before
|
||||
certificate expiration when you run the command.
|
||||
|
||||
[^directory]: The cached expiration timestamp is put in `$ZSH_CACHE_DIR` if that
|
||||
variable is defined (it should be for Oh-My-Zsh). Otherwise if `$XDG_CACHE_HOME`
|
||||
is set and exists, it will use that. If neither variable is set but `$HOME/.cache`
|
||||
exists, it will use that; and as a fallback it will use `$HOME`.
|
||||
|
||||
### With Oh-My-Zsh
|
||||
|
||||
To use it, copy the `gcert` directory
|
||||
(`/google/data/ro/users/mw/mweigel/oh-my-zsh/plugins/gcert`) to your custom
|
||||
plugin directory (by default this would be `~/.oh-my-zsh/custom/plugins`) and
|
||||
add `gcert` to the plugins array in your zshrc file:
|
||||
|
||||
```zsh
|
||||
plugins=(... gcert)
|
||||
```
|
||||
|
||||
### Without Oh-My-Zsh
|
||||
|
||||
If you aren't using Oh-My-Zsh, copy the file `gcert.plugin.zsh`
|
||||
somewhere local on your workstation and source it from your zshrc
|
||||
file. For example if you copied it to `~/.gcert.plugin.zsh` then
|
||||
you might add
|
||||
|
||||
```zsh
|
||||
source ~/.gcert.plugin.zsh
|
||||
```
|
||||
|
||||
To your zshrc.
|
||||
|
||||
### With Powerlevel9k / Powerlevel10k
|
||||
|
||||
Follow the above OMZ/not-OMZ instructions, and add `gcert` to
|
||||
`POWERLEVEL9K_LEFT_PROMPT_ELEMENTS` or `POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS`.
|
||||
|
||||
## Customization
|
||||
|
||||
### For Normal PROMPT
|
||||
|
||||
To see the gcert expiration time in your prompt, add
|
||||
`$(gcert_prompt_time)` somewhere in `$PROMPT`.
|
||||
|
||||
To change the file used for caching expiration time, set
|
||||
`ZSH_THEME_GCERT_EXPIRY_FILE` after the script loads.
|
||||
|
||||
You can set the duration (in hours) at which you want to change the
|
||||
display of the duration by setting the variable
|
||||
`ZSH_THEME_GCERT_PROMPT_WARN_HOURS` (the default is 2, for 2 hours).
|
||||
|
||||
You can decorate the display with `ZSH_THEME_GCERT_PROMPT_PREFIX` and
|
||||
`ZSH_THEME_GCERT_PROMPT_POSTFIX` or, in the warning state, with
|
||||
`ZSH_THEME_GCERT_PROMPT_WARN_PREFIX` and
|
||||
`ZSH_THEME_GCERT_PROMPT_WARN_POSTFIX`.
|
||||
|
||||
You can disable checking your history by setting
|
||||
`ZSH_THEME_GCERT_PROMPT_PARANOID` to "true". If you do that, you can
|
||||
still trigger an update to the file by running `gcert_update_expiry`.
|
||||
|
||||
### State for Powerlevel9k/Powerlevel10k
|
||||
|
||||
The `gcert` prompt segment has EXPIRED, LOW, and NORMAL states. You can set
|
||||
`POWERLEVEL9K_GCERT_LOW_THRESHOLD` to the number of hours left that triggers the
|
||||
LOW state instead of NORMAL. You can set foreground/background colors as usual
|
||||
for a segment with states: `POWERLEVEL9K_GCERT_{STATE}_(FOREGROUND,BACKGROUND)`.
|
||||
|
||||
You can also customize the messages with `POWERLEVEL9K_GCERT_{STATE}_MESSAGE`.
|
||||
|
||||
## Changes
|
||||
|
||||
The code for this plugin resides in
|
||||
[google3/experimental/users/mweigel/oh-my-zsh/plugins/gcert/](http://google3/experimental/users/mweigel/oh-my-zsh/plugins/gcert/). CLs
|
||||
are gratefully reviewed, just add reviewer:
|
||||
[mweigel](http://who/mweigel)
|
95
zsh/.oh-my-zsh/custom/plugins/gcert/gcert.plugin.zsh
Executable file
95
zsh/.oh-my-zsh/custom/plugins/gcert/gcert.plugin.zsh
Executable file
@ -0,0 +1,95 @@
|
||||
# track and calculate lifetime of gcert certificate
|
||||
|
||||
_gcert_expiry_cache_path() {
|
||||
local directory
|
||||
directory=${ZSH_CACHE_DIR:-${XDG_CACHE_HOME:-$HOME/.cache}}
|
||||
if [[ ! -d "$directory" ]]; then
|
||||
directory="$HOME"
|
||||
fi
|
||||
echo "$directory/.gcert_expiration"
|
||||
}
|
||||
|
||||
if [[ -z "$EXPIRY_FILE" ]]; then
|
||||
EXPIRY_FILE=$(_gcert_expiry_cache_path)
|
||||
fi
|
||||
|
||||
_gcert_expiry_clear_old_cache() {
|
||||
# migrate to Epoch-seconds format, from YYYY-MM-DD HH:MM format
|
||||
# not used yet
|
||||
if \grep -q -- - "$1"; then
|
||||
rm "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
_gcert_expiration_from_epoch() {
|
||||
strftime -r "%Y-%m-%d %R" "$1" 2>/dev/null
|
||||
if [[ $? != 0 ]]; then
|
||||
echo "0"
|
||||
fi
|
||||
}
|
||||
|
||||
gcert_expiry_update() {
|
||||
local expiration_text expiration_time
|
||||
expiration_text="$(gcertstatus -show_expiration_time 2>/dev/null)"
|
||||
if [[ "$?" -ne 0 ]]; then
|
||||
echo "0" > $EXPIRY_FILE
|
||||
else
|
||||
expiration_time=$(\grep "LOAS2" <<< $expiration_text | sed "s/LOAS2 expires at //")
|
||||
_gcert_expiration_from_epoch $expiration_time > $EXPIRY_FILE
|
||||
fi
|
||||
}
|
||||
|
||||
_gcert_expiry_check_update() {
|
||||
if [[ "${ZSH_THEME_GCERT_PROMPT_PARANOID:=false}" != true ]]; then
|
||||
if [[ ! -f "$EXPIRY_FILE" ]]; then
|
||||
gcert_expiry_update
|
||||
elif builtin fc -lm '*gcert*' -1 &>/dev/null; then
|
||||
gcert_expiry_update
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_gcert() {
|
||||
emulate -L zsh
|
||||
_gcert_expiry_check_update
|
||||
local -i expiration_time remaining_hours remaining_minutes
|
||||
local gcert_state glyph fg bg msg
|
||||
expiration_time=$(<$EXPIRY_FILE)
|
||||
remaining_hours=$(( ($expiration_time - $EPOCHSECONDS) / 3600 ))
|
||||
remaining_minutes=$(( (($expiration_time - $EPOCHSECONDS) / 60) % 60 ))
|
||||
if [[ $remaining_hours -lt 0 || $remaining_minutes -lt 0 ]]; then
|
||||
gcert_state=EXPIRED
|
||||
fg=red
|
||||
bg=black
|
||||
msg=${POWERLEVEL9K_GCERT_EXPIRED_MESSAGE:-Expired}
|
||||
elif [[ $remaining_hours -lt ${POWERLEVEL9K_GCERT_LOW_THRESHOLD=2} ]]; then
|
||||
gcert_state=LOW
|
||||
fg=yellow
|
||||
bg=black
|
||||
msg=${POWERLEVEL9K_GCERT_LOW_MESSAGE:-${remaining_hours}h ${remaining_minutes}m}
|
||||
else
|
||||
gcert_state=NORMAL
|
||||
fg=green
|
||||
bg=black
|
||||
msg=${POWERLEVEL9K_GCERT_NORMAL_MESSAGE:-${remaining_hours}h ${remaining_minutes}m}
|
||||
fi
|
||||
# glyph=$'\uf623'
|
||||
|
||||
p10k segment -s ${gcert_state} -i "$glyph" +r -f $fg -b $bg -t "$msg"
|
||||
}
|
||||
|
||||
gcert_prompt_time() {
|
||||
emulate -L zsh
|
||||
_gcert_expiry_check_update
|
||||
local -i expiration_time remaining_hours remaining_minutes
|
||||
expiration_time=$(<$EXPIRY_FILE)
|
||||
remaining_hours=$(( ($expiration_time - $EPOCHSECONDS) / 3600 ))
|
||||
remaining_minutes=$(( (($expiration_time - $EPOCHSECONDS) / 60) % 60 ))
|
||||
if [[ $remaining_hours -lt 0 || $remaining_minutes -lt 0 ]]; then
|
||||
echo "${ZSH_THEME_GCERT_PROMPT_EXPIRED=expired}"
|
||||
elif [[ $remaining_hours -lt ${ZSH_THEME_GCERT_PROMPT_WARN_HOURS=2} ]]; then
|
||||
echo "${ZSH_THEME_GCERT_PROMPT_WARN_PREFIX}${remaining_hours}h ${remaining_minutes}m${ZSH_THEME_GCERT_PROMPT_WARN_POSTFIX}"
|
||||
else
|
||||
echo "${ZSH_THEME_GCERT_PROMPT_PREFIX}${remaining_hours}h ${remaining_minutes}m${ZSH_THEME_GCERT_PROMPT_POSTFIX}"
|
||||
fi
|
||||
}
|
66
zsh/.oh-my-zsh/custom/plugins/google3/README.md
Normal file
66
zsh/.oh-my-zsh/custom/plugins/google3/README.md
Normal file
@ -0,0 +1,66 @@
|
||||
# Completion plugin for Piper / Google3
|
||||
|
||||
## Basics
|
||||
|
||||
This plugin shows "abbreviated" pathnames in Piper, as well as
|
||||
supports tilde expansion and autocomplete to your workspaces in Piper.
|
||||
|
||||
To use it, copy the `google3` directory
|
||||
(`/google/data/ro/users/mw/mweigel/oh-my-zsh/plugins/google3`) to your custom
|
||||
plugin directory (by default this would be `~/.oh-my-zsh/custom/plugins`) and
|
||||
add `google3` to the plugins array in your zshrc file:
|
||||
|
||||
```zsh
|
||||
plugins=(... google3)
|
||||
```
|
||||
|
||||
If you aren't using Oh-My-Zsh, copy the file `google3.plugin.zsh`
|
||||
somewhere local on your workstation and source it from your zshrc
|
||||
file. For example if you copied it to `~/.google3.plugin.zsh` then
|
||||
you might add
|
||||
|
||||
```zsh
|
||||
source ~/.google3.plugin.zsh
|
||||
```
|
||||
|
||||
To your zshrc.
|
||||
|
||||
## Examples
|
||||
|
||||
Then, if you have a CitC client named "pager-setup" and you wanted to
|
||||
go to the directory `/google/src/cloud/{{USERNAME}}/pager-setup`, you
|
||||
could issue the following command:
|
||||
|
||||
```zsh
|
||||
{{USERNAME}}:~$ cd ~[pager-setup:]
|
||||
{{USERNAME}}:~[pager-setup:]$ pwd
|
||||
/google/src/cloud/{{USERNAME}}/pager-setup
|
||||
{{USERNAME}}:~[pager-setup:]$
|
||||
```
|
||||
|
||||
You can also rely on tab-completion, e.g. hitting tab after typing the
|
||||
following:
|
||||
|
||||
```zsh
|
||||
{{USERNAME}}:~$ cd ~[pa
|
||||
```
|
||||
|
||||
would - assuming you only have one Citc client that begins with "pa" -
|
||||
expand to "pager-setup".
|
||||
|
||||
By default it will also smoosh "google3/java/com/google" in a path
|
||||
down to "g3/jcg" and "google3/javatests/com/google" down to "g3/jtcg".
|
||||
This can be disabled by setting the environment variable
|
||||
GOOGLE3_PLUGIN_DISABLE_JCG to "true".
|
||||
|
||||
From [Zsh Hacks](http://go/eng-resources/zsh#java), this plugin also
|
||||
incorporates the shell function `jt` for Java developers to quickly
|
||||
switch back and forth between the current directory in the java
|
||||
hierarchy and the javatests hierarchy.
|
||||
|
||||
## Changes
|
||||
|
||||
The code for this plugin resides in
|
||||
[google3/experimental/users/mweigel/oh-my-zsh/plugins/google3/](http://google3/experimental/users/mweigel/oh-my-zsh/plugins/google3/). CLs
|
||||
are gratefully reviewed, just add reviewer:
|
||||
[mweigel](http://who/mweigel)
|
114
zsh/.oh-my-zsh/custom/plugins/google3/google3.plugin.zsh
Normal file
114
zsh/.oh-my-zsh/custom/plugins/google3/google3.plugin.zsh
Normal file
@ -0,0 +1,114 @@
|
||||
# show "abbreviated" pathnames in Piper, as well as support tilde expansion and
|
||||
# autocomplete to your workspaces in Piper.
|
||||
|
||||
function jt() {
|
||||
if [[ $PWD =~ '(.*)/javatests(.*)' ]]; then
|
||||
cd "${match[1]}/java${match[2]}"
|
||||
else
|
||||
cd "${PWD/\/google3\/java//google3/javatests}"
|
||||
fi
|
||||
}
|
||||
|
||||
typeset -ga zsh_directory_name_functions
|
||||
zsh_directory_name_functions+=("google3_directory_name")
|
||||
|
||||
expand_jcg() {
|
||||
emulate -L zsh
|
||||
setopt extendedglob
|
||||
local -a match mbegin mend
|
||||
if [[ $1 = (#b)(*)/g3/jcg(*) ]]; then
|
||||
typeset -g expansion
|
||||
expansion="$match[1]/google3/java/com/google$match[2]"
|
||||
return 0;
|
||||
elif [[ $1 = (#b)(*)/g3/jtcg(*) ]]; then
|
||||
typeset -g expansion
|
||||
expansion="$match[1]/google3/javatests/com/google$match[2]"
|
||||
return 0;
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
shrink_javacomgoogle() {
|
||||
emulate -L zsh
|
||||
setopt extendedglob
|
||||
local -a match mbegin mend
|
||||
if [[ $1 = (#b)(*)/google3/java/com/google(*) ]]; then
|
||||
typeset -g expansion
|
||||
expansion="$match[1]/g3/jcg$match[2]"
|
||||
return 0;
|
||||
elif [[ $1 = (#b)(*)/google3/javatests/com/google(*) ]]; then
|
||||
typeset -g expansion
|
||||
expansion="$match[1]/g3/jtcg$match[2]"
|
||||
return 0;
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
google3_directory_name() {
|
||||
emulate -L zsh
|
||||
setopt extendedglob
|
||||
local -a match mbegin mend
|
||||
if [[ $1 = d ]]; then
|
||||
# turn the directory into a name
|
||||
if [[ $2 = (#b)(/google/src/cloud/${USER}/)([^/]##)(*) ]]; then
|
||||
# default case is one of my own workspaces
|
||||
local my_dir
|
||||
my_dir=$match[3]
|
||||
if [[ "$GOOGLE3_PLUGIN_DISABLE_JCG" != "true" ]]; then
|
||||
if shrink_javacomgoogle $my_dir; then
|
||||
my_dir=$expansion
|
||||
fi
|
||||
fi
|
||||
typeset -ga reply
|
||||
reply=($match[2]:$my_dir $(( ${#match[1]} + ${#match[2]} + ${#match[3]} )) )
|
||||
return 0
|
||||
elif [[ $2 = (#b)(/google/src/cloud/)([a-z]##)/([^/]##)(*) ]]; then
|
||||
# special case for other users' workspaces
|
||||
# note that setting up completion of other users' workspaces would be
|
||||
# prohibitive, and if I can't tab-complete someone else's workspace I
|
||||
# don't think this code should expand them at all; so it's left out of the
|
||||
# 'n' case
|
||||
local my_dir
|
||||
my_dir=$match[4]
|
||||
if shrink_javacomgoogle $my_dir; then
|
||||
my_dir=$expansion
|
||||
fi
|
||||
typeset -ga reply
|
||||
reply=($match[2]:$match[3]:$my_dir $(( 1 + ${#match[1]} + ${#match[2]} + ${#match[3]} + ${#match[4]} )) )
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
elif [[ $1 = n ]]; then
|
||||
# turn the name into a directory
|
||||
local dir
|
||||
for dir in `/bin/ls /google/src/cloud/${USER}/`; do
|
||||
if [[ $2 = ${dir}:(#b)(*) ]]; then
|
||||
local my_dir
|
||||
my_dir=$match[1]
|
||||
if [[ "$GOOGLE3_PLUGIN_DISABLE_JCG" != "true" ]]; then
|
||||
if expand_jcg $my_dir; then
|
||||
my_dir=$expansion
|
||||
fi
|
||||
fi
|
||||
typeset -ga reply
|
||||
reply=(/google/src/cloud/${USER}/${dir}$my_dir)
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
elif [[ $1 = c ]]; then
|
||||
# complete names
|
||||
local expl
|
||||
local -a dirs
|
||||
dirs=(/google/src/cloud/${USER}/*(/:t))
|
||||
dirs=(${^dirs}:)
|
||||
_wanted dynamic-dirs expl 'dynamic directory' compadd -S\] -a dirs
|
||||
return
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
version: 2
|
||||
jobs:
|
||||
build:
|
||||
parallelism: 4
|
||||
shell: /bin/bash --login
|
||||
docker:
|
||||
- image: ericfreese/zsh-autosuggestions-test:latest
|
||||
steps:
|
||||
- checkout
|
||||
- run:
|
||||
name: Running tests
|
||||
command: |
|
||||
for v in $(grep "^[^#]" ZSH_VERSIONS | awk "(NR + $CIRCLE_NODE_INDEX) % $CIRCLE_NODE_TOTAL == 0"); do
|
||||
TEST_ZSH_BIN=zsh-$v make test || exit 1
|
||||
done
|
@ -0,0 +1,18 @@
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
|
||||
[*.md]
|
||||
indent_style = space
|
||||
|
||||
[*.rb]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.yml]
|
||||
indent_style = space
|
||||
indent_size = 2
|
36
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/.github/ISSUE_TEMPLATE/bug-report.md
vendored
Normal file
36
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/.github/ISSUE_TEMPLATE/bug-report.md
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### Describe the bug
|
||||
<!-- A clear and concise description of what the bug is. -->
|
||||
|
||||
### To Reproduce
|
||||
Steps to reproduce the behavior:
|
||||
|
||||
<!-- If you are not able to reproduce it by running `zsh -df` and sourcing the plugin manually, it means there that the issue is caused by something in your local config file(s). Temporarily comment out or remove sections of your config and restart `zsh` until you narrow down exactly what is causing the issue. -->
|
||||
|
||||
```sh
|
||||
% zsh -df
|
||||
% source path/to/zsh-autosuggestions.zsh
|
||||
% ... # what do you do to reproduce?
|
||||
```
|
||||
|
||||
### Expected behavior
|
||||
<!-- A clear and concise description of what you expected to happen. -->
|
||||
|
||||
### Screenshots
|
||||
<!-- If applicable, add screenshots to help explain your problem. -->
|
||||
|
||||
### Desktop
|
||||
- OS + distribution: <!-- e.g. Arch Linux 2019.07.01 -->
|
||||
- Zsh version: <!-- `echo $ZSH_VERSION` -->
|
||||
- Plugin version: <!-- or git commit hash if installed via git -->
|
||||
|
||||
### Additional context
|
||||
<!-- Add any other context about the problem here. -->
|
20
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### Is your feature request related to a problem? Please describe.
|
||||
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
|
||||
|
||||
### Describe the solution you'd like
|
||||
<!-- A clear and concise description of what you want to happen. -->
|
||||
|
||||
### Describe alternatives you've considered
|
||||
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
|
||||
|
||||
### Additional context
|
||||
<!-- Add any other context or screenshots about the feature request here. -->
|
3
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/.rspec
Normal file
3
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/.rspec
Normal file
@ -0,0 +1,3 @@
|
||||
--color
|
||||
--require spec_helper
|
||||
--format documentation
|
@ -0,0 +1,30 @@
|
||||
# Rails:
|
||||
# Enabled: true
|
||||
|
||||
AllCops:
|
||||
TargetRubyVersion: 2.3
|
||||
Include:
|
||||
- '**/Rakefile'
|
||||
- '**/config.ru'
|
||||
- '**/Gemfile'
|
||||
|
||||
Metrics/LineLength:
|
||||
Max: 120
|
||||
|
||||
Style/Documentation:
|
||||
Enabled: false
|
||||
|
||||
Style/DotPosition:
|
||||
EnforcedStyle: trailing
|
||||
|
||||
Style/FrozenStringLiteralComment:
|
||||
Enabled: false
|
||||
|
||||
Style/Lambda:
|
||||
Enabled: false
|
||||
|
||||
Style/MultilineMethodCallIndentation:
|
||||
EnforcedStyle: indented
|
||||
|
||||
Style/TrailingUnderscoreVariable:
|
||||
Enabled: false
|
@ -0,0 +1 @@
|
||||
2.5.3
|
117
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/CHANGELOG.md
Normal file
117
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/CHANGELOG.md
Normal file
@ -0,0 +1,117 @@
|
||||
# Changelog
|
||||
|
||||
## v0.7.0
|
||||
- Enable asynchronous mode by default (#498)
|
||||
- No longer wrap user widgets starting with `autosuggest-` prefix (#496)
|
||||
- Fix a bug wrapping widgets that modify the buffer (#541)
|
||||
|
||||
|
||||
## v0.6.4
|
||||
- Fix `vi-forward-char` triggering a bell when using it to accept a suggestion (#488)
|
||||
- New configuration option to skip completion suggestions when buffer matches a pattern (#487)
|
||||
- New configuration option to ignore history entries matching a pattern (#456)
|
||||
|
||||
## v0.6.3
|
||||
- Fixed bug moving cursor to end of buffer after accepting suggestion (#453)
|
||||
|
||||
## v0.6.2
|
||||
- Fixed bug deleting the last character in the buffer in vi mode (#450)
|
||||
- Degrade gracefully when user doesn't have `zsh/system` module installed (#447)
|
||||
|
||||
## v0.6.1
|
||||
- Fixed bug occurring when `_complete` had been aliased (#443)
|
||||
|
||||
## v0.6.0
|
||||
- Added `completion` suggestion strategy powered by completion system (#111)
|
||||
- Allow setting `ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE` to an empty string (#422)
|
||||
- Don't fetch suggestions after copy-earlier-word (#439)
|
||||
- Allow users to unignore zle-\* widgets (e.g. zle-line-init) (#432)
|
||||
|
||||
|
||||
## v0.5.2
|
||||
- Allow disabling automatic widget re-binding for better performance (#418)
|
||||
- Fix async suggestions when `SH_WORD_SPLIT` is set
|
||||
- Refactor async mode to use process substitution instead of zpty (#417)
|
||||
|
||||
## v0.5.1
|
||||
- Speed up widget rebinding (#413)
|
||||
- Clean up global variable creations (#403)
|
||||
- Respect user's set options when running original widget (#402)
|
||||
|
||||
## v0.5.0
|
||||
- Don't overwrite config with default values (#335)
|
||||
- Support fallback strategies by supplying array to suggestion config var
|
||||
- Rename "default" suggestion strategy to "history" to name it based on what it actually does
|
||||
- Reset opts in some functions affected by `GLOB_SUBST` (#334)
|
||||
- Support widgets starting with dashes (ex: `-a-widget`) (#337)
|
||||
- Skip async tests in zsh versions less than 5.0.8 because of reliability issues
|
||||
- Fix handling of newline + carriage return in async pty (#333)
|
||||
|
||||
|
||||
## v0.4.3
|
||||
- Avoid bell when accepting suggestions with `autosuggest-accept` (#228)
|
||||
- Don't fetch suggestions after [up,down]-line-or-beginning-search (#227, #241)
|
||||
- We are now running CI against new 5.5.1 version
|
||||
- Fix partial-accept in vi mode (#188)
|
||||
- Fix suggestion disappearing on fast movement after switching to `vicmd` mode (#290)
|
||||
- Fix issue rotating through kill ring with `yank-pop` (#301)
|
||||
- Fix issue creating new pty for async mode when previous pty is not properly cleaned up (#249)
|
||||
|
||||
## v0.4.2
|
||||
- Fix bug in zsh versions older than 5.0.8 (#296)
|
||||
- Officially support back to zsh v4.3.11
|
||||
|
||||
## v0.4.1
|
||||
- Switch to [[ and (( conditionals instead of [ (#257)
|
||||
- Avoid warnnestedvar warnings with `typeset -g` (#275)
|
||||
- Replace tabs with spaces in yaml (#268)
|
||||
- Clean up and fix escaping of special characters (#267)
|
||||
- Add `emacs-forward-word` to default list of partial accept widgets (#246)
|
||||
|
||||
## v0.4.0
|
||||
- High-level integration tests using RSpec and tmux
|
||||
- Add continuous integration with Circle CI
|
||||
- Experimental support for asynchronous suggestions (#170)
|
||||
- Fix problems with multi-line suggestions (#225)
|
||||
- Optimize case where manually typing in suggestion
|
||||
- Avoid wrapping any zle-\* widgets (#206)
|
||||
- Remove support for deprecated options from v0.0.x
|
||||
- Handle history entries that begin with dashes
|
||||
- Gracefully handle being sourced multiple times (#126)
|
||||
- Add enable/disable/toggle widgets to disable/enable suggestions (#219)
|
||||
|
||||
|
||||
## v0.3.3
|
||||
- Switch from $history array to fc builtin for better performance with large HISTFILEs (#164)
|
||||
- Fix tilde handling when extended_glob is set (#168)
|
||||
- Add config option for maximum buffer length to fetch suggestions for (#178)
|
||||
- Add config option for list of widgets to ignore (#184)
|
||||
- Don't fetch a new suggestion unless a modification widget actually modifies the buffer (#183)
|
||||
|
||||
## v0.3.2
|
||||
- Test runner now supports running specific tests and choosing zsh binary
|
||||
- Return code from original widget is now correctly passed through (#135)
|
||||
- Add `vi-add-eol` to list of accept widgets (#143)
|
||||
- Escapes widget names within evals to fix problems with irregular widget names (#152)
|
||||
- Plugin now clears suggestion while within a completion menu (#149)
|
||||
- .plugin file no longer relies on symbolic link support, fixing issues on Windows (#156)
|
||||
|
||||
## v0.3.1
|
||||
|
||||
- Fixes issue with `vi-next-char` not accepting suggestion (#137).
|
||||
- Fixes global variable warning when WARN_CREATE_GLOBAL option enabled (#133).
|
||||
- Split out a separate test file for each widget.
|
||||
|
||||
## v0.3.0
|
||||
|
||||
- Adds `autosuggest-execute` widget (PR #124).
|
||||
- Adds concept of suggestion "strategies" for different ways of fetching suggestions.
|
||||
- Adds "match_prev_cmd" strategy (PR #131).
|
||||
- Uses git submodules for testing dependencies.
|
||||
- Lots of test cleanup.
|
||||
- Various bug fixes for zsh 5.0.x and `sh_word_split` option.
|
||||
|
||||
|
||||
## v0.2.17
|
||||
|
||||
Start of changelog.
|
@ -0,0 +1 @@
|
||||
Fish-like fast/unobtrusive autosuggestions for zsh.
|
20
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/Dockerfile
Normal file
20
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/Dockerfile
Normal file
@ -0,0 +1,20 @@
|
||||
FROM ruby:2.5.3-alpine
|
||||
|
||||
RUN apk add --no-cache autoconf
|
||||
RUN apk add --no-cache libtool
|
||||
RUN apk add --no-cache libcap-dev
|
||||
RUN apk add --no-cache pcre-dev
|
||||
RUN apk add --no-cache curl
|
||||
RUN apk add --no-cache build-base
|
||||
RUN apk add --no-cache ncurses-dev
|
||||
RUN apk add --no-cache tmux
|
||||
|
||||
WORKDIR /zsh-autosuggestions
|
||||
|
||||
ADD ZSH_VERSIONS /zsh-autosuggestions/ZSH_VERSIONS
|
||||
ADD install_test_zsh.sh /zsh-autosuggestions/install_test_zsh.sh
|
||||
RUN ./install_test_zsh.sh
|
||||
|
||||
ADD Gemfile /zsh-autosuggestions/Gemfile
|
||||
ADD Gemfile.lock /zsh-autosuggestions/Gemfile.lock
|
||||
RUN bundle install
|
@ -0,0 +1,5 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'rspec'
|
||||
gem 'rspec-wait'
|
||||
gem 'pry-byebug'
|
@ -0,0 +1,41 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
byebug (9.0.5)
|
||||
coderay (1.1.1)
|
||||
diff-lcs (1.3)
|
||||
method_source (0.8.2)
|
||||
pry (0.10.4)
|
||||
coderay (~> 1.1.0)
|
||||
method_source (~> 0.8.1)
|
||||
slop (~> 3.4)
|
||||
pry-byebug (3.4.0)
|
||||
byebug (~> 9.0)
|
||||
pry (~> 0.10)
|
||||
rspec (3.5.0)
|
||||
rspec-core (~> 3.5.0)
|
||||
rspec-expectations (~> 3.5.0)
|
||||
rspec-mocks (~> 3.5.0)
|
||||
rspec-core (3.5.4)
|
||||
rspec-support (~> 3.5.0)
|
||||
rspec-expectations (3.5.0)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.5.0)
|
||||
rspec-mocks (3.5.0)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.5.0)
|
||||
rspec-support (3.5.0)
|
||||
rspec-wait (0.0.9)
|
||||
rspec (>= 3, < 4)
|
||||
slop (3.6.0)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
pry-byebug
|
||||
rspec
|
||||
rspec-wait
|
||||
|
||||
BUNDLED WITH
|
||||
1.13.6
|
64
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/INSTALL.md
Normal file
64
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/INSTALL.md
Normal file
@ -0,0 +1,64 @@
|
||||
# Installation
|
||||
|
||||
* [Packages](#packages)
|
||||
* [Antigen](#antigen)
|
||||
* [Oh My Zsh](#oh-my-zsh)
|
||||
* [Manual](#manual-git-clone)
|
||||
|
||||
## Packages
|
||||
|
||||
| System | Package |
|
||||
| ------------- | ------------- |
|
||||
| Debian / Ubuntu | [zsh-autosuggestions OBS repository](https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-autosuggestions&package=zsh-autosuggestions) |
|
||||
| Fedora / CentOS / RHEL / Scientific Linux | [zsh-autosuggestions OBS repository](https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-autosuggestions&package=zsh-autosuggestions) |
|
||||
| OpenSUSE / SLE | [zsh-autosuggestions OBS repository](https://software.opensuse.org/download.html?project=shells%3Azsh-users%3Azsh-autosuggestions&package=zsh-autosuggestions) |
|
||||
| Arch Linux / Manjaro / Antergos / Hyperbola | [zsh-autosuggestions](https://www.archlinux.org/packages/zsh-autosuggestions), [zsh-autosuggestions-git](https://aur.archlinux.org/packages/zsh-autosuggestions-git) |
|
||||
| NixOS | [zsh-autosuggestions](https://github.com/NixOS/nixpkgs/blob/master/pkgs/shells/zsh/zsh-autosuggestions/default.nix) |
|
||||
| Void Linux | [zsh-autosuggestions](https://github.com/void-linux/void-packages/blob/master/srcpkgs/zsh-autosuggestions/template) |
|
||||
| Mac OS | [homebrew](https://github.com/Homebrew/homebrew-core/blob/master/Formula/zsh-autosuggestions.rb) |
|
||||
| NetBSD | [pkgsrc](http://ftp.netbsd.org/pub/pkgsrc/current/pkgsrc/shells/zsh-autosuggestions/README.html) |
|
||||
|
||||
## Antigen
|
||||
|
||||
1. Add the following to your `.zshrc`:
|
||||
|
||||
```sh
|
||||
antigen bundle zsh-users/zsh-autosuggestions
|
||||
```
|
||||
|
||||
2. Start a new terminal session.
|
||||
|
||||
## Oh My Zsh
|
||||
|
||||
1. Clone this repository into `$ZSH_CUSTOM/plugins` (by default `~/.oh-my-zsh/custom/plugins`)
|
||||
|
||||
```sh
|
||||
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
|
||||
```
|
||||
|
||||
2. Add the plugin to the list of plugins for Oh My Zsh to load (inside `~/.zshrc`):
|
||||
|
||||
```sh
|
||||
plugins=(
|
||||
# other plugins...
|
||||
zsh-autosuggestions
|
||||
)
|
||||
```
|
||||
|
||||
3. Start a new terminal session.
|
||||
|
||||
## Manual (Git Clone)
|
||||
|
||||
1. Clone this repository somewhere on your machine. This guide will assume `~/.zsh/zsh-autosuggestions`.
|
||||
|
||||
```sh
|
||||
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
|
||||
```
|
||||
|
||||
2. Add the following to your `.zshrc`:
|
||||
|
||||
```sh
|
||||
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
|
||||
```
|
||||
|
||||
3. Start a new terminal session.
|
23
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/LICENSE
Normal file
23
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/LICENSE
Normal file
@ -0,0 +1,23 @@
|
||||
Copyright (c) 2013 Thiago de Arruda
|
||||
Copyright (c) 2016-2021 Eric Freese
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
35
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/Makefile
Normal file
35
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/Makefile
Normal file
@ -0,0 +1,35 @@
|
||||
SRC_DIR := ./src
|
||||
|
||||
SRC_FILES := \
|
||||
$(SRC_DIR)/config.zsh \
|
||||
$(SRC_DIR)/util.zsh \
|
||||
$(SRC_DIR)/bind.zsh \
|
||||
$(SRC_DIR)/highlight.zsh \
|
||||
$(SRC_DIR)/widgets.zsh \
|
||||
$(SRC_DIR)/strategies/*.zsh \
|
||||
$(SRC_DIR)/fetch.zsh \
|
||||
$(SRC_DIR)/async.zsh \
|
||||
$(SRC_DIR)/start.zsh
|
||||
|
||||
HEADER_FILES := \
|
||||
DESCRIPTION \
|
||||
URL \
|
||||
VERSION \
|
||||
LICENSE
|
||||
|
||||
PLUGIN_TARGET := zsh-autosuggestions.zsh
|
||||
|
||||
all: $(PLUGIN_TARGET)
|
||||
|
||||
$(PLUGIN_TARGET): $(HEADER_FILES) $(SRC_FILES)
|
||||
cat $(HEADER_FILES) | sed -e 's/^/# /g' > $@
|
||||
cat $(SRC_FILES) >> $@
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm $(PLUGIN_TARGET)
|
||||
|
||||
.PHONY: test
|
||||
test: all
|
||||
@test -n "$$TEST_ZSH_BIN" && echo "Testing zsh binary: $(TEST_ZSH_BIN)" || true
|
||||
bundle exec rspec $(TESTS)
|
191
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/README.md
Normal file
191
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/README.md
Normal file
@ -0,0 +1,191 @@
|
||||
# zsh-autosuggestions
|
||||
|
||||
_[Fish](http://fishshell.com/)-like fast/unobtrusive autosuggestions for zsh._
|
||||
|
||||
It suggests commands as you type based on history and completions.
|
||||
|
||||
Requirements: Zsh v4.3.11 or later
|
||||
|
||||
[](https://circleci.com/gh/zsh-users/zsh-autosuggestions)
|
||||
[](https://gitter.im/zsh-users/zsh-autosuggestions)
|
||||
|
||||
<a href="https://asciinema.org/a/37390" target="_blank"><img src="https://asciinema.org/a/37390.png" width="400" /></a>
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
See [INSTALL.md](INSTALL.md).
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
As you type commands, you will see a completion offered after the cursor in a muted gray color. This color can be changed by setting the `ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE` variable. See [configuration](#configuration).
|
||||
|
||||
If you press the <kbd>→</kbd> key (`forward-char` widget) or <kbd>End</kbd> (`end-of-line` widget) with the cursor at the end of the buffer, it will accept the suggestion, replacing the contents of the command line buffer with the suggestion.
|
||||
|
||||
If you invoke the `forward-word` widget, it will partially accept the suggestion up to the point that the cursor moves to.
|
||||
|
||||
|
||||
## Configuration
|
||||
|
||||
You may want to override the default global config variables. Default values of these variables can be found [here](src/config.zsh).
|
||||
|
||||
**Note:** If you are using Oh My Zsh, you can put this configuration in a file in the `$ZSH_CUSTOM` directory. See their comments on [overriding internals](https://github.com/robbyrussell/oh-my-zsh/wiki/Customization#overriding-internals).
|
||||
|
||||
|
||||
### Suggestion Highlight Style
|
||||
|
||||
Set `ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE` to configure the style that the suggestion is shown with. The default is `fg=8`, which will set the foreground color to color 8 from the [256-color palette](https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.svg). If your terminal only supports 8 colors, you will need to use a number between 0 and 7.
|
||||
|
||||
Background color can also be set, and the suggestion can be styled bold, underlined, or standout. For example, this would show suggestions with bold, underlined, pink text on a cyan background:
|
||||
|
||||
```sh
|
||||
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff00ff,bg=cyan,bold,underline"
|
||||
```
|
||||
|
||||
For more info, read the Character Highlighting section of the zsh manual: `man zshzle` or [online](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting).
|
||||
|
||||
**Note:** Some iTerm2 users have reported [not being able to see the suggestions](https://github.com/zsh-users/zsh-autosuggestions/issues/416#issuecomment-486516333). If this affects you, the problem is likely caused by incorrect color settings. In order to correct this, go into iTerm2's setting, navigate to profile > colors and make sure that the colors for Basic Colors > Background and ANSI Colors > Bright Black are **different**.
|
||||
|
||||
|
||||
### Suggestion Strategy
|
||||
|
||||
`ZSH_AUTOSUGGEST_STRATEGY` is an array that specifies how suggestions should be generated. The strategies in the array are tried successively until a suggestion is found. There are currently three built-in strategies to choose from:
|
||||
|
||||
- `history`: Chooses the most recent match from history.
|
||||
- `completion`: Chooses a suggestion based on what tab-completion would suggest. (requires `zpty` module)
|
||||
- `match_prev_cmd`: Like `history`, but chooses the most recent match whose preceding history item matches the most recently executed command ([more info](src/strategies/match_prev_cmd.zsh)). Note that this strategy won't work as expected with ZSH options that don't preserve the history order such as `HIST_IGNORE_ALL_DUPS` or `HIST_EXPIRE_DUPS_FIRST`.
|
||||
|
||||
For example, setting `ZSH_AUTOSUGGEST_STRATEGY=(history completion)` will first try to find a suggestion from your history, but, if it can't find a match, will find a suggestion from the completion engine.
|
||||
|
||||
|
||||
### Widget Mapping
|
||||
|
||||
This plugin works by triggering custom behavior when certain [zle widgets](http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Widgets) are invoked. You can add and remove widgets from these arrays to change the behavior of this plugin:
|
||||
|
||||
- `ZSH_AUTOSUGGEST_CLEAR_WIDGETS`: Widgets in this array will clear the suggestion when invoked.
|
||||
- `ZSH_AUTOSUGGEST_ACCEPT_WIDGETS`: Widgets in this array will accept the suggestion when invoked.
|
||||
- `ZSH_AUTOSUGGEST_EXECUTE_WIDGETS`: Widgets in this array will execute the suggestion when invoked.
|
||||
- `ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS`: Widgets in this array will partially accept the suggestion when invoked.
|
||||
- `ZSH_AUTOSUGGEST_IGNORE_WIDGETS`: Widgets in this array will not trigger any custom behavior.
|
||||
|
||||
Widgets that modify the buffer and are not found in any of these arrays will fetch a new suggestion after they are invoked.
|
||||
|
||||
**Note:** A widget shouldn't belong to more than one of the above arrays.
|
||||
|
||||
|
||||
### Disabling suggestion for large buffers
|
||||
|
||||
Set `ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE` to an integer value to disable autosuggestion for large buffers. The default is unset, which means that autosuggestion will be tried for any buffer size. Recommended value is 20.
|
||||
This can be useful when pasting large amount of text in the terminal, to avoid triggering autosuggestion for strings that are too long.
|
||||
|
||||
### Asynchronous Mode
|
||||
|
||||
Suggestions are fetched asynchronously by default in zsh versions 5.0.8 and greater. To disable asynchronous suggestions and fetch them synchronously instead, `unset ZSH_AUTOSUGGEST_USE_ASYNC` after sourcing the plugin.
|
||||
|
||||
Alternatively, if you are using a version of zsh older than 5.0.8 and want to enable asynchronous mode, set the `ZSH_AUTOSUGGEST_USE_ASYNC` variable after sourcing the plugin (it can be set to anything). Note that there is [a bug](https://github.com/zsh-users/zsh-autosuggestions/issues/364#issuecomment-481423232) in versions of zsh older than 5.0.8 where <kbd>ctrl</kbd> + <kbd>c</kbd> will fail to reset the prompt immediately after fetching a suggestion asynchronously.
|
||||
|
||||
### Disabling automatic widget re-binding
|
||||
|
||||
Set `ZSH_AUTOSUGGEST_MANUAL_REBIND` (it can be set to anything) to disable automatic widget re-binding on each precmd. This can be a big boost to performance, but you'll need to handle re-binding yourself if any of the widget lists change or if you or another plugin wrap any of the autosuggest widgets. To re-bind widgets, run `_zsh_autosuggest_bind_widgets`.
|
||||
|
||||
### Ignoring history suggestions that match a pattern
|
||||
|
||||
Set `ZSH_AUTOSUGGEST_HISTORY_IGNORE` to a [glob pattern](http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Operators) to prevent offering suggestions for history entries that match the pattern. For example, set it to `"cd *"` to never suggest any `cd` commands from history. Or set to `"?(#c50,)"` to never suggest anything 50 characters or longer.
|
||||
|
||||
**Note:** This only affects the `history` and `match_prev_cmd` suggestion strategies.
|
||||
|
||||
### Skipping completion suggestions for certain cases
|
||||
|
||||
Set `ZSH_AUTOSUGGEST_COMPLETION_IGNORE` to a [glob pattern](http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Operators) to prevent offering completion suggestions when the buffer matches that pattern. For example, set it to `"git *"` to disable completion suggestions for git subcommands.
|
||||
|
||||
**Note:** This only affects the `completion` suggestion strategy.
|
||||
|
||||
|
||||
### Key Bindings
|
||||
|
||||
This plugin provides a few widgets that you can use with `bindkey`:
|
||||
|
||||
1. `autosuggest-accept`: Accepts the current suggestion.
|
||||
2. `autosuggest-execute`: Accepts and executes the current suggestion.
|
||||
3. `autosuggest-clear`: Clears the current suggestion.
|
||||
4. `autosuggest-fetch`: Fetches a suggestion (works even when suggestions are disabled).
|
||||
5. `autosuggest-disable`: Disables suggestions.
|
||||
6. `autosuggest-enable`: Re-enables suggestions.
|
||||
7. `autosuggest-toggle`: Toggles between enabled/disabled suggestions.
|
||||
|
||||
For example, this would bind <kbd>ctrl</kbd> + <kbd>space</kbd> to accept the current suggestion.
|
||||
|
||||
```sh
|
||||
bindkey '^ ' autosuggest-accept
|
||||
```
|
||||
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If you have a problem, please search through [the list of issues on GitHub](https://github.com/zsh-users/zsh-autosuggestions/issues?q=) to see if someone else has already reported it.
|
||||
|
||||
### Reporting an Issue
|
||||
|
||||
Before reporting an issue, please try temporarily disabling sections of your configuration and other plugins that may be conflicting with this plugin to isolate the problem.
|
||||
|
||||
When reporting an issue, please include:
|
||||
|
||||
- The smallest, simplest `.zshrc` configuration that will reproduce the problem. See [this comment](https://github.com/zsh-users/zsh-autosuggestions/issues/102#issuecomment-180944764) for a good example of what this means.
|
||||
- The version of zsh you're using (`zsh --version`)
|
||||
- Which operating system you're running
|
||||
|
||||
|
||||
## Uninstallation
|
||||
|
||||
1. Remove the code referencing this plugin from `~/.zshrc`.
|
||||
|
||||
2. Remove the git repository from your hard drive
|
||||
|
||||
```sh
|
||||
rm -rf ~/.zsh/zsh-autosuggestions # Or wherever you installed
|
||||
```
|
||||
|
||||
|
||||
## Development
|
||||
|
||||
### Build Process
|
||||
|
||||
Edit the source files in `src/`. Run `make` to build `zsh-autosuggestions.zsh` from those source files.
|
||||
|
||||
|
||||
### Pull Requests
|
||||
|
||||
Pull requests are welcome! If you send a pull request, please:
|
||||
|
||||
- Request to merge into the `develop` branch (*NOT* `master`)
|
||||
- Match the existing coding conventions.
|
||||
- Include helpful comments to keep the barrier-to-entry low for people new to the project.
|
||||
- Write tests that cover your code as much as possible.
|
||||
|
||||
|
||||
### Testing
|
||||
|
||||
Tests are written in ruby using the [`rspec`](http://rspec.info/) framework. They use [`tmux`](https://tmux.github.io/) to drive a pseudoterminal, sending simulated keystrokes and making assertions on the terminal content.
|
||||
|
||||
Test files live in `spec/`. To run the tests, run `make test`. To run a specific test, run `TESTS=spec/some_spec.rb make test`. You can also specify a `zsh` binary to use by setting the `TEST_ZSH_BIN` environment variable (ex: `TEST_ZSH_BIN=/bin/zsh make test`).
|
||||
|
||||
A docker image for testing is available [on docker hub](https://hub.docker.com/r/ericfreese/zsh-autosuggestions-test). It comes with ruby, the bundler dependencies, and all supported versions of zsh installed.
|
||||
|
||||
Pull the docker image with:
|
||||
|
||||
```sh
|
||||
docker pull ericfreese/zsh-autosuggestions-test
|
||||
```
|
||||
|
||||
To run the tests for a specific version of zsh (where `<version>` below is substituted with the contents of a line from the [`ZSH_VERSIONS`](ZSH_VERSIONS) file):
|
||||
|
||||
```sh
|
||||
docker run -it -e TEST_ZSH_BIN=zsh-<version> -v $PWD:/zsh-autosuggestions zsh-autosuggestions-test make test
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under [MIT license](http://opensource.org/licenses/MIT).
|
||||
For the full text of the license, see the [LICENSE](LICENSE) file.
|
1
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/URL
Normal file
1
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/URL
Normal file
@ -0,0 +1 @@
|
||||
https://github.com/zsh-users/zsh-autosuggestions
|
@ -0,0 +1 @@
|
||||
v0.7.0
|
@ -0,0 +1,17 @@
|
||||
# Zsh releases to run tests against
|
||||
# See https://github.com/zsh-users/zsh/releases
|
||||
#
|
||||
# When modifying this file, rebuild and push docker image:
|
||||
# $ docker build -t ericfreese/zsh-autosuggestions-test .
|
||||
# $ docker push ericfreese/zsh-autosuggestions-test
|
||||
4.3.11
|
||||
5.0.2
|
||||
5.0.8
|
||||
5.1.1
|
||||
5.2
|
||||
5.3.1
|
||||
5.4.2
|
||||
5.5.1
|
||||
5.6.2
|
||||
5.7.1
|
||||
5.8
|
26
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/install_test_zsh.sh
Executable file
26
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/install_test_zsh.sh
Executable file
@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
|
||||
for v in $(grep "^[^#]" ZSH_VERSIONS); do
|
||||
mkdir zsh-$v
|
||||
cd zsh-$v
|
||||
|
||||
curl -L https://api.github.com/repos/zsh-users/zsh/tarball/zsh-$v | tar xz --strip=1
|
||||
|
||||
./Util/preconfig
|
||||
./configure --enable-pcre \
|
||||
--enable-cap \
|
||||
--enable-multibyte \
|
||||
--with-term-lib='ncursesw tinfo' \
|
||||
--with-tcsetpgrp \
|
||||
--program-suffix="-$v"
|
||||
|
||||
make install.bin
|
||||
make install.modules
|
||||
make install.fns
|
||||
|
||||
cd ..
|
||||
|
||||
rm -rf zsh-$v
|
||||
done
|
@ -0,0 +1,70 @@
|
||||
context 'with asynchronous suggestions enabled' do
|
||||
let(:options) { ["ZSH_AUTOSUGGEST_USE_ASYNC="] }
|
||||
|
||||
describe '`up-line-or-beginning-search`' do
|
||||
let(:before_sourcing) do
|
||||
-> do
|
||||
session.
|
||||
run_command('autoload -U up-line-or-beginning-search').
|
||||
run_command('zle -N up-line-or-beginning-search').
|
||||
send_string('bindkey "').
|
||||
send_keys('C-v').send_keys('up').
|
||||
send_string('" up-line-or-beginning-search').
|
||||
send_keys('enter')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should show previous history entries' do
|
||||
with_history(
|
||||
'echo foo',
|
||||
'echo bar',
|
||||
'echo baz'
|
||||
) do
|
||||
session.clear_screen
|
||||
3.times { session.send_keys('up') }
|
||||
wait_for { session.content }.to eq("echo foo")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '`copy-earlier-word`' do
|
||||
let(:before_sourcing) do
|
||||
-> do
|
||||
session.
|
||||
run_command('autoload -Uz copy-earlier-word').
|
||||
run_command('zle -N copy-earlier-word').
|
||||
run_command('bindkey "^N" copy-earlier-word')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should cycle through previous words in the buffer' do
|
||||
session.clear_screen
|
||||
session.send_string('foo bar baz')
|
||||
sleep 0.5
|
||||
session.send_keys('C-n')
|
||||
wait_for { session.content }.to eq('foo bar bazbaz')
|
||||
session.send_keys('C-n')
|
||||
wait_for { session.content }.to eq('foo bar bazbar')
|
||||
session.send_keys('C-n')
|
||||
wait_for { session.content }.to eq('foo bar bazfoo')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'pressing ^C after fetching a suggestion' do
|
||||
before do
|
||||
skip 'Workaround does not work below v5.0.8' if session.zsh_version < Gem::Version.new('5.0.8')
|
||||
end
|
||||
|
||||
it 'terminates the prompt and begins a new one' do
|
||||
session.send_keys('e')
|
||||
sleep 0.5
|
||||
session.send_keys('C-c')
|
||||
sleep 0.5
|
||||
session.send_keys('echo')
|
||||
|
||||
wait_for { session.content }.to eq("e\necho")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -0,0 +1,14 @@
|
||||
describe 'with `AUTO_CD` option set' do
|
||||
let(:after_sourcing) do
|
||||
-> {
|
||||
session.run_command('setopt AUTO_CD')
|
||||
session.run_command('autoload compinit && compinit')
|
||||
}
|
||||
end
|
||||
|
||||
it 'directory names are still completed' do
|
||||
session.send_string('sr')
|
||||
session.send_keys('C-i')
|
||||
wait_for { session.content }.to eq('src/')
|
||||
end
|
||||
end
|
@ -0,0 +1,43 @@
|
||||
describe 'pasting using bracketed-paste-magic' do
|
||||
let(:before_sourcing) do
|
||||
-> do
|
||||
session.
|
||||
run_command('autoload -Uz bracketed-paste-magic').
|
||||
run_command('zle -N bracketed-paste bracketed-paste-magic')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with suggestions disabled while pasting' do
|
||||
before do
|
||||
session.
|
||||
run_command('bpm_init() { zle autosuggest-disable }').
|
||||
run_command('bpm_finish() { zle autosuggest-enable }').
|
||||
run_command('zstyle :bracketed-paste-magic paste-init bpm_init').
|
||||
run_command('zstyle :bracketed-paste-magic paste-finish bpm_finish')
|
||||
end
|
||||
|
||||
it 'does not show an incorrect suggestion' do
|
||||
with_history('echo hello') do
|
||||
session.paste_string("echo #{'a' * 60}")
|
||||
sleep 1
|
||||
expect(session.content).to eq("echo #{'a' * 60}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with `bracketed-paste` added to the list of widgets that clear the suggestion' do
|
||||
let(:options) { ['ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(bracketed-paste)'] }
|
||||
|
||||
it 'does not retain an old suggestion' do
|
||||
with_history ('echo foo') do
|
||||
session.send_string('echo ')
|
||||
wait_for { session.content }.to eq('echo foo')
|
||||
session.paste_string('bar')
|
||||
wait_for { session.content }.to eq('echo bar')
|
||||
session.send_keys('C-a') # Any cursor movement works
|
||||
sleep 1
|
||||
expect(session.content).to eq('echo bar')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,14 @@
|
||||
describe 'a running zpty command' do
|
||||
let(:before_sourcing) { -> { session.run_command('zmodload zsh/zpty && zpty -b kitty cat') } }
|
||||
|
||||
context 'when using `completion` strategy' do
|
||||
let(:options) { ["ZSH_AUTOSUGGEST_STRATEGY=completion"] }
|
||||
|
||||
it 'is not affected' do
|
||||
session.send_keys('a').send_keys('C-h')
|
||||
session.run_command('zpty -t kitty; echo $?')
|
||||
|
||||
wait_for { session.content }.to end_with("\n0")
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,12 @@
|
||||
describe 'with `GLOB_SUBST` option set' do
|
||||
let(:after_sourcing) do
|
||||
-> {
|
||||
session.run_command('setopt GLOB_SUBST')
|
||||
}
|
||||
end
|
||||
|
||||
it 'error messages are not printed' do
|
||||
session.send_string('[[')
|
||||
wait_for { session.content }.to eq('[[')
|
||||
end
|
||||
end
|
@ -0,0 +1,13 @@
|
||||
describe 'rebinding [' do
|
||||
context 'initialized before sourcing the plugin' do
|
||||
before do
|
||||
session.run_command("function [ { $commands[\\[] \"$@\" }")
|
||||
session.clear_screen
|
||||
end
|
||||
|
||||
it 'executes the custom behavior and the built-in behavior' do
|
||||
session.send_string('asdf')
|
||||
wait_for { session.content }.to eq('asdf')
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,80 @@
|
||||
describe 'when using vi mode' do
|
||||
let(:before_sourcing) do
|
||||
-> do
|
||||
session.run_command('bindkey -v')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'moving the cursor after exiting insert mode' do
|
||||
it 'should not clear the current suggestion' do
|
||||
with_history('foobar foo') do
|
||||
session.
|
||||
send_string('foo').
|
||||
send_keys('escape').
|
||||
send_keys('h')
|
||||
|
||||
wait_for { session.content }.to eq('foobar foo')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '`vi-forward-word-end`' do
|
||||
it 'should accept through the end of the current word' do
|
||||
with_history('foobar foo') do
|
||||
session.
|
||||
send_string('foo').
|
||||
send_keys('escape').
|
||||
send_keys('e'). # vi-forward-word-end
|
||||
send_keys('a'). # vi-add-next
|
||||
send_string('baz')
|
||||
|
||||
wait_for { session.content }.to eq('foobarbaz')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '`vi-forward-word`' do
|
||||
it 'should accept through the first character of the next word' do
|
||||
with_history('foobar foo') do
|
||||
session.
|
||||
send_string('foo').
|
||||
send_keys('escape').
|
||||
send_keys('w'). # vi-forward-word
|
||||
send_keys('a'). # vi-add-next
|
||||
send_string('az')
|
||||
|
||||
wait_for { session.content }.to eq('foobar faz')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '`vi-find-next-char`' do
|
||||
it 'should accept through the next occurrence of the character' do
|
||||
with_history('foobar foo') do
|
||||
session.
|
||||
send_string('foo').
|
||||
send_keys('escape').
|
||||
send_keys('f'). # vi-find-next-char
|
||||
send_keys('o').
|
||||
send_keys('a'). # vi-add-next
|
||||
send_string('b')
|
||||
|
||||
wait_for { session.content }.to eq('foobar fob')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '`vi-delete`' do
|
||||
it 'should be able to remove the last character in the buffer' do
|
||||
skip 'deleting last char did not work below zsh version 5.0.8' if session.zsh_version < Gem::Version.new('5.0.8')
|
||||
|
||||
session.
|
||||
send_string('echo foo').
|
||||
send_keys('escape').
|
||||
send_keys('d').
|
||||
send_keys('l')
|
||||
|
||||
wait_for { session.content }.to eq('echo fo')
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,39 @@
|
||||
describe 'a wrapped widget' do
|
||||
let(:widget) { 'backward-delete-char' }
|
||||
|
||||
context 'initialized before sourcing the plugin' do
|
||||
let(:before_sourcing) do
|
||||
-> do
|
||||
session.
|
||||
run_command("_orig_#{widget}() { zle .#{widget} }").
|
||||
run_command("zle -N orig-#{widget} _orig_#{widget}").
|
||||
run_command("#{widget}-magic() { zle orig-#{widget}; BUFFER+=b }").
|
||||
run_command("zle -N #{widget} #{widget}-magic")
|
||||
end
|
||||
end
|
||||
|
||||
it 'executes the custom behavior and the built-in behavior' do
|
||||
with_history('foobar', 'foodar') do
|
||||
session.send_string('food').send_keys('C-h')
|
||||
wait_for { session.content }.to eq('foobar')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'initialized after sourcing the plugin' do
|
||||
before do
|
||||
session.
|
||||
run_command("zle -N orig-#{widget} ${widgets[#{widget}]#*:}").
|
||||
run_command("#{widget}-magic() { zle orig-#{widget}; BUFFER+=b }").
|
||||
run_command("zle -N #{widget} #{widget}-magic").
|
||||
clear_screen
|
||||
end
|
||||
|
||||
it 'executes the custom behavior and the built-in behavior' do
|
||||
with_history('foobar', 'foodar') do
|
||||
session.send_string('food').send_keys('C-h')
|
||||
wait_for { session.content }.to eq('foobar')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,24 @@
|
||||
describe 'using `zle -U`' do
|
||||
let(:before_sourcing) do
|
||||
-> do
|
||||
session.
|
||||
run_command('_zsh_autosuggest_strategy_test() { sleep 1; _zsh_autosuggest_strategy_history "$1" }').
|
||||
run_command('foo() { zle -U - "echo hello" }; zle -N foo; bindkey ^B foo')
|
||||
end
|
||||
end
|
||||
|
||||
let(:options) { ['unset ZSH_AUTOSUGGEST_USE_ASYNC', 'ZSH_AUTOSUGGEST_STRATEGY=test'] }
|
||||
|
||||
# TODO: This is only possible with the $KEYS_QUEUED_COUNT widget parameter, coming soon...
|
||||
xit 'does not fetch a suggestion for every inserted character' do
|
||||
session.send_keys('C-b')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
end
|
||||
|
||||
it 'shows a suggestion when the widget completes' do
|
||||
with_history('echo hello world') do
|
||||
session.send_keys('C-b')
|
||||
wait_for { session.content(esc_seqs: true) }.to match(/\Aecho hello\e\[[0-9]+m world/)
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,23 @@
|
||||
context 'with some items in the kill ring' do
|
||||
before do
|
||||
session.
|
||||
send_string('echo foo').
|
||||
send_keys('C-u').
|
||||
send_string('echo bar').
|
||||
send_keys('C-u')
|
||||
end
|
||||
|
||||
describe '`yank-pop`' do
|
||||
it 'should cycle through all items in the kill ring' do
|
||||
session.send_keys('C-y')
|
||||
wait_for { session.content }.to eq('echo bar')
|
||||
|
||||
session.send_keys('escape').send_keys('y')
|
||||
wait_for { session.content }.to eq('echo foo')
|
||||
|
||||
session.send_keys('escape').send_keys('y')
|
||||
wait_for { session.content }.to eq('echo bar')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,17 @@
|
||||
context 'with zle-line-init unignored' do
|
||||
let(:after_sourcing) do
|
||||
-> do
|
||||
session.
|
||||
run_command('setopt extendedglob').
|
||||
run_command('ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(${(@)ZSH_AUTOSUGGEST_IGNORE_WIDGETS:#zle-\*} zle-\^line-init)').
|
||||
run_command('zle-line-init() { BUFFER="echo" }')
|
||||
end
|
||||
end
|
||||
|
||||
it 'should fetch a suggestion on each line initialization' do
|
||||
with_history('echo foo') do
|
||||
session.run_command('zle -N zle-line-init')
|
||||
wait_for { session.content }.to end_with('echo foo')
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,8 @@
|
||||
describe 'a multi-line suggestion' do
|
||||
it 'should be displayed on multiple lines' do
|
||||
with_history("echo \"\n\"") do
|
||||
session.send_keys('e')
|
||||
wait_for { session.content }.to eq("echo \"\n\"")
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,30 @@
|
||||
describe 'a suggestion' do
|
||||
let(:term_opts) { { width: 200 } }
|
||||
let(:long_command) { "echo #{'a' * 100}" }
|
||||
|
||||
around do |example|
|
||||
with_history(long_command) { example.run }
|
||||
end
|
||||
|
||||
it 'is provided for any buffer length' do
|
||||
session.send_string(long_command[0...-1])
|
||||
wait_for { session.content }.to eq(long_command)
|
||||
end
|
||||
|
||||
context 'when ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE is specified' do
|
||||
let(:buffer_max_size) { 10 }
|
||||
let(:options) { ["ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=#{buffer_max_size}"] }
|
||||
|
||||
it 'is provided when the buffer is shorter than the specified length' do
|
||||
session.send_string(long_command[0...(buffer_max_size - 1)])
|
||||
wait_for { session.content }.to eq(long_command)
|
||||
end
|
||||
|
||||
it 'is provided when the buffer is equal to the specified length' do
|
||||
session.send_string(long_command[0...(buffer_max_size)])
|
||||
wait_for { session.content }.to eq(long_command)
|
||||
end
|
||||
|
||||
it 'is not provided when the buffer is longer than the specified length'
|
||||
end
|
||||
end
|
@ -0,0 +1,7 @@
|
||||
describe 'a displayed suggestion' do
|
||||
it 'is shown in the default style'
|
||||
|
||||
describe 'when ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE is set to a zle_highlight string' do
|
||||
it 'is shown in the specified style'
|
||||
end
|
||||
end
|
@ -0,0 +1,7 @@
|
||||
describe 'an original zle widget' do
|
||||
context 'is accessible with the default prefix'
|
||||
|
||||
context 'when ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX is set' do
|
||||
it 'is accessible with the specified prefix'
|
||||
end
|
||||
end
|
@ -0,0 +1,55 @@
|
||||
describe 'a suggestion for a given prefix' do
|
||||
let(:history_strategy) { '_zsh_autosuggest_strategy_history() { suggestion="history" }' }
|
||||
let(:foobar_strategy) { '_zsh_autosuggest_strategy_foobar() { [[ "foobar baz" = $1* ]] && suggestion="foobar baz" }' }
|
||||
let(:foobaz_strategy) { '_zsh_autosuggest_strategy_foobaz() { [[ "foobaz bar" = $1* ]] && suggestion="foobaz bar" }' }
|
||||
|
||||
let(:after_sourcing) do
|
||||
-> do
|
||||
session.run_command(history_strategy)
|
||||
end
|
||||
end
|
||||
|
||||
it 'by default is determined by calling the `history` strategy function' do
|
||||
session.send_string('h')
|
||||
wait_for { session.content }.to eq('history')
|
||||
end
|
||||
|
||||
context 'when ZSH_AUTOSUGGEST_STRATEGY is set to an array' do
|
||||
let(:after_sourcing) do
|
||||
-> do
|
||||
session.
|
||||
run_command(foobar_strategy).
|
||||
run_command(foobaz_strategy).
|
||||
run_command('ZSH_AUTOSUGGEST_STRATEGY=(foobar foobaz)')
|
||||
end
|
||||
end
|
||||
|
||||
it 'is determined by the first strategy function to return a suggestion' do
|
||||
session.send_string('foo')
|
||||
wait_for { session.content }.to eq('foobar baz')
|
||||
|
||||
session.send_string('baz')
|
||||
wait_for { session.content }.to eq('foobaz bar')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ZSH_AUTOSUGGEST_STRATEGY is set to a string' do
|
||||
let(:after_sourcing) do
|
||||
-> do
|
||||
session.
|
||||
run_command(foobar_strategy).
|
||||
run_command(foobaz_strategy).
|
||||
run_command('ZSH_AUTOSUGGEST_STRATEGY="foobar foobaz"')
|
||||
end
|
||||
end
|
||||
|
||||
it 'is determined by the first strategy function to return a suggestion' do
|
||||
session.send_string('foo')
|
||||
wait_for { session.content }.to eq('foobar baz')
|
||||
|
||||
session.send_string('baz')
|
||||
wait_for { session.content }.to eq('foobaz bar')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,121 @@
|
||||
describe 'a zle widget' do
|
||||
let(:widget) { 'my-widget' }
|
||||
let(:before_sourcing) { -> { session.run_command("#{widget}() {}; zle -N #{widget}; bindkey ^B #{widget}") } }
|
||||
|
||||
context 'when added to ZSH_AUTOSUGGEST_ACCEPT_WIDGETS' do
|
||||
let(:options) { ["ZSH_AUTOSUGGEST_ACCEPT_WIDGETS+=(#{widget})"] }
|
||||
|
||||
it 'accepts the suggestion and moves the cursor to the end of the buffer when invoked' do
|
||||
with_history('echo hello') do
|
||||
session.send_string('e')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
session.send_keys('C-b')
|
||||
wait_for { session.content(esc_seqs: true) }.to eq('echo hello')
|
||||
wait_for { session.cursor }.to eq([10, 0])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when added to ZSH_AUTOSUGGEST_CLEAR_WIDGETS' do
|
||||
let(:options) { ["ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(#{widget})"] }
|
||||
|
||||
it 'clears the suggestion when invoked' do
|
||||
with_history('echo hello') do
|
||||
session.send_string('e')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
session.send_keys('C-b')
|
||||
wait_for { session.content }.to eq('e')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when added to ZSH_AUTOSUGGEST_EXECUTE_WIDGETS' do
|
||||
let(:options) { ["ZSH_AUTOSUGGEST_EXECUTE_WIDGETS+=(#{widget})"] }
|
||||
|
||||
it 'executes the suggestion when invoked' do
|
||||
with_history('echo hello') do
|
||||
session.send_string('e')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
session.send_keys('C-b')
|
||||
wait_for { session.content }.to end_with("\nhello")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when added to ZSH_AUTOSUGGEST_IGNORE_WIDGETS' do
|
||||
let(:options) { ["ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(#{widget})"] }
|
||||
|
||||
it 'should not be wrapped with an autosuggest widget' do
|
||||
session.run_command("echo $widgets[#{widget}]")
|
||||
wait_for { session.content }.to end_with("\nuser:#{widget}")
|
||||
end
|
||||
end
|
||||
|
||||
context 'that moves the cursor forward' do
|
||||
before { session.run_command("#{widget}() { zle forward-char }") }
|
||||
|
||||
context 'when added to ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS' do
|
||||
let(:options) { ["ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(#{widget})"] }
|
||||
|
||||
it 'accepts the suggestion as far as the cursor is moved when invoked' do
|
||||
with_history('echo hello') do
|
||||
session.send_string('e')
|
||||
wait_for { session.content }.to start_with('echo hello')
|
||||
session.send_keys('C-b')
|
||||
wait_for { session.content(esc_seqs: true) }.to match(/\Aec\e\[[0-9]+mho hello/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'that modifies the buffer' do
|
||||
before { session.run_command("#{widget}() { BUFFER=\"foo\" }") }
|
||||
|
||||
context 'when not added to any of the widget lists' do
|
||||
it 'modifies the buffer and fetches a new suggestion' do
|
||||
with_history('foobar') do
|
||||
session.send_keys('C-b')
|
||||
wait_for { session.content }.to eq('foobar')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'a modification to the widget lists' do
|
||||
let(:widget) { 'my-widget' }
|
||||
let(:before_sourcing) { -> { session.run_command("#{widget}() {}; zle -N #{widget}; bindkey ^B #{widget}") } }
|
||||
before { session.run_command("ZSH_AUTOSUGGEST_ACCEPT_WIDGETS+=(#{widget})") }
|
||||
|
||||
it 'takes effect on the next cmd line' do
|
||||
with_history('echo hello') do
|
||||
session.send_string('e')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
session.send_keys('C-b')
|
||||
wait_for { session.content(esc_seqs: true) }.to eq('echo hello')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when manual rebind is enabled' do
|
||||
let(:options) { ["ZSH_AUTOSUGGEST_MANUAL_REBIND=true"] }
|
||||
|
||||
it 'does not take effect until bind command is re-run' do
|
||||
with_history('echo hello') do
|
||||
session.send_string('e')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
session.send_keys('C-b')
|
||||
sleep 1
|
||||
expect(session.content(esc_seqs: true)).not_to eq('echo hello')
|
||||
|
||||
session.send_keys('C-c')
|
||||
session.run_command('_zsh_autosuggest_bind_widgets').clear_screen
|
||||
wait_for { session.content }.to eq('')
|
||||
|
||||
session.send_string('e')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
session.send_keys('C-b')
|
||||
wait_for { session.content(esc_seqs: true) }.to eq('echo hello')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,54 @@
|
||||
require 'pry'
|
||||
require 'rspec/wait'
|
||||
require 'terminal_session'
|
||||
require 'tempfile'
|
||||
|
||||
RSpec.shared_context 'terminal session' do
|
||||
let(:term_opts) { {} }
|
||||
let(:session) { TerminalSession.new(term_opts) }
|
||||
let(:before_sourcing) { -> {} }
|
||||
let(:after_sourcing) { -> {} }
|
||||
let(:options) { [] }
|
||||
|
||||
around do |example|
|
||||
before_sourcing.call
|
||||
session.run_command(['source zsh-autosuggestions.zsh', *options].join('; '))
|
||||
after_sourcing.call
|
||||
session.clear_screen
|
||||
|
||||
example.run
|
||||
|
||||
session.destroy
|
||||
end
|
||||
|
||||
def with_history(*commands, &block)
|
||||
Tempfile.create do |f|
|
||||
f.write(commands.map{|c| c.gsub("\n", "\\\n")}.join("\n"))
|
||||
f.flush
|
||||
|
||||
session.run_command('fc -p')
|
||||
session.run_command("fc -R #{f.path}")
|
||||
|
||||
session.clear_screen
|
||||
|
||||
yield block
|
||||
|
||||
session.send_keys('C-c')
|
||||
session.run_command('fc -P')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.expect_with :rspec do |expectations|
|
||||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
||||
end
|
||||
|
||||
config.mock_with :rspec do |mocks|
|
||||
mocks.verify_partial_doubles = true
|
||||
end
|
||||
|
||||
config.wait_timeout = 2
|
||||
|
||||
config.include_context 'terminal session'
|
||||
end
|
@ -0,0 +1,72 @@
|
||||
describe 'the `completion` suggestion strategy' do
|
||||
let(:options) { ['ZSH_AUTOSUGGEST_STRATEGY=completion'] }
|
||||
let(:before_sourcing) do
|
||||
-> do
|
||||
session.
|
||||
run_command('autoload compinit && compinit').
|
||||
run_command('_foo() { compadd bar; compadd bat }').
|
||||
run_command('_num() { compadd two; compadd three }').
|
||||
run_command('compdef _foo baz').
|
||||
run_command('compdef _num one')
|
||||
end
|
||||
end
|
||||
|
||||
it 'suggests the first completion result' do
|
||||
session.send_string('baz ')
|
||||
wait_for { session.content }.to eq('baz bar')
|
||||
end
|
||||
|
||||
it 'does not add extra carriage returns when prefix has a line feed' do
|
||||
skip '`stty` does not work inside zpty below zsh version 5.0.3' if session.zsh_version < Gem::Version.new('5.0.3')
|
||||
session.send_string('baz \\').send_keys('C-v', 'C-j')
|
||||
wait_for { session.content }.to eq("baz \\\nbar")
|
||||
end
|
||||
|
||||
context 'when `_complete` is aliased' do
|
||||
let(:before_sourcing) do
|
||||
-> do
|
||||
session.
|
||||
run_command('autoload compinit && compinit').
|
||||
run_command('_foo() { compadd bar; compadd bat }').
|
||||
run_command('compdef _foo baz').
|
||||
run_command('alias _complete=_complete')
|
||||
end
|
||||
end
|
||||
|
||||
it 'suggests the first completion result' do
|
||||
session.send_string('baz ')
|
||||
wait_for { session.content }.to eq('baz bar')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ZSH_AUTOSUGGEST_COMPLETION_IGNORE is set to a pattern' do
|
||||
let(:options) { ['ZSH_AUTOSUGGEST_STRATEGY=completion', 'ZSH_AUTOSUGGEST_COMPLETION_IGNORE="one *"'] }
|
||||
|
||||
it 'makes suggestions when the buffer does not match the pattern' do
|
||||
session.send_string('baz ')
|
||||
wait_for { session.content }.to eq('baz bar')
|
||||
end
|
||||
|
||||
it 'does not make suggestions when the buffer matches the pattern' do
|
||||
session.send_string('one t')
|
||||
sleep 1
|
||||
expect(session.content).to eq('one t')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when async mode is enabled' do
|
||||
let(:options) { ['ZSH_AUTOSUGGEST_USE_ASYNC=true', 'ZSH_AUTOSUGGEST_STRATEGY=completion'] }
|
||||
|
||||
it 'suggests the first completion result' do
|
||||
session.send_string('baz ')
|
||||
wait_for { session.content }.to eq('baz bar')
|
||||
end
|
||||
|
||||
it 'does not add extra carriage returns when prefix has a line feed' do
|
||||
skip '`stty` does not work inside zpty below zsh version 5.0.3' if session.zsh_version < Gem::Version.new('5.0.3')
|
||||
session.send_string('baz \\').send_keys('C-v', 'C-j')
|
||||
wait_for { session.content }.to eq("baz \\\nbar")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,23 @@
|
||||
require 'strategies/special_characters_helper'
|
||||
|
||||
describe 'the `history` suggestion strategy' do
|
||||
it 'suggests the last matching history entry' do
|
||||
with_history('ls foo', 'ls bar', 'echo baz') do
|
||||
session.send_string('ls')
|
||||
wait_for { session.content }.to eq('ls bar')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ZSH_AUTOSUGGEST_HISTORY_IGNORE is set to a pattern' do
|
||||
let(:options) { ['ZSH_AUTOSUGGEST_HISTORY_IGNORE="* bar"'] }
|
||||
|
||||
it 'does not make suggestions that match the pattern' do
|
||||
with_history('ls foo', 'ls bar', 'echo baz') do
|
||||
session.send_string('ls')
|
||||
wait_for { session.content }.to eq('ls foo')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
include_examples 'special characters'
|
||||
end
|
@ -0,0 +1,34 @@
|
||||
require 'strategies/special_characters_helper'
|
||||
|
||||
describe 'the `match_prev_cmd` strategy' do
|
||||
let(:options) { ['ZSH_AUTOSUGGEST_STRATEGY=match_prev_cmd'] }
|
||||
|
||||
let(:history) { [
|
||||
'echo what',
|
||||
'ls foo',
|
||||
'echo what',
|
||||
'ls bar',
|
||||
'ls baz',
|
||||
'echo what'
|
||||
] }
|
||||
|
||||
it 'suggests the last matching history entry after the previous command' do
|
||||
with_history(*history) do
|
||||
session.send_string('ls')
|
||||
wait_for { session.content }.to eq('ls bar')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ZSH_AUTOSUGGEST_HISTORY_IGNORE is set to a pattern' do
|
||||
let(:options) { ['ZSH_AUTOSUGGEST_STRATEGY=match_prev_cmd', 'ZSH_AUTOSUGGEST_HISTORY_IGNORE="* bar"'] }
|
||||
|
||||
it 'does not make suggestions that match the pattern' do
|
||||
with_history(*history) do
|
||||
session.send_string('ls')
|
||||
wait_for { session.content }.to eq('ls foo')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
include_examples 'special characters'
|
||||
end
|
@ -0,0 +1,75 @@
|
||||
shared_examples 'special characters' do
|
||||
describe 'a special character in the buffer should be treated like any other character' do
|
||||
it 'asterisk' do
|
||||
with_history('echo "hello*"', 'echo "hello."') do
|
||||
session.send_string('echo "hello*')
|
||||
wait_for { session.content }.to eq('echo "hello*"')
|
||||
end
|
||||
end
|
||||
|
||||
it 'question mark' do
|
||||
with_history('echo "hello?"', 'echo "hello."') do
|
||||
session.send_string('echo "hello?')
|
||||
wait_for { session.content }.to eq('echo "hello?"')
|
||||
end
|
||||
end
|
||||
|
||||
it 'backslash' do
|
||||
with_history('echo "hello\nworld"') do
|
||||
session.send_string('echo "hello\\')
|
||||
wait_for { session.content }.to eq('echo "hello\nworld"')
|
||||
end
|
||||
end
|
||||
|
||||
it 'double backslash' do
|
||||
with_history('echo "\\\\"') do
|
||||
session.send_string('echo "\\\\')
|
||||
wait_for { session.content }.to eq('echo "\\\\"')
|
||||
end
|
||||
end
|
||||
|
||||
it 'tilde' do
|
||||
with_history('echo ~/foo') do
|
||||
session.send_string('echo ~')
|
||||
wait_for { session.content }.to eq('echo ~/foo')
|
||||
end
|
||||
end
|
||||
|
||||
it 'parentheses' do
|
||||
with_history('echo "$(ls foo)"') do
|
||||
session.send_string('echo "$(')
|
||||
wait_for { session.content }.to eq('echo "$(ls foo)"')
|
||||
end
|
||||
end
|
||||
|
||||
it 'square bracket' do
|
||||
with_history('echo "$history[123]"') do
|
||||
session.send_string('echo "$history[')
|
||||
wait_for { session.content }.to eq('echo "$history[123]"')
|
||||
session.send_string('123]')
|
||||
wait_for { session.content }.to eq('echo "$history[123]"')
|
||||
end
|
||||
end
|
||||
|
||||
it 'octothorpe' do
|
||||
with_history('echo "#yolo"') do
|
||||
session.send_string('echo "#')
|
||||
wait_for { session.content }.to eq('echo "#yolo"')
|
||||
end
|
||||
end
|
||||
|
||||
it 'caret' do
|
||||
with_history('echo "^A"', 'echo "^B"') do
|
||||
session.send_string('echo "^A')
|
||||
wait_for { session.content }.to eq('echo "^A"')
|
||||
end
|
||||
end
|
||||
|
||||
it 'dash' do
|
||||
with_history('-foo() {}') do
|
||||
session.send_string('-')
|
||||
wait_for { session.content }.to eq('-foo() {}')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,99 @@
|
||||
require 'securerandom'
|
||||
|
||||
class TerminalSession
|
||||
ZSH_BIN = ENV['TEST_ZSH_BIN'] || 'zsh'
|
||||
|
||||
def initialize(opts = {})
|
||||
opts = {
|
||||
width: 80,
|
||||
height: 24,
|
||||
prompt: '',
|
||||
term: 'xterm-256color',
|
||||
zsh_bin: ZSH_BIN
|
||||
}.merge(opts)
|
||||
|
||||
@opts = opts
|
||||
|
||||
cmd="PS1=\"#{opts[:prompt]}\" TERM=#{opts[:term]} #{ZSH_BIN} -f"
|
||||
tmux_command("new-session -d -x #{opts[:width]} -y #{opts[:height]} '#{cmd}'")
|
||||
end
|
||||
|
||||
def zsh_version
|
||||
@zsh_version ||= Gem::Version.new(`#{ZSH_BIN} -c 'echo -n $ZSH_VERSION'`)
|
||||
end
|
||||
|
||||
def tmux_socket_name
|
||||
@tmux_socket_name ||= SecureRandom.hex(6)
|
||||
end
|
||||
|
||||
def run_command(command)
|
||||
send_string(command)
|
||||
send_keys('enter')
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
def send_string(str)
|
||||
tmux_command("send-keys -t 0 -l -- '#{str.gsub("'", "\\'")}'")
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
def send_keys(*keys)
|
||||
tmux_command("send-keys -t 0 #{keys.join(' ')}")
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
def paste_string(str)
|
||||
tmux_command("set-buffer -- '#{str}'")
|
||||
tmux_command("paste-buffer -dpr -t 0")
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
def content(esc_seqs: false)
|
||||
cmd = 'capture-pane -p -t 0'
|
||||
cmd += ' -e' if esc_seqs
|
||||
tmux_command(cmd).strip
|
||||
end
|
||||
|
||||
def clear_screen
|
||||
send_keys('C-l')
|
||||
|
||||
i = 0
|
||||
until content == opts[:prompt] || i > 20 do
|
||||
sleep(0.1)
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
def destroy
|
||||
tmux_command('kill-session')
|
||||
end
|
||||
|
||||
def cursor
|
||||
tmux_command("display-message -t 0 -p '\#{cursor_x},\#{cursor_y}'").
|
||||
strip.
|
||||
split(',').
|
||||
map(&:to_i)
|
||||
end
|
||||
|
||||
def attach!
|
||||
tmux_command('attach-session')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :opts
|
||||
|
||||
def tmux_command(cmd)
|
||||
out = `tmux -u -L #{tmux_socket_name} #{cmd}`
|
||||
|
||||
raise("tmux error running: '#{cmd}'") unless $?.success?
|
||||
|
||||
out
|
||||
end
|
||||
end
|
@ -0,0 +1,19 @@
|
||||
describe 'the `autosuggest-disable` widget' do
|
||||
before do
|
||||
session.run_command('bindkey ^B autosuggest-disable')
|
||||
end
|
||||
|
||||
it 'disables suggestions and clears the suggestion' do
|
||||
with_history('echo hello') do
|
||||
session.send_string('echo')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
|
||||
session.send_keys('C-b')
|
||||
wait_for { session.content }.to eq('echo')
|
||||
|
||||
session.send_string(' h')
|
||||
sleep 1
|
||||
expect(session.content).to eq('echo h')
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,42 @@
|
||||
describe 'the `autosuggest-enable` widget' do
|
||||
before do
|
||||
session.
|
||||
run_command('typeset -g _ZSH_AUTOSUGGEST_DISABLED').
|
||||
run_command('bindkey ^B autosuggest-enable')
|
||||
end
|
||||
|
||||
it 'enables suggestions and fetches a suggestion' do
|
||||
with_history('echo hello') do
|
||||
session.send_string('e')
|
||||
sleep 1
|
||||
expect(session.content).to eq('e')
|
||||
|
||||
session.send_keys('C-b')
|
||||
session.send_string('c')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
end
|
||||
end
|
||||
|
||||
context 'invoked on an empty buffer' do
|
||||
it 'does not fetch a suggestion' do
|
||||
with_history('echo hello') do
|
||||
session.send_keys('C-b')
|
||||
sleep 1
|
||||
expect(session.content).to eq('')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'invoked on a non-empty buffer' do
|
||||
it 'fetches a suggestion' do
|
||||
with_history('echo hello') do
|
||||
session.send_string('e')
|
||||
sleep 1
|
||||
expect(session.content).to eq('e')
|
||||
|
||||
session.send_keys('C-b')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,24 @@
|
||||
describe 'the `autosuggest-fetch` widget' do
|
||||
context 'when suggestions are disabled' do
|
||||
before do
|
||||
session.
|
||||
run_command('bindkey ^B autosuggest-disable').
|
||||
run_command('bindkey ^F autosuggest-fetch').
|
||||
send_keys('C-b')
|
||||
end
|
||||
|
||||
it 'will fetch and display a suggestion' do
|
||||
with_history('echo hello') do
|
||||
session.send_string('echo h')
|
||||
sleep 1
|
||||
expect(session.content).to eq('echo h')
|
||||
|
||||
session.send_keys('C-f')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
|
||||
session.send_string('e')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,26 @@
|
||||
describe 'the `autosuggest-toggle` widget' do
|
||||
before do
|
||||
session.run_command('bindkey ^B autosuggest-toggle')
|
||||
end
|
||||
|
||||
it 'toggles suggestions' do
|
||||
with_history('echo world', 'echo hello') do
|
||||
session.send_string('echo')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
|
||||
session.send_keys('C-b')
|
||||
wait_for { session.content }.to eq('echo')
|
||||
|
||||
session.send_string(' h')
|
||||
sleep 1
|
||||
expect(session.content).to eq('echo h')
|
||||
|
||||
session.send_keys('C-b')
|
||||
wait_for { session.content }.to eq('echo hello')
|
||||
|
||||
session.send_keys('C-h')
|
||||
session.send_string('w')
|
||||
wait_for { session.content }.to eq('echo world')
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,76 @@
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Async #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
_zsh_autosuggest_async_request() {
|
||||
zmodload zsh/system 2>/dev/null # For `$sysparams`
|
||||
|
||||
typeset -g _ZSH_AUTOSUGGEST_ASYNC_FD _ZSH_AUTOSUGGEST_CHILD_PID
|
||||
|
||||
# If we've got a pending request, cancel it
|
||||
if [[ -n "$_ZSH_AUTOSUGGEST_ASYNC_FD" ]] && { true <&$_ZSH_AUTOSUGGEST_ASYNC_FD } 2>/dev/null; then
|
||||
# Close the file descriptor and remove the handler
|
||||
exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&-
|
||||
zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD
|
||||
|
||||
# We won't know the pid unless the user has zsh/system module installed
|
||||
if [[ -n "$_ZSH_AUTOSUGGEST_CHILD_PID" ]]; then
|
||||
# Zsh will make a new process group for the child process only if job
|
||||
# control is enabled (MONITOR option)
|
||||
if [[ -o MONITOR ]]; then
|
||||
# Send the signal to the process group to kill any processes that may
|
||||
# have been forked by the suggestion strategy
|
||||
kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
||||
else
|
||||
# Kill just the child process since it wasn't placed in a new process
|
||||
# group. If the suggestion strategy forked any child processes they may
|
||||
# be orphaned and left behind.
|
||||
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Fork a process to fetch a suggestion and open a pipe to read from it
|
||||
exec {_ZSH_AUTOSUGGEST_ASYNC_FD}< <(
|
||||
# Tell parent process our pid
|
||||
echo $sysparams[pid]
|
||||
|
||||
# Fetch and print the suggestion
|
||||
local suggestion
|
||||
_zsh_autosuggest_fetch_suggestion "$1"
|
||||
echo -nE "$suggestion"
|
||||
)
|
||||
|
||||
# There's a weird bug here where ^C stops working unless we force a fork
|
||||
# See https://github.com/zsh-users/zsh-autosuggestions/issues/364
|
||||
autoload -Uz is-at-least
|
||||
is-at-least 5.8 || command true
|
||||
|
||||
# Read the pid from the child process
|
||||
read _ZSH_AUTOSUGGEST_CHILD_PID <&$_ZSH_AUTOSUGGEST_ASYNC_FD
|
||||
|
||||
# When the fd is readable, call the response handler
|
||||
zle -F "$_ZSH_AUTOSUGGEST_ASYNC_FD" _zsh_autosuggest_async_response
|
||||
}
|
||||
|
||||
# Called when new data is ready to be read from the pipe
|
||||
# First arg will be fd ready for reading
|
||||
# Second arg will be passed in case of error
|
||||
_zsh_autosuggest_async_response() {
|
||||
emulate -L zsh
|
||||
|
||||
local suggestion
|
||||
|
||||
if [[ -z "$2" || "$2" == "hup" ]]; then
|
||||
# Read everything from the fd and give it as a suggestion
|
||||
IFS='' read -rd '' -u $1 suggestion
|
||||
zle autosuggest-suggest -- "$suggestion"
|
||||
|
||||
# Close the fd
|
||||
exec {1}<&-
|
||||
fi
|
||||
|
||||
# Always remove the handler
|
||||
zle -F "$1"
|
||||
}
|
106
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/src/bind.zsh
Normal file
106
zsh/.oh-my-zsh/custom/plugins/zsh-autosuggestions/src/bind.zsh
Normal file
@ -0,0 +1,106 @@
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Widget Helpers #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
_zsh_autosuggest_incr_bind_count() {
|
||||
typeset -gi bind_count=$((_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]+1))
|
||||
_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=$bind_count
|
||||
}
|
||||
|
||||
# Bind a single widget to an autosuggest widget, saving a reference to the original widget
|
||||
_zsh_autosuggest_bind_widget() {
|
||||
typeset -gA _ZSH_AUTOSUGGEST_BIND_COUNTS
|
||||
|
||||
local widget=$1
|
||||
local autosuggest_action=$2
|
||||
local prefix=$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX
|
||||
|
||||
local -i bind_count
|
||||
|
||||
# Save a reference to the original widget
|
||||
case $widgets[$widget] in
|
||||
# Already bound
|
||||
user:_zsh_autosuggest_(bound|orig)_*)
|
||||
bind_count=$((_ZSH_AUTOSUGGEST_BIND_COUNTS[$widget]))
|
||||
;;
|
||||
|
||||
# User-defined widget
|
||||
user:*)
|
||||
_zsh_autosuggest_incr_bind_count $widget
|
||||
zle -N $prefix$bind_count-$widget ${widgets[$widget]#*:}
|
||||
;;
|
||||
|
||||
# Built-in widget
|
||||
builtin)
|
||||
_zsh_autosuggest_incr_bind_count $widget
|
||||
eval "_zsh_autosuggest_orig_${(q)widget}() { zle .${(q)widget} }"
|
||||
zle -N $prefix$bind_count-$widget _zsh_autosuggest_orig_$widget
|
||||
;;
|
||||
|
||||
# Completion widget
|
||||
completion:*)
|
||||
_zsh_autosuggest_incr_bind_count $widget
|
||||
eval "zle -C $prefix$bind_count-${(q)widget} ${${(s.:.)widgets[$widget]}[2,3]}"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Pass the original widget's name explicitly into the autosuggest
|
||||
# function. Use this passed in widget name to call the original
|
||||
# widget instead of relying on the $WIDGET variable being set
|
||||
# correctly. $WIDGET cannot be trusted because other plugins call
|
||||
# zle without the `-w` flag (e.g. `zle self-insert` instead of
|
||||
# `zle self-insert -w`).
|
||||
eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() {
|
||||
_zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@
|
||||
}"
|
||||
|
||||
# Create the bound widget
|
||||
zle -N -- $widget _zsh_autosuggest_bound_${bind_count}_$widget
|
||||
}
|
||||
|
||||
# Map all configured widgets to the right autosuggest widgets
|
||||
_zsh_autosuggest_bind_widgets() {
|
||||
emulate -L zsh
|
||||
|
||||
local widget
|
||||
local ignore_widgets
|
||||
|
||||
ignore_widgets=(
|
||||
.\*
|
||||
_\*
|
||||
${_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS/#/autosuggest-}
|
||||
$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
|
||||
$ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
||||
)
|
||||
|
||||
# Find every widget we might want to bind and bind it appropriately
|
||||
for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do
|
||||
if [[ -n ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]]; then
|
||||
_zsh_autosuggest_bind_widget $widget clear
|
||||
elif [[ -n ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]]; then
|
||||
_zsh_autosuggest_bind_widget $widget accept
|
||||
elif [[ -n ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]]; then
|
||||
_zsh_autosuggest_bind_widget $widget execute
|
||||
elif [[ -n ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]]; then
|
||||
_zsh_autosuggest_bind_widget $widget partial_accept
|
||||
else
|
||||
# Assume any unspecified widget might modify the buffer
|
||||
_zsh_autosuggest_bind_widget $widget modify
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Given the name of an original widget and args, invoke it, if it exists
|
||||
_zsh_autosuggest_invoke_original_widget() {
|
||||
# Do nothing unless called with at least one arg
|
||||
(( $# )) || return 0
|
||||
|
||||
local original_widget_name="$1"
|
||||
|
||||
shift
|
||||
|
||||
if (( ${+widgets[$original_widget_name]} )); then
|
||||
zle $original_widget_name -- $@
|
||||
fi
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Global Configuration Variables #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Color to use when highlighting suggestion
|
||||
# Uses format of `region_highlight`
|
||||
# More info: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Widgets
|
||||
(( ! ${+ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE} )) &&
|
||||
typeset -g ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'
|
||||
|
||||
# Prefix to use when saving original versions of bound widgets
|
||||
(( ! ${+ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX} )) &&
|
||||
typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
|
||||
|
||||
# Strategies to use to fetch a suggestion
|
||||
# Will try each strategy in order until a suggestion is returned
|
||||
(( ! ${+ZSH_AUTOSUGGEST_STRATEGY} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_STRATEGY
|
||||
ZSH_AUTOSUGGEST_STRATEGY=(history)
|
||||
}
|
||||
|
||||
# Widgets that clear the suggestion
|
||||
(( ! ${+ZSH_AUTOSUGGEST_CLEAR_WIDGETS} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_CLEAR_WIDGETS
|
||||
ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(
|
||||
history-search-forward
|
||||
history-search-backward
|
||||
history-beginning-search-forward
|
||||
history-beginning-search-backward
|
||||
history-substring-search-up
|
||||
history-substring-search-down
|
||||
up-line-or-beginning-search
|
||||
down-line-or-beginning-search
|
||||
up-line-or-history
|
||||
down-line-or-history
|
||||
accept-line
|
||||
copy-earlier-word
|
||||
)
|
||||
}
|
||||
|
||||
# Widgets that accept the entire suggestion
|
||||
(( ! ${+ZSH_AUTOSUGGEST_ACCEPT_WIDGETS} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_ACCEPT_WIDGETS
|
||||
ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
|
||||
forward-char
|
||||
end-of-line
|
||||
vi-forward-char
|
||||
vi-end-of-line
|
||||
vi-add-eol
|
||||
)
|
||||
}
|
||||
|
||||
# Widgets that accept the entire suggestion and execute it
|
||||
(( ! ${+ZSH_AUTOSUGGEST_EXECUTE_WIDGETS} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_EXECUTE_WIDGETS
|
||||
ZSH_AUTOSUGGEST_EXECUTE_WIDGETS=(
|
||||
)
|
||||
}
|
||||
|
||||
# Widgets that accept the suggestion as far as the cursor moves
|
||||
(( ! ${+ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS
|
||||
ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
|
||||
forward-word
|
||||
emacs-forward-word
|
||||
vi-forward-word
|
||||
vi-forward-word-end
|
||||
vi-forward-blank-word
|
||||
vi-forward-blank-word-end
|
||||
vi-find-next-char
|
||||
vi-find-next-char-skip
|
||||
)
|
||||
}
|
||||
|
||||
# Widgets that should be ignored (globbing supported but must be escaped)
|
||||
(( ! ${+ZSH_AUTOSUGGEST_IGNORE_WIDGETS} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
||||
ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(
|
||||
orig-\*
|
||||
beep
|
||||
run-help
|
||||
set-local-history
|
||||
which-command
|
||||
yank
|
||||
yank-pop
|
||||
zle-\*
|
||||
)
|
||||
}
|
||||
|
||||
# Pty name for capturing completions for completion suggestion strategy
|
||||
(( ! ${+ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME} )) &&
|
||||
typeset -g ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME=zsh_autosuggest_completion_pty
|
@ -0,0 +1,27 @@
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Fetch Suggestion #
|
||||
#--------------------------------------------------------------------#
|
||||
# Loops through all specified strategies and returns a suggestion
|
||||
# from the first strategy to provide one.
|
||||
#
|
||||
|
||||
_zsh_autosuggest_fetch_suggestion() {
|
||||
typeset -g suggestion
|
||||
local -a strategies
|
||||
local strategy
|
||||
|
||||
# Ensure we are working with an array
|
||||
strategies=(${=ZSH_AUTOSUGGEST_STRATEGY})
|
||||
|
||||
for strategy in $strategies; do
|
||||
# Try to get a suggestion from this strategy
|
||||
_zsh_autosuggest_strategy_$strategy "$1"
|
||||
|
||||
# Ensure the suggestion matches the prefix
|
||||
[[ "$suggestion" != "$1"* ]] && unset suggestion
|
||||
|
||||
# Break once we've found a valid suggestion
|
||||
[[ -n "$suggestion" ]] && break
|
||||
done
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Highlighting #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# If there was a highlight, remove it
|
||||
_zsh_autosuggest_highlight_reset() {
|
||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||
|
||||
if [[ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then
|
||||
region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
|
||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||
fi
|
||||
}
|
||||
|
||||
# If there's a suggestion, highlight it
|
||||
_zsh_autosuggest_highlight_apply() {
|
||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||
|
||||
if (( $#POSTDISPLAY )); then
|
||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
|
||||
region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT")
|
||||
else
|
||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||
fi
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Start #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Start the autosuggestion widgets
|
||||
_zsh_autosuggest_start() {
|
||||
# By default we re-bind widgets on every precmd to ensure we wrap other
|
||||
# wrappers. Specifically, highlighting breaks if our widgets are wrapped by
|
||||
# zsh-syntax-highlighting widgets. This also allows modifications to the
|
||||
# widget list variables to take effect on the next precmd. However this has
|
||||
# a decent performance hit, so users can set ZSH_AUTOSUGGEST_MANUAL_REBIND
|
||||
# to disable the automatic re-binding.
|
||||
if (( ${+ZSH_AUTOSUGGEST_MANUAL_REBIND} )); then
|
||||
add-zsh-hook -d precmd _zsh_autosuggest_start
|
||||
fi
|
||||
|
||||
_zsh_autosuggest_bind_widgets
|
||||
}
|
||||
|
||||
# Mark for auto-loading the functions that we use
|
||||
autoload -Uz add-zsh-hook is-at-least
|
||||
|
||||
# Automatically enable asynchronous mode in newer versions of zsh. Disable for
|
||||
# older versions because there is a bug when using async mode where ^C does not
|
||||
# work immediately after fetching a suggestion.
|
||||
# See https://github.com/zsh-users/zsh-autosuggestions/issues/364
|
||||
if is-at-least 5.0.8; then
|
||||
typeset -g ZSH_AUTOSUGGEST_USE_ASYNC=
|
||||
fi
|
||||
|
||||
# Start the autosuggestion widgets on the next precmd
|
||||
add-zsh-hook precmd _zsh_autosuggest_start
|
@ -0,0 +1,137 @@
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Completion Suggestion Strategy #
|
||||
#--------------------------------------------------------------------#
|
||||
# Fetches a suggestion from the completion engine
|
||||
#
|
||||
|
||||
_zsh_autosuggest_capture_postcompletion() {
|
||||
# Always insert the first completion into the buffer
|
||||
compstate[insert]=1
|
||||
|
||||
# Don't list completions
|
||||
unset 'compstate[list]'
|
||||
}
|
||||
|
||||
_zsh_autosuggest_capture_completion_widget() {
|
||||
# Add a post-completion hook to be called after all completions have been
|
||||
# gathered. The hook can modify compstate to affect what is done with the
|
||||
# gathered completions.
|
||||
local -a +h comppostfuncs
|
||||
comppostfuncs=(_zsh_autosuggest_capture_postcompletion)
|
||||
|
||||
# Only capture completions at the end of the buffer
|
||||
CURSOR=$#BUFFER
|
||||
|
||||
# Run the original widget wrapping `.complete-word` so we don't
|
||||
# recursively try to fetch suggestions, since our pty is forked
|
||||
# after autosuggestions is initialized.
|
||||
zle -- ${(k)widgets[(r)completion:.complete-word:_main_complete]}
|
||||
|
||||
if is-at-least 5.0.3; then
|
||||
# Don't do any cr/lf transformations. We need to do this immediately before
|
||||
# output because if we do it in setup, onlcr will be re-enabled when we enter
|
||||
# vared in the async code path. There is a bug in zpty module in older versions
|
||||
# where the tty is not properly attached to the pty slave, resulting in stty
|
||||
# getting stopped with a SIGTTOU. See zsh-workers thread 31660 and upstream
|
||||
# commit f75904a38
|
||||
stty -onlcr -ocrnl -F /dev/tty
|
||||
fi
|
||||
|
||||
# The completion has been added, print the buffer as the suggestion
|
||||
echo -nE - $'\0'$BUFFER$'\0'
|
||||
}
|
||||
|
||||
zle -N autosuggest-capture-completion _zsh_autosuggest_capture_completion_widget
|
||||
|
||||
_zsh_autosuggest_capture_setup() {
|
||||
# There is a bug in zpty module in older zsh versions by which a
|
||||
# zpty that exits will kill all zpty processes that were forked
|
||||
# before it. Here we set up a zsh exit hook to SIGKILL the zpty
|
||||
# process immediately, before it has a chance to kill any other
|
||||
# zpty processes.
|
||||
if ! is-at-least 5.4; then
|
||||
zshexit() {
|
||||
# The zsh builtin `kill` fails sometimes in older versions
|
||||
# https://unix.stackexchange.com/a/477647/156673
|
||||
kill -KILL $$ 2>&- || command kill -KILL $$
|
||||
|
||||
# Block for long enough for the signal to come through
|
||||
sleep 1
|
||||
}
|
||||
fi
|
||||
|
||||
# Try to avoid any suggestions that wouldn't match the prefix
|
||||
zstyle ':completion:*' matcher-list ''
|
||||
zstyle ':completion:*' path-completion false
|
||||
zstyle ':completion:*' max-errors 0 not-numeric
|
||||
|
||||
bindkey '^I' autosuggest-capture-completion
|
||||
}
|
||||
|
||||
_zsh_autosuggest_capture_completion_sync() {
|
||||
_zsh_autosuggest_capture_setup
|
||||
|
||||
zle autosuggest-capture-completion
|
||||
}
|
||||
|
||||
_zsh_autosuggest_capture_completion_async() {
|
||||
_zsh_autosuggest_capture_setup
|
||||
|
||||
zmodload zsh/parameter 2>/dev/null || return # For `$functions`
|
||||
|
||||
# Make vared completion work as if for a normal command line
|
||||
# https://stackoverflow.com/a/7057118/154703
|
||||
autoload +X _complete
|
||||
functions[_original_complete]=$functions[_complete]
|
||||
function _complete() {
|
||||
unset 'compstate[vared]'
|
||||
_original_complete "$@"
|
||||
}
|
||||
|
||||
# Open zle with buffer set so we can capture completions for it
|
||||
vared 1
|
||||
}
|
||||
|
||||
_zsh_autosuggest_strategy_completion() {
|
||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
||||
emulate -L zsh
|
||||
|
||||
# Enable extended glob for completion ignore pattern
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
typeset -g suggestion
|
||||
local line REPLY
|
||||
|
||||
# Exit if we don't have completions
|
||||
whence compdef >/dev/null || return
|
||||
|
||||
# Exit if we don't have zpty
|
||||
zmodload zsh/zpty 2>/dev/null || return
|
||||
|
||||
# Exit if our search string matches the ignore pattern
|
||||
[[ -n "$ZSH_AUTOSUGGEST_COMPLETION_IGNORE" ]] && [[ "$1" == $~ZSH_AUTOSUGGEST_COMPLETION_IGNORE ]] && return
|
||||
|
||||
# Zle will be inactive if we are in async mode
|
||||
if zle; then
|
||||
zpty $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME _zsh_autosuggest_capture_completion_sync
|
||||
else
|
||||
zpty $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME _zsh_autosuggest_capture_completion_async "\$1"
|
||||
zpty -w $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME $'\t'
|
||||
fi
|
||||
|
||||
{
|
||||
# The completion result is surrounded by null bytes, so read the
|
||||
# content between the first two null bytes.
|
||||
zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0''*'$'\0'
|
||||
|
||||
# Extract the suggestion from between the null bytes. On older
|
||||
# versions of zsh (older than 5.3), we sometimes get extra bytes after
|
||||
# the second null byte, so trim those off the end.
|
||||
# See http://www.zsh.org/mla/workers/2015/msg03290.html
|
||||
suggestion="${${(@0)line}[2]}"
|
||||
} always {
|
||||
# Destroy the pty
|
||||
zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# History Suggestion Strategy #
|
||||
#--------------------------------------------------------------------#
|
||||
# Suggests the most recent history item that matches the given
|
||||
# prefix.
|
||||
#
|
||||
|
||||
_zsh_autosuggest_strategy_history() {
|
||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
||||
emulate -L zsh
|
||||
|
||||
# Enable globbing flags so that we can use (#m) and (x~y) glob operator
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
# Escape backslashes and all of the glob operators so we can use
|
||||
# this string as a pattern to search the $history associative array.
|
||||
# - (#m) globbing flag enables setting references for match data
|
||||
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
|
||||
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
||||
|
||||
# Get the history items that match the prefix, excluding those that match
|
||||
# the ignore pattern
|
||||
local pattern="$prefix*"
|
||||
if [[ -n $ZSH_AUTOSUGGEST_HISTORY_IGNORE ]]; then
|
||||
pattern="($pattern)~($ZSH_AUTOSUGGEST_HISTORY_IGNORE)"
|
||||
fi
|
||||
|
||||
# Give the first history item matching the pattern as the suggestion
|
||||
# - (r) subscript flag makes the pattern match on values
|
||||
typeset -g suggestion="${history[(r)$pattern]}"
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Match Previous Command Suggestion Strategy #
|
||||
#--------------------------------------------------------------------#
|
||||
# Suggests the most recent history item that matches the given
|
||||
# prefix and whose preceding history item also matches the most
|
||||
# recently executed command.
|
||||
#
|
||||
# For example, suppose your history has the following entries:
|
||||
# - pwd
|
||||
# - ls foo
|
||||
# - ls bar
|
||||
# - pwd
|
||||
#
|
||||
# Given the history list above, when you type 'ls', the suggestion
|
||||
# will be 'ls foo' rather than 'ls bar' because your most recently
|
||||
# executed command (pwd) was previously followed by 'ls foo'.
|
||||
#
|
||||
# Note that this strategy won't work as expected with ZSH options that don't
|
||||
# preserve the history order such as `HIST_IGNORE_ALL_DUPS` or
|
||||
# `HIST_EXPIRE_DUPS_FIRST`.
|
||||
|
||||
_zsh_autosuggest_strategy_match_prev_cmd() {
|
||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
||||
emulate -L zsh
|
||||
|
||||
# Enable globbing flags so that we can use (#m) and (x~y) glob operator
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
|
||||
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
||||
|
||||
# Get the history items that match the prefix, excluding those that match
|
||||
# the ignore pattern
|
||||
local pattern="$prefix*"
|
||||
if [[ -n $ZSH_AUTOSUGGEST_HISTORY_IGNORE ]]; then
|
||||
pattern="($pattern)~($ZSH_AUTOSUGGEST_HISTORY_IGNORE)"
|
||||
fi
|
||||
|
||||
# Get all history event numbers that correspond to history
|
||||
# entries that match the pattern
|
||||
local history_match_keys
|
||||
history_match_keys=(${(k)history[(R)$~pattern]})
|
||||
|
||||
# By default we use the first history number (most recent history entry)
|
||||
local histkey="${history_match_keys[1]}"
|
||||
|
||||
# Get the previously executed command
|
||||
local prev_cmd="$(_zsh_autosuggest_escape_command "${history[$((HISTCMD-1))]}")"
|
||||
|
||||
# Iterate up to the first 200 history event numbers that match $prefix
|
||||
for key in "${(@)history_match_keys[1,200]}"; do
|
||||
# Stop if we ran out of history
|
||||
[[ $key -gt 1 ]] || break
|
||||
|
||||
# See if the history entry preceding the suggestion matches the
|
||||
# previous command, and use it if it does
|
||||
if [[ "${history[$((key - 1))]}" == "$prev_cmd" ]]; then
|
||||
histkey="$key"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Give back the matched history entry
|
||||
typeset -g suggestion="$history[$histkey]"
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Utility Functions #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
_zsh_autosuggest_escape_command() {
|
||||
setopt localoptions EXTENDED_GLOB
|
||||
|
||||
# Escape special chars in the string (requires EXTENDED_GLOB)
|
||||
echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}"
|
||||
}
|
@ -0,0 +1,231 @@
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Autosuggest Widget Implementations #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Disable suggestions
|
||||
_zsh_autosuggest_disable() {
|
||||
typeset -g _ZSH_AUTOSUGGEST_DISABLED
|
||||
_zsh_autosuggest_clear
|
||||
}
|
||||
|
||||
# Enable suggestions
|
||||
_zsh_autosuggest_enable() {
|
||||
unset _ZSH_AUTOSUGGEST_DISABLED
|
||||
|
||||
if (( $#BUFFER )); then
|
||||
_zsh_autosuggest_fetch
|
||||
fi
|
||||
}
|
||||
|
||||
# Toggle suggestions (enable/disable)
|
||||
_zsh_autosuggest_toggle() {
|
||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
||||
_zsh_autosuggest_enable
|
||||
else
|
||||
_zsh_autosuggest_disable
|
||||
fi
|
||||
}
|
||||
|
||||
# Clear the suggestion
|
||||
_zsh_autosuggest_clear() {
|
||||
# Remove the suggestion
|
||||
unset POSTDISPLAY
|
||||
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
}
|
||||
|
||||
# Modify the buffer and get a new suggestion
|
||||
_zsh_autosuggest_modify() {
|
||||
local -i retval
|
||||
|
||||
# Only available in zsh >= 5.4
|
||||
local -i KEYS_QUEUED_COUNT
|
||||
|
||||
# Save the contents of the buffer/postdisplay
|
||||
local orig_buffer="$BUFFER"
|
||||
local orig_postdisplay="$POSTDISPLAY"
|
||||
|
||||
# Clear suggestion while waiting for next one
|
||||
unset POSTDISPLAY
|
||||
|
||||
# Original widget may modify the buffer
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
retval=$?
|
||||
|
||||
emulate -L zsh
|
||||
|
||||
# Don't fetch a new suggestion if there's more input to be read immediately
|
||||
if (( $PENDING > 0 || $KEYS_QUEUED_COUNT > 0 )); then
|
||||
POSTDISPLAY="$orig_postdisplay"
|
||||
return $retval
|
||||
fi
|
||||
|
||||
# Optimize if manually typing in the suggestion or if buffer hasn't changed
|
||||
if [[ "$BUFFER" = "$orig_buffer"* && "$orig_postdisplay" = "${BUFFER:$#orig_buffer}"* ]]; then
|
||||
POSTDISPLAY="${orig_postdisplay:$(($#BUFFER - $#orig_buffer))}"
|
||||
return $retval
|
||||
fi
|
||||
|
||||
# Bail out if suggestions are disabled
|
||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
||||
return $?
|
||||
fi
|
||||
|
||||
# Get a new suggestion if the buffer is not empty after modification
|
||||
if (( $#BUFFER > 0 )); then
|
||||
if [[ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= $ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE )); then
|
||||
_zsh_autosuggest_fetch
|
||||
fi
|
||||
fi
|
||||
|
||||
return $retval
|
||||
}
|
||||
|
||||
# Fetch a new suggestion based on what's currently in the buffer
|
||||
_zsh_autosuggest_fetch() {
|
||||
if (( ${+ZSH_AUTOSUGGEST_USE_ASYNC} )); then
|
||||
_zsh_autosuggest_async_request "$BUFFER"
|
||||
else
|
||||
local suggestion
|
||||
_zsh_autosuggest_fetch_suggestion "$BUFFER"
|
||||
_zsh_autosuggest_suggest "$suggestion"
|
||||
fi
|
||||
}
|
||||
|
||||
# Offer a suggestion
|
||||
_zsh_autosuggest_suggest() {
|
||||
emulate -L zsh
|
||||
|
||||
local suggestion="$1"
|
||||
|
||||
if [[ -n "$suggestion" ]] && (( $#BUFFER )); then
|
||||
POSTDISPLAY="${suggestion#$BUFFER}"
|
||||
else
|
||||
unset POSTDISPLAY
|
||||
fi
|
||||
}
|
||||
|
||||
# Accept the entire suggestion
|
||||
_zsh_autosuggest_accept() {
|
||||
local -i retval max_cursor_pos=$#BUFFER
|
||||
|
||||
# When vicmd keymap is active, the cursor can't move all the way
|
||||
# to the end of the buffer
|
||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||
max_cursor_pos=$((max_cursor_pos - 1))
|
||||
fi
|
||||
|
||||
# If we're not in a valid state to accept a suggestion, just run the
|
||||
# original widget and bail out
|
||||
if (( $CURSOR != $max_cursor_pos || !$#POSTDISPLAY )); then
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
return
|
||||
fi
|
||||
|
||||
# Only accept if the cursor is at the end of the buffer
|
||||
# Add the suggestion to the buffer
|
||||
BUFFER="$BUFFER$POSTDISPLAY"
|
||||
|
||||
# Remove the suggestion
|
||||
unset POSTDISPLAY
|
||||
|
||||
# Run the original widget before manually moving the cursor so that the
|
||||
# cursor movement doesn't make the widget do something unexpected
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
retval=$?
|
||||
|
||||
# Move the cursor to the end of the buffer
|
||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||
CURSOR=$(($#BUFFER - 1))
|
||||
else
|
||||
CURSOR=$#BUFFER
|
||||
fi
|
||||
|
||||
return $retval
|
||||
}
|
||||
|
||||
# Accept the entire suggestion and execute it
|
||||
_zsh_autosuggest_execute() {
|
||||
# Add the suggestion to the buffer
|
||||
BUFFER="$BUFFER$POSTDISPLAY"
|
||||
|
||||
# Remove the suggestion
|
||||
unset POSTDISPLAY
|
||||
|
||||
# Call the original `accept-line` to handle syntax highlighting or
|
||||
# other potential custom behavior
|
||||
_zsh_autosuggest_invoke_original_widget "accept-line"
|
||||
}
|
||||
|
||||
# Partially accept the suggestion
|
||||
_zsh_autosuggest_partial_accept() {
|
||||
local -i retval cursor_loc
|
||||
|
||||
# Save the contents of the buffer so we can restore later if needed
|
||||
local original_buffer="$BUFFER"
|
||||
|
||||
# Temporarily accept the suggestion.
|
||||
BUFFER="$BUFFER$POSTDISPLAY"
|
||||
|
||||
# Original widget moves the cursor
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
retval=$?
|
||||
|
||||
# Normalize cursor location across vi/emacs modes
|
||||
cursor_loc=$CURSOR
|
||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||
cursor_loc=$((cursor_loc + 1))
|
||||
fi
|
||||
|
||||
# If we've moved past the end of the original buffer
|
||||
if (( $cursor_loc > $#original_buffer )); then
|
||||
# Set POSTDISPLAY to text right of the cursor
|
||||
POSTDISPLAY="${BUFFER[$(($cursor_loc + 1)),$#BUFFER]}"
|
||||
|
||||
# Clip the buffer at the cursor
|
||||
BUFFER="${BUFFER[1,$cursor_loc]}"
|
||||
else
|
||||
# Restore the original buffer
|
||||
BUFFER="$original_buffer"
|
||||
fi
|
||||
|
||||
return $retval
|
||||
}
|
||||
|
||||
() {
|
||||
typeset -ga _ZSH_AUTOSUGGEST_BUILTIN_ACTIONS
|
||||
|
||||
_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS=(
|
||||
clear
|
||||
fetch
|
||||
suggest
|
||||
accept
|
||||
execute
|
||||
enable
|
||||
disable
|
||||
toggle
|
||||
)
|
||||
|
||||
local action
|
||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS modify partial_accept; do
|
||||
eval "_zsh_autosuggest_widget_$action() {
|
||||
local -i retval
|
||||
|
||||
_zsh_autosuggest_highlight_reset
|
||||
|
||||
_zsh_autosuggest_$action \$@
|
||||
retval=\$?
|
||||
|
||||
_zsh_autosuggest_highlight_apply
|
||||
|
||||
zle -R
|
||||
|
||||
return \$retval
|
||||
}"
|
||||
done
|
||||
|
||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS; do
|
||||
zle -N autosuggest-$action _zsh_autosuggest_widget_$action
|
||||
done
|
||||
}
|
@ -0,0 +1 @@
|
||||
source ${0:A:h}/zsh-autosuggestions.zsh
|
@ -0,0 +1,864 @@
|
||||
# Fish-like fast/unobtrusive autosuggestions for zsh.
|
||||
# https://github.com/zsh-users/zsh-autosuggestions
|
||||
# v0.7.0
|
||||
# Copyright (c) 2013 Thiago de Arruda
|
||||
# Copyright (c) 2016-2021 Eric Freese
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person
|
||||
# obtaining a copy of this software and associated documentation
|
||||
# files (the "Software"), to deal in the Software without
|
||||
# restriction, including without limitation the rights to use,
|
||||
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the
|
||||
# Software is furnished to do so, subject to the following
|
||||
# conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
# OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Global Configuration Variables #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Color to use when highlighting suggestion
|
||||
# Uses format of `region_highlight`
|
||||
# More info: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Widgets
|
||||
(( ! ${+ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE} )) &&
|
||||
typeset -g ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'
|
||||
|
||||
# Prefix to use when saving original versions of bound widgets
|
||||
(( ! ${+ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX} )) &&
|
||||
typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
|
||||
|
||||
# Strategies to use to fetch a suggestion
|
||||
# Will try each strategy in order until a suggestion is returned
|
||||
(( ! ${+ZSH_AUTOSUGGEST_STRATEGY} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_STRATEGY
|
||||
ZSH_AUTOSUGGEST_STRATEGY=(history)
|
||||
}
|
||||
|
||||
# Widgets that clear the suggestion
|
||||
(( ! ${+ZSH_AUTOSUGGEST_CLEAR_WIDGETS} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_CLEAR_WIDGETS
|
||||
ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(
|
||||
history-search-forward
|
||||
history-search-backward
|
||||
history-beginning-search-forward
|
||||
history-beginning-search-backward
|
||||
history-substring-search-up
|
||||
history-substring-search-down
|
||||
up-line-or-beginning-search
|
||||
down-line-or-beginning-search
|
||||
up-line-or-history
|
||||
down-line-or-history
|
||||
accept-line
|
||||
copy-earlier-word
|
||||
)
|
||||
}
|
||||
|
||||
# Widgets that accept the entire suggestion
|
||||
(( ! ${+ZSH_AUTOSUGGEST_ACCEPT_WIDGETS} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_ACCEPT_WIDGETS
|
||||
ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
|
||||
forward-char
|
||||
end-of-line
|
||||
vi-forward-char
|
||||
vi-end-of-line
|
||||
vi-add-eol
|
||||
)
|
||||
}
|
||||
|
||||
# Widgets that accept the entire suggestion and execute it
|
||||
(( ! ${+ZSH_AUTOSUGGEST_EXECUTE_WIDGETS} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_EXECUTE_WIDGETS
|
||||
ZSH_AUTOSUGGEST_EXECUTE_WIDGETS=(
|
||||
)
|
||||
}
|
||||
|
||||
# Widgets that accept the suggestion as far as the cursor moves
|
||||
(( ! ${+ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS
|
||||
ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
|
||||
forward-word
|
||||
emacs-forward-word
|
||||
vi-forward-word
|
||||
vi-forward-word-end
|
||||
vi-forward-blank-word
|
||||
vi-forward-blank-word-end
|
||||
vi-find-next-char
|
||||
vi-find-next-char-skip
|
||||
)
|
||||
}
|
||||
|
||||
# Widgets that should be ignored (globbing supported but must be escaped)
|
||||
(( ! ${+ZSH_AUTOSUGGEST_IGNORE_WIDGETS} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
||||
ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(
|
||||
orig-\*
|
||||
beep
|
||||
run-help
|
||||
set-local-history
|
||||
which-command
|
||||
yank
|
||||
yank-pop
|
||||
zle-\*
|
||||
)
|
||||
}
|
||||
|
||||
# Pty name for capturing completions for completion suggestion strategy
|
||||
(( ! ${+ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME} )) &&
|
||||
typeset -g ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME=zsh_autosuggest_completion_pty
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Utility Functions #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
_zsh_autosuggest_escape_command() {
|
||||
setopt localoptions EXTENDED_GLOB
|
||||
|
||||
# Escape special chars in the string (requires EXTENDED_GLOB)
|
||||
echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}"
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Widget Helpers #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
_zsh_autosuggest_incr_bind_count() {
|
||||
typeset -gi bind_count=$((_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]+1))
|
||||
_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=$bind_count
|
||||
}
|
||||
|
||||
# Bind a single widget to an autosuggest widget, saving a reference to the original widget
|
||||
_zsh_autosuggest_bind_widget() {
|
||||
typeset -gA _ZSH_AUTOSUGGEST_BIND_COUNTS
|
||||
|
||||
local widget=$1
|
||||
local autosuggest_action=$2
|
||||
local prefix=$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX
|
||||
|
||||
local -i bind_count
|
||||
|
||||
# Save a reference to the original widget
|
||||
case $widgets[$widget] in
|
||||
# Already bound
|
||||
user:_zsh_autosuggest_(bound|orig)_*)
|
||||
bind_count=$((_ZSH_AUTOSUGGEST_BIND_COUNTS[$widget]))
|
||||
;;
|
||||
|
||||
# User-defined widget
|
||||
user:*)
|
||||
_zsh_autosuggest_incr_bind_count $widget
|
||||
zle -N $prefix$bind_count-$widget ${widgets[$widget]#*:}
|
||||
;;
|
||||
|
||||
# Built-in widget
|
||||
builtin)
|
||||
_zsh_autosuggest_incr_bind_count $widget
|
||||
eval "_zsh_autosuggest_orig_${(q)widget}() { zle .${(q)widget} }"
|
||||
zle -N $prefix$bind_count-$widget _zsh_autosuggest_orig_$widget
|
||||
;;
|
||||
|
||||
# Completion widget
|
||||
completion:*)
|
||||
_zsh_autosuggest_incr_bind_count $widget
|
||||
eval "zle -C $prefix$bind_count-${(q)widget} ${${(s.:.)widgets[$widget]}[2,3]}"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Pass the original widget's name explicitly into the autosuggest
|
||||
# function. Use this passed in widget name to call the original
|
||||
# widget instead of relying on the $WIDGET variable being set
|
||||
# correctly. $WIDGET cannot be trusted because other plugins call
|
||||
# zle without the `-w` flag (e.g. `zle self-insert` instead of
|
||||
# `zle self-insert -w`).
|
||||
eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() {
|
||||
_zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@
|
||||
}"
|
||||
|
||||
# Create the bound widget
|
||||
zle -N -- $widget _zsh_autosuggest_bound_${bind_count}_$widget
|
||||
}
|
||||
|
||||
# Map all configured widgets to the right autosuggest widgets
|
||||
_zsh_autosuggest_bind_widgets() {
|
||||
emulate -L zsh
|
||||
|
||||
local widget
|
||||
local ignore_widgets
|
||||
|
||||
ignore_widgets=(
|
||||
.\*
|
||||
_\*
|
||||
${_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS/#/autosuggest-}
|
||||
$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
|
||||
$ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
||||
)
|
||||
|
||||
# Find every widget we might want to bind and bind it appropriately
|
||||
for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do
|
||||
if [[ -n ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]]; then
|
||||
_zsh_autosuggest_bind_widget $widget clear
|
||||
elif [[ -n ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]]; then
|
||||
_zsh_autosuggest_bind_widget $widget accept
|
||||
elif [[ -n ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]]; then
|
||||
_zsh_autosuggest_bind_widget $widget execute
|
||||
elif [[ -n ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]]; then
|
||||
_zsh_autosuggest_bind_widget $widget partial_accept
|
||||
else
|
||||
# Assume any unspecified widget might modify the buffer
|
||||
_zsh_autosuggest_bind_widget $widget modify
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Given the name of an original widget and args, invoke it, if it exists
|
||||
_zsh_autosuggest_invoke_original_widget() {
|
||||
# Do nothing unless called with at least one arg
|
||||
(( $# )) || return 0
|
||||
|
||||
local original_widget_name="$1"
|
||||
|
||||
shift
|
||||
|
||||
if (( ${+widgets[$original_widget_name]} )); then
|
||||
zle $original_widget_name -- $@
|
||||
fi
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Highlighting #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# If there was a highlight, remove it
|
||||
_zsh_autosuggest_highlight_reset() {
|
||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||
|
||||
if [[ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then
|
||||
region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
|
||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||
fi
|
||||
}
|
||||
|
||||
# If there's a suggestion, highlight it
|
||||
_zsh_autosuggest_highlight_apply() {
|
||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||
|
||||
if (( $#POSTDISPLAY )); then
|
||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
|
||||
region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT")
|
||||
else
|
||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||
fi
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Autosuggest Widget Implementations #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Disable suggestions
|
||||
_zsh_autosuggest_disable() {
|
||||
typeset -g _ZSH_AUTOSUGGEST_DISABLED
|
||||
_zsh_autosuggest_clear
|
||||
}
|
||||
|
||||
# Enable suggestions
|
||||
_zsh_autosuggest_enable() {
|
||||
unset _ZSH_AUTOSUGGEST_DISABLED
|
||||
|
||||
if (( $#BUFFER )); then
|
||||
_zsh_autosuggest_fetch
|
||||
fi
|
||||
}
|
||||
|
||||
# Toggle suggestions (enable/disable)
|
||||
_zsh_autosuggest_toggle() {
|
||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
||||
_zsh_autosuggest_enable
|
||||
else
|
||||
_zsh_autosuggest_disable
|
||||
fi
|
||||
}
|
||||
|
||||
# Clear the suggestion
|
||||
_zsh_autosuggest_clear() {
|
||||
# Remove the suggestion
|
||||
unset POSTDISPLAY
|
||||
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
}
|
||||
|
||||
# Modify the buffer and get a new suggestion
|
||||
_zsh_autosuggest_modify() {
|
||||
local -i retval
|
||||
|
||||
# Only available in zsh >= 5.4
|
||||
local -i KEYS_QUEUED_COUNT
|
||||
|
||||
# Save the contents of the buffer/postdisplay
|
||||
local orig_buffer="$BUFFER"
|
||||
local orig_postdisplay="$POSTDISPLAY"
|
||||
|
||||
# Clear suggestion while waiting for next one
|
||||
unset POSTDISPLAY
|
||||
|
||||
# Original widget may modify the buffer
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
retval=$?
|
||||
|
||||
emulate -L zsh
|
||||
|
||||
# Don't fetch a new suggestion if there's more input to be read immediately
|
||||
if (( $PENDING > 0 || $KEYS_QUEUED_COUNT > 0 )); then
|
||||
POSTDISPLAY="$orig_postdisplay"
|
||||
return $retval
|
||||
fi
|
||||
|
||||
# Optimize if manually typing in the suggestion or if buffer hasn't changed
|
||||
if [[ "$BUFFER" = "$orig_buffer"* && "$orig_postdisplay" = "${BUFFER:$#orig_buffer}"* ]]; then
|
||||
POSTDISPLAY="${orig_postdisplay:$(($#BUFFER - $#orig_buffer))}"
|
||||
return $retval
|
||||
fi
|
||||
|
||||
# Bail out if suggestions are disabled
|
||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
||||
return $?
|
||||
fi
|
||||
|
||||
# Get a new suggestion if the buffer is not empty after modification
|
||||
if (( $#BUFFER > 0 )); then
|
||||
if [[ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= $ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE )); then
|
||||
_zsh_autosuggest_fetch
|
||||
fi
|
||||
fi
|
||||
|
||||
return $retval
|
||||
}
|
||||
|
||||
# Fetch a new suggestion based on what's currently in the buffer
|
||||
_zsh_autosuggest_fetch() {
|
||||
if (( ${+ZSH_AUTOSUGGEST_USE_ASYNC} )); then
|
||||
_zsh_autosuggest_async_request "$BUFFER"
|
||||
else
|
||||
local suggestion
|
||||
_zsh_autosuggest_fetch_suggestion "$BUFFER"
|
||||
_zsh_autosuggest_suggest "$suggestion"
|
||||
fi
|
||||
}
|
||||
|
||||
# Offer a suggestion
|
||||
_zsh_autosuggest_suggest() {
|
||||
emulate -L zsh
|
||||
|
||||
local suggestion="$1"
|
||||
|
||||
if [[ -n "$suggestion" ]] && (( $#BUFFER )); then
|
||||
POSTDISPLAY="${suggestion#$BUFFER}"
|
||||
else
|
||||
unset POSTDISPLAY
|
||||
fi
|
||||
}
|
||||
|
||||
# Accept the entire suggestion
|
||||
_zsh_autosuggest_accept() {
|
||||
local -i retval max_cursor_pos=$#BUFFER
|
||||
|
||||
# When vicmd keymap is active, the cursor can't move all the way
|
||||
# to the end of the buffer
|
||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||
max_cursor_pos=$((max_cursor_pos - 1))
|
||||
fi
|
||||
|
||||
# If we're not in a valid state to accept a suggestion, just run the
|
||||
# original widget and bail out
|
||||
if (( $CURSOR != $max_cursor_pos || !$#POSTDISPLAY )); then
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
return
|
||||
fi
|
||||
|
||||
# Only accept if the cursor is at the end of the buffer
|
||||
# Add the suggestion to the buffer
|
||||
BUFFER="$BUFFER$POSTDISPLAY"
|
||||
|
||||
# Remove the suggestion
|
||||
unset POSTDISPLAY
|
||||
|
||||
# Run the original widget before manually moving the cursor so that the
|
||||
# cursor movement doesn't make the widget do something unexpected
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
retval=$?
|
||||
|
||||
# Move the cursor to the end of the buffer
|
||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||
CURSOR=$(($#BUFFER - 1))
|
||||
else
|
||||
CURSOR=$#BUFFER
|
||||
fi
|
||||
|
||||
return $retval
|
||||
}
|
||||
|
||||
# Accept the entire suggestion and execute it
|
||||
_zsh_autosuggest_execute() {
|
||||
# Add the suggestion to the buffer
|
||||
BUFFER="$BUFFER$POSTDISPLAY"
|
||||
|
||||
# Remove the suggestion
|
||||
unset POSTDISPLAY
|
||||
|
||||
# Call the original `accept-line` to handle syntax highlighting or
|
||||
# other potential custom behavior
|
||||
_zsh_autosuggest_invoke_original_widget "accept-line"
|
||||
}
|
||||
|
||||
# Partially accept the suggestion
|
||||
_zsh_autosuggest_partial_accept() {
|
||||
local -i retval cursor_loc
|
||||
|
||||
# Save the contents of the buffer so we can restore later if needed
|
||||
local original_buffer="$BUFFER"
|
||||
|
||||
# Temporarily accept the suggestion.
|
||||
BUFFER="$BUFFER$POSTDISPLAY"
|
||||
|
||||
# Original widget moves the cursor
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
retval=$?
|
||||
|
||||
# Normalize cursor location across vi/emacs modes
|
||||
cursor_loc=$CURSOR
|
||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||
cursor_loc=$((cursor_loc + 1))
|
||||
fi
|
||||
|
||||
# If we've moved past the end of the original buffer
|
||||
if (( $cursor_loc > $#original_buffer )); then
|
||||
# Set POSTDISPLAY to text right of the cursor
|
||||
POSTDISPLAY="${BUFFER[$(($cursor_loc + 1)),$#BUFFER]}"
|
||||
|
||||
# Clip the buffer at the cursor
|
||||
BUFFER="${BUFFER[1,$cursor_loc]}"
|
||||
else
|
||||
# Restore the original buffer
|
||||
BUFFER="$original_buffer"
|
||||
fi
|
||||
|
||||
return $retval
|
||||
}
|
||||
|
||||
() {
|
||||
typeset -ga _ZSH_AUTOSUGGEST_BUILTIN_ACTIONS
|
||||
|
||||
_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS=(
|
||||
clear
|
||||
fetch
|
||||
suggest
|
||||
accept
|
||||
execute
|
||||
enable
|
||||
disable
|
||||
toggle
|
||||
)
|
||||
|
||||
local action
|
||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS modify partial_accept; do
|
||||
eval "_zsh_autosuggest_widget_$action() {
|
||||
local -i retval
|
||||
|
||||
_zsh_autosuggest_highlight_reset
|
||||
|
||||
_zsh_autosuggest_$action \$@
|
||||
retval=\$?
|
||||
|
||||
_zsh_autosuggest_highlight_apply
|
||||
|
||||
zle -R
|
||||
|
||||
return \$retval
|
||||
}"
|
||||
done
|
||||
|
||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS; do
|
||||
zle -N autosuggest-$action _zsh_autosuggest_widget_$action
|
||||
done
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Completion Suggestion Strategy #
|
||||
#--------------------------------------------------------------------#
|
||||
# Fetches a suggestion from the completion engine
|
||||
#
|
||||
|
||||
_zsh_autosuggest_capture_postcompletion() {
|
||||
# Always insert the first completion into the buffer
|
||||
compstate[insert]=1
|
||||
|
||||
# Don't list completions
|
||||
unset 'compstate[list]'
|
||||
}
|
||||
|
||||
_zsh_autosuggest_capture_completion_widget() {
|
||||
# Add a post-completion hook to be called after all completions have been
|
||||
# gathered. The hook can modify compstate to affect what is done with the
|
||||
# gathered completions.
|
||||
local -a +h comppostfuncs
|
||||
comppostfuncs=(_zsh_autosuggest_capture_postcompletion)
|
||||
|
||||
# Only capture completions at the end of the buffer
|
||||
CURSOR=$#BUFFER
|
||||
|
||||
# Run the original widget wrapping `.complete-word` so we don't
|
||||
# recursively try to fetch suggestions, since our pty is forked
|
||||
# after autosuggestions is initialized.
|
||||
zle -- ${(k)widgets[(r)completion:.complete-word:_main_complete]}
|
||||
|
||||
if is-at-least 5.0.3; then
|
||||
# Don't do any cr/lf transformations. We need to do this immediately before
|
||||
# output because if we do it in setup, onlcr will be re-enabled when we enter
|
||||
# vared in the async code path. There is a bug in zpty module in older versions
|
||||
# where the tty is not properly attached to the pty slave, resulting in stty
|
||||
# getting stopped with a SIGTTOU. See zsh-workers thread 31660 and upstream
|
||||
# commit f75904a38
|
||||
stty -onlcr -ocrnl -F /dev/tty
|
||||
fi
|
||||
|
||||
# The completion has been added, print the buffer as the suggestion
|
||||
echo -nE - $'\0'$BUFFER$'\0'
|
||||
}
|
||||
|
||||
zle -N autosuggest-capture-completion _zsh_autosuggest_capture_completion_widget
|
||||
|
||||
_zsh_autosuggest_capture_setup() {
|
||||
# There is a bug in zpty module in older zsh versions by which a
|
||||
# zpty that exits will kill all zpty processes that were forked
|
||||
# before it. Here we set up a zsh exit hook to SIGKILL the zpty
|
||||
# process immediately, before it has a chance to kill any other
|
||||
# zpty processes.
|
||||
if ! is-at-least 5.4; then
|
||||
zshexit() {
|
||||
# The zsh builtin `kill` fails sometimes in older versions
|
||||
# https://unix.stackexchange.com/a/477647/156673
|
||||
kill -KILL $$ 2>&- || command kill -KILL $$
|
||||
|
||||
# Block for long enough for the signal to come through
|
||||
sleep 1
|
||||
}
|
||||
fi
|
||||
|
||||
# Try to avoid any suggestions that wouldn't match the prefix
|
||||
zstyle ':completion:*' matcher-list ''
|
||||
zstyle ':completion:*' path-completion false
|
||||
zstyle ':completion:*' max-errors 0 not-numeric
|
||||
|
||||
bindkey '^I' autosuggest-capture-completion
|
||||
}
|
||||
|
||||
_zsh_autosuggest_capture_completion_sync() {
|
||||
_zsh_autosuggest_capture_setup
|
||||
|
||||
zle autosuggest-capture-completion
|
||||
}
|
||||
|
||||
_zsh_autosuggest_capture_completion_async() {
|
||||
_zsh_autosuggest_capture_setup
|
||||
|
||||
zmodload zsh/parameter 2>/dev/null || return # For `$functions`
|
||||
|
||||
# Make vared completion work as if for a normal command line
|
||||
# https://stackoverflow.com/a/7057118/154703
|
||||
autoload +X _complete
|
||||
functions[_original_complete]=$functions[_complete]
|
||||
function _complete() {
|
||||
unset 'compstate[vared]'
|
||||
_original_complete "$@"
|
||||
}
|
||||
|
||||
# Open zle with buffer set so we can capture completions for it
|
||||
vared 1
|
||||
}
|
||||
|
||||
_zsh_autosuggest_strategy_completion() {
|
||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
||||
emulate -L zsh
|
||||
|
||||
# Enable extended glob for completion ignore pattern
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
typeset -g suggestion
|
||||
local line REPLY
|
||||
|
||||
# Exit if we don't have completions
|
||||
whence compdef >/dev/null || return
|
||||
|
||||
# Exit if we don't have zpty
|
||||
zmodload zsh/zpty 2>/dev/null || return
|
||||
|
||||
# Exit if our search string matches the ignore pattern
|
||||
[[ -n "$ZSH_AUTOSUGGEST_COMPLETION_IGNORE" ]] && [[ "$1" == $~ZSH_AUTOSUGGEST_COMPLETION_IGNORE ]] && return
|
||||
|
||||
# Zle will be inactive if we are in async mode
|
||||
if zle; then
|
||||
zpty $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME _zsh_autosuggest_capture_completion_sync
|
||||
else
|
||||
zpty $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME _zsh_autosuggest_capture_completion_async "\$1"
|
||||
zpty -w $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME $'\t'
|
||||
fi
|
||||
|
||||
{
|
||||
# The completion result is surrounded by null bytes, so read the
|
||||
# content between the first two null bytes.
|
||||
zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0''*'$'\0'
|
||||
|
||||
# Extract the suggestion from between the null bytes. On older
|
||||
# versions of zsh (older than 5.3), we sometimes get extra bytes after
|
||||
# the second null byte, so trim those off the end.
|
||||
# See http://www.zsh.org/mla/workers/2015/msg03290.html
|
||||
suggestion="${${(@0)line}[2]}"
|
||||
} always {
|
||||
# Destroy the pty
|
||||
zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME
|
||||
}
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# History Suggestion Strategy #
|
||||
#--------------------------------------------------------------------#
|
||||
# Suggests the most recent history item that matches the given
|
||||
# prefix.
|
||||
#
|
||||
|
||||
_zsh_autosuggest_strategy_history() {
|
||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
||||
emulate -L zsh
|
||||
|
||||
# Enable globbing flags so that we can use (#m) and (x~y) glob operator
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
# Escape backslashes and all of the glob operators so we can use
|
||||
# this string as a pattern to search the $history associative array.
|
||||
# - (#m) globbing flag enables setting references for match data
|
||||
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
|
||||
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
||||
|
||||
# Get the history items that match the prefix, excluding those that match
|
||||
# the ignore pattern
|
||||
local pattern="$prefix*"
|
||||
if [[ -n $ZSH_AUTOSUGGEST_HISTORY_IGNORE ]]; then
|
||||
pattern="($pattern)~($ZSH_AUTOSUGGEST_HISTORY_IGNORE)"
|
||||
fi
|
||||
|
||||
# Give the first history item matching the pattern as the suggestion
|
||||
# - (r) subscript flag makes the pattern match on values
|
||||
typeset -g suggestion="${history[(r)$pattern]}"
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Match Previous Command Suggestion Strategy #
|
||||
#--------------------------------------------------------------------#
|
||||
# Suggests the most recent history item that matches the given
|
||||
# prefix and whose preceding history item also matches the most
|
||||
# recently executed command.
|
||||
#
|
||||
# For example, suppose your history has the following entries:
|
||||
# - pwd
|
||||
# - ls foo
|
||||
# - ls bar
|
||||
# - pwd
|
||||
#
|
||||
# Given the history list above, when you type 'ls', the suggestion
|
||||
# will be 'ls foo' rather than 'ls bar' because your most recently
|
||||
# executed command (pwd) was previously followed by 'ls foo'.
|
||||
#
|
||||
# Note that this strategy won't work as expected with ZSH options that don't
|
||||
# preserve the history order such as `HIST_IGNORE_ALL_DUPS` or
|
||||
# `HIST_EXPIRE_DUPS_FIRST`.
|
||||
|
||||
_zsh_autosuggest_strategy_match_prev_cmd() {
|
||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
||||
emulate -L zsh
|
||||
|
||||
# Enable globbing flags so that we can use (#m) and (x~y) glob operator
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
|
||||
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
||||
|
||||
# Get the history items that match the prefix, excluding those that match
|
||||
# the ignore pattern
|
||||
local pattern="$prefix*"
|
||||
if [[ -n $ZSH_AUTOSUGGEST_HISTORY_IGNORE ]]; then
|
||||
pattern="($pattern)~($ZSH_AUTOSUGGEST_HISTORY_IGNORE)"
|
||||
fi
|
||||
|
||||
# Get all history event numbers that correspond to history
|
||||
# entries that match the pattern
|
||||
local history_match_keys
|
||||
history_match_keys=(${(k)history[(R)$~pattern]})
|
||||
|
||||
# By default we use the first history number (most recent history entry)
|
||||
local histkey="${history_match_keys[1]}"
|
||||
|
||||
# Get the previously executed command
|
||||
local prev_cmd="$(_zsh_autosuggest_escape_command "${history[$((HISTCMD-1))]}")"
|
||||
|
||||
# Iterate up to the first 200 history event numbers that match $prefix
|
||||
for key in "${(@)history_match_keys[1,200]}"; do
|
||||
# Stop if we ran out of history
|
||||
[[ $key -gt 1 ]] || break
|
||||
|
||||
# See if the history entry preceding the suggestion matches the
|
||||
# previous command, and use it if it does
|
||||
if [[ "${history[$((key - 1))]}" == "$prev_cmd" ]]; then
|
||||
histkey="$key"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Give back the matched history entry
|
||||
typeset -g suggestion="$history[$histkey]"
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Fetch Suggestion #
|
||||
#--------------------------------------------------------------------#
|
||||
# Loops through all specified strategies and returns a suggestion
|
||||
# from the first strategy to provide one.
|
||||
#
|
||||
|
||||
_zsh_autosuggest_fetch_suggestion() {
|
||||
typeset -g suggestion
|
||||
local -a strategies
|
||||
local strategy
|
||||
|
||||
# Ensure we are working with an array
|
||||
strategies=(${=ZSH_AUTOSUGGEST_STRATEGY})
|
||||
|
||||
for strategy in $strategies; do
|
||||
# Try to get a suggestion from this strategy
|
||||
_zsh_autosuggest_strategy_$strategy "$1"
|
||||
|
||||
# Ensure the suggestion matches the prefix
|
||||
[[ "$suggestion" != "$1"* ]] && unset suggestion
|
||||
|
||||
# Break once we've found a valid suggestion
|
||||
[[ -n "$suggestion" ]] && break
|
||||
done
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Async #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
_zsh_autosuggest_async_request() {
|
||||
zmodload zsh/system 2>/dev/null # For `$sysparams`
|
||||
|
||||
typeset -g _ZSH_AUTOSUGGEST_ASYNC_FD _ZSH_AUTOSUGGEST_CHILD_PID
|
||||
|
||||
# If we've got a pending request, cancel it
|
||||
if [[ -n "$_ZSH_AUTOSUGGEST_ASYNC_FD" ]] && { true <&$_ZSH_AUTOSUGGEST_ASYNC_FD } 2>/dev/null; then
|
||||
# Close the file descriptor and remove the handler
|
||||
exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&-
|
||||
zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD
|
||||
|
||||
# We won't know the pid unless the user has zsh/system module installed
|
||||
if [[ -n "$_ZSH_AUTOSUGGEST_CHILD_PID" ]]; then
|
||||
# Zsh will make a new process group for the child process only if job
|
||||
# control is enabled (MONITOR option)
|
||||
if [[ -o MONITOR ]]; then
|
||||
# Send the signal to the process group to kill any processes that may
|
||||
# have been forked by the suggestion strategy
|
||||
kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
||||
else
|
||||
# Kill just the child process since it wasn't placed in a new process
|
||||
# group. If the suggestion strategy forked any child processes they may
|
||||
# be orphaned and left behind.
|
||||
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Fork a process to fetch a suggestion and open a pipe to read from it
|
||||
exec {_ZSH_AUTOSUGGEST_ASYNC_FD}< <(
|
||||
# Tell parent process our pid
|
||||
echo $sysparams[pid]
|
||||
|
||||
# Fetch and print the suggestion
|
||||
local suggestion
|
||||
_zsh_autosuggest_fetch_suggestion "$1"
|
||||
echo -nE "$suggestion"
|
||||
)
|
||||
|
||||
# There's a weird bug here where ^C stops working unless we force a fork
|
||||
# See https://github.com/zsh-users/zsh-autosuggestions/issues/364
|
||||
autoload -Uz is-at-least
|
||||
is-at-least 5.8 || command true
|
||||
|
||||
# Read the pid from the child process
|
||||
read _ZSH_AUTOSUGGEST_CHILD_PID <&$_ZSH_AUTOSUGGEST_ASYNC_FD
|
||||
|
||||
# When the fd is readable, call the response handler
|
||||
zle -F "$_ZSH_AUTOSUGGEST_ASYNC_FD" _zsh_autosuggest_async_response
|
||||
}
|
||||
|
||||
# Called when new data is ready to be read from the pipe
|
||||
# First arg will be fd ready for reading
|
||||
# Second arg will be passed in case of error
|
||||
_zsh_autosuggest_async_response() {
|
||||
emulate -L zsh
|
||||
|
||||
local suggestion
|
||||
|
||||
if [[ -z "$2" || "$2" == "hup" ]]; then
|
||||
# Read everything from the fd and give it as a suggestion
|
||||
IFS='' read -rd '' -u $1 suggestion
|
||||
zle autosuggest-suggest -- "$suggestion"
|
||||
|
||||
# Close the fd
|
||||
exec {1}<&-
|
||||
fi
|
||||
|
||||
# Always remove the handler
|
||||
zle -F "$1"
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Start #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Start the autosuggestion widgets
|
||||
_zsh_autosuggest_start() {
|
||||
# By default we re-bind widgets on every precmd to ensure we wrap other
|
||||
# wrappers. Specifically, highlighting breaks if our widgets are wrapped by
|
||||
# zsh-syntax-highlighting widgets. This also allows modifications to the
|
||||
# widget list variables to take effect on the next precmd. However this has
|
||||
# a decent performance hit, so users can set ZSH_AUTOSUGGEST_MANUAL_REBIND
|
||||
# to disable the automatic re-binding.
|
||||
if (( ${+ZSH_AUTOSUGGEST_MANUAL_REBIND} )); then
|
||||
add-zsh-hook -d precmd _zsh_autosuggest_start
|
||||
fi
|
||||
|
||||
_zsh_autosuggest_bind_widgets
|
||||
}
|
||||
|
||||
# Mark for auto-loading the functions that we use
|
||||
autoload -Uz add-zsh-hook is-at-least
|
||||
|
||||
# Automatically enable asynchronous mode in newer versions of zsh. Disable for
|
||||
# older versions because there is a bug when using async mode where ^C does not
|
||||
# work immediately after fetching a suggestion.
|
||||
# See https://github.com/zsh-users/zsh-autosuggestions/issues/364
|
||||
if is-at-least 5.0.8; then
|
||||
typeset -g ZSH_AUTOSUGGEST_USE_ASYNC=
|
||||
fi
|
||||
|
||||
# Start the autosuggestion widgets on the next precmd
|
||||
add-zsh-hook precmd _zsh_autosuggest_start
|
268
zsh/.oh-my-zsh/custom/themes/agnosterg3.zsh-theme
Normal file
268
zsh/.oh-my-zsh/custom/themes/agnosterg3.zsh-theme
Normal file
@ -0,0 +1,268 @@
|
||||
# vim:ft=zsh ts=2 sw=2 sts=2
|
||||
#
|
||||
# agnoster's Theme - https://gist.github.com/3712874
|
||||
# A Powerline-inspired theme for ZSH
|
||||
#
|
||||
# # README
|
||||
#
|
||||
# In order for this theme to render correctly, you will need a
|
||||
# [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
|
||||
# Make sure you have a recent version: the code points that Powerline
|
||||
# uses changed in 2012, and older versions will display incorrectly,
|
||||
# in confusing ways.
|
||||
#
|
||||
# In addition, I recommend the
|
||||
# [Solarized theme](https://github.com/altercation/solarized/) and, if you're
|
||||
# using it on Mac OS X, [iTerm 2](https://iterm2.com/) over Terminal.app -
|
||||
# it has significantly better color fidelity.
|
||||
#
|
||||
# If using with "light" variant of the Solarized color schema, set
|
||||
# SOLARIZED_THEME variable to "light". If you don't specify, we'll assume
|
||||
# you're using the "dark" variant.
|
||||
#
|
||||
# # Goals
|
||||
#
|
||||
# The aim of this theme is to only show you *relevant* information. Like most
|
||||
# prompts, it will only show git information when in a git working directory.
|
||||
# However, it goes a step further: everything from the current user and
|
||||
# hostname to whether the last call exited with an error to whether background
|
||||
# jobs are running in this shell will all be displayed automatically when
|
||||
# appropriate.
|
||||
|
||||
### Segment drawing
|
||||
# A few utility functions to make it easy and re-usable to draw segmented prompts
|
||||
|
||||
CURRENT_BG='NONE'
|
||||
|
||||
case ${SOLARIZED_THEME:-dark} in
|
||||
light) CURRENT_FG='white';;
|
||||
*) CURRENT_FG='black';;
|
||||
esac
|
||||
|
||||
# Special Powerline characters
|
||||
|
||||
() {
|
||||
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
|
||||
# NOTE: This segment separator character is correct. In 2012, Powerline changed
|
||||
# the code points they use for their special characters. This is the new code point.
|
||||
# If this is not working for you, you probably have an old version of the
|
||||
# Powerline-patched fonts installed. Download and install the new version.
|
||||
# Do not submit PRs to change this unless you have reviewed the Powerline code point
|
||||
# history and have new information.
|
||||
# This is defined using a Unicode escape sequence so it is unambiguously readable, regardless of
|
||||
# what font the user is viewing this source code in. Do not replace the
|
||||
# escape sequence with a single literal character.
|
||||
# Do not change this! Do not make it '\u2b80'; that is the old, wrong code point.
|
||||
SEGMENT_SEPARATOR=$'\ue0b0'
|
||||
}
|
||||
|
||||
# Begin a segment
|
||||
# Takes two arguments, background and foreground. Both can be omitted,
|
||||
# rendering default background/foreground.
|
||||
prompt_segment() {
|
||||
local bg fg
|
||||
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
|
||||
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
|
||||
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
|
||||
echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
|
||||
else
|
||||
echo -n "%{$bg%}%{$fg%} "
|
||||
fi
|
||||
CURRENT_BG=$1
|
||||
[[ -n $3 ]] && echo -n $3
|
||||
}
|
||||
|
||||
# End the prompt, closing any open segments
|
||||
prompt_end() {
|
||||
if [[ -n $CURRENT_BG ]]; then
|
||||
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
|
||||
else
|
||||
echo -n "%{%k%}"
|
||||
fi
|
||||
echo -n "%{%f%}"
|
||||
CURRENT_BG=''
|
||||
}
|
||||
|
||||
### Prompt components
|
||||
# Each component will draw itself, and hide itself if no information needs to be shown
|
||||
|
||||
# Context: user@hostname (who am I and where am I)
|
||||
prompt_context() {
|
||||
if [[ "$USERNAME" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
|
||||
prompt_segment black default "%(!.%{%F{yellow}%}.)%n@%m"
|
||||
fi
|
||||
}
|
||||
|
||||
# Git: branch/detached head, dirty status
|
||||
prompt_git() {
|
||||
(( $+commands[git] )) || return
|
||||
if [[ "$(git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]]; then
|
||||
return
|
||||
fi
|
||||
local PL_BRANCH_CHAR
|
||||
() {
|
||||
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
|
||||
PL_BRANCH_CHAR=$'\ue0a0' #
|
||||
}
|
||||
local ref dirty mode repo_path
|
||||
|
||||
if [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]]; then
|
||||
repo_path=$(git rev-parse --git-dir 2>/dev/null)
|
||||
dirty=$(parse_git_dirty)
|
||||
ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git rev-parse --short HEAD 2> /dev/null)"
|
||||
if [[ -n $dirty ]]; then
|
||||
prompt_segment yellow black
|
||||
else
|
||||
prompt_segment green $CURRENT_FG
|
||||
fi
|
||||
|
||||
if [[ -e "${repo_path}/BISECT_LOG" ]]; then
|
||||
mode=" <B>"
|
||||
elif [[ -e "${repo_path}/MERGE_HEAD" ]]; then
|
||||
mode=" >M<"
|
||||
elif [[ -e "${repo_path}/rebase" || -e "${repo_path}/rebase-apply" || -e "${repo_path}/rebase-merge" || -e "${repo_path}/../.dotest" ]]; then
|
||||
mode=" >R>"
|
||||
fi
|
||||
|
||||
setopt promptsubst
|
||||
autoload -Uz vcs_info
|
||||
|
||||
zstyle ':vcs_info:*' enable git
|
||||
zstyle ':vcs_info:*' get-revision true
|
||||
zstyle ':vcs_info:*' check-for-changes true
|
||||
zstyle ':vcs_info:*' stagedstr '✚'
|
||||
zstyle ':vcs_info:*' unstagedstr '±'
|
||||
zstyle ':vcs_info:*' formats ' %u%c'
|
||||
zstyle ':vcs_info:*' actionformats ' %u%c'
|
||||
vcs_info
|
||||
echo -n "${ref/refs\/heads\//$PL_BRANCH_CHAR }${vcs_info_msg_0_%% }${mode}"
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_bzr() {
|
||||
(( $+commands[bzr] )) || return
|
||||
|
||||
# Test if bzr repository in directory hierarchy
|
||||
local dir="$PWD"
|
||||
while [[ ! -d "$dir/.bzr" ]]; do
|
||||
[[ "$dir" = "/" ]] && return
|
||||
dir="${dir:h}"
|
||||
done
|
||||
|
||||
local bzr_status status_mod status_all revision
|
||||
if bzr_status=$(bzr status 2>&1); then
|
||||
status_mod=$(echo -n "$bzr_status" | head -n1 | grep "modified" | wc -m)
|
||||
status_all=$(echo -n "$bzr_status" | head -n1 | wc -m)
|
||||
revision=$(bzr log -r-1 --log-format line | cut -d: -f1)
|
||||
if [[ $status_mod -gt 0 ]] ; then
|
||||
prompt_segment yellow black "bzr@$revision ✚"
|
||||
else
|
||||
if [[ $status_all -gt 0 ]] ; then
|
||||
prompt_segment yellow black "bzr@$revision"
|
||||
else
|
||||
prompt_segment green black "bzr@$revision"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_hg() {
|
||||
(( $+commands[hg] )) || return
|
||||
local rev st branch
|
||||
if $(hg id >/dev/null 2>&1); then
|
||||
if $(hg prompt >/dev/null 2>&1); then
|
||||
if [[ $(hg prompt "{status|unknown}") = "?" ]]; then
|
||||
# if files are not added
|
||||
prompt_segment red white
|
||||
st='±'
|
||||
elif [[ -n $(hg prompt "{status|modified}") ]]; then
|
||||
# if any modification
|
||||
prompt_segment yellow black
|
||||
st='±'
|
||||
else
|
||||
# if working copy is clean
|
||||
prompt_segment green $CURRENT_FG
|
||||
fi
|
||||
echo -n $(hg prompt "☿ {rev}@{branch}") $st
|
||||
else
|
||||
st=""
|
||||
rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
|
||||
branch=$(hg id -b 2>/dev/null)
|
||||
if `hg st | grep -q "^\?"`; then
|
||||
prompt_segment red black
|
||||
st='±'
|
||||
elif `hg st | grep -q "^[MA]"`; then
|
||||
prompt_segment yellow black
|
||||
st='±'
|
||||
else
|
||||
prompt_segment green $CURRENT_FG
|
||||
fi
|
||||
echo -n "☿ $rev@$branch" $st
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Dir:
|
||||
# - current working directory
|
||||
# - CitC client name and //-abbreviated directory when in google3
|
||||
prompt_dir() {
|
||||
if [[ $PWD =~ '/google/src/cloud/[^/]+/(.+)/google3(.*)' ]]; then
|
||||
prompt_segment cyan black "${match[1]}"
|
||||
prompt_segment blue $CURRENT_FG "//${match[2]#/}"
|
||||
# Use CitC client names as window titles in screen/tmux
|
||||
print -n "\e]2;${match[1]}\a" >/dev/tty
|
||||
else
|
||||
prompt_segment blue $CURRENT_FG '%~'
|
||||
fi
|
||||
}
|
||||
|
||||
# Virtualenv: current working virtualenv
|
||||
prompt_virtualenv() {
|
||||
local virtualenv_path="$VIRTUAL_ENV"
|
||||
if [[ -n $virtualenv_path && -n $VIRTUAL_ENV_DISABLE_PROMPT ]]; then
|
||||
prompt_segment blue black "(`basename $virtualenv_path`)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Status:
|
||||
# - was there an error
|
||||
# - am I root
|
||||
# - are there background jobs?
|
||||
prompt_status() {
|
||||
local -a symbols
|
||||
|
||||
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘"
|
||||
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
|
||||
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
|
||||
|
||||
[[ -n "$symbols" ]] && prompt_segment black default "$symbols"
|
||||
}
|
||||
|
||||
#AWS Profile:
|
||||
# - display current AWS_PROFILE name
|
||||
# - displays yellow on red if profile name contains 'production' or
|
||||
# ends in '-prod'
|
||||
# - displays black on green otherwise
|
||||
prompt_aws() {
|
||||
[[ -z "$AWS_PROFILE" || "$SHOW_AWS_PROMPT" = false ]] && return
|
||||
case "$AWS_PROFILE" in
|
||||
*-prod|*production*) prompt_segment red yellow "AWS: $AWS_PROFILE" ;;
|
||||
*) prompt_segment green black "AWS: $AWS_PROFILE" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
## Main prompt
|
||||
build_prompt() {
|
||||
RETVAL=$?
|
||||
prompt_status
|
||||
prompt_virtualenv
|
||||
prompt_aws
|
||||
prompt_context
|
||||
prompt_dir
|
||||
prompt_git
|
||||
prompt_bzr
|
||||
prompt_hg
|
||||
prompt_end
|
||||
}
|
||||
|
||||
PROMPT='%{%f%b%k%}$(build_prompt) '
|
4
zsh/.oh-my-zsh/custom/themes/example.zsh-theme
Normal file
4
zsh/.oh-my-zsh/custom/themes/example.zsh-theme
Normal file
@ -0,0 +1,4 @@
|
||||
# Put your custom themes in this folder.
|
||||
# Example:
|
||||
|
||||
PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}%% "
|
5
zsh/.oh-my-zsh/custom/themes/powerlevel10k/.gitattributes
vendored
Normal file
5
zsh/.oh-my-zsh/custom/themes/powerlevel10k/.gitattributes
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
* text=auto
|
||||
*.zsh text eol=lf
|
||||
*.zsh-theme text eol=lf
|
||||
/prompt_powerlevel9k_setup text eol=lf
|
||||
/prompt_powerlevel10k_setup text eol=lf
|
1
zsh/.oh-my-zsh/custom/themes/powerlevel10k/.gitignore
vendored
Normal file
1
zsh/.oh-my-zsh/custom/themes/powerlevel10k/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.zwc
|
22
zsh/.oh-my-zsh/custom/themes/powerlevel10k/LICENSE
Normal file
22
zsh/.oh-my-zsh/custom/themes/powerlevel10k/LICENSE
Normal file
@ -0,0 +1,22 @@
|
||||
Copyright (c) 2009-2014 Robby Russell and contributors (see https://github.com/robbyrussell/oh-my-zsh/contributors)
|
||||
Copyright (c) 2014-2017 Ben Hilburn <bhilburn@gmail.com>
|
||||
Copyright (c) 2019 Roman Perepelitsa <roman.perepelitsa@gmail.com> and contributors (see https://github.com/romkatv/powerlevel10k/contributors)
|
||||
|
||||
MIT LICENSE
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
14
zsh/.oh-my-zsh/custom/themes/powerlevel10k/Makefile
Normal file
14
zsh/.oh-my-zsh/custom/themes/powerlevel10k/Makefile
Normal file
@ -0,0 +1,14 @@
|
||||
ZSH := $(shell command -v zsh 2> /dev/null)
|
||||
|
||||
all:
|
||||
|
||||
zwc:
|
||||
$(MAKE) -C gitstatus zwc
|
||||
$(or $(ZSH),:) -fc 'for f in *.zsh-theme internal/*.zsh; do zcompile -R -- $$f.zwc $$f || exit; done'
|
||||
|
||||
minify:
|
||||
$(MAKE) -C gitstatus minify
|
||||
rm -rf -- .git .gitattributes .gitignore LICENSE Makefile README.md font.md powerlevel10k.png
|
||||
|
||||
pkg: zwc
|
||||
$(MAKE) -C gitstatus pkg
|
1877
zsh/.oh-my-zsh/custom/themes/powerlevel10k/README.md
Normal file
1877
zsh/.oh-my-zsh/custom/themes/powerlevel10k/README.md
Normal file
File diff suppressed because it is too large
Load Diff
1634
zsh/.oh-my-zsh/custom/themes/powerlevel10k/config/p10k-classic.zsh
Normal file
1634
zsh/.oh-my-zsh/custom/themes/powerlevel10k/config/p10k-classic.zsh
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1611
zsh/.oh-my-zsh/custom/themes/powerlevel10k/config/p10k-lean.zsh
Normal file
1611
zsh/.oh-my-zsh/custom/themes/powerlevel10k/config/p10k-lean.zsh
Normal file
File diff suppressed because it is too large
Load Diff
193
zsh/.oh-my-zsh/custom/themes/powerlevel10k/config/p10k-pure.zsh
Normal file
193
zsh/.oh-my-zsh/custom/themes/powerlevel10k/config/p10k-pure.zsh
Normal file
@ -0,0 +1,193 @@
|
||||
# Config file for Powerlevel10k with the style of Pure (https://github.com/sindresorhus/pure).
|
||||
#
|
||||
# Differences from Pure:
|
||||
#
|
||||
# - Git:
|
||||
# - `@c4d3ec2c` instead of something like `v1.4.0~11` when in detached HEAD state.
|
||||
# - No automatic `git fetch` (the same as in Pure with `PURE_GIT_PULL=0`).
|
||||
#
|
||||
# Apart from the differences listed above, the replication of Pure prompt is exact. This includes
|
||||
# even the questionable parts. For example, just like in Pure, there is no indication of Git status
|
||||
# being stale; prompt symbol is the same in command, visual and overwrite vi modes; when prompt
|
||||
# doesn't fit on one line, it wraps around with no attempt to shorten it.
|
||||
#
|
||||
# If you like the general style of Pure but not particularly attached to all its quirks, type
|
||||
# `p10k configure` and pick "Lean" style. This will give you slick minimalist prompt while taking
|
||||
# advantage of Powerlevel10k features that aren't present in Pure.
|
||||
|
||||
# Temporarily change options.
|
||||
'builtin' 'local' '-a' 'p10k_config_opts'
|
||||
[[ ! -o 'aliases' ]] || p10k_config_opts+=('aliases')
|
||||
[[ ! -o 'sh_glob' ]] || p10k_config_opts+=('sh_glob')
|
||||
[[ ! -o 'no_brace_expand' ]] || p10k_config_opts+=('no_brace_expand')
|
||||
'builtin' 'setopt' 'no_aliases' 'no_sh_glob' 'brace_expand'
|
||||
|
||||
() {
|
||||
emulate -L zsh -o extended_glob
|
||||
|
||||
# Unset all configuration options.
|
||||
unset -m '(POWERLEVEL9K_*|DEFAULT_USER)~POWERLEVEL9K_GITSTATUS_DIR'
|
||||
|
||||
# Zsh >= 5.1 is required.
|
||||
autoload -Uz is-at-least && is-at-least 5.1 || return
|
||||
|
||||
# Prompt colors.
|
||||
local grey=242
|
||||
local red=1
|
||||
local yellow=3
|
||||
local blue=4
|
||||
local magenta=5
|
||||
local cyan=6
|
||||
local white=7
|
||||
|
||||
# Left prompt segments.
|
||||
typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(
|
||||
# =========================[ Line #1 ]=========================
|
||||
context # user@host
|
||||
dir # current directory
|
||||
vcs # git status
|
||||
command_execution_time # previous command duration
|
||||
# =========================[ Line #2 ]=========================
|
||||
newline # \n
|
||||
virtualenv # python virtual environment
|
||||
prompt_char # prompt symbol
|
||||
)
|
||||
|
||||
# Right prompt segments.
|
||||
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(
|
||||
# =========================[ Line #1 ]=========================
|
||||
# command_execution_time # previous command duration
|
||||
# virtualenv # python virtual environment
|
||||
# context # user@host
|
||||
# time # current time
|
||||
# =========================[ Line #2 ]=========================
|
||||
newline # \n
|
||||
)
|
||||
|
||||
# Basic style options that define the overall prompt look.
|
||||
typeset -g POWERLEVEL9K_BACKGROUND= # transparent background
|
||||
typeset -g POWERLEVEL9K_{LEFT,RIGHT}_{LEFT,RIGHT}_WHITESPACE= # no surrounding whitespace
|
||||
typeset -g POWERLEVEL9K_{LEFT,RIGHT}_SUBSEGMENT_SEPARATOR=' ' # separate segments with a space
|
||||
typeset -g POWERLEVEL9K_{LEFT,RIGHT}_SEGMENT_SEPARATOR= # no end-of-line symbol
|
||||
typeset -g POWERLEVEL9K_VISUAL_IDENTIFIER_EXPANSION= # no segment icons
|
||||
|
||||
# Add an empty line before each prompt except the first. This doesn't emulate the bug
|
||||
# in Pure that makes prompt drift down whenever you use the Alt-C binding from fzf or similar.
|
||||
typeset -g POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
|
||||
|
||||
# Magenta prompt symbol if the last command succeeded.
|
||||
typeset -g POWERLEVEL9K_PROMPT_CHAR_OK_{VIINS,VICMD,VIVIS}_FOREGROUND=$magenta
|
||||
# Red prompt symbol if the last command failed.
|
||||
typeset -g POWERLEVEL9K_PROMPT_CHAR_ERROR_{VIINS,VICMD,VIVIS}_FOREGROUND=$red
|
||||
# Default prompt symbol.
|
||||
typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VIINS_CONTENT_EXPANSION='❯'
|
||||
# Prompt symbol in command vi mode.
|
||||
typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VICMD_CONTENT_EXPANSION='❮'
|
||||
# Prompt symbol in visual vi mode is the same as in command mode.
|
||||
typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VIVIS_CONTENT_EXPANSION='❮'
|
||||
# Prompt symbol in overwrite vi mode is the same as in command mode.
|
||||
typeset -g POWERLEVEL9K_PROMPT_CHAR_OVERWRITE_STATE=false
|
||||
|
||||
# Grey Python Virtual Environment.
|
||||
typeset -g POWERLEVEL9K_VIRTUALENV_FOREGROUND=$grey
|
||||
# Don't show Python version.
|
||||
typeset -g POWERLEVEL9K_VIRTUALENV_SHOW_PYTHON_VERSION=false
|
||||
typeset -g POWERLEVEL9K_VIRTUALENV_{LEFT,RIGHT}_DELIMITER=
|
||||
|
||||
# Blue current directory.
|
||||
typeset -g POWERLEVEL9K_DIR_FOREGROUND=$blue
|
||||
|
||||
# Context format when root: user@host. The first part white, the rest grey.
|
||||
typeset -g POWERLEVEL9K_CONTEXT_ROOT_TEMPLATE="%F{$white}%n%f%F{$grey}@%m%f"
|
||||
# Context format when not root: user@host. The whole thing grey.
|
||||
typeset -g POWERLEVEL9K_CONTEXT_TEMPLATE="%F{$grey}%n@%m%f"
|
||||
# Don't show context unless root or in SSH.
|
||||
typeset -g POWERLEVEL9K_CONTEXT_{DEFAULT,SUDO}_CONTENT_EXPANSION=
|
||||
|
||||
# Show previous command duration only if it's >= 5s.
|
||||
typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=5
|
||||
# Don't show fractional seconds. Thus, 7s rather than 7.3s.
|
||||
typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0
|
||||
# Duration format: 1d 2h 3m 4s.
|
||||
typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_FORMAT='d h m s'
|
||||
# Yellow previous command duration.
|
||||
typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND=$yellow
|
||||
|
||||
# Grey Git prompt. This makes stale prompts indistinguishable from up-to-date ones.
|
||||
typeset -g POWERLEVEL9K_VCS_FOREGROUND=$grey
|
||||
|
||||
# Disable async loading indicator to make directories that aren't Git repositories
|
||||
# indistinguishable from large Git repositories without known state.
|
||||
typeset -g POWERLEVEL9K_VCS_LOADING_TEXT=
|
||||
|
||||
# Don't wait for Git status even for a millisecond, so that prompt always updates
|
||||
# asynchronously when Git state changes.
|
||||
typeset -g POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS=0
|
||||
|
||||
# Cyan ahead/behind arrows.
|
||||
typeset -g POWERLEVEL9K_VCS_{INCOMING,OUTGOING}_CHANGESFORMAT_FOREGROUND=$cyan
|
||||
# Don't show remote branch, current tag or stashes.
|
||||
typeset -g POWERLEVEL9K_VCS_GIT_HOOKS=(vcs-detect-changes git-untracked git-aheadbehind)
|
||||
# Don't show the branch icon.
|
||||
typeset -g POWERLEVEL9K_VCS_BRANCH_ICON=
|
||||
# When in detached HEAD state, show @commit where branch normally goes.
|
||||
typeset -g POWERLEVEL9K_VCS_COMMIT_ICON='@'
|
||||
# Don't show staged, unstaged, untracked indicators.
|
||||
typeset -g POWERLEVEL9K_VCS_{STAGED,UNSTAGED,UNTRACKED}_ICON=
|
||||
# Show '*' when there are staged, unstaged or untracked files.
|
||||
typeset -g POWERLEVEL9K_VCS_DIRTY_ICON='*'
|
||||
# Show '⇣' if local branch is behind remote.
|
||||
typeset -g POWERLEVEL9K_VCS_INCOMING_CHANGES_ICON=':⇣'
|
||||
# Show '⇡' if local branch is ahead of remote.
|
||||
typeset -g POWERLEVEL9K_VCS_OUTGOING_CHANGES_ICON=':⇡'
|
||||
# Don't show the number of commits next to the ahead/behind arrows.
|
||||
typeset -g POWERLEVEL9K_VCS_{COMMITS_AHEAD,COMMITS_BEHIND}_MAX_NUM=1
|
||||
# Remove space between '⇣' and '⇡' and all trailing spaces.
|
||||
typeset -g POWERLEVEL9K_VCS_CONTENT_EXPANSION='${${${P9K_CONTENT/⇣* :⇡/⇣⇡}// }//:/ }'
|
||||
|
||||
# Grey current time.
|
||||
typeset -g POWERLEVEL9K_TIME_FOREGROUND=$grey
|
||||
# Format for the current time: 09:51:02. See `man 3 strftime`.
|
||||
typeset -g POWERLEVEL9K_TIME_FORMAT='%D{%H:%M:%S}'
|
||||
# If set to true, time will update when you hit enter. This way prompts for the past
|
||||
# commands will contain the start times of their commands rather than the end times of
|
||||
# their preceding commands.
|
||||
typeset -g POWERLEVEL9K_TIME_UPDATE_ON_COMMAND=false
|
||||
|
||||
# Transient prompt works similarly to the builtin transient_rprompt option. It trims down prompt
|
||||
# when accepting a command line. Supported values:
|
||||
#
|
||||
# - off: Don't change prompt when accepting a command line.
|
||||
# - always: Trim down prompt when accepting a command line.
|
||||
# - same-dir: Trim down prompt when accepting a command line unless this is the first command
|
||||
# typed after changing current working directory.
|
||||
typeset -g POWERLEVEL9K_TRANSIENT_PROMPT=off
|
||||
|
||||
# Instant prompt mode.
|
||||
#
|
||||
# - off: Disable instant prompt. Choose this if you've tried instant prompt and found
|
||||
# it incompatible with your zsh configuration files.
|
||||
# - quiet: Enable instant prompt and don't print warnings when detecting console output
|
||||
# during zsh initialization. Choose this if you've read and understood
|
||||
# https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt.
|
||||
# - verbose: Enable instant prompt and print a warning when detecting console output during
|
||||
# zsh initialization. Choose this if you've never tried instant prompt, haven't
|
||||
# seen the warning, or if you are unsure what this all means.
|
||||
typeset -g POWERLEVEL9K_INSTANT_PROMPT=verbose
|
||||
|
||||
# Hot reload allows you to change POWERLEVEL9K options after Powerlevel10k has been initialized.
|
||||
# For example, you can type POWERLEVEL9K_BACKGROUND=red and see your prompt turn red. Hot reload
|
||||
# can slow down prompt by 1-2 milliseconds, so it's better to keep it turned off unless you
|
||||
# really need it.
|
||||
typeset -g POWERLEVEL9K_DISABLE_HOT_RELOAD=true
|
||||
|
||||
# If p10k is already loaded, reload configuration.
|
||||
# This works even with POWERLEVEL9K_DISABLE_HOT_RELOAD=true.
|
||||
(( ! $+functions[p10k] )) || p10k reload
|
||||
}
|
||||
|
||||
# Tell `p10k configure` which file it should overwrite.
|
||||
typeset -g POWERLEVEL9K_CONFIG_FILE=${${(%):-%x}:a}
|
||||
|
||||
(( ${#p10k_config_opts} )) && setopt ${p10k_config_opts[@]}
|
||||
'builtin' 'unset' 'p10k_config_opts'
|
1722
zsh/.oh-my-zsh/custom/themes/powerlevel10k/config/p10k-rainbow.zsh
Normal file
1722
zsh/.oh-my-zsh/custom/themes/powerlevel10k/config/p10k-rainbow.zsh
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,111 @@
|
||||
# Config file for Powerlevel10k with the style of robbyrussell theme from Oh My Zsh.
|
||||
#
|
||||
# Original: https://github.com/ohmyzsh/ohmyzsh/wiki/Themes#robbyrussell.
|
||||
#
|
||||
# Replication of robbyrussell theme is exact. The only observable difference is in
|
||||
# performance. Powerlevel10k prompt is very fast everywhere, even in large Git repositories.
|
||||
#
|
||||
# Usage: Source this file either before or after loading Powerlevel10k.
|
||||
#
|
||||
# source ~/powerlevel10k/config/p10k-robbyrussell.zsh
|
||||
# source ~/powerlevel10k/powerlevel10k.zsh-theme
|
||||
|
||||
# Temporarily change options.
|
||||
'builtin' 'local' '-a' 'p10k_config_opts'
|
||||
[[ ! -o 'aliases' ]] || p10k_config_opts+=('aliases')
|
||||
[[ ! -o 'sh_glob' ]] || p10k_config_opts+=('sh_glob')
|
||||
[[ ! -o 'no_brace_expand' ]] || p10k_config_opts+=('no_brace_expand')
|
||||
'builtin' 'setopt' 'no_aliases' 'no_sh_glob' 'brace_expand'
|
||||
|
||||
() {
|
||||
emulate -L zsh -o extended_glob
|
||||
|
||||
# Unset all configuration options.
|
||||
unset -m '(POWERLEVEL9K_*|DEFAULT_USER)~POWERLEVEL9K_GITSTATUS_DIR'
|
||||
|
||||
# Zsh >= 5.1 is required.
|
||||
autoload -Uz is-at-least && is-at-least 5.1 || return
|
||||
|
||||
# Left prompt segments.
|
||||
typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(prompt_char dir vcs)
|
||||
# Right prompt segments.
|
||||
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
|
||||
|
||||
# Basic style options that define the overall prompt look.
|
||||
typeset -g POWERLEVEL9K_BACKGROUND= # transparent background
|
||||
typeset -g POWERLEVEL9K_{LEFT,RIGHT}_{LEFT,RIGHT}_WHITESPACE= # no surrounding whitespace
|
||||
typeset -g POWERLEVEL9K_{LEFT,RIGHT}_SUBSEGMENT_SEPARATOR=' ' # separate segments with a space
|
||||
typeset -g POWERLEVEL9K_{LEFT,RIGHT}_SEGMENT_SEPARATOR= # no end-of-line symbol
|
||||
typeset -g POWERLEVEL9K_VISUAL_IDENTIFIER_EXPANSION= # no segment icons
|
||||
|
||||
# Green prompt symbol if the last command succeeded.
|
||||
typeset -g POWERLEVEL9K_PROMPT_CHAR_OK_{VIINS,VICMD,VIVIS}_FOREGROUND=green
|
||||
# Red prompt symbol if the last command failed.
|
||||
typeset -g POWERLEVEL9K_PROMPT_CHAR_ERROR_{VIINS,VICMD,VIVIS}_FOREGROUND=red
|
||||
# Prompt symbol: bold arrow.
|
||||
typeset -g POWERLEVEL9K_PROMPT_CHAR_CONTENT_EXPANSION='%B➜ '
|
||||
|
||||
# Cyan current directory.
|
||||
typeset -g POWERLEVEL9K_DIR_FOREGROUND=cyan
|
||||
# Show only the last segment of the current directory.
|
||||
typeset -g POWERLEVEL9K_SHORTEN_STRATEGY=truncate_to_last
|
||||
# Bold directory.
|
||||
typeset -g POWERLEVEL9K_DIR_CONTENT_EXPANSION='%B$P9K_CONTENT'
|
||||
|
||||
# Git status formatter.
|
||||
function my_git_formatter() {
|
||||
emulate -L zsh
|
||||
if [[ -n $P9K_CONTENT ]]; then
|
||||
# If P9K_CONTENT is not empty, it's either "loading" or from vcs_info (not from
|
||||
# gitstatus plugin). VCS_STATUS_* parameters are not available in this case.
|
||||
typeset -g my_git_format=$P9K_CONTENT
|
||||
else
|
||||
# Use VCS_STATUS_* parameters to assemble Git status. See reference:
|
||||
# https://github.com/romkatv/gitstatus/blob/master/gitstatus.plugin.zsh.
|
||||
typeset -g my_git_format="${1+%B%4F}git:(${1+%1F}"
|
||||
my_git_format+=${${VCS_STATUS_LOCAL_BRANCH:-${VCS_STATUS_COMMIT[1,8]}}//\%/%%}
|
||||
my_git_format+="${1+%4F})"
|
||||
if (( VCS_STATUS_NUM_CONFLICTED || VCS_STATUS_NUM_STAGED ||
|
||||
VCS_STATUS_NUM_UNSTAGED || VCS_STATUS_NUM_UNTRACKED )); then
|
||||
my_git_format+=" ${1+%3F}✗"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
functions -M my_git_formatter 2>/dev/null
|
||||
|
||||
# Disable the default Git status formatting.
|
||||
typeset -g POWERLEVEL9K_VCS_DISABLE_GITSTATUS_FORMATTING=true
|
||||
# Install our own Git status formatter.
|
||||
typeset -g POWERLEVEL9K_VCS_CONTENT_EXPANSION='${$((my_git_formatter(1)))+${my_git_format}}'
|
||||
typeset -g POWERLEVEL9K_VCS_LOADING_CONTENT_EXPANSION='${$((my_git_formatter()))+${my_git_format}}'
|
||||
# Grey Git status when loading.
|
||||
typeset -g POWERLEVEL9K_VCS_LOADING_FOREGROUND=246
|
||||
|
||||
# Instant prompt mode.
|
||||
#
|
||||
# - off: Disable instant prompt. Choose this if you've tried instant prompt and found
|
||||
# it incompatible with your zsh configuration files.
|
||||
# - quiet: Enable instant prompt and don't print warnings when detecting console output
|
||||
# during zsh initialization. Choose this if you've read and understood
|
||||
# https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt.
|
||||
# - verbose: Enable instant prompt and print a warning when detecting console output during
|
||||
# zsh initialization. Choose this if you've never tried instant prompt, haven't
|
||||
# seen the warning, or if you are unsure what this all means.
|
||||
typeset -g POWERLEVEL9K_INSTANT_PROMPT=verbose
|
||||
|
||||
# Hot reload allows you to change POWERLEVEL9K options after Powerlevel10k has been initialized.
|
||||
# For example, you can type POWERLEVEL9K_BACKGROUND=red and see your prompt turn red. Hot reload
|
||||
# can slow down prompt by 1-2 milliseconds, so it's better to keep it turned off unless you
|
||||
# really need it.
|
||||
typeset -g POWERLEVEL9K_DISABLE_HOT_RELOAD=true
|
||||
|
||||
# If p10k is already loaded, reload configuration.
|
||||
# This works even with POWERLEVEL9K_DISABLE_HOT_RELOAD=true.
|
||||
(( ! $+functions[p10k] )) || p10k reload
|
||||
}
|
||||
|
||||
# Tell `p10k configure` which file it should overwrite.
|
||||
typeset -g POWERLEVEL9K_CONFIG_FILE=${${(%):-%x}:a}
|
||||
|
||||
(( ${#p10k_config_opts} )) && setopt ${p10k_config_opts[@]}
|
||||
'builtin' 'unset' 'p10k_config_opts'
|
116
zsh/.oh-my-zsh/custom/themes/powerlevel10k/font.md
Normal file
116
zsh/.oh-my-zsh/custom/themes/powerlevel10k/font.md
Normal file
@ -0,0 +1,116 @@
|
||||
# Recommended font: Meslo Nerd Font patched for Powerlevel10k
|
||||
|
||||
Gorgeous monospace font designed by Jim Lyles for Bitstream, customized by the same for Apple,
|
||||
further customized by André Berg, and finally patched by yours truly with customized scripts
|
||||
originally developed by Ryan L McIntyre of Nerd Fonts. Contains all glyphs and symbols that
|
||||
Powerlevel10k may need. Battle-tested in dozens of different terminals on all major operating
|
||||
systems.
|
||||
|
||||
*FAQ*: [How was the recommended font created?](README.md#how-was-the-recommended-font-created)
|
||||
|
||||
## Automatic font installation
|
||||
|
||||
If you are using iTerm2 or Termux, `p10k configure` can install the recommended font for you.
|
||||
Simply answer `Yes` when asked whether to install *Meslo Nerd Font*.
|
||||
|
||||
If you are using a different terminal, proceed with manual font installation. 👇
|
||||
|
||||
## Manual font installation
|
||||
|
||||
1. Download these four ttf files:
|
||||
- [MesloLGS NF Regular.ttf](
|
||||
https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf)
|
||||
- [MesloLGS NF Bold.ttf](
|
||||
https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf)
|
||||
- [MesloLGS NF Italic.ttf](
|
||||
https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf)
|
||||
- [MesloLGS NF Bold Italic.ttf](
|
||||
https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf)
|
||||
1. Double-click on each file and click "Install". This will make `MesloLGS NF` font available to all
|
||||
applications on your system.
|
||||
1. Configure your terminal to use this font:
|
||||
- **iTerm2**: Type `p10k configure` and answer `Yes` when asked whether to install
|
||||
*Meslo Nerd Font*. Alternatively, open *iTerm2 → Preferences → Profiles → Text* and set *Font* to
|
||||
`MesloLGS NF`.
|
||||
- **Apple Terminal**: Open *Terminal → Preferences → Profiles → Text*, click *Change* under *Font*
|
||||
and select `MesloLGS NF` family.
|
||||
- **Hyper**: Open *Hyper → Edit → Preferences* and change the value of `fontFamily` under
|
||||
`module.exports.config` to `MesloLGS NF`.
|
||||
- **Visual Studio Code**: Open *File → Preferences → Settings* (PC) or
|
||||
*Code → Preferences → Settings* (Mac), enter `terminal.integrated.fontFamily` in the search box at
|
||||
the top of *Settings* tab and set the value below to `MesloLGS NF`.
|
||||
Consult [this screenshot](
|
||||
https://raw.githubusercontent.com/romkatv/powerlevel10k-media/389133fb8c9a2347929a23702ce3039aacc46c3d/visual-studio-code-font-settings.jpg)
|
||||
to see how it should look like or see [this issue](
|
||||
https://github.com/romkatv/powerlevel10k/issues/671) for extra information.
|
||||
- **GNOME Terminal** (the default Ubuntu terminal): Open *Terminal → Preferences* and click on the
|
||||
selected profile under *Profiles*. Check *Custom font* under *Text Appearance* and select
|
||||
`MesloLGS NF Regular`.
|
||||
- **Konsole**: Open *Settings → Edit Current Profile → Appearance*, click *Select Font* and select
|
||||
`MesloLGS NF Regular`.
|
||||
- **Tilix**: Open *Tilix → Preferences* and click on the selected profile under *Profiles*. Check
|
||||
*Custom font* under *Text Appearance* and select `MesloLGS NF Regular`.
|
||||
- **Windows Console Host** (the old thing): Click the icon in the top left corner, then
|
||||
*Properties → Font* and set *Font* to `MesloLGS NF`.
|
||||
- **Windows Terminal** by Microsoft (the new thing): Open `settings.json` (<kbd>Ctrl+Shift+,</kbd>),
|
||||
search for `fontFace` and set the value to `MesloLGS NF` for every profile. If you don't find
|
||||
`fontFace`, add it under *profiles → defaults*. See [this settings file](
|
||||
https://raw.githubusercontent.com/romkatv/dotfiles-public/aba0e6c4657d705ed6c344d700d659977385f25c/dotfiles/microsoft-terminal-settings.json)
|
||||
for example.
|
||||
- **IntelliJ** (and other IDEs by Jet Brains): Open *IDE → Edit → Preferences → Editor →
|
||||
Color Scheme → Console Font*. Select *Use console font instead of the default* and set the font
|
||||
name to `MesloLGS NF`.
|
||||
- **Termux**: Type `p10k configure` and answer `Yes` when asked whether to install
|
||||
*Meslo Nerd Font*.
|
||||
- **Blink**: Type `config`, go to *Appearance*, tap *Add a new font*, tap *Open Gallery*, select
|
||||
*MesloLGS NF.css*, tap *import* and type `exit` in the home view to reload the font.
|
||||
- **Terminus**: Open *Settings → Appearance* and set *Font* to `MesloLGS NF`.
|
||||
- **Terminator**: Open *Preferences* using the context menu. Under *Profiles* select the *General*
|
||||
tab (should be selected already), uncheck *Use the system fixed width font* (if not already)
|
||||
and select `MesloLGS NF Regular`. Exit the Preferences dialog by clicking *Close*.
|
||||
- **Guake**: Right Click on an open terminal and open *Preferences*. Under *Appearance*
|
||||
tab, uncheck *Use the system fixed width font* (if not already) and select `MesloLGS NF Regular`.
|
||||
Exit the Preferences dialog by clicking *Close*.
|
||||
- **MobaXterm**: Open *Settings* → *Configuration* → *Terminal* → (under *Terminal look and feel*)
|
||||
and change *Font* to `MesloLGS NF`.
|
||||
- **Asbrú Connection Manager**: Open *Preferences → Local Shell Options → Look and Feel*, enable
|
||||
*Use these personal options* and change *Font:* under *Terminal UI* to `MesloLGS NF Regular`.
|
||||
To change the font for the remote host connections, go to *Preferences → Terminal Options →
|
||||
Look and Feel* and change *Font:* under *Terminal UI* to `MesloLGS NF Regular`.
|
||||
- **WSLtty**: Right click on an open terminal and then on *Options*. In the *Text* section, under
|
||||
*Font*, click *"Select..."* and set Font to `MesloLGS NF Regular`.
|
||||
- **Yakuake**: Click *≡* → *Manage Profiles* → *New* → *Appearance*. Click *Choose* next to the
|
||||
*Font* dropdown, select `MesloLGS NF` and click *OK*. Click *OK* to save the profile. Select the
|
||||
new profile and click *Set as Default*.
|
||||
- **Alacritty**: Create or open `~/.config/alacritty/alacritty.yml` and add the following section
|
||||
to it:
|
||||
```yaml
|
||||
font:
|
||||
normal:
|
||||
family: "MesloLGS NF"
|
||||
```
|
||||
- **Kitty**: Create or open `~/.config/kitty/kitty.conf` and add the following line to it:
|
||||
```text
|
||||
font_family MesloLGS NF
|
||||
```
|
||||
Restart Kitty by closing all sessions and opening a new session.
|
||||
- **WezTerm**: Create or open `$HOME/.config/wezterm/wezterm.lua` and add the following:
|
||||
```lua
|
||||
local wezterm = require 'wezterm';
|
||||
return {
|
||||
font = wezterm.font("MesloLGS NF"),
|
||||
}
|
||||
```
|
||||
If the file already exists, only add the line with the font to the existing return.
|
||||
Also add the first line if it is not already present.
|
||||
- **urxvt**: Create or open `~/.Xresources` and add the following line to it:
|
||||
```text
|
||||
URxvt.font: xft:MesloLGS NF:size=11
|
||||
```
|
||||
You can adjust the font size to your preference. After changing the configuration use `xrdb ~/.Xresources` to reload the config.
|
||||
The new config is applied for all new terminals.
|
||||
1. Run `p10k configure` to generate a new `~/.p10k.zsh`. The old config may work
|
||||
incorrectly with the new font.
|
||||
|
||||
_Using a different terminal and know how to set the font for it? Share your knowledge by sending a
|
||||
PR to expand the list!_
|
@ -0,0 +1,4 @@
|
||||
BasedOnStyle: Google
|
||||
ColumnLimit: 100
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Left
|
16
zsh/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/.gitattributes
vendored
Normal file
16
zsh/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/.gitattributes
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
* text=auto
|
||||
|
||||
*.cc text eol=lf
|
||||
*.h text eol=lf
|
||||
*.info text eol=lf
|
||||
*.json text eol=lf
|
||||
*.md text eol=lf
|
||||
*.sh text eol=lf
|
||||
*.zsh text eol=lf
|
||||
|
||||
/.clang-format text eol=lf
|
||||
/LICENSE text eol=lf
|
||||
/Makefile text eol=lf
|
||||
/build text eol=lf
|
||||
/install text eol=lf
|
||||
/mbuild text eol=lf
|
8
zsh/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/.gitignore
vendored
Normal file
8
zsh/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
*.zwc
|
||||
/core
|
||||
/deps/libgit2-*.tar.gz
|
||||
/locks
|
||||
/logs
|
||||
/obj
|
||||
/usrbin/gitstatusd*
|
||||
/.vscode/ipch
|
17
zsh/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/.vscode/c_cpp_properties.json
vendored
Normal file
17
zsh/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/src"
|
||||
],
|
||||
"defines": [
|
||||
],
|
||||
"compilerPath": "/usr/bin/g++",
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++17",
|
||||
"intelliSenseMode": "gcc-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
72
zsh/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/.vscode/settings.json
vendored
Normal file
72
zsh/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
{
|
||||
"files.exclude": {
|
||||
"*.zwc": true,
|
||||
"core": true,
|
||||
"locks/": true,
|
||||
"logs/": true,
|
||||
"obj/": true,
|
||||
"usrbin/": true,
|
||||
},
|
||||
"files.associations": {
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cctype": "cpp",
|
||||
"chrono": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"complex": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"unordered_set": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"fstream": "cpp",
|
||||
"functional": "cpp",
|
||||
"future": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"memory": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"ostream": "cpp",
|
||||
"ratio": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"thread": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"tuple": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"utility": "cpp",
|
||||
"variant": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"charconv": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"iterator": "cpp",
|
||||
"map": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"random": "cpp",
|
||||
"string": "cpp",
|
||||
"bit": "cpp",
|
||||
"netfwd": "cpp"
|
||||
}
|
||||
}
|
674
zsh/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/LICENSE
Normal file
674
zsh/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/LICENSE
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
@ -0,0 +1,46 @@
|
||||
APPNAME ?= gitstatusd
|
||||
OBJDIR ?= obj
|
||||
|
||||
CXX ?= g++
|
||||
ZSH := $(shell command -v zsh 2> /dev/null)
|
||||
|
||||
VERSION ?= $(shell . ./build.info && printf "%s" "$$gitstatus_version")
|
||||
|
||||
# Note: -fsized-deallocation is not used to avoid binary compatibility issues on macOS.
|
||||
#
|
||||
# Sized delete is implemented as __ZdlPvm in /usr/lib/libc++.1.dylib but this symbol is
|
||||
# missing in macOS prior to 10.13.
|
||||
CXXFLAGS += -std=c++14 -funsigned-char -O3 -DNDEBUG -DGITSTATUS_VERSION=$(VERSION) -Wall -Werror # -g -fsanitize=thread
|
||||
LDFLAGS += -pthread # -fsanitize=thread
|
||||
LDLIBS += -lgit2 # -lprofiler -lunwind
|
||||
|
||||
SRCS := $(shell find src -name "*.cc")
|
||||
OBJS := $(patsubst src/%.cc, $(OBJDIR)/%.o, $(SRCS))
|
||||
|
||||
all: $(APPNAME)
|
||||
|
||||
$(APPNAME): usrbin/$(APPNAME)
|
||||
|
||||
usrbin/$(APPNAME): $(OBJS)
|
||||
$(CXX) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $@
|
||||
|
||||
$(OBJDIR):
|
||||
mkdir -p -- $(OBJDIR)
|
||||
|
||||
$(OBJDIR)/%.o: src/%.cc Makefile build.info | $(OBJDIR)
|
||||
$(CXX) $(CXXFLAGS) -MM -MT $@ src/$*.cc >$(OBJDIR)/$*.dep
|
||||
$(CXX) $(CXXFLAGS) -Wall -c -o $@ src/$*.cc
|
||||
|
||||
clean:
|
||||
rm -rf -- $(OBJDIR)
|
||||
|
||||
zwc:
|
||||
$(or $(ZSH),:) -fc 'for f in *.zsh install; do zcompile -R -- $$f.zwc $$f || exit; done'
|
||||
|
||||
minify:
|
||||
rm -rf -- .clang-format .git .gitattributes .gitignore .vscode deps docs src usrbin/.gitkeep LICENSE Makefile README.md build mbuild
|
||||
|
||||
pkg: zwc
|
||||
GITSTATUS_DAEMON= GITSTATUS_CACHE_DIR=$(shell pwd)/usrbin ./install -f
|
||||
|
||||
-include $(OBJS:.o=.dep)
|
529
zsh/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/README.md
Normal file
529
zsh/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/README.md
Normal file
@ -0,0 +1,529 @@
|
||||
# gitstatus
|
||||
|
||||
**gitstatus** is a 10x faster alternative to `git status` and `git describe`. Its primary use
|
||||
case is to enable fast git prompt in interactive shells.
|
||||
|
||||
Heavy lifting is done by **gitstatusd** -- a custom binary written in C++. It comes with Zsh and
|
||||
Bash bindings for integration with shell.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
1. [Using from Zsh](#using-from-zsh)
|
||||
1. [Using from Bash](#using-from-bash)
|
||||
2. [Using from other shells](#using-from-other-shells)
|
||||
1. [How it works](#how-it-works)
|
||||
1. [Benchmarks](#benchmarks)
|
||||
1. [Why fast](#why-fast)
|
||||
1. [Requirements](#requirements)
|
||||
1. [Compiling](#compiling)
|
||||
1. [License](#license)
|
||||
|
||||
## Using from Zsh
|
||||
|
||||
The easiest way to take advantage of gitstatus from Zsh is to use a theme that's already integrated
|
||||
with it. For example, [Powerlevel10k](https://github.com/romkatv/powerlevel10k) is a flexible and
|
||||
fast theme with first-class gitstatus integration.
|
||||
|
||||

|
||||
|
||||
For those who wish to use gitstatus without a theme, there is
|
||||
[gitstatus.prompt.zsh](gitstatus.prompt.zsh). Install it as follows:
|
||||
|
||||
```zsh
|
||||
git clone --depth=1 https://github.com/romkatv/gitstatus.git ~/gitstatus
|
||||
echo 'source ~/gitstatus/gitstatus.prompt.zsh' >>! ~/.zshrc
|
||||
```
|
||||
|
||||
Users in mainland China can use the official mirror on gitee.com for faster download.<br>
|
||||
中国大陆用户可以使用 gitee.com 上的官方镜像加速下载.
|
||||
|
||||
```zsh
|
||||
git clone --depth=1 https://gitee.com/romkatv/gitstatus.git ~/gitstatus
|
||||
echo 'source ~/gitstatus/gitstatus.prompt.zsh' >>! ~/.zshrc
|
||||
```
|
||||
|
||||
Alternatively, if you have Homebrew installed:
|
||||
|
||||
```zsh
|
||||
brew install romkatv/gitstatus/gitstatus
|
||||
echo "source $(brew --prefix)/opt/gitstatus/gitstatus.prompt.zsh" >>! ~/.zshrc
|
||||
```
|
||||
|
||||
(If you choose this option, replace `~/gitstatus` with `$(brew --prefix)/opt/gitstatus/gitstatus`
|
||||
in all code snippets below.)
|
||||
|
||||
_Make sure to disable your current theme if you have one._
|
||||
|
||||
This will give you a basic yet functional prompt with git status in it. It's
|
||||
[over 10x faster](#benchmarks) than any alternative that can give you comparable prompt. In order
|
||||
to customize it, set `PROMPT` and/or `RPROMPT` at the end of `~/.zshrc` after sourcing
|
||||
`gitstatus.prompt.zsh`. Insert `${GITSTATUS_PROMPT}` where you want git status to go. For example:
|
||||
|
||||
```zsh
|
||||
source ~/gitstatus/gitstatus.prompt.zsh
|
||||
|
||||
PROMPT='%~%# ' # left prompt: directory followed by %/# (normal/root)
|
||||
RPROMPT='$GITSTATUS_PROMPT' # right prompt: git status
|
||||
```
|
||||
|
||||
The expansion of `${GITSTATUS_PROMPT}` can contain the following bits:
|
||||
|
||||
| segment | meaning |
|
||||
|-------------|-------------------------------------------------------|
|
||||
| `master` | current branch |
|
||||
| `#v1` | HEAD is tagged with `v1`; not shown when on a branch |
|
||||
| `@5fc6fca4` | current commit; not shown when on a branch or tag |
|
||||
| `⇣1` | local branch is behind the remote by 1 commit |
|
||||
| `⇡2` | local branch is ahead of the remote by 2 commits |
|
||||
| `⇠3` | local branch is behind the push remote by 3 commits |
|
||||
| `⇢4` | local branch is ahead of the push remote by 4 commits |
|
||||
| `*5` | there are 5 stashes |
|
||||
| `merge` | merge is in progress (could be some other action) |
|
||||
| `~6` | there are 6 merge conflicts |
|
||||
| `+7` | there are 7 staged changes |
|
||||
| `!8` | there are 8 unstaged changes |
|
||||
| `?9` | there are 9 untracked files |
|
||||
|
||||
`$GITSTATUS_PROMPT_LEN` tells you how long `$GITSTATUS_PROMPT` is when printed to the console.
|
||||
[gitstatus.prompt.zsh](gitstatus.prompt.zsh) has an example of using it to truncate the current
|
||||
directory.
|
||||
|
||||
If you'd like to change the format of git status, or want to have greater control over the
|
||||
process of assembling `PROMPT`, you can copy and modify parts of
|
||||
[gitstatus.prompt.zsh](gitstatus.prompt.zsh) instead of sourcing the script. Your `~/.zshrc`
|
||||
might look something like this:
|
||||
|
||||
```zsh
|
||||
source ~/gitstatus/gitstatus.plugin.zsh
|
||||
|
||||
function my_set_prompt() {
|
||||
PROMPT='%~%# '
|
||||
RPROMPT=''
|
||||
|
||||
if gitstatus_query MY && [[ $VCS_STATUS_RESULT == ok-sync ]]; then
|
||||
RPROMPT=${${VCS_STATUS_LOCAL_BRANCH:-@${VCS_STATUS_COMMIT}}//\%/%%} # escape %
|
||||
(( VCS_STATUS_NUM_STAGED )) && RPROMPT+='+'
|
||||
(( VCS_STATUS_NUM_UNSTAGED )) && RPROMPT+='!'
|
||||
(( VCS_STATUS_NUM_UNTRACKED )) && RPROMPT+='?'
|
||||
fi
|
||||
|
||||
setopt no_prompt_{bang,subst} prompt_percent # enable/disable correct prompt expansions
|
||||
}
|
||||
|
||||
gitstatus_stop 'MY' && gitstatus_start -s -1 -u -1 -c -1 -d -1 'MY'
|
||||
autoload -Uz add-zsh-hook
|
||||
add-zsh-hook precmd my_set_prompt
|
||||
```
|
||||
|
||||
This snippet is sourcing `gitstatus.plugin.zsh` rather than `gitstatus.prompt.zsh`. The former
|
||||
defines low-level bindings that communicate with gitstatusd over pipes. The latter is a simple
|
||||
script that uses these bindings to assemble git prompt.
|
||||
|
||||
Unlike [Powerlevel10k](https://github.com/romkatv/powerlevel10k), code based on
|
||||
[gitstatus.prompt.zsh](gitstatus.prompt.zsh) is communicating with gitstatusd synchronously. This
|
||||
can make your prompt slow when working in a large git repository or on a slow machine. To avoid
|
||||
this problem, call `gitstatus_query` asynchronously as documented in
|
||||
[gitstatus.plugin.zsh](gitstatus.plugin.zsh). This can be quite challenging.
|
||||
|
||||
## Using from Bash
|
||||
|
||||
The easiest way to take advantage of gitstatus from Bash is via
|
||||
[gitstatus.prompt.sh](gitstatus.prompt.sh). Install it as follows:
|
||||
|
||||
```bash
|
||||
git clone --depth=1 https://github.com/romkatv/gitstatus.git ~/gitstatus
|
||||
echo 'source ~/gitstatus/gitstatus.prompt.sh' >> ~/.bashrc
|
||||
```
|
||||
|
||||
Users in mainland China can use the official mirror on gitee.com for faster download.<br>
|
||||
中国大陆用户可以使用 gitee.com 上的官方镜像加速下载.
|
||||
|
||||
```bash
|
||||
git clone --depth=1 https://gitee.com/romkatv/gitstatus.git ~/gitstatus
|
||||
echo 'source ~/gitstatus/gitstatus.prompt.sh' >> ~/.bashrc
|
||||
```
|
||||
|
||||
Alternatively, if you have Homebrew installed:
|
||||
|
||||
```zsh
|
||||
brew install romkatv/gitstatus/gitstatus
|
||||
echo "source $(brew --prefix)/opt/gitstatus/gitstatus.prompt.sh" >> ~/.bashrc
|
||||
```
|
||||
|
||||
(If you choose this option, replace `~/gitstatus` with `$(brew --prefix)/opt/gitstatus/gitstatus`
|
||||
in all code snippets below.)
|
||||
|
||||
This will give you a basic yet functional prompt with git status in it. It's
|
||||
[over 10x faster](#benchmarks) than any alternative that can give you comparable prompt.
|
||||
|
||||

|
||||
|
||||
In order to customize your prompt, set `PS1` at the end of `~/.bashrc` after sourcing
|
||||
`gitstatus.prompt.sh`. Insert `${GITSTATUS_PROMPT}` where you want git status to go. For example:
|
||||
|
||||
```bash
|
||||
source ~/gitstatus/gitstatus.prompt.sh
|
||||
|
||||
PS1='\w ${GITSTATUS_PROMPT}\n\$ ' # directory followed by git status and $/# (normal/root)
|
||||
```
|
||||
|
||||
The expansion of `${GITSTATUS_PROMPT}` can contain the following bits:
|
||||
|
||||
| segment | meaning |
|
||||
|-------------|-------------------------------------------------------|
|
||||
| `master` | current branch |
|
||||
| `#v1` | HEAD is tagged with `v1`; not shown when on a branch |
|
||||
| `@5fc6fca4` | current commit; not shown when on a branch or tag |
|
||||
| `⇣1` | local branch is behind the remote by 1 commit |
|
||||
| `⇡2` | local branch is ahead of the remote by 2 commits |
|
||||
| `⇠3` | local branch is behind the push remote by 3 commits |
|
||||
| `⇢4` | local branch is ahead of the push remote by 4 commits |
|
||||
| `*5` | there are 5 stashes |
|
||||
| `merge` | merge is in progress (could be some other action) |
|
||||
| `~6` | there are 6 merge conflicts |
|
||||
| `+7` | there are 7 staged changes |
|
||||
| `!8` | there are 8 unstaged changes |
|
||||
| `?9` | there are 9 untracked files |
|
||||
|
||||
If you'd like to change the format of git status, or want to have greater control over the
|
||||
process of assembling `PS1`, you can copy and modify parts of
|
||||
[gitstatus.prompt.sh](gitstatus.prompt.sh) instead of sourcing the script. Your `~/.bashrc` might
|
||||
look something like this:
|
||||
|
||||
```bash
|
||||
source ~/gitstatus/gitstatus.plugin.sh
|
||||
|
||||
function my_set_prompt() {
|
||||
PS1='\w'
|
||||
|
||||
if gitstatus_query && [[ "$VCS_STATUS_RESULT" == ok-sync ]]; then
|
||||
if [[ -n "$VCS_STATUS_LOCAL_BRANCH" ]]; then
|
||||
PS1+=" ${VCS_STATUS_LOCAL_BRANCH//\\/\\\\}" # escape backslash
|
||||
else
|
||||
PS1+=" @${VCS_STATUS_COMMIT//\\/\\\\}" # escape backslash
|
||||
fi
|
||||
(( VCS_STATUS_HAS_STAGED" )) && PS1+='+'
|
||||
(( VCS_STATUS_HAS_UNSTAGED" )) && PS1+='!'
|
||||
(( VCS_STATUS_HAS_UNTRACKED" )) && PS1+='?'
|
||||
fi
|
||||
|
||||
PS1+='\n\$ '
|
||||
|
||||
shopt -u promptvars # disable expansion of '$(...)' and the like
|
||||
}
|
||||
|
||||
gitstatus_stop && gitstatus_start
|
||||
PROMPT_COMMAND=my_set_prompt
|
||||
```
|
||||
|
||||
This snippet is sourcing `gitstatus.plugin.sh` rather than `gitstatus.prompt.sh`. The former
|
||||
defines low-level bindings that communicate with gitstatusd over pipes. The latter is a simple
|
||||
script that uses these bindings to assemble git prompt.
|
||||
|
||||
Note: Bash bindings, unlike Zsh bindings, don't support asynchronous calls.
|
||||
|
||||
## Using from other shells
|
||||
|
||||
If there are no gitstatusd bindings for your shell, you'll need to get your hands dirty.
|
||||
Use the existing bindings for inspiration; run `gitstatusd --help` or read the same thing in
|
||||
[options.cc](src/options.cc).
|
||||
|
||||
## How it works
|
||||
|
||||
gitstatusd reads requests from stdin and prints responses to stdout. Requests contain an ID and
|
||||
a directory. Responses contain the same ID and machine-readable git status for the directory.
|
||||
gitstatusd keeps some state in memory for the directories it has seen in order to serve future
|
||||
requests faster.
|
||||
|
||||
[Zsh bindings](gitstatus.plugin.zsh) and [Bash bindings](gitstatus.plugin.sh) start gitstatusd in
|
||||
the background and communicate with it via pipes. Themes such as
|
||||
[Powerlevel10k](https://github.com/romkatv/powerlevel10k) use these bindings to put git status in
|
||||
`PROMPT`.
|
||||
|
||||
Note that gitstatus cannot be used as a drop-in replacement for `git status` command as it doesn't
|
||||
produce output in the same format. It does perform the same computation though.
|
||||
|
||||
## Benchmarks
|
||||
|
||||
The following benchmark results were obtained on Intel i9-7900X running Ubuntu 18.04 in
|
||||
a clean [chromium](https://github.com/chromium/chromium) repository synced to `9394e49a`. The
|
||||
repository was checked out to an ext4 filesystem on M.2 SSD.
|
||||
|
||||
Three functionally equivalent tools for computing git status were benchmarked:
|
||||
|
||||
* `gitstatusd`
|
||||
* `git` with untracked cache enabled
|
||||
* `lg2` -- a demo/example executable from [libgit2](https://github.com/romkatv/libgit2) that
|
||||
implements a subset of `git` functionality on top of libgit2 API; for the purposes of this
|
||||
benchmark the subset is sufficient to generate the same data as the other tools
|
||||
|
||||
Every tool was benchmark in cold and hot conditions. For `git` the first run in a repository was
|
||||
considered cold, with the following runs considered hot. `lg2` was patched to compute results twice
|
||||
in a single invocation without freeing the repository in between; the second run was considered hot.
|
||||
The same patching was not done for `git` because `git` cannot be easily modified to refresh inmemory
|
||||
index state between invocations; in fact, this limitation is one of the primary reasons developers
|
||||
use libgit2. `gitstatusd` was benchmarked similarly to `lg2` with two result computations in the
|
||||
same invocation.
|
||||
|
||||
Two commands were benchmarked: `status` and `describe`.
|
||||
|
||||
### Status
|
||||
|
||||
In this benchmark all tools were computing the equivalent of `git status`. Lower numbers are better.
|
||||
|
||||
| Tool | Cold | Hot |
|
||||
|---------------|-----------:|------------:|
|
||||
| **gitstatus** | **291 ms** | **30.9 ms** |
|
||||
| git | 876 ms | 295 ms |
|
||||
| lg2 | 1730 ms | 1310 ms |
|
||||
|
||||
gitstatusd is substantially faster than the alternatives, especially on hot runs. Note that hot runs
|
||||
are of primary importance to the main use case of gitstatus in interactive shells.
|
||||
|
||||
The performance of `git status` fluctuated wildly in this benchmarks for reasons unknown to the
|
||||
author. Moreover, performance is sticky -- once `git status` settles around a number, it stays
|
||||
there for a long time. Numbers as diverse as 295, 352, 663 and 730 had been observed on hot runs on
|
||||
the same repository. The number in the table is the lowest (fastest or best) that `git status` had
|
||||
shown.
|
||||
|
||||
### Describe
|
||||
|
||||
In this benchmark all tools were computing the equivalent of `git describe --tags --exact-match`
|
||||
to find tags that resolve to the same commit as `HEAD`. Lower numbers are better.
|
||||
|
||||
| Tool | Cold | Hot |
|
||||
|---------------|------------:|--------------:|
|
||||
| **gitstatus** | **4.04 ms** | **0.0345 ms** |
|
||||
| git | 18.0 ms | 14.5 ms |
|
||||
| lg2 | 185 ms | 45.2 ms |
|
||||
|
||||
gitstatusd is once again faster than the alternatives, more so on hot runs.
|
||||
|
||||
## Why fast
|
||||
|
||||
Since gitstatusd doesn't have to print all staged/unstaged/untracked files but only report
|
||||
whether there are any, it can terminate repository scan early. It can also remember which files
|
||||
were dirty on the previous run and check them first on the next run to avoid the scan entirely if
|
||||
the files are still dirty. However, the benchmarks above were performed in a clean repository where
|
||||
these shortcuts do not trigger. All benchmarked tools had to do the same work -- check the status
|
||||
of every file in the index to see if it has changed, check every directory for newly created files,
|
||||
etc. And yet, gitstatusd came ahead by a large margin. This section describes what it does that
|
||||
makes it so fast.
|
||||
|
||||
Most of the following comparisons are done against libgit2 rather than git because of the author's
|
||||
familiarity with the former but not the with latter. libgit2 has clean, well-documented APIs and an
|
||||
elegant implementation, which makes it so much easier to work with and to analyze performance
|
||||
bottlenecks.
|
||||
|
||||
### Summary for the impatient
|
||||
|
||||
Under the benchmark conditions described above, the equivalent of libgit2's
|
||||
`git_diff_index_to_workdir` (the most expensive part of `status` command) is 46.3 times faster in
|
||||
gitstatusd. The speedup comes from the following sources.
|
||||
|
||||
* gitstatusd uses more efficient data structures and algorithms and employs performance-conscious
|
||||
coding style throughout the codebase. This reduces CPU time in userspace by 32x compared to libgit2.
|
||||
* gitstatusd uses less expensive system calls and makes fewer of them. This reduces CPU time spent
|
||||
in kernel by 1.9x.
|
||||
* gitstatusd can utilize multiple cores to scan index and workdir in parallel with almost perfect
|
||||
scaling. This reduces total run time by 12.4x while having virtually no effect on total CPU time.
|
||||
|
||||
### Problem statement
|
||||
|
||||
The most resource-intensive part of the `status` command is finding the difference between _index_
|
||||
and _workdir_ (`git_diff_index_to_workdir` in libgit2). Index is a list of all files in the git
|
||||
repository with their last modification times. This is an obvious simplification but it suffices for
|
||||
this exposition. On disk, index is stored sorted by file path. Here's an example of git index:
|
||||
|
||||
| File | Last modification time |
|
||||
|-------------|-----------------------:|
|
||||
| Makefile | 2019-04-01T14:12:32Z |
|
||||
| src/hello.c | 2019-04-01T14:12:00Z |
|
||||
| src/hello.h | 2019-04-01T14:12:32Z |
|
||||
|
||||
This list needs to be compared to the list of files in the working directory. If any of the files
|
||||
listed in the index are missing from the workdir or have different last modification time, they are
|
||||
"unstaged" in gitstatusd parlance. If you run `git status`, they'll be shown as "changes not staged
|
||||
for commit". Thus, any implementation of `status` command has to call `stat()` or one of its
|
||||
variants on every file in the index.
|
||||
|
||||
In addition, all files in the working directory for which there is no entry in the index at all are
|
||||
"untracked". `git status` will show them as "untracked files". Finding untracked files requires some
|
||||
form of work directory traversal.
|
||||
|
||||
### Single-threaded scan
|
||||
|
||||
Let's see how `git_diff_index_to_workdir` from libgit2 accomplishes these tasks. Here's its CPU
|
||||
profile from 200 hot runs over chromium repository.
|
||||
|
||||

|
||||
|
||||
(The CPU profile was created with [gperftools](https://github.com/gperftools/gperftools) and
|
||||
rendered with [pprof](https://github.com/google/pprof)).
|
||||
|
||||
We can see `__GI__lxstat` taking a lot of time. This is the `stat()` call for every file in the
|
||||
index. We can also identify `__opendir`, `__readdir` and `__GI___close_nocancel` -- glibc wrappers
|
||||
for reading the contents of a directory. This is for finding untracked files. Out of the total 232
|
||||
seconds, 111 seconds -- or 47.7% -- was spent on these calls. The rest is computation -- comparing
|
||||
strings, sorting arrays, etc.
|
||||
|
||||
Now let's take a look at the CPU profile of gitstatusd on the same task.
|
||||
|
||||

|
||||
|
||||
The first impression is that this profile looks pruned. This isn't an artifact. The profile was
|
||||
generated with the same tools and the same flags as the profile of libgit2.
|
||||
|
||||
Since both profiles were generated from the same workload, absolute numbers can be compared. We can
|
||||
see that gitstatusd took 62 seconds in total compared to libgit2's 232 seconds. System calls at the
|
||||
core of the algorithm are cleary visible. `__GI___fxstatat` is a flavor of `stat()`, and the other
|
||||
three calls -- `__libc_openat64`, `__libc_close` and `__GI___fxstat` are responsible for opening
|
||||
directories and finding untracked files. Notice that there is almost nothing else in the profile
|
||||
apart from these calls. The rest of the code accounts for 3.77 seconds of CPU time -- 32 times less
|
||||
than in libgit2.
|
||||
|
||||
So, one reason gitstatusd is fast is that it has efficient diffing code -- very little time is spent
|
||||
outside of kernel. However, if we look closely, we can notice that system calls in gitstatusd are
|
||||
_also_ faster than in libgit2. For example, libgit2 spent 72.07 seconds in `__GI__lxstat` while
|
||||
gitstatusd spent only 48.82 seconds in `__GI___fxstatat`. There are two reasons for this difference.
|
||||
First, libgit2 makes more `stat()` calls than is strictly required. It's not necessary to stat
|
||||
directories because index only has files. There are 25k directories in chromium repository (and 300k
|
||||
files) -- that's 25k `stat()` calls that could be avoided. The second reason is that libgit2 and
|
||||
gitstatusd use different flavors of `stat()`. libgit2 uses `lstat()`, which takes a path to the file
|
||||
as input. Its performance is linear in the number of subdirectories in the path because it needs to
|
||||
perform a lookup for every one of them and to check permissions. gitstatusd uses `fstatat()`, which
|
||||
takes a file descriptor to the parent directory and a name of the file. Just a single lookup, less
|
||||
CPU time.
|
||||
|
||||
Similarly to `lstat()` vs `fstatat()`, it's faster to open files and directories with `openat()`
|
||||
from the parent directory file descriptor than with regular `open()` that accepts full file path.
|
||||
gitstatusd takes advantage of `openat()` to open directories as fast as possible. It opens about 90%
|
||||
of the directories (this depends on the actual directory structure of the repository) from the
|
||||
immediate parent -- the most efficient way -- and the remaining 10% it opens from the repository's
|
||||
root directory. The reason it's done this way is to keep the maximum number of simultaneously open
|
||||
file descriptors bounded. libgit2 can have O(repository depth) simultaneously open file descriptors,
|
||||
which may be OK for a single-threaded application but can balloon to a large number when scans are
|
||||
done by many threads simultaneously, like in gitstatusd.
|
||||
|
||||
There is no equivalent to `__opendir` or `__readdir` in the gitstatusd profile because it uses the
|
||||
equivalent of [untracked cache](https://git-scm.com/docs/git-update-index#_untracked_cache) from
|
||||
git. On the first scan of the workdir gitstatusd lists all files just like libgit2. But, unlike
|
||||
libgit2, it remembers the last modification time of every directory along with the list of
|
||||
untracked files under it. On the next scan, gitstatusd can skip listing files in directories whose
|
||||
last modification time hasn't changed.
|
||||
|
||||
To summarize, here's what gitstatusd was doing when the CPU profile was captured:
|
||||
|
||||
1. `__libc_openat64`: Open every directory for which there are files in the index.
|
||||
2. `__GI___fxstat`: Check last modification time of the directory. Since it's the same as on the
|
||||
last scan, this directory has the same list of untracked files as before, which is empty (the
|
||||
repository is clean).
|
||||
3. `__GI___fxstatat`: Check last modification time for every file in the index that belongs to this
|
||||
directory.
|
||||
4. `__libc_close`: Close the file descriptor to the directory.
|
||||
|
||||
Here's how the very first scan of a repository looks like in gitstatusd:
|
||||
|
||||

|
||||
|
||||
(Some glibc functions are mislabel on this profile. `explicit_bzero` and `__nss_passwd_lookup` are
|
||||
in reality `strcmp` and `memcmp`.)
|
||||
|
||||
This is a superset of the previous -- hot -- profile, with an extra `syscall` and string sorting for
|
||||
directory listing. gitstatusd uses `getdents64` Linux system call directly, bypassing the glibc
|
||||
wrapper that libgit2 uses. This is 23% faster. The details of this optimization can be found in a
|
||||
[separate document](docs/listdir.md).
|
||||
|
||||
### Multithreading
|
||||
|
||||
The diffing algorithm in gitstatusd was designed from the ground up with the intention of using it
|
||||
concurrently from multiple threads. With a fast SSD, `status` is CPU bound, so taking advantage of
|
||||
all available CPU cores is an obvious way to yield results faster.
|
||||
|
||||
gitstatusd exhibits almost perfect scaling from multithreading. Engaging all cores allows it to
|
||||
produce results 12.4 times faster than in single-threaded execution. This is on Intel i9-7900X with
|
||||
10 cores (20 with hyperthreading) with single-core frequency of 4.3GHz and all-core frequency of
|
||||
4.0GHz.
|
||||
|
||||
Note: `git status` also uses all available cores in some parts of its algorithm while `lg2` does
|
||||
everything in a single thread.
|
||||
|
||||
### Postprocessing
|
||||
|
||||
Once the difference between the index and the workdir is found, we have a list of _candidates_ --
|
||||
files that may be unstaged or untracked. To make the final judgement, these files need to be checked
|
||||
against `.gitignore` rules and a few other things.
|
||||
|
||||
gitstatusd uses [patched libgit2](https://github.com/romkatv/libgit2) for this step. This fork
|
||||
adds several optimizations that make libgit2 faster. The patched libgit2 performs more than twice
|
||||
as fast in the benchmark as the original even without changes in the user code (that is, in the
|
||||
code that uses the libgit2 APIs). The fork also adds several API extensions, most notable of which
|
||||
is the support for multi-threaded scans. If `lg2 status` is modified to take advantage of these
|
||||
extensions, it outperforms the original libgit2 by a factor of 18. Lastly, the fork fixes a score of
|
||||
bugs, most of which become apparent only when using libgit2 from multiple threads.
|
||||
|
||||
_WARNING: Changes to libgit2 are extensive but the testing they underwent isn't. It is
|
||||
**not recommended** to use the patched libgit2 in production._
|
||||
|
||||
## Requirements
|
||||
|
||||
* To compile: binutils, cmake, gcc, g++, git and GNU make.
|
||||
* To run: Linux, macOS, FreeBSD, Android, WSL, Cygwin or MSYS2.
|
||||
|
||||
## Compiling
|
||||
|
||||
There are prebuilt `gitstatusd` binaries in [releases](
|
||||
https://github.com/romkatv/gitstatus/releases). When using the official shell bindings
|
||||
provided by gitstatus, the right binary for your architecture gets downloaded automatically.
|
||||
|
||||
If prebuilt binaries don't work for you, you'll need to get your hands dirty.
|
||||
|
||||
### Compiling for personal use
|
||||
|
||||
```zsh
|
||||
git clone --depth=1 https://github.com/romkatv/gitstatus.git
|
||||
cd gitstatus
|
||||
./build -w -s -d docker
|
||||
```
|
||||
|
||||
Users in mainland China can use the official mirror on gitee.com for faster download.<br>
|
||||
中国大陆用户可以使用 gitee.com 上的官方镜像加速下载.
|
||||
|
||||
```zsh
|
||||
git clone --depth=1 https://gitee.com/romkatv/gitstatus.git
|
||||
cd gitstatus
|
||||
./build -w -s -d docker
|
||||
```
|
||||
|
||||
- If it says that `-d docker` is not supported on your OS, remove this flag.
|
||||
- If it says that `-s` is not supported on your OS, remove this flag.
|
||||
- If it tell you to install docker but you cannot or don't want to, remove `-d docker`.
|
||||
- If it says that some command is missing, install it.
|
||||
|
||||
If everything goes well, the newly built binary will appear in `./usrbin`. It'll be picked up
|
||||
by shell bindings automatically.
|
||||
|
||||
When you update shell bindings, they may refuse to work with the binary you've built earlier. In
|
||||
this case you'll need to rebuild.
|
||||
|
||||
If you are using gitstatus through [Powerlevel10k](https://github.com/romkatv/powerlevel10k), the
|
||||
instructions are the same except that you don't need to clone gitstatus. Instead, change your
|
||||
current directory to `/path/to/powerlevel10k/gitstatus` (`/path/to/powerlevel10k` is the directory
|
||||
where you've installed Powerlevel10k) and run `./build -w -s -d docker` from there as described
|
||||
above.
|
||||
|
||||
### Compiling for distribution
|
||||
|
||||
It's currently neither easy nor recommended to package and distribute gitstatus. There are no
|
||||
instructions you can follow that would allow you to easily update your package when new versions of
|
||||
gitstatus are released. This may change in the future but not soon.
|
||||
|
||||
## License
|
||||
|
||||
GNU General Public License v3.0. See [LICENSE](LICENSE). Contributions are covered by the same
|
||||
license.
|
623
zsh/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/build
Executable file
623
zsh/.oh-my-zsh/custom/themes/powerlevel10k/gitstatus/build
Executable file
@ -0,0 +1,623 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Type `build -h` for help and see https://github.com/romkatv/gitstatus
|
||||
# for full documentation.
|
||||
|
||||
set -ue
|
||||
|
||||
if [ -n "${ZSH_VERSION:-}" ]; then
|
||||
emulate sh -o err_exit -o no_unset
|
||||
fi
|
||||
|
||||
export LC_ALL=C
|
||||
|
||||
if [ -z "${ZSH_VERSION-}" ] && command -v zsh >/dev/null 2>&1; then
|
||||
case "${BASH_VERSION-}" in
|
||||
[0-3].*) exec zsh "$0" "$@";;
|
||||
esac
|
||||
fi
|
||||
|
||||
usage="$(command cat <<\END
|
||||
Usage: build [-m ARCH] [-c CPU] [-d CMD] [-i IMAGE] [-s] [-w]
|
||||
|
||||
Options:
|
||||
|
||||
-m ARCH `uname -m` from the target machine; defaults to `uname -m`
|
||||
from the local machine
|
||||
-c CPU generate machine instructions for CPU of this type; this
|
||||
value gets passed as `-march` (or `-mcpu` for ppc64le) to gcc;
|
||||
inferred from ARCH if not set explicitly
|
||||
-d CMD build in a Docker container and use CMD as the `docker`
|
||||
command; e.g., `-d docker` or `-d podman`
|
||||
-i IMAGE build in this Docker image; inferred from ARCH if not set
|
||||
explicitly
|
||||
-s install whatever software is necessary for build to
|
||||
succeed; on some operating systems this option is not
|
||||
supported; on others it can have partial effect
|
||||
-w automatically download tarballs for dependencies if they
|
||||
do not already exist in ./deps; dependencies are described
|
||||
in ./build.info
|
||||
END
|
||||
)"
|
||||
|
||||
build="$(command cat <<\END
|
||||
outdir="$(command pwd)"
|
||||
|
||||
if command -v mktemp >/dev/null 2>&1; then
|
||||
workdir="$(command mktemp -d "${TMPDIR:-/tmp}"/gitstatus-build.XXXXXXXXXX)"
|
||||
else
|
||||
workdir="${TMPDIR:-/tmp}/gitstatus-build.tmp.$$"
|
||||
command mkdir -- "$workdir"
|
||||
fi
|
||||
|
||||
cd -- "$workdir"
|
||||
workdir="$(command pwd)"
|
||||
|
||||
narg() { echo $#; }
|
||||
|
||||
if [ "$(narg $workdir)" != 1 -o -z "${workdir##*:*}" -o -z "${workdir##*=*}" ]; then
|
||||
>&2 echo "[error] cannot build in this directory: $workdir"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
appname=gitstatusd
|
||||
libgit2_tmp="$outdir"/deps/"$appname".libgit2.tmp
|
||||
|
||||
cleanup() {
|
||||
trap - INT QUIT TERM ILL PIPE
|
||||
cd /
|
||||
if ! command rm -rf -- "$workdir" "$outdir"/usrbin/"$appname".tmp "$libgit2_tmp"; then
|
||||
command sleep 5
|
||||
command rm -rf -- "$workdir" "$outdir"/usrbin/"$appname".tmp "$libgit2_tmp"
|
||||
fi
|
||||
}
|
||||
trap cleanup INT QUIT TERM ILL PIPE
|
||||
|
||||
if [ -n "$gitstatus_install_tools" ]; then
|
||||
case "$gitstatus_kernel" in
|
||||
linux)
|
||||
if command -v apk >/dev/null 2>&1; then
|
||||
command apk update
|
||||
command apk add binutils cmake gcc g++ git make musl-dev perl-utils
|
||||
elif command -v apt-get >/dev/null 2>&1; then
|
||||
apt-get update
|
||||
apt-get install -y binutils cmake gcc g++ make wget
|
||||
else
|
||||
>&2 echo "[error] -s is not supported on this system"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
freebsd)
|
||||
command pkg install -y cmake gmake binutils git perl5 wget
|
||||
;;
|
||||
openbsd)
|
||||
command pkg_add install cmake gmake gcc git wget
|
||||
;;
|
||||
netbsd)
|
||||
command pkgin -y install cmake gmake binutils git
|
||||
;;
|
||||
darwin)
|
||||
if ! command -v make >/dev/null 2>&1 || ! command -v gcc >/dev/null 2>&1; then
|
||||
>&2 echo "[error] please run 'xcode-select --install' and retry"
|
||||
exit 1
|
||||
fi
|
||||
if command -v port >/dev/null 2>&1; then
|
||||
sudo port -N install libiconv cmake wget
|
||||
elif command -v brew >/dev/null 2>&1; then
|
||||
for formula in libiconv cmake git wget; do
|
||||
if command brew ls --version "$formula" &>/dev/null; then
|
||||
command brew upgrade "$formula"
|
||||
else
|
||||
command brew install "$formula"
|
||||
fi
|
||||
done
|
||||
else
|
||||
>&2 echo "[error] please install MacPorts or Homebrew and retry"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
msys*|mingw*)
|
||||
command pacman -Syu --noconfirm
|
||||
command pacman -S --needed --noconfirm binutils cmake gcc git make perl
|
||||
;;
|
||||
*)
|
||||
>&2 echo "[internal error] unhandled kernel: $gitstatus_kernel"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
cpus="$(command getconf _NPROCESSORS_ONLN 2>/dev/null)" ||
|
||||
cpus="$(command sysctl -n hw.ncpu 2>/dev/null)" ||
|
||||
cpus=8
|
||||
|
||||
case "$gitstatus_cpu" in
|
||||
powerpc64le) archflag="-mcpu";;
|
||||
*) archflag="-march";;
|
||||
esac
|
||||
|
||||
cflags="$archflag=$gitstatus_cpu -fno-plt -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fpie"
|
||||
ldflags=
|
||||
static_pie=
|
||||
|
||||
if [ -z "${CC-}" ]; then
|
||||
case "$gitstatus_kernel" in
|
||||
freebsd) export CC=clang;;
|
||||
*) export CC=cc;;
|
||||
esac
|
||||
fi
|
||||
|
||||
printf 'int main() {}\n' >"$workdir"/cc-test.c
|
||||
if 2>/dev/null "$CC" \
|
||||
-ffile-prefix-map=x=y \
|
||||
-Werror \
|
||||
-c "$workdir"/cc-test.c \
|
||||
-o "$workdir"/cc-test.o; then
|
||||
cflags="$cflags -ffile-prefix-map=$workdir/="
|
||||
fi
|
||||
|
||||
command rm -f -- "$workdir"/cc-test "$workdir"/cc-test.o
|
||||
if 2>/dev/null "$CC" \
|
||||
-fstack-clash-protection -fcf-protection \
|
||||
-Werror \
|
||||
-c "$workdir"/cc-test.c \
|
||||
-o "$workdir"/cc-test.o; then
|
||||
cflags="$cflags -fstack-clash-protection -fcf-protection"
|
||||
fi
|
||||
|
||||
command rm -f -- "$workdir"/cc-test "$workdir"/cc-test.o
|
||||
if 2>/dev/null "$CC" \
|
||||
-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now \
|
||||
-Werror \
|
||||
"$workdir"/cc-test.c \
|
||||
-o "$workdir"/cc-test; then
|
||||
ldflags="$ldflags -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now"
|
||||
fi
|
||||
|
||||
command rm -f -- "$workdir"/cc-test "$workdir"/cc-test.o
|
||||
if 2>/dev/null "$CC" \
|
||||
-fpie -static-pie \
|
||||
-Werror \
|
||||
"$workdir"/cc-test.c \
|
||||
-o "$workdir"/cc-test; then
|
||||
static_pie='-static-pie'
|
||||
fi
|
||||
|
||||
if [ "$gitstatus_cpu" = x86-64 ]; then
|
||||
cflags="$cflags -mtune=generic"
|
||||
fi
|
||||
|
||||
libgit2_cmake_flags=
|
||||
libgit2_cflags="${CFLAGS-} $cflags -O3 -DNDEBUG"
|
||||
|
||||
gitstatus_cxx=g++
|
||||
gitstatus_cxxflags="${CXXFLAGS-} $cflags -I${workdir}/libgit2/include -DGITSTATUS_ZERO_NSEC -D_GNU_SOURCE -D_GLIBCXX_ASSERTIONS"
|
||||
gitstatus_ldflags="${LDFLAGS-} $ldflags -L${workdir}/libgit2/build"
|
||||
gitstatus_ldlibs=
|
||||
gitstatus_make=make
|
||||
|
||||
case "$gitstatus_kernel" in
|
||||
linux)
|
||||
gitstatus_ldflags="$gitstatus_ldflags ${static_pie:--static}"
|
||||
libgit2_cmake_flags="$libgit2_cmake_flags -DENABLE_REPRODUCIBLE_BUILDS=ON"
|
||||
;;
|
||||
freebsd)
|
||||
gitstatus_cxx=clang++
|
||||
gitstatus_make=gmake
|
||||
gitstatus_ldflags="$gitstatus_ldflags ${static_pie:--static}"
|
||||
libgit2_cmake_flags="$libgit2_cmake_flags -DENABLE_REPRODUCIBLE_BUILDS=ON"
|
||||
;;
|
||||
openbsd)
|
||||
gitstatus_cxx=eg++
|
||||
gitstatus_make=gmake
|
||||
gitstatus_ldflags="$gitstatus_ldflags ${static_pie:--static}"
|
||||
libgit2_cmake_flags="$libgit2_cmake_flags -DENABLE_REPRODUCIBLE_BUILDS=ON"
|
||||
;;
|
||||
netbsd)
|
||||
gitstatus_make=gmake
|
||||
gitstatus_ldflags="$gitstatus_ldflags ${static_pie:--static}"
|
||||
libgit2_cmake_flags="$libgit2_cmake_flags -DENABLE_REPRODUCIBLE_BUILDS=ON"
|
||||
;;
|
||||
darwin)
|
||||
command mkdir -- "$workdir"/lib
|
||||
if [ -e /opt/local/lib/libiconv.a ]; then
|
||||
command ln -s -- /opt/local/lib/libiconv.a "$workdir"/lib
|
||||
libgit2_cflags="$libgit2_cflags -I/opt/local/include"
|
||||
gitstatus_cxxflags="$gitstatus_cxxflags -I/opt/local/include"
|
||||
else
|
||||
brew_prefix="$(command brew --prefix)"
|
||||
command ln -s -- "$brew_prefix"/opt/libiconv/lib/libiconv.a "$workdir"/lib
|
||||
libgit2_cflags="$libgit2_cflags -I"$brew_prefix"/opt/libiconv/include"
|
||||
gitstatus_cxxflags="$gitstatus_cxxflags -I"$brew_prefix"/opt/libiconv/include"
|
||||
fi
|
||||
libgit2_cmake_flags="$libgit2_cmake_flags -DUSE_ICONV=ON"
|
||||
gitstatus_ldlibs="$gitstatus_ldlibs -liconv"
|
||||
gitstatus_ldflags="$gitstatus_ldflags -L${workdir}/lib"
|
||||
libgit2_cmake_flags="$libgit2_cmake_flags -DENABLE_REPRODUCIBLE_BUILDS=OFF"
|
||||
;;
|
||||
msys*|mingw*)
|
||||
gitstatus_ldflags="$gitstatus_ldflags ${static_pie:--static}"
|
||||
libgit2_cmake_flags="$libgit2_cmake_flags -DENABLE_REPRODUCIBLE_BUILDS=ON"
|
||||
;;
|
||||
cygwin*)
|
||||
gitstatus_ldflags="$gitstatus_ldflags ${static_pie:--static}"
|
||||
libgit2_cmake_flags="$libgit2_cmake_flags -DENABLE_REPRODUCIBLE_BUILDS=ON"
|
||||
;;
|
||||
*)
|
||||
>&2 echo "[internal error] unhandled kernel: $gitstatus_kernel"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
for cmd in cat cmake git ld ln mkdir rm strip tar "$gitstatus_make"; do
|
||||
if ! command -v "$cmd" >/dev/null 2>&1; then
|
||||
if [ -n "$gitstatus_install_tools" ]; then
|
||||
>&2 echo "[internal error] $cmd not found"
|
||||
exit 1
|
||||
else
|
||||
>&2 echo "[error] command not found: $cmd"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
. "$outdir"/build.info
|
||||
if [ -z "${libgit2_version:-}" ]; then
|
||||
>&2 echo "[internal error] libgit2_version not set"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "${libgit2_sha256:-}" ]; then
|
||||
>&2 echo "[internal error] libgit2_sha256 not set"
|
||||
exit 1
|
||||
fi
|
||||
libgit2_tarball="$outdir"/deps/libgit2-"$libgit2_version".tar.gz
|
||||
if [ ! -e "$libgit2_tarball" ]; then
|
||||
if [ -n "$gitstatus_download_deps" ]; then
|
||||
if ! command -v wget >/dev/null 2>&1; then
|
||||
if [ -n "$gitstatus_install_tools" ]; then
|
||||
>&2 echo "[internal error] wget not found"
|
||||
exit 1
|
||||
else
|
||||
>&2 echo "[error] command not found: wget"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
libgit2_url=https://github.com/romkatv/libgit2/archive/"$libgit2_version".tar.gz
|
||||
if ! >"$libgit2_tmp" command wget --no-config -qO- -- "$libgit2_url" &&
|
||||
! >"$libgit2_tmp" command wget -qO- -- "$libgit2_url"; then
|
||||
set -x
|
||||
>&2 command which wget
|
||||
>&2 command ls -lAd -- "$(command which wget)"
|
||||
>&2 command ls -lAd -- "$outdir"
|
||||
>&2 command ls -lA -- "$outdir"
|
||||
>&2 command ls -lAd -- "$outdir"/deps
|
||||
>&2 command ls -lA -- "$outdir"/deps
|
||||
set +x
|
||||
exit 1
|
||||
fi
|
||||
command mv -f -- "$libgit2_tmp" "$libgit2_tarball"
|
||||
else
|
||||
>&2 echo "[error] file not found: deps/libgit2-"$libgit2_version".tar.gz"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
libgit2_actual_sha256=
|
||||
if command -v shasum >/dev/null 2>/dev/null; then
|
||||
libgit2_actual_sha256="$(command shasum -b -a 256 -- "$libgit2_tarball")"
|
||||
libgit2_actual_sha256="${libgit2_actual_sha256%% *}"
|
||||
elif command -v sha256sum >/dev/null 2>/dev/null; then
|
||||
libgit2_actual_sha256="$(command sha256sum -b -- "$libgit2_tarball")"
|
||||
libgit2_actual_sha256="${libgit2_actual_sha256%% *}"
|
||||
elif command -v sha256 >/dev/null 2>/dev/null; then
|
||||
libgit2_actual_sha256="$(command sha256 -- "$libgit2_tarball" </dev/null)"
|
||||
# Ignore sha256 output if it's from hashalot. It's incompatible.
|
||||
if [ ${#libgit2_actual_sha256} -lt 64 ]; then
|
||||
libgit2_actual_sha256=
|
||||
else
|
||||
libgit2_actual_sha256="${libgit2_actual_sha256##* }"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$libgit2_actual_sha256" ]; then
|
||||
>&2 echo "[error] command not found: shasum or sha256sum"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$libgit2_actual_sha256" != "$libgit2_sha256" ]; then
|
||||
>&2 echo "[error] sha256 mismatch"
|
||||
>&2 echo ""
|
||||
>&2 echo " file : deps/libgit2-$libgit2_version.tar.gz"
|
||||
>&2 echo " expected: $libgit2_sha256"
|
||||
>&2 echo " actual : $libgit2_actual_sha256"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd -- "$workdir"
|
||||
command tar -xzf "$libgit2_tarball"
|
||||
command mv -- libgit2-"$libgit2_version" libgit2
|
||||
command mkdir libgit2/build
|
||||
cd libgit2/build
|
||||
|
||||
CFLAGS="$libgit2_cflags" command cmake \
|
||||
-DCMAKE_BUILD_TYPE=None \
|
||||
-DZERO_NSEC=ON \
|
||||
-DTHREADSAFE=ON \
|
||||
-DUSE_BUNDLED_ZLIB=ON \
|
||||
-DREGEX_BACKEND=builtin \
|
||||
-DUSE_HTTP_PARSER=builtin \
|
||||
-DUSE_SSH=OFF \
|
||||
-DUSE_HTTPS=OFF \
|
||||
-DBUILD_CLAR=OFF \
|
||||
-DUSE_GSSAPI=OFF \
|
||||
-DUSE_NTLMCLIENT=OFF \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
$libgit2_cmake_flags \
|
||||
..
|
||||
command make -j "$cpus" VERBOSE=1
|
||||
|
||||
APPNAME="$appname".tmp \
|
||||
OBJDIR="$workdir"/gitstatus \
|
||||
CXX="${CXX:-$gitstatus_cxx}" \
|
||||
CXXFLAGS="$gitstatus_cxxflags" \
|
||||
LDFLAGS="$gitstatus_ldflags" \
|
||||
LDLIBS="$gitstatus_ldlibs" \
|
||||
command "$gitstatus_make" -C "$outdir" -j "$cpus"
|
||||
|
||||
app="$outdir"/usrbin/"$appname"
|
||||
|
||||
command strip "$app".tmp
|
||||
|
||||
command mkdir -- "$workdir"/repo
|
||||
printf '[init]\n defaultBranch = master\n' >"$workdir"/.gitconfig
|
||||
(
|
||||
cd -- "$workdir"/repo
|
||||
GIT_CONFIG_NOSYSTEM=1 HOME="$workdir" command git init
|
||||
GIT_CONFIG_NOSYSTEM=1 HOME="$workdir" command git config user.name "Your Name"
|
||||
GIT_CONFIG_NOSYSTEM=1 HOME="$workdir" command git config user.email "you@example.com"
|
||||
GIT_CONFIG_NOSYSTEM=1 HOME="$workdir" command git commit \
|
||||
--allow-empty --allow-empty-message --no-gpg-sign -m ''
|
||||
)
|
||||
|
||||
resp="$(printf "hello\037$workdir/repo\036" | "$app".tmp)"
|
||||
case "$resp" in
|
||||
hello*1*/repo*master*);;
|
||||
*)
|
||||
>&2 echo 'error: invalid gitstatusd response for a git repo'
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
resp="$(printf 'hello\037\036' | "$app".tmp)"
|
||||
case "$resp" in
|
||||
hello*0*);;
|
||||
*)
|
||||
>&2 echo 'error: invalid gitstatusd response for a non-repo'
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
command mv -f -- "$app".tmp "$app"
|
||||
|
||||
cleanup
|
||||
|
||||
command cat >&2 <<-END
|
||||
-------------------------------------------------
|
||||
SUCCESS: created usrbin/$appname
|
||||
END
|
||||
END
|
||||
)"
|
||||
|
||||
docker_image=
|
||||
docker_cmd=
|
||||
|
||||
gitstatus_arch=
|
||||
gitstatus_cpu=
|
||||
gitstatus_install_tools=
|
||||
gitstatus_download_deps=
|
||||
|
||||
while getopts ':m:c:i:d:swh' opt "$@"; do
|
||||
case "$opt" in
|
||||
h)
|
||||
printf '%s\n' "$usage"
|
||||
exit
|
||||
;;
|
||||
m)
|
||||
if [ -n "$gitstatus_arch" ]; then
|
||||
>&2 echo "[error] duplicate option: -$opt"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$OPTARG" ]; then
|
||||
>&2 echo "[error] incorrect value of -$opt: $OPTARG"
|
||||
exit 1
|
||||
fi
|
||||
gitstatus_arch="$OPTARG"
|
||||
;;
|
||||
c)
|
||||
if [ -n "$gitstatus_cpu" ]; then
|
||||
>&2 echo "[error] duplicate option: -$opt"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$OPTARG" ]; then
|
||||
>&2 echo "[error] incorrect value of -$opt: $OPTARG"
|
||||
exit 1
|
||||
fi
|
||||
gitstatus_cpu="$OPTARG"
|
||||
;;
|
||||
i)
|
||||
if [ -n "$docker_image" ]; then
|
||||
>&2 echo "[error] duplicate option: -$opt"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$OPTARG" ]; then
|
||||
>&2 echo "[error] incorrect value of -$opt: $OPTARG"
|
||||
exit 1
|
||||
fi
|
||||
docker_image="$OPTARG"
|
||||
;;
|
||||
d)
|
||||
if [ -n "$docker_cmd" ]; then
|
||||
>&2 echo "[error] duplicate option: -$opt"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$OPTARG" ]; then
|
||||
>&2 echo "[error] incorrect value of -$opt: $OPTARG"
|
||||
exit 1
|
||||
fi
|
||||
docker_cmd="$OPTARG"
|
||||
;;
|
||||
s)
|
||||
if [ -n "$gitstatus_install_tools" ]; then
|
||||
>&2 echo "[error] duplicate option: -$opt"
|
||||
exit 1
|
||||
fi
|
||||
gitstatus_install_tools=1
|
||||
;;
|
||||
w)
|
||||
if [ -n "$gitstatus_download_deps" ]; then
|
||||
>&2 echo "[error] duplicate option: -$opt"
|
||||
exit 1
|
||||
fi
|
||||
gitstatus_download_deps=1
|
||||
;;
|
||||
\?) >&2 echo "[error] invalid option: -$OPTARG" ; exit 1;;
|
||||
:) >&2 echo "[error] missing required argument: -$OPTARG"; exit 1;;
|
||||
*) >&2 echo "[internal error] unhandled option: -$opt" ; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$OPTIND" -le $# ]; then
|
||||
>&2 echo "[error] unexpected positional argument"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -n "$docker_image" -a -z "$docker_cmd" ]; then
|
||||
>&2 echo "[error] cannot use -i without -d"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$gitstatus_arch" ]; then
|
||||
gitstatus_arch="$(uname -m)"
|
||||
gitstatus_arch="$(printf '%s' "$gitstatus_arch" | tr '[A-Z]' '[a-z]')"
|
||||
fi
|
||||
|
||||
if [ -z "$gitstatus_cpu" ]; then
|
||||
case "$gitstatus_arch" in
|
||||
armel) gitstatus_cpu=armv5;;
|
||||
armv6l|armhf) gitstatus_cpu=armv6;;
|
||||
armv7l) gitstatus_cpu=armv7;;
|
||||
arm64|aarch64) gitstatus_cpu=armv8-a;;
|
||||
ppc64le) gitstatus_cpu=powerpc64le;;
|
||||
riscv64) gitstatus_cpu=rv64imafdc;;
|
||||
x86_64|amd64) gitstatus_cpu=x86-64;;
|
||||
x86) gitstatus_cpu=i586;;
|
||||
s390x) gitstatus_cpu=z900;;
|
||||
i386|i586|i686) gitstatus_cpu="$gitstatus_arch";;
|
||||
*)
|
||||
>&2 echo '[error] unable to infer target CPU architecture'
|
||||
>&2 echo 'Please specify explicitly with `-c CPU`.'
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
gitstatus_kernel="$(uname -s)"
|
||||
gitstatus_kernel="$(printf '%s' "$gitstatus_kernel" | tr '[A-Z]' '[a-z]')"
|
||||
|
||||
case "$gitstatus_kernel" in
|
||||
linux)
|
||||
if [ -n "$docker_cmd" ]; then
|
||||
if [ -z "${docker_cmd##*/*}" ]; then
|
||||
if [ ! -x "$docker_cmd" ]; then
|
||||
>&2 echo "[error] not an executable file: $docker_cmd"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if ! command -v "$docker_cmd" >/dev/null 2>&1; then
|
||||
>&2 echo "[error] command not found: $docker_cmd"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
if [ -z "$docker_image" ]; then
|
||||
case "$gitstatus_arch" in
|
||||
x86_64) docker_image=alpine:3.11.6;;
|
||||
x86|i386|i586|i686) docker_image=i386/alpine:3.11.6;;
|
||||
armv6l|armhf) docker_image=arm32v6/alpine:3.11.6;;
|
||||
armv7l) docker_image=arm32v7/alpine:3.11.6;;
|
||||
aarch64) docker_image=arm64v8/alpine:3.11.6;;
|
||||
ppc64le) docker_image=ppc64le/alpine:3.11.6;;
|
||||
s390x) docker_image=s390x/alpine:3.11.6;;
|
||||
*)
|
||||
>&2 echo '[error] unable to infer docker image'
|
||||
>&2 echo 'Please specify explicitly with `-i IMAGE`.'
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
freebsd|openbsd|netbsd|darwin)
|
||||
if [ -n "$docker_cmd" ]; then
|
||||
>&2 echo "[error] docker (-d) is not supported on $gitstatus_kernel"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
msys_nt-*|mingw32_nt-*|mingw64_nt-*|cygwin_nt-*)
|
||||
if ! printf '%s' "$gitstatus_kernel" | grep -Eqx '[^-]+-[0-9]+\.[0-9]+(-.*)?'; then
|
||||
>&2 echo '[error] unsupported kernel, sorry!'
|
||||
exit 1
|
||||
fi
|
||||
gitstatus_kernel="$(printf '%s' "$gitstatus_kernel" | sed 's/^\([^-]*-[0-9]*\.[0-9]*\).*/\1/')"
|
||||
if [ -n "$docker_cmd" ]; then
|
||||
>&2 echo '[error] docker (-d) is not supported on windows'
|
||||
exit 1
|
||||
fi
|
||||
if [ -n "$gitstatus_install_tools" -a -z "${gitstatus_kernel##cygwin_nt-*}" ]; then
|
||||
>&2 echo '[error] -s is not supported on cygwin'
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
>&2 echo '[error] unsupported kernel, sorry!'
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
dir="$(dirname -- "$0")"
|
||||
cd -- "$dir"
|
||||
dir="$(pwd)"
|
||||
|
||||
>&2 echo "Building gitstatusd..."
|
||||
>&2 echo ""
|
||||
>&2 echo " kernel := $gitstatus_kernel"
|
||||
>&2 echo " arch := $gitstatus_arch"
|
||||
>&2 echo " cpu := $gitstatus_cpu"
|
||||
[ -z "$docker_cmd" ] || >&2 echo " docker command := $docker_cmd"
|
||||
[ -z "$docker_image" ] || >&2 echo " docker image := $docker_image"
|
||||
if [ -n "$gitstatus_install_tools" ]; then
|
||||
>&2 echo " install tools := yes"
|
||||
else
|
||||
>&2 echo " install tools := no"
|
||||
fi
|
||||
if [ -n "$gitstatus_download_deps" ]; then
|
||||
>&2 echo " download deps := yes"
|
||||
else
|
||||
>&2 echo " download deps := no"
|
||||
fi
|
||||
|
||||
if [ -n "$docker_cmd" ]; then
|
||||
"$docker_cmd" run \
|
||||
-e docker_cmd="$docker_cmd" \
|
||||
-e docker_image="$docker_image" \
|
||||
-e gitstatus_kernel="$gitstatus_kernel" \
|
||||
-e gitstatus_arch="$gitstatus_arch" \
|
||||
-e gitstatus_cpu="$gitstatus_cpu" \
|
||||
-e gitstatus_install_tools="$gitstatus_install_tools" \
|
||||
-e gitstatus_download_deps="$gitstatus_download_deps" \
|
||||
-v "$dir":/out \
|
||||
-w /out \
|
||||
--rm \
|
||||
-- "$docker_image" /bin/sh -uexc "$build"
|
||||
else
|
||||
eval "$build"
|
||||
fi
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user