1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2026-01-21 00:57:24 +08:00

Compare commits

..

No commits in common. "ed4e317bbbd9966da2b4b85893c8d55c9ffbfd66" and "c58572d5fe51b3ba09801837b6eee2cb6f0bf913" have entirely different histories.

9 changed files with 101 additions and 218 deletions

View File

@ -27,8 +27,8 @@ esac
## History file configuration ## History file configuration
[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history" [ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history"
[ "$HISTSIZE" -lt 50000 ] && HISTSIZE=50000 HISTSIZE=50000
[ "$SAVEHIST" -lt 10000 ] && SAVEHIST=10000 SAVEHIST=10000
## History command configuration ## History command configuration
setopt extended_history # record timestamp of command in HISTFILE setopt extended_history # record timestamp of command in HISTFILE

View File

@ -85,9 +85,7 @@ fi
# Append zcompdump metadata if missing # Append zcompdump metadata if missing
if (( $zcompdump_refresh )); then if (( $zcompdump_refresh )); then
# Use `tee` in case the $ZSH_COMPDUMP filename is invalid, to silence the error cat >>| "$ZSH_COMPDUMP" <<EOF
# See https://github.com/ohmyzsh/ohmyzsh/commit/dd1a7269#commitcomment-39003489
tee -a "$ZSH_COMPDUMP" &>/dev/null <<EOF
$zcompdump_revision $zcompdump_revision
$zcompdump_fpath $zcompdump_fpath

View File

@ -1,4 +1,5 @@
# wd wd
==
[![Build Status](https://travis-ci.org/mfaerevaag/wd.png?branch=master)](https://travis-ci.org/mfaerevaag/wd) [![Build Status](https://travis-ci.org/mfaerevaag/wd.png?branch=master)](https://travis-ci.org/mfaerevaag/wd)
@ -8,232 +9,150 @@
*NEWS*: If you are not using zsh, check out the c-port, [wd-c](https://github.com/mfaerevaag/wd-c), which works with all shells using wrapper functions. *NEWS*: If you are not using zsh, check out the c-port, [wd-c](https://github.com/mfaerevaag/wd-c), which works with all shells using wrapper functions.
## Setup ### Setup
### oh-my-zsh ### oh-my-zsh
`wd` comes bundled with [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh)! `wd` comes bundled with [oh-my-zshell](https://github.com/ohmyzsh/ohmyzsh)!
Just add the plugin in your `~/.zshrc` file: Just add the plugin in your `~/.zshrc` file:
```zsh plugins=(... wd)
plugins=(... wd)
```
### [Antigen](https://github.com/zsh-users/antigen)
In your `.zshrc`: #### Automatic
```zsh
antigen bundle mfaerevaag/wd
```
### [Antibody](https://github.com/getantibody/antibody)
In your `.zshrc`:
```zsh
antibody bundle mfaerevaag/wd
```
### Arch ([AUR](https://aur.archlinux.org/packages/zsh-plugin-wd-git/))
```zsh
yay -S zsh-plugin-wd-git
# or use any other AUR helper
```
### [zplug](https://github.com/zplug/zplug)
```zsh
zplug "mfaerevaag/wd", as:command, use:"wd.sh", hook-load:"wd() { . $ZPLUG_REPOS/mfaerevaag/wd/wd.sh }"
```
### Automatic
Run either in terminal: Run either in terminal:
```zsh * `curl -L https://github.com/mfaerevaag/wd/raw/master/install.sh | sh`
curl -L https://github.com/mfaerevaag/wd/raw/master/install.sh | sh
```
or * `wget --no-check-certificate https://github.com/mfaerevaag/wd/raw/master/install.sh -O - | sh`
```zsh ##### Arch ([AUR](https://aur.archlinux.org/))
wget --no-check-certificate https://github.com/mfaerevaag/wd/raw/master/install.sh -O - | sh
```
### Manual # yaourt -S zsh-plugin-wd-git
* Clone this repo to your liking
* Add `wd` function to `.zshrc` (or `.profile` etc.): #### Manual
```zsh * Clone this repo to your liking
wd() {
. ~/path/to/cloned/repo/wd/wd.sh
}
```
* Install manpage. From `wd`'s base directory (requires root permissions): * Add `wd` function to `.zshrc` (or `.profile` etc.):
```zsh wd() {
cp wd.1 /usr/share/man/man1/wd.1 . ~/path/to/cloned/repo/wd/wd.sh
chmod 644 /usr/share/man/man1/wd.1 }
```
**Note:** when pulling and updating `wd`, you'll need to do this again in case of changes to the manpage. * Install manpage. From `wd`'s base directory (requires root permissions):
## Completion # cp wd.1 /usr/share/man/man1/wd.1
# chmod 644 /usr/share/man/man1/wd.1
If you're NOT using [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) and you want to utilize the zsh-completion feature, you will also need to add the path to your `wd` installation (`~/bin/wd` if you used the automatic installer) to your `fpath`. E.g. in your `~/.zshrc`: Note, when pulling and updating `wd`, you'll need to do this again in case of changes to the manpage.
```zsh
fpath=(~/path/to/wd $fpath) #### Completion
```
If you're NOT using [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh) and you want to utilize the zsh-completion feature, you will also need to add the path to your `wd` installation (`~/bin/wd` if you used the automatic installer) to your `fpath`. E.g. in your `~/.zshrc`:
fpath=(~/path/to/wd $fpath)
Also, you may have to force a rebuild of `zcompdump` by running: Also, you may have to force a rebuild of `zcompdump` by running:
```zsh $ rm -f ~/.zcompdump; compinit
rm -f ~/.zcompdump; compinit
```
## Usage
* Add warp point to current working directory:
```zsh ### Usage
wd add foo
```
If a warp point with the same name exists, use `wd add! foo` to overwrite it. * Add warp point to current working directory:
**Note:** a warp point cannot contain colons, or consist of only spaces and dots. The first will conflict in how `wd` stores the warp points, and the second will conflict with other features, as below. $ wd add foo
You can omit point name to automatically use the current directory's name instead. If a warp point with the same name exists, use `add!` to overwrite it.
* From any directory, warp to `foo` with: Note, a warp point cannot contain colons, or only consist of only spaces and dots. The first will conflict in how `wd` stores the warp points, and the second will conflict with other features, as below.
```zsh You can omit point name to use the current directory's name instead.
wd foo
```
* You can also warp to a directory within foo, with autocompletion: * From an other directory (not necessarily), warp to `foo` with:
```zsh $ wd foo
wd foo some/inner/path
```
* You can warp back to previous directory and higher, with this dot syntax: * You can warp back to previous directory, and so on, with this dot syntax:
```zsh $ wd ..
wd .. $ wd ...
wd ...
```
This is a wrapper for the zsh's `dirs` function. This is a wrapper for the zsh `dirs` function.
_You might need to add `setopt AUTO_PUSHD` to your `.zshrc` if you are not using [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh))._ (You might need `setopt AUTO_PUSHD` in your `.zshrc` if you hare not using [oh-my-zshell](https://github.com/ohmyzsh/ohmyzsh)).
* Remove warp point: * Remove warp point test point:
```zsh $ wd rm foo
wd rm foo
```
You can omit point name to use the current directory's name instead. You can omit point name to use the current directory's name instead.
* List all warp points (stored in `~/.warprc`): * List all warp points (stored in `~/.warprc`):
```zsh $ wd list
wd list
```
* List files in given warp point: * List files in given warp point:
```zsh $ wd ls foo
wd ls foo
```
* Show path of given warp point: * Show path of given warp point:
```zsh $ wd path foo
wd path foo
```
* List warp points to current directory, or optionally, path to given warp point: * List warp points to current directory, or optionally, path to given warp point:
```zsh $ wd show
wd show
```
* Remove warp points to non-existent directories. * Remove warp points to non-existent directories.
```zsh $ wd clean
wd clean
```
Use `wd clean!` to not be prompted with confirmation (force). Use `clean!` to not be prompted with confirmation (force).
* Print usage info: * Print usage with no opts or the `help` argument:
```zsh $ wd help
wd help
```
The usage will be printed also if you call `wd` with no command * Print the running version of `wd`:
* Print the running version of `wd`: $ wd --version
```zsh * Specifically set the config file (default `~/.warprc`), which is useful when testing:
wd --version
```
* Specifically set the config file (default being `~/.warprc`), which is useful for testing: $ wd --config ./file <action>
```zsh * Force `exit` with return code after running. This is not default, as it will *exit your terminal*, though required when testing/debugging.
wd --config ./file <command>
```
* Force `exit` with return code after running. This is not default, as it will *exit your terminal*, though required for testing/debugging. $ wd --debug <action>
```zsh * Silence all output:
wd --debug <command>
```
* Silence all output: $ wd --quiet <action>
```zsh
wd --quiet <command>
```
## Configuration ### Testing
You can configure `wd` with the following environment variables: `wd` comes with a small test suite, run with [shunit2](https://code.google.com/p/shunit2/). This can be used to confirm that things are working as it should on your setup, or to demonstrate an issue.
### `WD_CONFIG`
Defines the path where warp points get stored. Defaults to `$HOME/.warprc`.
## Testing
`wd` comes with a small test suite, run with [shunit2](https://code.google.com/p/shunit2/). This can be used to confirm that things are working as they should on your setup, or to demonstrate an issue.
To run, simply `cd` into the `test` directory and run the `tests.sh`. To run, simply `cd` into the `test` directory and run the `tests.sh`.
```zsh $ ./tests.sh
cd ./test
./tests.sh
```
## License
The project is licensed under the [MIT license](https://github.com/mfaerevaag/wd/blob/master/LICENSE). ### License
## Contributing The project is licensed under the [MIT-license](https://github.com/mfaerevaag/wd/blob/master/LICENSE).
If you have issues, feedback or improvements, don't hesitate to report it or submit a pull request. In the case of an issue, we would much appreciate if you would include a failing test in `test/tests.sh`. For an explanation on how to run the tests, read the section "Testing" in this README.
---- ### Finally
If you have issues, feedback or improvements, don't hesitate to report it or submit a pull-request. In the case of an issue, we would much appreciate if you would include a failing test in `test/tests.sh`. For an explanation on how to run the tests, read the section "Testing" in this README.
Credit to [altschuler](https://github.com/altschuler) for an awesome idea. Credit to [altschuler](https://github.com/altschuler) for an awesome idea.

View File

@ -1,6 +1,6 @@
#compdef wd #compdef wd
zstyle ':completion::complete:wd:*:descriptions' format '%B%d%b' zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion::complete:wd:*:commands' group-name commands zstyle ':completion::complete:wd:*:commands' group-name commands
zstyle ':completion::complete:wd:*:warp_points' group-name warp_points zstyle ':completion::complete:wd:*:warp_points' group-name warp_points
zstyle ':completion::complete:wd::' list-grouped zstyle ':completion::complete:wd::' list-grouped
@ -8,13 +8,13 @@ zstyle ':completion::complete:wd::' list-grouped
zmodload zsh/mapfile zmodload zsh/mapfile
function _wd() { function _wd() {
local WD_CONFIG=${WD_CONFIG:-$HOME/.warprc} local CONFIG=$HOME/.warprc
local ret=1 local ret=1
local -a commands local -a commands
local -a warp_points local -a warp_points
warp_points=( "${(f)mapfile[$WD_CONFIG]//$HOME/~}" ) warp_points=( "${(f)mapfile[$CONFIG]//$HOME/~}" )
typeset -A points typeset -A points
while read -r line while read -r line
@ -27,12 +27,11 @@ function _wd() {
target_path=${target_path/#\~/$HOME} target_path=${target_path/#\~/$HOME}
points[$name]=$target_path points[$name]=$target_path
done < $WD_CONFIG done < $CONFIG
commands=( commands=(
'add:Adds the current working directory to your warp points' 'add:Adds the current working directory to your warp points'
'add!:Overwrites existing warp point' 'add!:Overwrites existing warp point'
'export:Export warp points as static named directories'
'rm:Removes the given warp point' 'rm:Removes the given warp point'
'list:Outputs all stored warp points' 'list:Outputs all stored warp points'
'ls:Show files from given warp point' 'ls:Show files from given warp point'
@ -73,12 +72,8 @@ function _wd() {
_describe -t points "Warp points" warp_points && ret=0 _describe -t points "Warp points" warp_points && ret=0
;; ;;
*) *)
if [[ -v points[$target] ]]; then # complete sub directories from the warp point
# complete sub directories from the warp point _path_files -W "(${points[$target]})" -/ && ret=0
_path_files -W "(${points[$target]})" -/ && ret=0
fi
# don't complete anything if warp point is not valid
;; ;;
esac esac
;; ;;

View File

@ -1,9 +1,6 @@
#!/bin/zsh
# WARP DIRECTORY # WARP DIRECTORY
# ============== # ==============
# Jump to custom directories in terminal # oh-my-zsh plugin
# because `cd` takes too long...
# #
# @github.com/mfaerevaag/wd # @github.com/mfaerevaag/wd

View File

@ -36,11 +36,11 @@ wd_yesorno()
read -r answer read -r answer
case ${answer:=${default}} in case ${answer:=${default}} in
"Y"|"y"|"YES"|"yes"|"Yes" ) Y|y|YES|yes|Yes )
RETVAL=${yes_RETVAL} && \ RETVAL=${yes_RETVAL} && \
break break
;; ;;
"N"|"n"|"NO"|"no"|"No" ) N|n|NO|no|No )
RETVAL=${no_RETVAL} && \ RETVAL=${no_RETVAL} && \
break break
;; ;;
@ -75,8 +75,6 @@ wd_print_usage()
Usage: wd [command] [point] Usage: wd [command] [point]
Commands: Commands:
<point> Warps to the directory specified by the warp point
<point> <path> Warps to the directory specified by the warp point with path appended
add <point> Adds the current working directory to your warp points add <point> Adds the current working directory to your warp points
add Adds the current working directory to your warp points with current directory's name add Adds the current working directory to your warp points with current directory's name
add! <point> Overwrites existing warp point add! <point> Overwrites existing warp point
@ -184,8 +182,6 @@ wd_add()
wd_remove $point > /dev/null wd_remove $point > /dev/null
printf "%q:%s\n" "${point}" "${PWD/#$HOME/~}" >> $WD_CONFIG printf "%q:%s\n" "${point}" "${PWD/#$HOME/~}" >> $WD_CONFIG
wd_export_static_named_directories
wd_print_msg $WD_GREEN "Warp point added" wd_print_msg $WD_GREEN "Warp point added"
# override exit code in case wd_remove did not remove any points # override exit code in case wd_remove did not remove any points
@ -207,9 +203,8 @@ wd_remove()
if [[ ${points[$point]} != "" ]] if [[ ${points[$point]} != "" ]]
then then
local config_tmp=$(mktemp "${TMPDIR:-/tmp}/wd.XXXXXXXXXX") local config_tmp=$WD_CONFIG.tmp
# Copy and delete in two steps in order to preserve symlinks if sed -n "/^${point}:.*$/!p" $WD_CONFIG > $config_tmp && mv $config_tmp $WD_CONFIG
if sed -n "/^${point}:.*$/!p" $WD_CONFIG > $config_tmp && cp $config_tmp $WD_CONFIG && rm $config_tmp
then then
wd_print_msg $WD_GREEN "Warp point removed" wd_print_msg $WD_GREEN "Warp point removed"
else else
@ -339,16 +334,7 @@ wd_clean() {
fi fi
} }
wd_export_static_named_directories() { local WD_CONFIG=$HOME/.warprc
if [[ -z $WD_SKIP_EXPORT ]]
then
grep '^[0-9a-zA-Z_-]\+:' "$WD_CONFIG" | sed -e "s,~,$HOME," -e 's/:/=/' | while read warpdir ; do
hash -d "$warpdir"
done
fi
}
local WD_CONFIG=${WD_CONFIG:-$HOME/.warprc}
local WD_QUIET=0 local WD_QUIET=0
local WD_EXIT_CODE=0 local WD_EXIT_CODE=0
local WD_DEBUG=0 local WD_DEBUG=0
@ -378,8 +364,6 @@ if [ ! -e $WD_CONFIG ]
then then
# if not, create config file # if not, create config file
touch $WD_CONFIG touch $WD_CONFIG
else
wd_export_static_named_directories
fi fi
# load warp points # load warp points
@ -412,57 +396,52 @@ then
else else
# parse rest of options # parse rest of options
local wd_o for o
for wd_o
do do
case "$wd_o" case "$o"
in in
"-a"|"--add"|"add") -a|--add|add)
wd_add false $2 wd_add false $2
break break
;; ;;
"-a!"|"--add!"|"add!") -a!|--add!|add!)
wd_add true $2 wd_add true $2
break break
;; ;;
"-e"|"export") -r|--remove|rm)
wd_export_static_named_directories
break
;;
"-r"|"--remove"|"rm")
wd_remove $2 wd_remove $2
break break
;; ;;
"-l"|"list") -l|list)
wd_list_all wd_list_all
break break
;; ;;
"-ls"|"ls") -ls|ls)
wd_ls $2 wd_ls $2
break break
;; ;;
"-p"|"--path"|"path") -p|--path|path)
wd_path $2 wd_path $2
break break
;; ;;
"-h"|"--help"|"help") -h|--help|help)
wd_print_usage wd_print_usage
break break
;; ;;
"-s"|"--show"|"show") -s|--show|show)
wd_show $2 wd_show $2
break break
;; ;;
"-c"|"--clean"|"clean") -c|--clean|clean)
wd_clean false wd_clean false
break break
;; ;;
"-c!"|"--clean!"|"clean!") -c!|--clean!|clean!)
wd_clean true wd_clean true
break break
;; ;;
*) *)
wd_warp $wd_o $2 wd_warp $o $2
break break
;; ;;
--) --)
@ -487,8 +466,6 @@ unset wd_print_usage
unset wd_alt_config unset wd_alt_config
unset wd_quiet_mode unset wd_quiet_mode
unset wd_print_version unset wd_print_version
unset wd_export_static_named_directories
unset wd_o
unset args unset args
unset points unset points

