mirror of https://github.com/zimfw/zimfw.git
This is a major change, where Zsh modules/plugins are not git submodules in the Zim repo anymore, but customized and installed separately as individual repositories. The discussion about this started more than 2 years ago in #88. Closes #299. This will allow contributors' modules to live in their own repositories. See #33, #138, #262, #281, #324. The current code has what, up to this point, I considered to be the best balance between simplicity, execution speed and number of files. One measured decision was to make the initialization of modules depend only on the `':zim' modules` style, keeping it as fast as possible. The `':zim:module' module` style is used to install, update and clean the modules, all operations that happen after the user got his as-blazing-fast-possible shell prompt. Even though I didn't care much about making install or update fast, `xargs` has a nice feature of allowing commands to be executed in parallel with `-P`. I took advantage of that. I've also worked on making the `zimfw` utility give the user some nice (while still minimalistic) output. Also I'm suggesting this as the new name for the `zmanage` tool, since `zimfw` does not shadow the `zim` wiki tool.pull/358/head
parent
5371975f37
commit
8dc3e43a0d
@ -1,28 +0,0 @@ |
||||
[submodule "modules/history-substring-search/external"] |
||||
path = modules/history-substring-search/external |
||||
url = https://github.com/zsh-users/zsh-history-substring-search.git |
||||
ignore = untracked |
||||
[submodule "modules/completion/external"] |
||||
path = modules/completion/external |
||||
url = https://github.com/zsh-users/zsh-completions.git |
||||
ignore = untracked |
||||
[submodule "modules/syntax-highlighting/external"] |
||||
path = modules/syntax-highlighting/external |
||||
url = https://github.com/zsh-users/zsh-syntax-highlighting.git |
||||
ignore = untracked |
||||
[submodule "modules/prompt/external-themes/pure"] |
||||
path = modules/prompt/external-themes/pure |
||||
url = https://github.com/sindresorhus/pure.git |
||||
ignore = untracked |
||||
[submodule "modules/prompt/external-themes/liquidprompt"] |
||||
path = modules/prompt/external-themes/liquidprompt |
||||
url = https://github.com/nojhan/liquidprompt.git |
||||
ignore = untracked |
||||
[submodule "modules/prompt/external-themes/lean"] |
||||
path = modules/prompt/external-themes/lean |
||||
url = https://github.com/miekg/lean |
||||
ignore = untracked |
||||
[submodule "modules/autosuggestions/external"] |
||||
path = modules/autosuggestions/external |
||||
url = https://github.com/zsh-users/zsh-autosuggestions.git |
||||
ignore = untracked |
@ -1,33 +1 @@ |
||||
# |
||||
# startup file read in interactive login shells |
||||
# |
||||
# The following code helps us by optimizing the existing framework. |
||||
# This includes zcompile, zcompdump, etc. |
||||
# |
||||
|
||||
( |
||||
local dir file |
||||
setopt LOCAL_OPTIONS EXTENDED_GLOB |
||||
autoload -U zrecompile |
||||
|
||||
# zcompile the completion cache; siginificant speedup |
||||
zrecompile -pq ${ZDOTDIR:-${HOME}}/${zcompdump_file:-.zcompdump} |
||||
|
||||
# zcompile .zshrc |
||||
zrecompile -pq ${ZDOTDIR:-${HOME}}/.zshrc |
||||
|
||||
# zcompile enabled module autoloaded functions |
||||
for dir in ${ZIM_HOME}/modules/${^zmodules}/functions(/FN); do |
||||
zrecompile -pq ${dir}.zwc ${dir}/^(_*|prompt_*_setup|*.*)(-.N) |
||||
done |
||||
|
||||
# zcompile enabled module scripts |
||||
for file in ${ZIM_HOME}/modules/${^zmodules}/(^*test*/)#*.zsh{,-theme}(.NLk+1); do |
||||
zrecompile -pq ${file} |
||||
done |
||||
|
||||
# zcompile all prompt setup scripts |
||||
for file in ${ZIM_HOME}/modules/prompt/functions/prompt_*_setup; do |
||||
zrecompile -pq ${file} |
||||
done |
||||
) &! |
||||
zimfw login-init -q &! |
||||
|
@ -1,31 +0,0 @@ |
||||
archive |
||||
======= |
||||
|
||||
Provides `archive` and `unarchive` functions for easy archive manipulation. |
||||
|
||||
This module will make use of `pigz` and `pbzip2` if available to make use of all available CPU cores. |
||||
|
||||
Functions |
||||
--------- |
||||
|
||||
* `archive` generates an archive based on file extension. Syntax is `archive myarchive.tar.gz /path/to/archive` |
||||
* `unarchive` unarchives files based on the extensions. Syntax is `unarchive myarchive.7z` |
||||
|
||||
Archive formats |
||||
--------------- |
||||
|
||||
| Format | Requirements | |
||||
| ------ | ------------ | |
||||
| .tar | `tar` | |
||||
| .tar.gz, .tgz | `tar` or `pigz` | |
||||
| .tar.bz, .tar.bz2, .tbz, .tbz2 | `tar` or `pbzip2` | |
||||
| .tar.xz, .txz | `tar` with xz support | |
||||
| .tar.zma, .tlz | `tar` with lzma support | |
||||
| .gz | `gunzip` or `pigz` | |
||||
| .bz, .bz2 | `bunzip2` or `pbzip2` | |
||||
| .xz | `unxz` | |
||||
| .lzma | `unzlma` | |
||||
| .Z | `uncompress` | |
||||
| .zip | `unzip` | |
||||
| .rar | `unrar` or `rar` | |
||||
| .7z | `7za` | |
@ -1,4 +0,0 @@ |
||||
#compdef unarchive |
||||
|
||||
_arguments \ |
||||
"*:archive:_files -g '(#i)*.(tar|gz|tgz|bz|bz2|tbz|tbz2|xz|txz|tlz|lzma|Z|zip|rar|7z|001)(-.)'" |
@ -1,34 +0,0 @@ |
||||
# vim:et sts=2 sw=2 ft=zsh |
||||
# |
||||
# Creates archive files |
||||
# |
||||
|
||||
if (( # < 2 )); then |
||||
print "usage: ${0} <archive_name.ext> <file>..." >&2 |
||||
return 1 |
||||
fi |
||||
|
||||
# we are quitting (above) if there are less than 2 vars, |
||||
# so we don't need any argc check here. |
||||
|
||||
local archive_name="${1}" |
||||
shift |
||||
|
||||
# pigz and pbzip2 are aliased in the init.zsh file. This provides a significant speedup, resulting in a |
||||
# near-liner decrease in compression time based on on the number of available cores. |
||||
|
||||
case "${archive_name}" in |
||||
(*.tar.gz|*.tgz) tar -cvzf "${archive_name}" "${@}" ;; |
||||
(*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar -cvjf "${archive_name}" "${@}" ;; |
||||
(*.tar.xz|*.txz) tar -J --help &>/dev/null && tar -cvJf "${archive_name}" "${@}" ;; |
||||
(*.tar.lzma|*.tlz) tar --lzma --help &>/dev/null && tar --lzma -cvf "${archive_name}" "${@}" ;; |
||||
(*.tar) tar -cvf "${archive_name}" "${@}" ;; |
||||
(*.zip) zip -r "${archive_name}" "${@}" ;; |
||||
(*.rar) rar a "${archive_name}" "${@}" ;; |
||||
(*.7z) 7za a "${archive_name}" "${@}" ;; |
||||
(*.gz) print "${0}: .gz is only useful for single files, and does not capture permissions. Use .tar.gz" ;; |
||||
(*.bz|*.bz2) print "${0}: .bzip2 is only useful for single files, and does not capture permissions. Use .tar.bz2" ;; |
||||
(*.xz) print "${0}: .xz is only useful for single files, and does not capture permissions. Use .tar.xz" ;; |
||||
(*.lzma) print "${0}: .lzma is only useful for single files, and does not capture permissions. Use .tar.lzma" ;; |
||||
(*) print "${0}: unknown archive type: ${archive_name}" ;; |
||||
esac |
@ -1,41 +0,0 @@ |
||||
# vim:et sts=2 sw=2 ft=zsh |
||||
# |
||||
# Unarchives files |
||||
# |
||||
|
||||
if (( # < 1 )); then |
||||
print "usage: ${0} <archive_name.ext>..." >&2 |
||||
return 1 |
||||
fi |
||||
|
||||
setopt LOCAL_OPTIONS ERR_RETURN |
||||
|
||||
# using unpigz/pbunzip2 provides little to decompression time; the benefit is mainly in compression time. |
||||
# setting it as an alias in the init.zsh file should be sufficient here. |
||||
|
||||
while (( # > 0 )); do |
||||
local archive_name="${1}" |
||||
case "${archive_name}" in |
||||
(*.tar.gz|*.tgz) tar -xvzf "${archive_name}" ;; |
||||
(*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar -xvjf "${archive_name}" ;; |
||||
(*.tar.xz|*.txz) tar -J --help &>/dev/null && tar -xvJf "${archive_name}" \ |
||||
|| xzcat "${archive_name}" | tar xvf - ;; |
||||
(*.tar.lzma|*.tlz) tar --lzma --help &>/dev/null && tar --lzma -xvf "${archive_name}" \ |
||||
|| lzcat "${archive_name}" | tar xvf - ;; |
||||
(*.tar) tar xvf "${archive_name}" ;; |
||||
(*.gz) gunzip "${archive_name}" ;; |
||||
(*.bz|*.bz2) bunzip2 "${archive_name}" ;; |
||||
(*.xz) unxz "${archive_name}" ;; |
||||
(*.lzma) unlzma "${archive_name}" ;; |
||||
(*.Z) uncompress "${archive_name}" ;; |
||||
(*.zip) unzip "${archive_name}";; |
||||
(*.rar) (( $+{commands[unrar]} )) && unrar x -ad "${archive_name}" \ |
||||
|| rar x -ad "${archive_name}" ;; |
||||
(*.7z|*.001) 7za x "${archive_name}" ;; |
||||
(*) |
||||
print "${0}: unknown archive type: ${archive_name}" |
||||
return 1 |
||||
;; |
||||
esac |
||||
shift |
||||
done |
@ -1,17 +0,0 @@ |
||||
# |
||||
# Archive aliases |
||||
# |
||||
|
||||
# if pigz/pbzip2 are available, alias them as they are drop-in replacements for gzip and bzip2, respectively. |
||||
|
||||
# |
||||
# pigz |
||||
# |
||||
(( ${+commands[pigz]} )) && alias gzip='pigz' |
||||
(( ${+commands[unpigz]} )) && alias gunzip='unpigz' |
||||
|
||||
# |
||||
# pbzip2 |
||||
# |
||||
(( ${+commands[pbzip2]} )) && alias bzip2='pbzip2' |
||||
(( ${+commands[pbunzip2]} )) && alias bunzip2='pbunzip2' |
@ -1,13 +0,0 @@ |
||||
zsh-autosuggestions |
||||
=================== |
||||
|
||||
_[Fish](http://fishshell.com/)-like fast/unobtrusive autosuggestions for Zsh._ |
||||
|
||||
It suggests commands as you type, based on command history. |
||||
|
||||
<a href="https://asciinema.org/a/37390" target="_blank"><img src="https://asciinema.org/a/37390.png" width="400" /></a> |
||||
|
||||
Contributing |
||||
------------ |
||||
|
||||
Contributions should be submitted [upstream to zsh-autosuggestions](https://github.com/zsh-users/zsh-autosuggestions) |
@ -1 +0,0 @@ |
||||
Subproject commit a7f0106b31c2538a36cab30428e6ca65d9a2ae60 |
@ -1,9 +0,0 @@ |
||||
# |
||||
# Fish-like fast/unobtrusive autosuggestions for zsh. |
||||
# |
||||
# It suggests commands as you type, based on command history. |
||||
# |
||||
|
||||
# source script |
||||
source ${0:h}/external/zsh-autosuggestions.zsh || return 1 |
||||
|
@ -1,21 +0,0 @@ |
||||
completion |
||||
========== |
||||
|
||||
Enables and configures smart and extensive tab completion. |
||||
|
||||
Completions are sourced from [zsh-completions][zsh-completions]. |
||||
|
||||
Zsh options |
||||
----------- |
||||
|
||||
* `ALWAYS_TO_END` moves cursor to end of word if a full completion is inserted. |
||||
* `PATH_DIRS` performs path search even on command names with slashes in them. |
||||
* `NO_CASE_GLOB` makes globbing case insensitive. |
||||
* `NO_LIST_BEEP` doesn't beep on ambiguous completions. |
||||
|
||||
Contributing |
||||
------------ |
||||
|
||||
Command completions should be submitted [upstream to zsh-completions][zsh-completions]. |
||||
|
||||
[zsh-completions]: https://github.com/zsh-users/zsh-completions |
@ -1 +0,0 @@ |
||||
Subproject commit 8ec8c8c5c662c3cb77231b7458ce1975d2f8c967 |
@ -1,96 +0,0 @@ |
||||
# |
||||
# Completion enhancements |
||||
# |
||||
|
||||
|
||||
# |
||||
# initialization |
||||
# |
||||
|
||||
# if it's a dumb terminal, return. |
||||
if [[ ${TERM} == 'dumb' ]]; then |
||||
return 1 |
||||
fi |
||||
|
||||
# add the completions to the fpath |
||||
fpath=(${0:h}/external/src ${fpath}) |
||||
|
||||
# load and initialize the completion system |
||||
autoload -Uz compinit && compinit -C -d "${ZDOTDIR:-${HOME}}/${zcompdump_file:-.zcompdump}" |
||||
|
||||
|
||||
# |
||||
# zsh options |
||||
# |
||||
|
||||
# If a completion is performed with the cursor within a word, and a full |
||||
# completion is inserted, the cursor is moved to the end of the word. |
||||
setopt ALWAYS_TO_END |
||||
|
||||
# Perform a path search even on command names with slashes in them. |
||||
setopt PATH_DIRS |
||||
|
||||
# Make globbing (filename generation) not sensitive to case. |
||||
setopt NO_CASE_GLOB |
||||
|
||||
# Don't beep on an ambiguous completion. |
||||
setopt NO_LIST_BEEP |
||||
|
||||
|
||||
# |
||||
# completion module options |
||||
# |
||||
|
||||
# group matches and describe. |
||||
zstyle ':completion:*:*:*:*:*' menu select |
||||
zstyle ':completion:*:matches' group yes |
||||
zstyle ':completion:*:options' description yes |
||||
zstyle ':completion:*:options' auto-description '%d' |
||||
zstyle ':completion:*:corrections' format '%F{green}-- %d (errors: %e) --%f' |
||||
zstyle ':completion:*:descriptions' format '%F{yellow}-- %d --%f' |
||||
zstyle ':completion:*:messages' format '%F{purple}-- %d --%f' |
||||
zstyle ':completion:*:warnings' format '%F{red}-- no matches found --%f' |
||||
zstyle ':completion:*' format '%F{yellow}-- %d --%f' |
||||
zstyle ':completion:*' group-name '' |
||||
zstyle ':completion:*' verbose yes |
||||
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' '+r:|?=**' |
||||
|
||||
# directories |
||||
if (( ! ${+LS_COLORS} )); then |
||||
# Locally use same LS_COLORS definition from utility module, in case it was not set |
||||
local LS_COLORS='di=1;34:ln=35:so=32:pi=33:ex=31:bd=1;36:cd=1;33:su=30;41:sg=30;46:tw=30;42:ow=30;43' |
||||
fi |
||||
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} |
||||
zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories |
||||
zstyle ':completion:*:*:cd:*:directory-stack' menu yes select |
||||
zstyle ':completion:*:-tilde-:*' group-order 'named-directories' 'path-directories' 'expand' |
||||
zstyle ':completion:*' squeeze-slashes true |
||||
|
||||
# enable caching |
||||
zstyle ':completion::complete:*' use-cache on |
||||
zstyle ':completion::complete:*' cache-path "${ZDOTDIR:-${HOME}}/.zcompcache" |
||||
|
||||
# ignore useless commands and functions |
||||
zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec)|prompt_*)' |
||||
|
||||
# completion sorting |
||||
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters |
||||
|
||||
# Man |
||||
zstyle ':completion:*:manuals' separate-sections true |
||||
zstyle ':completion:*:manuals.(^1*)' insert-sections true |
||||
|
||||
# history |
||||
zstyle ':completion:*:history-words' stop yes |
||||
zstyle ':completion:*:history-words' remove-all-dups yes |
||||
zstyle ':completion:*:history-words' list false |
||||
zstyle ':completion:*:history-words' menu yes |
||||
|
||||
# ignore multiple entries. |
||||
zstyle ':completion:*:(rm|kill|diff):*' ignore-line other |
||||
zstyle ':completion:*:rm:*' file-patterns '*:all-files' |
||||
|
||||
# If the _my_hosts function is defined, it will be called to add the ssh hosts |
||||
# completion, otherwise _ssh_hosts will fall through and read the ~/.ssh/config |
||||
zstyle -e ':completion:*:*:ssh:*:my-accounts' users-hosts \ |
||||
'[[ -f ${HOME}/.ssh/config && ${key} == hosts ]] && key=my_hosts reply=()' |
@ -1,19 +0,0 @@ |
||||
custom |
||||
====== |
||||
|
||||
Add any custom aliases/settings to the `init.zsh` file. |
||||
|
||||
Any functions should go in the `functions` subdirectory, where the name of the |
||||
file is the name of the function. |
||||
|
||||
For example, this function from your `.zshrc`: |
||||
```zsh |
||||
foo() { |
||||
print 'bar' |
||||
} |
||||
``` |
||||
|
||||
becomes a file named `foo` in the `functions` subdirectory containing: |
||||
```zsh |
||||
print 'bar' |
||||
``` |
@ -1,4 +0,0 @@ |
||||
# this is an example function |
||||
# running 'example_function' in a zsh session will execute the code below |
||||
|
||||
print "executed example function: ${ZIM_HOME}/modules/custom/functions/example_function!" |
@ -1,8 +0,0 @@ |
||||
# |
||||
# Custom aliases/settings |
||||
# |
||||
|
||||
# any custom stuff should go here. |
||||
# ensure that 'custom' exists in the zmodules array in your .zimrc |
||||
|
||||
|
@ -1,18 +0,0 @@ |
||||
debug |
||||
===== |
||||
|
||||
Provides a function to debug Zim. |
||||
|
||||
Functions |
||||
--------- |
||||
|
||||
* `trace-zim` provides a trace of Zsh/Zim startup |
||||
|
||||
Notes |
||||
----- |
||||
|
||||
`trace-zim` will not alter your current dotfiles. It will copy your environment |
||||
to a temporary directory, launch Zsh within that environment, and output logs. |
||||
|
||||
This will provide a `ztrace.tar.gz` archive, which should be attached to any bug |
||||
reports if you need help with an issue that you don't understand. |
@ -1,105 +0,0 @@ |
||||
#!/usr/bin/env zsh |
||||
# |
||||
# Generates trace log to debug zim and zsh issues |
||||
# |
||||
|
||||
print "This function creates a trace log to debug |
||||
Zsh and Zim functionality. |
||||
|
||||
It will copy your .zshrc to /tmp/ztrace/, ammend profiling |
||||
code, launch a new shell, log the trace, close the shell, |
||||
archive the logs, and finally print the path to the archive." |
||||
|
||||
read \?"Press [Enter] to begin trace." |
||||
|
||||
mkdir -p /tmp/ztrace |
||||
# make sure that we were able to create the directory |
||||
if [[ ! -d /tmp/ztrace ]]; then |
||||
print 'failed to create /tmp/ztrace directory. Aborting.' |
||||
return 1 |
||||
else |
||||
# check if known output file, if exists |
||||
# rm all directory contents |
||||
if [[ -e /tmp/ztrace/ztrace.log ]]; then |
||||
print "\nLogs from previous run of trace-zim are present |
||||
Deleting old logs now..." |
||||
# use of anonymous function for dotglob opt |
||||
() { |
||||
setopt dotglob |
||||
rm -rf /tmp/ztrace/* |
||||
} |
||||
fi |
||||
fi |
||||
|
||||
# get some basic system information (kernel and zsh version) |
||||
print "Zsh version: |
||||
$(zsh --version) |
||||
Kernel information: |
||||
$(uname -a) |
||||
fpath info: |
||||
${fpath}" >! /tmp/ztrace/sysinfo |
||||
|
||||
cp ${ZDOTDIR:-${HOME}}/.zshrc /tmp/ztrace/.zshrc.orig |
||||
cp ${ZDOTDIR:-${HOME}}/.zimrc /tmp/ztrace/.zimrc |
||||
# rsync will allow us to not have to copy the .git folder; use if available |
||||
if (( ${+commands[rsync]} )); then |
||||
rsync -az --exclude .git ${ZIM_HOME} /tmp/ztrace/ |
||||
else |
||||
cp -R ${ZIM_HOME} /tmp/ztrace/ |
||||
fi |
||||
|
||||
# create a modified .zshrc to produce a trace log |
||||
cat <<EOF >! /tmp/ztrace/.zshrc |
||||
################### |
||||
# zim trace start # |
||||
################### |
||||
PS4=$'%D{%s%6.}-_-' |
||||
exec 3>&2 2>/tmp/ztrace/sample-time.$$.log |
||||
zmodload zsh/zprof |
||||
setopt xtrace prompt_subst |
||||
EOF |
||||
|
||||
cat /tmp/ztrace/.zshrc.orig >>! /tmp/ztrace/.zshrc |
||||
|
||||
cat <<EOF >>! /tmp/ztrace/.zshrc |
||||
################# |
||||
# zim trace end # |
||||
################# |
||||
|
||||
unsetopt xtrace |
||||
zprof >! /tmp/ztrace/zprof |
||||
#non-linux systems have weird fd; also, no real need to redirect back |
||||
#prompt is (practically speaking) non-interactive, fd exists only for that process |
||||
#which is closed (by typing exit) |
||||
|
||||
#exec 2>&3 3>&- |
||||
EOF |
||||
|
||||
print "\nSpawning zsh and producing trace...\n\n" |
||||
ZDOTDIR=/tmp/ztrace zsh -ic 'exit' |
||||
print "Trace complete. |
||||
Parsing logs to a nicer format; this may take some time..." |
||||
|
||||
# this is ugly thing makes it pretty... |
||||
while read line; do if [[ ${line} =~ '^[0-9]+-_-' ]]; then crt=000000$((${line%%-_-*}-10#0$last)); printf "%12.9f %s\n" ${crt:0:${#crt}-6}.${crt:${#crt}-6} ${line#*-_-}; last=${line%%-_-*}; fi; done < /tmp/ztrace/sample-time.(*).log > /tmp/ztrace/ztrace.log |
||||
print "Parsing complete!" |
||||
|
||||
# safe to remove old, unneeded environment files |
||||
print "Tidying up before archive..." |
||||
rm -f /tmp/ztrace/sample-time.* |
||||
rm -rf /tmp/ztrace/.zim |
||||
rm -f /tmp/ztrace/.zshrc |
||||
mv /tmp/ztrace/.zshrc.orig /tmp/ztrace/.zshrc |
||||
rm -f /tmp/ztrace/.zhistory |
||||
rm -f /tmp/ztrace/.zcompdump* |
||||
|
||||
print "Archiving trace logs...\n" |
||||
|
||||
tar -czf /tmp/ztrace.tar.gz /tmp/ztrace/ |
||||
|
||||
print "Archive complete!\n |
||||
Trace by with execution time available at: |
||||
/tmp/ztrace/ztrace.log |
||||
Archive (for sharing/help) available at: |
||||
/tmp/ztrace.tar.gz" |
||||
|
@ -1,16 +0,0 @@ |
||||
directory |
||||
========= |
||||
|
||||
Sets directory, navigation, and redirect options. |
||||
|
||||
Zsh options |
||||
----------- |
||||
|
||||
* `AUTO_CD` performs cd to a directory if the typed command is invalid, but is a directory. |
||||
* `AUTO_PUSHD` makes cd push the old directory to the directory stack. |
||||
* `PUSHD_IGNORE_DUPS` does not push multiple copies of the same directory to the stack. |
||||
* `PUSHD_SILENT` does not print the directory stack after pushd or popd. |
||||
* `PUSHD_TO_HOME` has pushd without arguments act like `pushd ${HOME}`. |
||||
* `EXTENDED_GLOB` treats `#`, `~`, and `^` as patterns for filename globbing. |
||||
* `MULTIOS` performs implicit tees or cats when using multiple redirections. |
||||
* `NO_CLOBBER` disallows `>` to overwrite existing files. Use `>|` or `>!` instead. |
@ -1,38 +0,0 @@ |
||||
# |
||||
# Directory navigation options |
||||
# |
||||
|
||||
# |
||||
# Navigation |
||||
# |
||||
|
||||
# If a command is issued that canโt be executed as a normal command, |
||||
# and the command is the name of a directory, perform the cd command to that directory. |
||||
setopt AUTO_CD |
||||
|
||||
# Make cd push the old directory onto the directory stack. |
||||
setopt AUTO_PUSHD |
||||
|
||||
# Donโt push multiple copies of the same directory onto the directory stack. |
||||
setopt PUSHD_IGNORE_DUPS |
||||
|
||||
# Do not print the directory stack after pushd or popd. |
||||
setopt PUSHD_SILENT |
||||
|
||||
# Have pushd with no arguments act like โpushd ${HOME}โ. |
||||
setopt PUSHD_TO_HOME |
||||
|
||||
# |
||||
# Globbing and fds |
||||
# |
||||
|
||||
# Treat the โ#โ, โ~โ and โ^โ characters as part of patterns for filename generation, etc. |
||||
# (An initial unquoted โ~โ always produces named directory expansion.) |
||||
setopt EXTENDED_GLOB |
||||
|
||||
# Perform implicit tees or cats when multiple redirections are attempted. |
||||
setopt MULTIOS |
||||
|
||||
# Disallow โ>โ redirection to overwrite existing files. |
||||
# โ>|โ or โ>!โ must be used to overwrite a file. |
||||
setopt NO_CLOBBER |
@ -1,19 +0,0 @@ |
||||
environment |
||||
=========== |
||||
|
||||
Sets generic Zsh built-in environment options. |
||||
|
||||
Also enables smart URL-pasting. This prevents the user from having to manually escape URLs. |
||||
|
||||
Uses `.zimrc` defined `${ztermtitle}` variable to set the terminal title, if defined. |
||||
|
||||
Zsh options |
||||
----------- |
||||
|
||||
* `AUTO_RESUME` resumes an existing job before creating a new one. |
||||
* `INTERACTIVE_COMMENTS` allows comments starting with `#` in the shell. |
||||
* `LONG_LIST_JOBS` lists jobs in verbose format by default. |
||||
* `NOTIFY` reports job status immediately instead of waiting for the prompt. |
||||
* `NO_BG_NICE` prevents background jobs being given a lower priority. |
||||
* `NO_CHECK_JOBS` prevents status report of jobs on shell exit. |
||||
* `NO_HUP` prevents SIGHUP to jobs on shell exit. |
@ -1,52 +0,0 @@ |
||||
# |
||||
# generic options and environment settings |
||||
# |
||||
|
||||
# Use smart URL pasting and escaping. |
||||
autoload -Uz bracketed-paste-url-magic && zle -N bracketed-paste bracketed-paste-url-magic |
||||
autoload -Uz url-quote-magic && zle -N self-insert url-quote-magic |
||||
|
||||
# Treat single word simple commands without redirection as candidates for resumption of an existing job. |
||||
setopt AUTO_RESUME |
||||
|
||||
# Allow comments starting with `#` even in interactive shells. |
||||
setopt INTERACTIVE_COMMENTS |
||||
|
||||
# List jobs in the long format by default. |
||||
setopt LONG_LIST_JOBS |
||||
|
||||
# Report the status of background jobs immediately, rather than waiting until just before printing a prompt. |
||||
setopt NOTIFY |
||||
|
||||
# Prevent runing all background jobs at a lower priority. |
||||
setopt NO_BG_NICE |
||||
|
||||
# Prevent reporting the status of background and suspended jobs before exiting a shell with job control. |
||||
# NO_CHECK_JOBS is best used only in combination with NO_HUP, else such jobs will be killed automatically. |
||||
setopt NO_CHECK_JOBS |
||||
|
||||
# Prevent sending the HUP signal to running jobs when the shell exits. |
||||
setopt NO_HUP |
||||
|
||||
# Remove path separtor from WORDCHARS. |
||||
WORDCHARS=${WORDCHARS//[\/]} |
||||
|
||||
# Set less or more as the default pager. |
||||
if (( ! ${+PAGER} )); then |
||||
if (( ${+commands[less]} )); then |
||||
export PAGER=less |
||||
else |
||||
export PAGER=more |
||||
fi |
||||
fi |
||||
|
||||
# sets the window title and updates upon directory change |
||||
# more work probably needs to be done here to support multiplexers |
||||
if (( ${+ztermtitle} )); then |
||||
case ${TERM} in |
||||
xterm*|*rxvt) |
||||
precmd() { print -Pn "\e]0;${ztermtitle}\a" } |
||||
precmd # we execute it once to initialize the window title |
||||
;; |
||||
esac |
||||
fi |
@ -1,14 +0,0 @@ |
||||
fasd |
||||
==== |
||||
|
||||
[Fasd](https://github.com/clvv/fasd) (pronounced similar to "fast") is a command-line productivity booster. |
||||
Fasd offers quick access to files and directories for POSIX shells. It is |
||||
inspired by tools like [autojump](https://github.com/joelthelion/autojump), |
||||
[z](http://github.com/rupa/z) and [v](https://github.com/rupa/v). Fasd keeps |
||||
track of files and directories you have accessed, so that you can quickly |
||||
reference them in the command line. |
||||
|
||||
Contributing |
||||
------------ |
||||
|
||||
Contributions should be submitted [upstream to fasd](https://github.com/clvv/fasd). |
@ -1,424 +0,0 @@ |
||||
# Fasd is originally written based on code from z (https://github.com/rupa/z) |
||||
# by rupa deadwyler under the WTFPL license. Most if not all of the code has |
||||
# been rewritten. |
||||
|
||||
# Copyright (C) 2011, 2012 by Wei Dai. All rights reserved. |
||||
# |
||||
# 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. |
||||
|
||||
# make zsh do word splitting inside this function |
||||
[ "$ZSH_VERSION" ] && emulate sh && setopt localoptions |
||||
|
||||
case $1 in |
||||
--init) shift |
||||
while [ "$1" ]; do |
||||
case $1 in |
||||
env) |
||||
{ # Load configuration files |
||||
|
||||
if [[ -s ${XDG_CONFIG_HOME:-"${HOME}/.config"}/fasd/config ]]; then |
||||
source ${XDG_CONFIG_HOME:-"${HOME}/.config"}/fasd/config |
||||
else |
||||
[[ -s /etc/fasdrc ]] && source /etc/fasd |
||||
[[ -s ${HOME}/.fasdrc ]] && source ${HOME}/.fasdrc |
||||
fi |
||||
|
||||
# set default options |
||||
(( ! ${+_FASD_DATA} )) && _FASD_DATA="$HOME/.fasd" |
||||
(( ! ${+_FASD_BLACKLIST} )) && _FASD_BLACKLIST="--help" |
||||
(( ! ${+_FASD_SHIFT} )) && _FASD_SHIFT="sudo busybox" |
||||
(( ! ${+_FASD_IGNORE} )) && _FASD_IGNORE="fasd ls echo" |
||||
(( ! ${+_FASD_SINK} )) && _FASD_SINK=/dev/null |
||||
(( ! ${+_FASD_TRACK_PWD} )) && _FASD_TRACK_PWD=1 |
||||
(( ! ${+_FASD_MAX} )) && _FASD_MAX=2000 |
||||
(( ! ${+_FASD_BACKENDS} )) && _FASD_BACKENDS=native |
||||
(( ! ${+_FASD_FUZZY} )) && _FASD_FUZZY=2 |
||||
(( ! ${+_FASD_VIMINFO} )) && _FASD_VIMINFO="$HOME/.viminfo" |
||||
(( ! ${+_FASD_RECENTLY_USED_XBEL} )) && \ |
||||
_FASD_RECENTLY_USED_XBEL="$HOME/.local/share/recently-used.xbel" |
||||
|
||||
if (( ! ${+_FASD_AWK} )); then |
||||
# awk preferences |
||||
local awk; for awk in mawk gawk original-awk nawk awk; do |
||||
$awk "" && _FASD_AWK=$awk && break |
||||
done |
||||
fi |
||||
} >> ${_FASD_SINK:-/dev/null} 2>&1 |
||||
;; |
||||
esac; shift |
||||
done |
||||
;; |
||||
|
||||
# if "$_fasd_cur" or "$2" is a query, then output shell code to be eval'd |
||||
--word-complete-trigger) |
||||
shift; [ "$2" ] && local _fasd_cur="$2" || return |
||||
case $_fasd_cur in |
||||
,*) printf %s\\n "$1 e $_fasd_cur";; |
||||
f,*) printf %s\\n "$1 f ${_fasd_cur#?}";; |
||||
d,*) printf %s\\n "$1 d ${_fasd_cur#?}";; |
||||
*,,) printf %s\\n "$1 e $_fasd_cur";; |
||||
*,,f) printf %s\\n "$1 f ${_fasd_cur%?}";; |
||||
*,,d) printf %s\\n "$1 d ${_fasd_cur%?}";; |
||||
esac |
||||
;; |
||||
|
||||
--sanitize) shift; printf %s\\n "$*" | \ |
||||
sed 's/\([^\]\)$( *[^ ]* *\([^)]*\)))*/\1\2/g |
||||
s/\([^\]\)[|&;<>$`{}]\{1,\}/\1 /g' |
||||
;; |
||||
|
||||
--proc) shift # process commands |
||||
# stop if we don't own $_FASD_DATA or $_FASD_RO is set |
||||
[ -f "$_FASD_DATA" -a ! -O "$_FASD_DATA" ] || [ "$_FASD_RO" ] && return |
||||
|
||||
# blacklists |
||||
local each; for each in $_FASD_BLACKLIST; do |
||||
case " $* " in *\ $each\ *) return;; esac |
||||
done |
||||
|
||||
# shifts |
||||
while true; do |
||||
case " $_FASD_SHIFT " in |
||||
*\ $1\ *) shift;; |
||||
*) break;; |
||||
esac |
||||
done |
||||
|
||||
# ignores |
||||
case " $_FASD_IGNORE " in |
||||
*\ $1\ *) return;; |
||||
esac |
||||
|
||||
shift; fasd --add "$@" # add all arguments except command |
||||
;; |
||||
|
||||
--add|-A) shift # add entries |
||||
# stop if we don't own $_FASD_DATA or $_FASD_RO is set |
||||
[ -f "$_FASD_DATA" -a ! -O "$_FASD_DATA" ] || [ "$_FASD_RO" ] && return |
||||
|
||||
# find all valid path arguments, convert them to simplest absolute form |
||||
local paths="$(while [ "$1" ]; do |
||||
[ -e "$1" ] && printf %s\\n "$1"; shift |
||||
done | sed '/^[^/]/s@^@'"$PWD"'/@ |
||||
s@/\.\.$@/../@;s@/\(\./\)\{1,\}@/@g;:0 |
||||
s@[^/][^/]*//*\.\./@/@;t 0 |
||||
s@^/*\.\./@/@;s@//*@/@g;s@/\.\{0,1\}$@@;s@^$@/@' 2>> "$_FASD_SINK" \ |
||||
| tr '\n' '|')" |
||||
|
||||
# add current pwd if the option is set |
||||
[ "$_FASD_TRACK_PWD" = "1" -a "$PWD" != "$HOME" ] && paths="$paths|$PWD" |
||||
|
||||
[ -z "${paths##\|}" ] && return # stop if we have nothing to add |
||||
|
||||
# maintain the file |
||||
local tempfile |
||||
tempfile="$(mktemp "$_FASD_DATA".XXXXXX)" || return |
||||
$_FASD_AWK -v list="$paths" -v now="$(date +%s)" -v max="$_FASD_MAX" -F"|" ' |
||||
BEGIN { |
||||
split(list, files, "|") |
||||
for(i in files) { |
||||
path = files[i] |
||||
if(path == "") continue |
||||
paths[path] = path # array for checking |
||||
rank[path] = 1 |
||||
time[path] = now |
||||
} |
||||
} |
||||
$2 >= 1 { |
||||
if($1 in paths) { |
||||
rank[$1] = $2 + 1 / $2 |
||||
time[$1] = now |
||||
} else { |
||||
rank[$1] = $2 |
||||
time[$1] = $3 |
||||
} |
||||
count += $2 |
||||
} |
||||
END { |
||||
if(count > max) |
||||
for(i in rank) print i "|" 0.9*rank[i] "|" time[i] # aging |
||||
else |
||||
for(i in rank) print i "|" rank[i] "|" time[i] |
||||
}' "$_FASD_DATA" 2>> "$_FASD_SINK" >| "$tempfile" |
||||
if [ $? -ne 0 -a -f "$_FASD_DATA" ]; then |
||||
env rm -f "$tempfile" |
||||
else |
||||
env mv -f "$tempfile" "$_FASD_DATA" |
||||
fi |
||||
;; |
||||
|
||||
--delete|-D) shift # delete entries |
||||
# stop if we don't own $_FASD_DATA or $_FASD_RO is set |
||||
[ -f "$_FASD_DATA" -a ! -O "$_FASD_DATA" ] || [ "$_FASD_RO" ] && return |
||||
|
||||
# turn valid arguments into entry-deleting sed commands |
||||
local sed_cmd="$(while [ "$1" ]; do printf %s\\n "$1"; shift; done | \ |
||||
sed '/^[^/]/s@^@'"$PWD"'/@;s@/\.\.$@/../@;s@/\(\./\)\{1,\}@/@g;:0 |
||||
s@[^/][^/]*//*\.\./@/@;t 0 |
||||
s@^/*\.\./@/@;s@//*@/@g;s@/\.\{0,1\}$@@ |
||||
s@^$@/@;s@\([.[\/*^$]\)@\\\1@g;s@^\(.*\)$@/^\1|/d@' 2>> "$_FASD_SINK")" |
||||
|
||||
# maintain the file |
||||
local tempfile |
||||
tempfile="$(mktemp "$_FASD_DATA".XXXXXX)" || return |
||||
|
||||
sed "$sed_cmd" "$_FASD_DATA" 2>> "$_FASD_SINK" >| "$tempfile" |
||||
|
||||
if [ $? -ne 0 -a -f "$_FASD_DATA" ]; then |
||||
env rm -f "$tempfile" |
||||
else |
||||
env mv -f "$tempfile" "$_FASD_DATA" |
||||
fi |
||||
;; |
||||
|
||||
--query) shift # query the db, --query [$typ ["$fnd" [$mode]]] |
||||
[ -f "$_FASD_DATA" ] || return # no db yet |
||||
[ "$1" ] && local typ="$1" |
||||
[ "$2" ] && local fnd="$2" |
||||
[ "$3" ] && local mode="$3" |
||||
|
||||
# cat all backends |
||||
local each _fasd_data; for each in $_FASD_BACKENDS; do |
||||
_fasd_data="$_fasd_data |
||||
$(fasd --backend $each)" |
||||
done |
||||
[ "$_fasd_data" ] || _fasd_data="$(cat "$_FASD_DATA")" |
||||
|
||||
# set mode specific code for calculating the prior |
||||
case $mode in |
||||
rank) local prior='times[i]';; |
||||
recent) local prior='sqrt(100000/(1+t-la[i]))';; |
||||
*) local prior='times[i] * frecent(la[i])';; |
||||
esac |
||||
|
||||
if [ "$fnd" ]; then # dafault matching |
||||
local bre="$(printf %s\\n "$fnd" | sed 's/\([*\.\\\[]\)/\\\1/g |
||||
s@ @[^|]*@g;s/\$$/|/')" |
||||
bre='^[^|]*'"$bre"'[^|/]*|' |
||||
local _ret="$(printf %s\\n "$_fasd_data" | grep "$bre")" |
||||
[ "$_ret" ] && _ret="$(printf %s\\n "$_ret" | while read -r line; do |
||||
[ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line" |
||||
done)" |
||||
if [ "$_ret" ]; then |
||||
_fasd_data="$_ret" |
||||
else # no case mathcing |
||||
_ret="$(printf %s\\n "$_fasd_data" | grep -i "$bre")" |
||||
[ "$_ret" ] && _ret="$(printf %s\\n "$_ret" | while read -r line; do |
||||
[ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line" |
||||
done)" |
||||
if [ "$_ret" ]; then |
||||
_fasd_data="$_ret" |
||||
elif [ "${_FASD_FUZZY:-0}" -gt 0 ]; then # fuzzy matching |
||||
local fuzzy_bre="$(printf %s\\n "$fnd" | \ |
||||
sed 's/\([*\.\\\[]\)/\\\1/g;s/\$$/|/ |
||||
s@\(\\\{0,1\}[^ ]\)@\1[^|/]\\{0,'"$_FASD_FUZZY"'\\}@g |
||||
s@ @[^|]*@g')" |
||||
fuzzy_bre='^[^|]*'"$fuzzy_bre"'[^|/]*|' |
||||
_ret="$(printf %s\\n "$_fasd_data" | grep -i "$fuzzy_bre")" |
||||
[ "$_ret" ] && _ret="$(printf %s\\n "$_ret" | while read -r line; do |
||||
[ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line" |
||||
done)" |
||||
[ "$_ret" ] && _fasd_data="$_ret" || _fasd_data= |
||||
fi |
||||
fi |
||||
else # no query arugments |
||||
_fasd_data="$(printf %s\\n "$_fasd_data" | while read -r line; do |
||||
[ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line" |
||||
done)" |
||||
fi |
||||
|
||||
# query the database |
||||
[ "$_fasd_data" ] && printf %s\\n "$_fasd_data" | \ |
||||
$_FASD_AWK -v t="$(date +%s)" -F"|" ' |
||||
function frecent(time) { |
||||
dx = t-time |
||||
if( dx < 3600 ) return 6 |
||||
if( dx < 86400 ) return 4 |
||||
if( dx < 604800 ) return 2 |
||||
return 1 |
||||
} |
||||
{ |
||||
if(!paths[$1]) { |
||||
times[$1] = $2 |
||||
la[$1] = $3 |
||||
paths[$1] = 1 |
||||
} else { |
||||
times[$1] += $2 |
||||
if($3 > la[$1]) la[$1] = $3 |
||||
} |
||||
} |
||||
END { |
||||
for(i in paths) printf "%-10s %s\n", '"$prior"', i |
||||
}' - 2>> "$_FASD_SINK" |
||||
;; |
||||
|
||||
--backend) |
||||
case $2 in |
||||
native) cat "$_FASD_DATA";; |
||||
viminfo) |
||||
< "$_FASD_VIMINFO" sed -n '/^>/{s@~@'"$HOME"'@ |
||||
s/^..// |
||||
p |
||||
}' | $_FASD_AWK -v t="$(date +%s)" '{ |
||||
t -= 60 |
||||
print $0 "|1|" t |
||||
}' |
||||
;; |
||||
recently-used) |
||||
local nl="$(printf '\\\nX')"; nl="${nl%X}" # slash newline for sed |
||||
tr -d '\n' < "$_FASD_RECENTLY_USED_XBEL" | \ |
||||
sed 's@file:/@'"$nl"'@g;s@count="@'"$nl"'@g' | sed '1d;s/".*$//' | \ |
||||
tr '\n' '|' | sed 's@|/@'"$nl"'@g' | $_FASD_AWK -F'|' '{ |
||||
sum = 0 |
||||
for( i=2; i<=NF; i++ ) sum += $i |
||||
print $1 "|" sum |
||||
}' |
||||
;; |
||||
current) |
||||
for path in *; do |
||||
printf "$PWD/%s|1\\n" "$path" |
||||
done |
||||
;; |
||||
spotlight) |
||||
mdfind '(kMDItemFSContentChangeDate >= $time.today) || |
||||
kMDItemLastUsedDate >= $time.this_month' \ |
||||
| sed '/Library\//d |
||||
/\.app$/d |
||||
s/$/|2/' |
||||
;; |
||||
*) eval "$2";; |
||||
esac |
||||
;; |
||||
|
||||
*) # parsing logic and processing |
||||
local fnd= last= _FASD_BACKENDS="$_FASD_BACKENDS" _fasd_data= comp= exec= |
||||
while [ "$1" ]; do case $1 in |
||||
--complete) [ "$2" = "--" ] && shift; set -- $2; local lst=1 r=r comp=1;; |
||||
--query|--add|--delete|-A|-D) fasd "$@"; return $?;; |
||||
--version) [ -z "$comp" ] && echo "1.0.1" && return;; |
||||
--) while [ "$2" ]; do shift; fnd="$fnd $1"; last="$1"; done;; |
||||
-*) local o="${1#-}"; while [ "$o" ]; do case $o in |
||||
s*) local show=1;; |
||||
l*) local lst=1;; |
||||
i*) [ -z "$comp" ] && local interactive=1 show=1;; |
||||
r*) local mode=rank;; |
||||
t*) local mode=recent;; |
||||
e*) o="${o#?}"; if [ "$o" ]; then # there are characters after "-e" |
||||
local exec="$o" # anything after "-e" |
||||
else # use the next argument |
||||
local exec="${2:?"-e: Argument needed "}" |
||||
shift |
||||
fi; break;; |
||||
b*) o="${o#?}"; if [ "$o" ]; then |
||||
_FASD_BACKENDS="$o" |
||||
else |
||||
_FASD_BACKENDS="${2:?"-b: Argument needed"}" |
||||
shift |
||||
fi; break;; |
||||
B*) o="${o#?}"; if [ "$o" ]; then |
||||
_FASD_BACKENDS="$_FASD_BACKENDS $o" |
||||
else |
||||
_FASD_BACKENDS="$_FASD_BACKENDS ${2:?"-B: Argument needed"}" |
||||
shift |
||||
fi; break;; |
||||
a*) local typ=e;; |
||||
d*) local typ=d;; |
||||
f*) local typ=f;; |
||||
R*) local r=r;; |
||||
[0-9]*) local _fasd_i="$o"; break;; |
||||
h*) [ -z "$comp" ] && echo "fasd [options] [query ...] |
||||
[f|a|s|d|z] [options] [query ...] |
||||
options: |
||||
-s list paths with scores |
||||
-l list paths without scores |
||||
-i interactive mode |
||||
-e <cmd> set command to execute on the result file |
||||
-b <name> only use <name> backend |
||||
-B <name> add additional backend <name> |
||||
-a match files and directories |
||||
-d match directories only |
||||
-f match files only |
||||
-r match by rank only |
||||
-t match by recent access only |
||||
-R reverse listing order |
||||
-h show a brief help message |
||||
-[0-9] select the nth entry |
||||
|
||||
fasd [-A|-D] [paths ...] |
||||
-A add paths |
||||
-D delete paths" >&2 && return;; |
||||
esac; o="${o#?}"; done;; |
||||
*) fnd="$fnd $1"; last="$1";; |
||||
esac; shift; done |
||||
|
||||
# guess whether the last query is selected from tab completion |
||||
case $last in |
||||
/?*) if [ -z "$show$lst" -a -${typ:-e} "$last" -a "$exec" ]; then |
||||
$exec "$last" |
||||
return |
||||
fi;; |
||||
esac |
||||
|
||||
local R; [ -z "$r" ] && R=r || R= # let $R be the opposite of $r |
||||
fnd="${fnd# }" |
||||
|
||||
local res |
||||
res="$(fasd --query 2>> "$_FASD_SINK")" # query the database |
||||
[ $? -gt 0 ] && return |
||||
if [ 0 -lt ${_fasd_i:-0} ] 2>> "$_FASD_SINK"; then |
||||
res="$(printf %s\\n "$res" | sort -n${R} | \ |
||||
sed -n "$_fasd_i"'s/^[^ ]*[ ]*//p')" |
||||
elif [ "$interactive" ] || [ "$exec" -a -z "$fnd$lst$show" -a -t 1 ]; then |
||||
if [ "$(printf %s "$res" | sed -n '$=')" -gt 1 ]; then |
||||
res="$(printf %s\\n "$res" | sort -n${R})" |
||||
printf %s\\n "$res" | sed = | sed 'N;s/\n/ /' | sort -nr >&2 |
||||
printf "> " >&2 |
||||
local i; read i; [ 0 -lt "${i:-0}" ] 2>> "$_FASD_SINK" || return 1 |
||||
fi |
||||
res="$(printf %s\\n "$res" | sed -n "${i:-1}"'s/^[^ ]*[ ]*//p')" |
||||
elif [ "$lst" ]; then |
||||
[ "$res" ] && printf %s\\n "$res" | sort -n${r} | sed 's/^[^ ]*[ ]*//' |
||||
return |
||||
elif [ "$show" ]; then |
||||
[ "$res" ] && printf %s\\n "$res" | sort -n${r} |
||||
return |
||||
elif [ "$fnd" ] && [ "$exec" -o ! -t 1 ]; then # exec or subshell |
||||
res="$(printf %s\\n "$res" | sort -n | sed -n '$s/^[^ ]*[ ]*//p')" |
||||
else # no args, show |
||||
[ "$res" ] && printf %s\\n "$res" | sort -n${r} |
||||
return |
||||
fi |
||||
if [ "$res" ]; then |
||||
fasd --add "$res" |
||||
[ -z "$exec" ] && exec='printf %s\n' |
||||
$exec "$res" |
||||
fi |
||||
;; |
||||
esac |
||||
|
||||
#case $- in |
||||
# *i*) ;; # assume being sourced, do nothing |
||||
# *) # assume being executed as an executable |
||||
# if [ -x "$_FASD_SHELL" -a -z "$_FASD_SET" ]; then |
||||
# _FASD_SET=1 exec $_FASD_SHELL "$0" "$@" |
||||
# else |
||||
# fasd "$@" |
||||
# fi;; |
||||
#esac |
@ -1,88 +0,0 @@ |
||||
fasd --init env |
||||
|
||||
# function to execute built-in cd |
||||
fasd_cd() { |
||||
if [ $# -le 1 ]; then |
||||
fasd "$@" |
||||
else |
||||
local _fasd_ret="$(fasd -e 'printf %s' "$@")" |
||||
[ -z "$_fasd_ret" ] && return |
||||
[ -d "$_fasd_ret" ] && cd "$_fasd_ret" || printf %s\n "$_fasd_ret" |
||||
fi |
||||
} |
||||
|
||||
alias a='fasd -a' |
||||
alias s='fasd -si' |
||||
alias sd='fasd -sid' |
||||
alias sf='fasd -sif' |
||||
alias d='fasd -d' |
||||
alias f='fasd -f' |
||||
alias v='f -e vim -b viminfo' |
||||
alias z='fasd_cd -d' |
||||
alias zz='fasd_cd -d -i' |
||||
|
||||
# add zsh hook |
||||
_fasd_preexec() { |
||||
{ eval "fasd --proc $(fasd --sanitize $2)"; } >> "/dev/null" 2>&1 |
||||
} |
||||
autoload -Uz add-zsh-hook |
||||
add-zsh-hook preexec _fasd_preexec |
||||
|
||||
# zsh command mode completion |
||||
_fasd_zsh_cmd_complete() { |
||||
local compl |
||||
read -c compl |
||||
(( $+compstate )) && compstate[insert]=menu # no expand if compsys loaded |
||||
reply=(${(f)"$(fasd --complete "$compl")"}) |
||||
} |
||||
|
||||
# enable command mode completion |
||||
compctl -U -K _fasd_zsh_cmd_complete -V fasd -x 'C[-1,-*e],s[-]n[1,e]' -c - \ |
||||
'c[-1,-A][-1,-D]' -f -- fasd fasd_cd |
||||
|
||||
(( $+functions[compdef] )) && { |
||||
# zsh word mode completion |
||||
_fasd_zsh_word_complete() { |
||||
[ "$2" ] && local _fasd_cur="$2" |
||||
[ -z "$_fasd_cur" ] && local _fasd_cur="${words[CURRENT]}" |
||||
local fnd="${_fasd_cur//,/ }" |
||||
local typ=${1:-e} |
||||
fasd --query $typ "$fnd" 2>> "/dev/null" | \ |
||||
sort -nr | sed 's/^[^ ]*[ ]*//' | while read -r line; do |
||||
compadd -U -V fasd "$line" |
||||
done |
||||
compstate[insert]=menu # no expand |
||||
} |
||||
_fasd_zsh_word_complete_f() { _fasd_zsh_word_complete f ; } |
||||
_fasd_zsh_word_complete_d() { _fasd_zsh_word_complete d ; } |
||||
_fasd_zsh_word_complete_trigger() { |
||||
local _fasd_cur="${words[CURRENT]}" |
||||
eval $(fasd --word-complete-trigger _fasd_zsh_word_complete $_fasd_cur) |
||||
} |
||||
# define zle widgets |
||||
zle -C fasd-complete complete-word _generic |
||||
zstyle ':completion:fasd-complete:*' completer _fasd_zsh_word_complete |
||||
zstyle ':completion:fasd-complete:*' menu-select |
||||
|
||||
zle -C fasd-complete-f complete-word _generic |
||||
zstyle ':completion:fasd-complete-f:*' completer _fasd_zsh_word_complete_f |
||||
zstyle ':completion:fasd-complete-f:*' menu-select |
||||
|
||||
zle -C fasd-complete-d complete-word _generic |
||||
zstyle ':completion:fasd-complete-d:*' completer _fasd_zsh_word_complete_d |
||||
zstyle ':completion:fasd-complete-d:*' menu-select |
||||
} |
||||
|
||||
(( $+functions[compdef] )) && { |
||||
# enable word mode completion |
||||
orig_comp="$(zstyle -L ':completion:\*' completer 2>> "/dev/null")" |
||||
if [ "$orig_comp" ]; then |
||||
case $orig_comp in |
||||
*_fasd_zsh_word_complete_trigger*);; |
||||
*) eval "$orig_comp _fasd_zsh_word_complete_trigger";; |
||||
esac |
||||
else |
||||
zstyle ':completion:*' completer _complete _fasd_zsh_word_complete_trigger |
||||
fi |
||||
unset orig_comp |
||||
} |