mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-12 15:34:50 +08:00
Compare commits
9 Commits
17428f3c9a
...
a6df94d2c6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6df94d2c6 | ||
|
|
3ec04997eb | ||
|
|
e178ae39b4 | ||
|
|
ebaccba6d8 | ||
|
|
15a03744a9 | ||
|
|
b8b8762915 | ||
|
|
5f6f7b6e8d | ||
|
|
39e61614f2 | ||
|
|
1bd7a7ad21 |
@ -11,22 +11,21 @@
|
|||||||
# Modified to add support for FreeBSD #
|
# Modified to add support for FreeBSD #
|
||||||
###########################################
|
###########################################
|
||||||
|
|
||||||
if [[ "$OSTYPE" = darwin* ]] ; then
|
if [[ "$OSTYPE" = darwin* ]]; then
|
||||||
|
|
||||||
function battery_pct() {
|
function battery_is_charging() {
|
||||||
local smart_battery_status="$(ioreg -rc "AppleSmartBattery")"
|
ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ Yes'
|
||||||
typeset -F maxcapacity=$(echo $smart_battery_status | grep '^.*"MaxCapacity"\ =\ ' | sed -e 's/^.*"MaxCapacity"\ =\ //')
|
|
||||||
typeset -F currentcapacity=$(echo $smart_battery_status | grep '^.*"CurrentCapacity"\ =\ ' | sed -e 's/^.*CurrentCapacity"\ =\ //')
|
|
||||||
integer i=$(((currentcapacity/maxcapacity) * 100))
|
|
||||||
echo $i
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function plugged_in() {
|
function battery_pct() {
|
||||||
[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ Yes') -eq 1 ]
|
local smart_battery_status="$(ioreg -rc AppleSmartBattery)"
|
||||||
|
local -F maxcapacity=$(command grep '^.*"MaxCapacity"\ =\ ' <<< $smart_battery_status | sed -e 's/^.*"MaxCapacity"\ =\ //')
|
||||||
|
local -F currentcapacity=$(command grep '^.*"CurrentCapacity"\ =\ ' <<< $smart_battery_status | sed -e 's/^.*CurrentCapacity"\ =\ //')
|
||||||
|
echo $(( (currentcapacity/maxcapacity) * 100 ))
|
||||||
}
|
}
|
||||||
|
|
||||||
function battery_pct_remaining() {
|
function battery_pct_remaining() {
|
||||||
if plugged_in ; then
|
if battery_is_charging; then
|
||||||
echo "External Power"
|
echo "External Power"
|
||||||
else
|
else
|
||||||
battery_pct
|
battery_pct
|
||||||
@ -35,9 +34,9 @@ if [[ "$OSTYPE" = darwin* ]] ; then
|
|||||||
|
|
||||||
function battery_time_remaining() {
|
function battery_time_remaining() {
|
||||||
local smart_battery_status="$(ioreg -rc "AppleSmartBattery")"
|
local smart_battery_status="$(ioreg -rc "AppleSmartBattery")"
|
||||||
if [[ $(echo $smart_battery_status | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then
|
if [[ $(echo $smart_battery_status | command grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]]; then
|
||||||
timeremaining=$(echo $smart_battery_status | grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //')
|
timeremaining=$(echo $smart_battery_status | command grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //')
|
||||||
if [ $timeremaining -gt 720 ] ; then
|
if [ $timeremaining -gt 720 ]; then
|
||||||
echo "::"
|
echo "::"
|
||||||
else
|
else
|
||||||
echo "~$((timeremaining / 60)):$((timeremaining % 60))"
|
echo "~$((timeremaining / 60)):$((timeremaining % 60))"
|
||||||
@ -48,11 +47,11 @@ if [[ "$OSTYPE" = darwin* ]] ; then
|
|||||||
}
|
}
|
||||||
|
|
||||||
function battery_pct_prompt () {
|
function battery_pct_prompt () {
|
||||||
if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then
|
if ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ No'; then
|
||||||
b=$(battery_pct_remaining)
|
b=$(battery_pct_remaining)
|
||||||
if [ $b -gt 50 ] ; then
|
if [[ $b -gt 50 ]]; then
|
||||||
color='green'
|
color='green'
|
||||||
elif [ $b -gt 20 ] ; then
|
elif [[ $b -gt 20 ]]; then
|
||||||
color='yellow'
|
color='yellow'
|
||||||
else
|
else
|
||||||
color='red'
|
color='red'
|
||||||
@ -63,24 +62,20 @@ if [[ "$OSTYPE" = darwin* ]] ; then
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function battery_is_charging() {
|
elif [[ "$OSTYPE" = freebsd* ]]; then
|
||||||
[[ $(ioreg -rc "AppleSmartBattery"| grep '^.*"IsCharging"\ =\ ' | sed -e 's/^.*"IsCharging"\ =\ //') == "Yes" ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
elif [[ "$OSTYPE" = freebsd* ]] ; then
|
|
||||||
|
|
||||||
function battery_is_charging() {
|
function battery_is_charging() {
|
||||||
[[ $(sysctl -n hw.acpi.battery.state) -eq 2 ]]
|
[[ $(sysctl -n hw.acpi.battery.state) -eq 2 ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
function battery_pct() {
|
function battery_pct() {
|
||||||
if (( $+commands[sysctl] )) ; then
|
if (( $+commands[sysctl] )); then
|
||||||
echo "$(sysctl -n hw.acpi.battery.life)"
|
sysctl -n hw.acpi.battery.life
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function battery_pct_remaining() {
|
function battery_pct_remaining() {
|
||||||
if [ ! $(battery_is_charging) ] ; then
|
if ! battery_is_charging; then
|
||||||
battery_pct
|
battery_pct
|
||||||
else
|
else
|
||||||
echo "External Power"
|
echo "External Power"
|
||||||
@ -88,45 +83,46 @@ elif [[ "$OSTYPE" = freebsd* ]] ; then
|
|||||||
}
|
}
|
||||||
|
|
||||||
function battery_time_remaining() {
|
function battery_time_remaining() {
|
||||||
|
local remaining_time
|
||||||
remaining_time=$(sysctl -n hw.acpi.battery.time)
|
remaining_time=$(sysctl -n hw.acpi.battery.time)
|
||||||
if [[ $remaining_time -ge 0 ]] ; then
|
if [[ $remaining_time -ge 0 ]]; then
|
||||||
# calculation from https://www.unix.com/shell-programming-and-scripting/23695-convert-minutes-hours-minutes-seconds.html
|
((hour = $remaining_time / 60 ))
|
||||||
((hour=$remaining_time/60))
|
((minute = $remaining_time % 60 ))
|
||||||
((minute=$remaining_time-$hour*60))
|
printf %02d:%02d $hour $minute
|
||||||
echo $hour:$minute
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function battery_pct_prompt() {
|
function battery_pct_prompt() {
|
||||||
|
local b color
|
||||||
b=$(battery_pct_remaining)
|
b=$(battery_pct_remaining)
|
||||||
if [ ! $(battery_is_charging) ] ; then
|
if battery_is_charging; then
|
||||||
if [ $b -gt 50 ] ; then
|
echo "∞"
|
||||||
|
else
|
||||||
|
if [[ $b -gt 50 ]]; then
|
||||||
color='green'
|
color='green'
|
||||||
elif [ $b -gt 20 ] ; then
|
elif [[ $b -gt 20 ]]; then
|
||||||
color='yellow'
|
color='yellow'
|
||||||
else
|
else
|
||||||
color='red'
|
color='red'
|
||||||
fi
|
fi
|
||||||
echo "%{$fg[$color]%}$(battery_pct_remaining)%%%{$reset_color%}"
|
echo "%{$fg[$color]%}$(battery_pct_remaining)%%%{$reset_color%}"
|
||||||
else
|
|
||||||
echo "∞"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
elif [[ "$OSTYPE" = linux* ]] ; then
|
elif [[ "$OSTYPE" = linux* ]]; then
|
||||||
|
|
||||||
function battery_is_charging() {
|
function battery_is_charging() {
|
||||||
! [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]]
|
! acpi 2>/dev/null | command grep -v "rate information unavailable" | command grep -q '^Battery.*Discharging'
|
||||||
}
|
}
|
||||||
|
|
||||||
function battery_pct() {
|
function battery_pct() {
|
||||||
if (( $+commands[acpi] )) ; then
|
if (( $+commands[acpi] )); then
|
||||||
echo "$(acpi 2>/dev/null | cut -f2 -d ',' | tr -cd '[:digit:]')"
|
acpi 2>/dev/null | command grep -v "rate information unavailable" | command grep -E '^Battery.*(Disc|C)harging' | cut -f2 -d ',' | tr -cd '[:digit:]'
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function battery_pct_remaining() {
|
function battery_pct_remaining() {
|
||||||
if [ ! $(battery_is_charging) ] ; then
|
if ! battery_is_charging; then
|
||||||
battery_pct
|
battery_pct
|
||||||
else
|
else
|
||||||
echo "External Power"
|
echo "External Power"
|
||||||
@ -134,76 +130,81 @@ elif [[ "$OSTYPE" = linux* ]] ; then
|
|||||||
}
|
}
|
||||||
|
|
||||||
function battery_time_remaining() {
|
function battery_time_remaining() {
|
||||||
if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
|
if ! battery_is_charging; then
|
||||||
echo $(acpi 2>/dev/null | cut -f3 -d ',')
|
acpi 2>/dev/null | command grep -v "rate information unavailable" | cut -f3 -d ','
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function battery_pct_prompt() {
|
function battery_pct_prompt() {
|
||||||
b=$(battery_pct_remaining)
|
local b color
|
||||||
if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
|
b=$(battery_pct_remaining)
|
||||||
if [ $b -gt 50 ] ; then
|
if battery_is_charging; then
|
||||||
|
echo "∞"
|
||||||
|
else
|
||||||
|
if [[ $b -gt 50 ]]; then
|
||||||
color='green'
|
color='green'
|
||||||
elif [ $b -gt 20 ] ; then
|
elif [[ $b -gt 20 ]]; then
|
||||||
color='yellow'
|
color='yellow'
|
||||||
else
|
else
|
||||||
color='red'
|
color='red'
|
||||||
fi
|
fi
|
||||||
echo "%{$fg[$color]%}$(battery_pct_remaining)%%%{$reset_color%}"
|
echo "%{$fg[$color]%}$(battery_pct_remaining)%%%{$reset_color%}"
|
||||||
else
|
|
||||||
echo "∞"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
# Empty functions so we don't cause errors in prompts
|
# Empty functions so we don't cause errors in prompts
|
||||||
function battery_pct_remaining() {
|
function battery_is_charging { false }
|
||||||
}
|
function battery_pct \
|
||||||
|
battery_pct_remaining \
|
||||||
function battery_time_remaining() {
|
battery_time_remaining \
|
||||||
}
|
battery_pct_prompt { }
|
||||||
|
|
||||||
function battery_pct_prompt() {
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function battery_level_gauge() {
|
function battery_level_gauge() {
|
||||||
local gauge_slots=${BATTERY_GAUGE_SLOTS:-10};
|
local gauge_slots=${BATTERY_GAUGE_SLOTS:-10}
|
||||||
local green_threshold=${BATTERY_GREEN_THRESHOLD:-6};
|
local green_threshold=${BATTERY_GREEN_THRESHOLD:-$(( gauge_slots * 0.6 ))}
|
||||||
local yellow_threshold=${BATTERY_YELLOW_THRESHOLD:-4};
|
local yellow_threshold=${BATTERY_YELLOW_THRESHOLD:-$(( gauge_slots * 0.4 ))}
|
||||||
local color_green=${BATTERY_COLOR_GREEN:-%F{green}};
|
local color_green=${BATTERY_COLOR_GREEN:-%F{green}}
|
||||||
local color_yellow=${BATTERY_COLOR_YELLOW:-%F{yellow}};
|
local color_yellow=${BATTERY_COLOR_YELLOW:-%F{yellow}}
|
||||||
local color_red=${BATTERY_COLOR_RED:-%F{red}};
|
local color_red=${BATTERY_COLOR_RED:-%F{red}}
|
||||||
local color_reset=${BATTERY_COLOR_RESET:-%{%f%k%b%}};
|
local color_reset=${BATTERY_COLOR_RESET:-%{%f%k%b%}}
|
||||||
local battery_prefix=${BATTERY_GAUGE_PREFIX:-'['};
|
local battery_prefix=${BATTERY_GAUGE_PREFIX:-'['}
|
||||||
local battery_suffix=${BATTERY_GAUGE_SUFFIX:-']'};
|
local battery_suffix=${BATTERY_GAUGE_SUFFIX:-']'}
|
||||||
local filled_symbol=${BATTERY_GAUGE_FILLED_SYMBOL:-'▶'};
|
local filled_symbol=${BATTERY_GAUGE_FILLED_SYMBOL:-'▶'}
|
||||||
local empty_symbol=${BATTERY_GAUGE_EMPTY_SYMBOL:-'▷'};
|
local empty_symbol=${BATTERY_GAUGE_EMPTY_SYMBOL:-'▷'}
|
||||||
local charging_color=${BATTERY_CHARGING_COLOR:-$color_yellow};
|
local charging_color=${BATTERY_CHARGING_COLOR:-$color_yellow}
|
||||||
local charging_symbol=${BATTERY_CHARGING_SYMBOL:-'⚡'};
|
local charging_symbol=${BATTERY_CHARGING_SYMBOL:-'⚡'}
|
||||||
|
|
||||||
local battery_remaining_percentage=$(battery_pct);
|
local battery_remaining_percentage=$(battery_pct)
|
||||||
|
local filled empty gauge_color
|
||||||
|
|
||||||
if [[ $battery_remaining_percentage =~ [0-9]+ ]]; then
|
if [[ $battery_remaining_percentage =~ [0-9]+ ]]; then
|
||||||
local filled=$(((( $battery_remaining_percentage + $gauge_slots - 1) / $gauge_slots)));
|
filled=$(( ($battery_remaining_percentage * $gauge_slots) / 100 ))
|
||||||
local empty=$(($gauge_slots - $filled));
|
empty=$(( $gauge_slots - $filled ))
|
||||||
|
|
||||||
if [[ $filled -gt $green_threshold ]]; then local gauge_color=$color_green;
|
if [[ $filled -gt $green_threshold ]]; then
|
||||||
elif [[ $filled -gt $yellow_threshold ]]; then local gauge_color=$color_yellow;
|
gauge_color=$color_green
|
||||||
else local gauge_color=$color_red;
|
elif [[ $filled -gt $yellow_threshold ]]; then
|
||||||
|
gauge_color=$color_yellow
|
||||||
|
else
|
||||||
|
gauge_color=$color_red
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
local filled=$gauge_slots;
|
filled=$gauge_slots
|
||||||
local empty=0;
|
empty=0
|
||||||
filled_symbol=${BATTERY_UNKNOWN_SYMBOL:-'.'};
|
filled_symbol=${BATTERY_UNKNOWN_SYMBOL:-'.'}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local charging=' ' && battery_is_charging && charging=$charging_symbol;
|
local charging=' '
|
||||||
|
battery_is_charging && charging=$charging_symbol
|
||||||
|
|
||||||
|
# Charging status and prefix
|
||||||
printf ${charging_color//\%/\%\%}$charging${color_reset//\%/\%\%}${battery_prefix//\%/\%\%}${gauge_color//\%/\%\%}
|
printf ${charging_color//\%/\%\%}$charging${color_reset//\%/\%\%}${battery_prefix//\%/\%\%}${gauge_color//\%/\%\%}
|
||||||
printf ${filled_symbol//\%/\%\%}'%.0s' {1..$filled}
|
# Filled slots
|
||||||
|
[[ $filled -gt 0 ]] && printf ${filled_symbol//\%/\%\%}'%.0s' {1..$filled}
|
||||||
|
# Empty slots
|
||||||
[[ $filled -lt $gauge_slots ]] && printf ${empty_symbol//\%/\%\%}'%.0s' {1..$empty}
|
[[ $filled -lt $gauge_slots ]] && printf ${empty_symbol//\%/\%\%}'%.0s' {1..$empty}
|
||||||
|
# Suffix
|
||||||
printf ${color_reset//\%/\%\%}${battery_suffix//\%/\%\%}${color_reset//\%/\%\%}
|
printf ${color_reset//\%/\%\%}${battery_suffix//\%/\%\%}${color_reset//\%/\%\%}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,12 @@
|
|||||||
source_env() {
|
source_env() {
|
||||||
if [[ -f $ZSH_DOTENV_FILE ]]; then
|
if [[ -f $ZSH_DOTENV_FILE ]]; then
|
||||||
|
# confirm before sourcing .env file
|
||||||
|
local confirmation
|
||||||
|
echo -n "dotenv: source '$ZSH_DOTENV_FILE' file in the directory? (Y/n) "
|
||||||
|
if read -k 1 confirmation && [[ $confirmation = [nN] ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
# test .env syntax
|
# test .env syntax
|
||||||
zsh -fn $ZSH_DOTENV_FILE || echo "dotenv: error when sourcing '$ZSH_DOTENV_FILE' file" >&2
|
zsh -fn $ZSH_DOTENV_FILE || echo "dotenv: error when sourcing '$ZSH_DOTENV_FILE' file" >&2
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ gradle-or-gradlew() {
|
|||||||
echo "executing gradlew instead of gradle";
|
echo "executing gradlew instead of gradle";
|
||||||
./gradlew "$@";
|
./gradlew "$@";
|
||||||
else
|
else
|
||||||
gradle "$@";
|
command gradle "$@";
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
23
plugins/zsh-interactive-cd/README.md
Normal file
23
plugins/zsh-interactive-cd/README.md
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# zsh-interactive-cd
|
||||||
|
|
||||||
|
This plugin adds a fish-like interactive tab completion for the `cd` command.
|
||||||
|
|
||||||
|
To use it, add `zsh-interactive-cd` to the plugins array of your zshrc file:
|
||||||
|
```zsh
|
||||||
|
plugins=(... zsh-interactive-cd)
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Press tab for completion as usual, it'll launch fzf automatically. Check fzf’s [readme](https://github.com/junegunn/fzf#search-syntax) for more search syntax usage.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
This plugin requires [fzf](https://github.com/junegunn/fzf). Install it by following
|
||||||
|
its [installation instructions](https://github.com/junegunn/fzf#installation).
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
[Henry Chang](https://github.com/changyuheng)
|
||||||
147
plugins/zsh-interactive-cd/zsh-interactive-cd.plugin.zsh
Normal file
147
plugins/zsh-interactive-cd/zsh-interactive-cd.plugin.zsh
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
# Copyright (c) 2017 Henry Chang
|
||||||
|
|
||||||
|
__zic_fzf_prog() {
|
||||||
|
[ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] \
|
||||||
|
&& echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
|
||||||
|
}
|
||||||
|
|
||||||
|
__zic_matched_subdir_list() {
|
||||||
|
local dir length seg starts_with_dir
|
||||||
|
if [[ "$1" == */ ]]; then
|
||||||
|
dir="$1"
|
||||||
|
if [[ "$dir" != / ]]; then
|
||||||
|
dir="${dir: : -1}"
|
||||||
|
fi
|
||||||
|
length=$(echo -n "$dir" | wc -c)
|
||||||
|
if [ "$dir" = "/" ]; then
|
||||||
|
length=0
|
||||||
|
fi
|
||||||
|
find -L "$dir" -mindepth 1 -maxdepth 1 -type d 2>/dev/null \
|
||||||
|
| cut -b $(( ${length} + 2 ))- | sed '/^$/d' | while read -r line; do
|
||||||
|
if [[ "${line[1]}" == "." ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
echo "$line"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
dir=$(dirname -- "$1")
|
||||||
|
length=$(echo -n "$dir" | wc -c)
|
||||||
|
if [ "$dir" = "/" ]; then
|
||||||
|
length=0
|
||||||
|
fi
|
||||||
|
seg=$(basename -- "$1")
|
||||||
|
starts_with_dir=$( \
|
||||||
|
find -L "$dir" -mindepth 1 -maxdepth 1 -type d \
|
||||||
|
2>/dev/null | cut -b $(( ${length} + 2 ))- | sed '/^$/d' \
|
||||||
|
| while read -r line; do
|
||||||
|
if [[ "${seg[1]}" != "." && "${line[1]}" == "." ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [[ "$line" == "$seg"* ]]; then
|
||||||
|
echo "$line"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
)
|
||||||
|
if [ -n "$starts_with_dir" ]; then
|
||||||
|
echo "$starts_with_dir"
|
||||||
|
else
|
||||||
|
find -L "$dir" -mindepth 1 -maxdepth 1 -type d \
|
||||||
|
2>/dev/null | cut -b $(( ${length} + 2 ))- | sed '/^$/d' \
|
||||||
|
| while read -r line; do
|
||||||
|
if [[ "${seg[1]}" != "." && "${line[1]}" == "." ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [[ "$line" == *"$seg"* ]]; then
|
||||||
|
echo "$line"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_zic_list_generator() {
|
||||||
|
__zic_matched_subdir_list "${(Q)@[-1]}" | sort
|
||||||
|
}
|
||||||
|
|
||||||
|
_zic_complete() {
|
||||||
|
setopt localoptions nonomatch
|
||||||
|
local l matches fzf tokens base
|
||||||
|
|
||||||
|
l=$(_zic_list_generator $@)
|
||||||
|
|
||||||
|
if [ -z "$l" ]; then
|
||||||
|
zle ${__zic_default_completion:-expand-or-complete}
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
fzf=$(__zic_fzf_prog)
|
||||||
|
|
||||||
|
if [ $(echo $l | wc -l) -eq 1 ]; then
|
||||||
|
matches=${(q)l}
|
||||||
|
else
|
||||||
|
matches=$(echo $l \
|
||||||
|
| FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} \
|
||||||
|
--reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS \
|
||||||
|
--bind 'shift-tab:up,tab:down'" ${=fzf} \
|
||||||
|
| while read -r item; do
|
||||||
|
echo -n "${(q)item} "
|
||||||
|
done)
|
||||||
|
fi
|
||||||
|
|
||||||
|
matches=${matches% }
|
||||||
|
if [ -n "$matches" ]; then
|
||||||
|
tokens=(${(z)LBUFFER})
|
||||||
|
base="${(Q)@[-1]}"
|
||||||
|
if [[ "$base" != */ ]]; then
|
||||||
|
if [[ "$base" == */* ]]; then
|
||||||
|
base="$(dirname -- "$base")"
|
||||||
|
if [[ ${base[-1]} != / ]]; then
|
||||||
|
base="$base/"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
base=""
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
LBUFFER="${tokens[1]} "
|
||||||
|
if [ -n "$base" ]; then
|
||||||
|
base="${(q)base}"
|
||||||
|
if [ "${tokens[2][1]}" = "~" ]; then
|
||||||
|
base="${base/#$HOME/~}"
|
||||||
|
fi
|
||||||
|
LBUFFER="${LBUFFER}${base}"
|
||||||
|
fi
|
||||||
|
LBUFFER="${LBUFFER}${matches}/"
|
||||||
|
fi
|
||||||
|
zle redisplay
|
||||||
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
||||||
|
}
|
||||||
|
|
||||||
|
zic-completion() {
|
||||||
|
setopt localoptions noshwordsplit noksh_arrays noposixbuiltins
|
||||||
|
local tokens cmd
|
||||||
|
|
||||||
|
tokens=(${(z)LBUFFER})
|
||||||
|
cmd=${tokens[1]}
|
||||||
|
|
||||||
|
if [[ "$LBUFFER" =~ "^\ *cd$" ]]; then
|
||||||
|
zle ${__zic_default_completion:-expand-or-complete}
|
||||||
|
elif [ "$cmd" = cd ]; then
|
||||||
|
_zic_complete ${tokens[2,${#tokens}]/#\~/$HOME}
|
||||||
|
else
|
||||||
|
zle ${__zic_default_completion:-expand-or-complete}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
[ -z "$__zic_default_completion" ] && {
|
||||||
|
binding=$(bindkey '^I')
|
||||||
|
# $binding[(s: :w)2]
|
||||||
|
# The command substitution and following word splitting to determine the
|
||||||
|
# default zle widget for ^I formerly only works if the IFS parameter contains
|
||||||
|
# a space via $binding[(w)2]. Now it specifically splits at spaces, regardless
|
||||||
|
# of IFS.
|
||||||
|
[[ $binding =~ 'undefined-key' ]] || __zic_default_completion=$binding[(s: :w)2]
|
||||||
|
unset binding
|
||||||
|
}
|
||||||
|
|
||||||
|
zle -N zic-completion
|
||||||
|
bindkey '^I' zic-completion
|
||||||
Loading…
Reference in New Issue
Block a user