View File

@ -40,7 +40,6 @@ Available search contexts are:
| `givero` | `https://www.givero.com/search?q=` | | `givero` | `https://www.givero.com/search?q=` |
| `stackoverflow` | `https://stackoverflow.com/search?q=` | | `stackoverflow` | `https://stackoverflow.com/search?q=` |
| `wolframalpha` | `https://wolframalpha.com/input?i=` | | `wolframalpha` | `https://wolframalpha.com/input?i=` |
| `archive` | `https://web.archive.org/web/*/` |
Also there are aliases for bang-searching DuckDuckGo: Also there are aliases for bang-searching DuckDuckGo:

View File

@ -20,7 +20,6 @@ function web_search() {
givero "https://www.givero.com/search?q=" givero "https://www.givero.com/search?q="
stackoverflow "https://stackoverflow.com/search?q=" stackoverflow "https://stackoverflow.com/search?q="
wolframalpha "https://www.wolframalpha.com/input/?i=" wolframalpha "https://www.wolframalpha.com/input/?i="
archive "https://web.archive.org/web/*/"
) )
# check whether the search engine is supported # check whether the search engine is supported
@ -58,7 +57,6 @@ alias qwant='web_search qwant'
alias givero='web_search givero' alias givero='web_search givero'
alias stackoverflow='web_search stackoverflow' alias stackoverflow='web_search stackoverflow'
alias wolframalpha='web_search wolframalpha' alias wolframalpha='web_search wolframalpha'
alias archive='web_search archive'
#add your own !bang searches here #add your own !bang searches here
alias wiki='web_search duckduckgo \!w' alias wiki='web_search duckduckgo \!w'

View File

@ -26,7 +26,7 @@ function box_name {
PROMPT="╭─%{$FG[040]%}%n%{$reset_color%} %{$FG[239]%}at%{$reset_color%} %{$FG[033]%}$(box_name)%{$reset_color%} %{$FG[239]%}in%{$reset_color%} %{$terminfo[bold]$FG[226]%}%~%{$reset_color%}\$(git_prompt_info)\$(ruby_prompt_info) %D - %* PROMPT="╭─%{$FG[040]%}%n%{$reset_color%} %{$FG[239]%}at%{$reset_color%} %{$FG[033]%}$(box_name)%{$reset_color%} %{$FG[239]%}in%{$reset_color%} %{$terminfo[bold]$FG[226]%}%~%{$reset_color%}\$(git_prompt_info)\$(ruby_prompt_info) %D - %*
╰─\$(virtualenv_info)\$(prompt_char) " ╰─$(virtualenv_info)$(prompt_char) "
ZSH_THEME_GIT_PROMPT_PREFIX=" %{$FG[239]%}on%{$reset_color%} %{$fg[255]%}" ZSH_THEME_GIT_PROMPT_PREFIX=" %{$FG[239]%}on%{$reset_color%} %{$fg[255]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"