mirror of https://github.com/ohmyzsh/ohmyzsh.git
Compare commits
9 Commits
1aba66082a
...
a463e0e13d
Author | SHA1 | Date |
---|---|---|
|
a463e0e13d | |
|
30e516a3aa | |
|
b58bf31444 | |
|
f246f4612a | |
|
ca467bd9d9 | |
|
5889f4cfc9 | |
|
3cb5a9097b | |
|
aa9043f5ea | |
|
bc0433e518 |
|
@ -56,27 +56,110 @@ autoload -Uz is-at-least
|
||||||
if is-at-least 4.2.0; then
|
if is-at-least 4.2.0; then
|
||||||
# open browser on urls
|
# open browser on urls
|
||||||
if [[ -n "$BROWSER" ]]; then
|
if [[ -n "$BROWSER" ]]; then
|
||||||
_browser_fts=(htm html de org net com at cx nl se dk)
|
_browser_fts=(htm html xhtml)
|
||||||
for ft in $_browser_fts; do alias -s $ft='$BROWSER'; done
|
for ft in $_browser_fts; do alias -s $ft='$BROWSER'; done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_editor_fts=(cpp cxx cc c hh h inl asc txt TXT tex)
|
# open editable text files in text editor
|
||||||
for ft in $_editor_fts; do alias -s $ft='$EDITOR'; done
|
if [[ -n "$VISUAL" ]] || [[ -n "$EDITOR" ]]; then
|
||||||
|
_aliases_launch_editor() {
|
||||||
|
# directly launch matched files with executable bit and shebang present
|
||||||
|
if [[ -x "${1}" ]]; then
|
||||||
|
read -r <"${1}"
|
||||||
|
if [[ ${#REPLY} -ge 3 ]] && [[ ${REPLY:0:2} = '#!' ]]; then
|
||||||
|
"$@"
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$VISUAL" ]]; then
|
||||||
|
$VISUAL "$@"
|
||||||
|
else
|
||||||
|
$EDITOR "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
# Taken from the /language/metadata/property[name="globs"] sections of the
|
||||||
|
# gtksourceview language definition files in
|
||||||
|
# /usr/share/gtksourceview-3.0/language-specs/*.lang
|
||||||
|
_editor_fts=(
|
||||||
|
abnf as adb ads 4th forth asp am awk prg bib bsv boo cg h c cmake ctest
|
||||||
|
cbl cob cbd cdb cdc hh hp hpp h++ cpp cxx cc C c++ cs css CSSL csv cu cuh
|
||||||
|
desktop kdelnk diff patch rej d docbook bat cmd sys dot gv dpatch dtd dtl
|
||||||
|
e eif erl hrl fcl frt fs f f90 f95 for F F90 fs g gd gi gap gdb gs glslv
|
||||||
|
glslf go groovy hs lhs hx pro idl igm ini jade pug java js node ijs json
|
||||||
|
geojson topojson jl kt tex ltx sty cls dtx ins bbl l lex flex la lai lo
|
||||||
|
ll logcat lua m4 ac in make mak mk page markdown md mkd m mac MAC dem DEM
|
||||||
|
wxm WXM build mo mop mxml n nrx nai nsh m j ml mli mll mly ocl ooc sign
|
||||||
|
impl cl p pas txt TXT pl pm al perl t php php3 php4 phtml pig pc po pot
|
||||||
|
prolog proto pp py3 py pyw R Rout r Rhistory Rtspec rst rb rake gemspe rs
|
||||||
|
scala scm sce sci sh bash sml sig rq sql rnw Rnw snw Snw swift sv svh t2t
|
||||||
|
tcl tk tera texi texinfo thrift toml tml lock vala vapi vb v vhd xml xspf
|
||||||
|
siv smil smi sml kino xul xbel abw zabw glabe jnlp mml rdf rss wml xmi fo
|
||||||
|
xslfo xslt xsl y yacc yaml yml
|
||||||
|
)
|
||||||
|
for ft in $_editor_fts; do alias -s $ft=_aliases_launch_editor; done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# open image files in image viewer
|
||||||
if [[ -n "$XIVIEWER" ]]; then
|
if [[ -n "$XIVIEWER" ]]; then
|
||||||
_image_fts=(jpg jpeg png gif mng tiff tif xpm)
|
# List inspired by https://en.wikipedia.org/wiki/Image_file_formats
|
||||||
|
_image_fts=(
|
||||||
|
#: Raster formats
|
||||||
|
# JPEG, JPEG2000, HEIF/HEVC, JBIG
|
||||||
|
jpg jpeg jpe jif jfif jfi jp2 j2k jpf jpx jpm mj2 heif heic jbg jbig
|
||||||
|
# BMP, BPG, GIF, ICO/ANI, PCX, PNG+MNG, TGA, TIFF, WebP (Web)
|
||||||
|
bmp bpg gif dib ico cur ani pcx png mng tga tiff tif webp
|
||||||
|
# NetPBM, XBM/XPM/XWD (ASCII)
|
||||||
|
pbm bgm ppm pnm xbm xpm xwd
|
||||||
|
# CIFF, DNG, DPX, ECW, FITS, ICS, RGBE (HDR & Raw)
|
||||||
|
crw dng dpx ecw fits ics ids fit fts hdr
|
||||||
|
# DDS ICNS OpenRaster SunRaster (Other)
|
||||||
|
dds icns ora ras sun
|
||||||
|
#: Vector formats
|
||||||
|
# CGM WMF Gerber IGES SVG
|
||||||
|
cgm wmf emf wmz emz gbr iges svg svgz
|
||||||
|
)
|
||||||
for ft in $_image_fts; do alias -s $ft='$XIVIEWER'; done
|
for ft in $_image_fts; do alias -s $ft='$XIVIEWER'; done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_media_fts=(ape avi flv m4a mkv mov mp3 mpeg mpg ogg ogm rm wav webm)
|
if [[ -n "$XMVIEWER" ]]; then
|
||||||
for ft in $_media_fts; do alias -s $ft=mplayer; done
|
_media_fts=(
|
||||||
|
#: Audio (container) formats
|
||||||
|
# https://en.wikipedia.org/wiki/Audio_file_format#List_of_formats
|
||||||
|
aac act aiff ape au awb dct dss flac gsm m4a m4b mp3 mpc oga opus ra sln
|
||||||
|
tta vox wav wma wv
|
||||||
|
#: Video (container) formats
|
||||||
|
# https://en.wikipedia.org/wiki/Video_file_format#List_of_video_file_formats
|
||||||
|
mkv flv f4v f4p f4a f4b vob ogv drc gifv avi mov qt wmv yuv rmvb asf amv
|
||||||
|
m4v mpg mp2 m2v mpeg mpe mpv svi 3g2 mxf nsv
|
||||||
|
#: Container formats that may store both
|
||||||
|
3gp ogg mogg mp4 m4p rm webm
|
||||||
|
)
|
||||||
|
for ft in $_media_fts; do alias -s $ft=$XMVIEWER; done
|
||||||
|
fi
|
||||||
|
|
||||||
#read documents
|
#open complex document formats using the system viewer
|
||||||
alias -s pdf=acroread
|
_document_fts=(
|
||||||
alias -s ps=gv
|
# Long-term storage formats
|
||||||
alias -s dvi=xdvi
|
djvu dvi fb2 epub pdf ps rtf
|
||||||
alias -s chm=xchm
|
# Office Binary & Office OpenXML
|
||||||
alias -s djvu=djview
|
doc docx docm ppt pptx pptm xls xlsx xlsm
|
||||||
|
# OpenDocument
|
||||||
|
odt fodt ods fods odp fodp odg fodg odf
|
||||||
|
# Uniform Office Format
|
||||||
|
uof uot uos uop
|
||||||
|
# StarOffice
|
||||||
|
sdw sxw sdc sxc sdd sci sda sxd smf sxm
|
||||||
|
# WordPerfect
|
||||||
|
wpd wp wp4 wp5 wp6 wp7
|
||||||
|
# Others
|
||||||
|
abw gnm gnumeric pages hwp
|
||||||
|
)
|
||||||
|
if type xdg-open >/dev/null; then
|
||||||
|
for ft in $_document_fts; do alias -s $ft=xdg-open; done
|
||||||
|
elif type open >/dev/null; then
|
||||||
|
for ft in $_document_fts; do alias -s $ft=open; done
|
||||||
|
fi
|
||||||
|
|
||||||
#list whats inside packed file
|
#list whats inside packed file
|
||||||
alias -s zip="unzip -l"
|
alias -s zip="unzip -l"
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
# jj - Jujutsu CLI
|
||||||
|
|
||||||
|
This plugin provides autocompletion for [jj](https://martinvonz.github.io/jj).
|
||||||
|
|
||||||
|
To use it, add `jj` to the plugins array of your zshrc file:
|
||||||
|
|
||||||
|
```zsh
|
||||||
|
plugins=(... jj)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Aliases
|
||||||
|
|
||||||
|
| Alias | Command |
|
||||||
|
| ------ | ----------------------------- |
|
||||||
|
| jjc | `jj commit` |
|
||||||
|
| jjcmsg | `jj commit --message` |
|
||||||
|
| jjd | `jj diff` |
|
||||||
|
| jjdmsg | `jj desc --message` |
|
||||||
|
| jjds | `jj desc` |
|
||||||
|
| jje | `jj edit` |
|
||||||
|
| jjgcl | `jj git clone` |
|
||||||
|
| jjgf | `jj git fetch` |
|
||||||
|
| jjgp | `jj git push` |
|
||||||
|
| jjl | `jj log` |
|
||||||
|
| jjla | `jj log -r "all()"` |
|
||||||
|
| jjn | `jj new` |
|
||||||
|
| jjrb | `jj rebase` |
|
||||||
|
| jjrs | `jj restore` |
|
||||||
|
| jjrt | `cd "$(jj root \|\| echo .)"` |
|
||||||
|
| jjsp | `jj split` |
|
||||||
|
| jjsq | `jj squash` |
|
||||||
|
|
||||||
|
## Prompt usage
|
||||||
|
|
||||||
|
Because `jj` has a very powerful [template syntax](https://martinvonz.github.io/jj/latest/templates/), this
|
||||||
|
plugin only exposes a convenience function `jj_prompt_template` to read information from the current change.
|
||||||
|
It is basically the same as `jj log --no-graph -r @ -T $1`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
_my_theme_jj_info() {
|
||||||
|
jj_prompt_template 'self.change_id().shortest(3)'
|
||||||
|
}
|
||||||
|
|
||||||
|
PROMPT='$(_my_theme_jj_info) $'
|
||||||
|
```
|
||||||
|
|
||||||
|
`jj_prompt_template` escapes `%` signs in the output. Use `jj_prompt_template_raw` if you don't want that
|
||||||
|
(e.g. to colorize the output).
|
||||||
|
|
||||||
|
However, because `jj` can be used inside a Git repository, some themes might clash with it. Generally, you can
|
||||||
|
fix it with a wrapper function that tries `jj` first and then falls back to `git` if it didn't work:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
_my_theme_vcs_info() {
|
||||||
|
jj_prompt_template 'self.change_id().shortest(3)' \
|
||||||
|
|| git_prompt_info
|
||||||
|
}
|
||||||
|
|
||||||
|
PROMPT='$(_my_theme_vcs_info) $'
|
||||||
|
```
|
||||||
|
|
||||||
|
You can find an example
|
||||||
|
[here](https://github.com/nasso/omzsh/blob/e439e494f22f4fd4ef1b6cb64626255f4b341c1b/themes/sunakayu.zsh-theme).
|
||||||
|
|
||||||
|
### Performance
|
||||||
|
|
||||||
|
Sometimes `jj` can be slower than `git`.
|
||||||
|
|
||||||
|
If you feel slowdowns, consider using the following:
|
||||||
|
|
||||||
|
```
|
||||||
|
zstyle :omz:plugins:jj ignore-working-copy yes
|
||||||
|
```
|
||||||
|
|
||||||
|
This will add `--ignore-working-copy` to all `jj` commands executed by your prompt. The downside here is that
|
||||||
|
your prompt might be out-of-sync until the next time `jj` gets a chance to _not_ ignore the working copy (i.e.
|
||||||
|
you manually run a `jj` command).
|
||||||
|
|
||||||
|
If you prefer to keep your prompt always up-to-date but still don't want to _feel_ the slowdown, you can make
|
||||||
|
your prompt asynchronous. This plugin doesn't do this automatically so you'd have to hack your theme a bit for
|
||||||
|
that.
|
||||||
|
|
||||||
|
## See Also
|
||||||
|
|
||||||
|
- [martinvonz/jj](https://github.com/martinvonz/jj)
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
- [nasso](https://github.com/nasso) - Plugin Author
|
|
@ -0,0 +1,53 @@
|
||||||
|
# if jj is not found, don't do the rest of the script
|
||||||
|
if (( ! $+commands[jj] )); then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If the completion file doesn't exist yet, we need to autoload it and
|
||||||
|
# bind it to `jj`. Otherwise, compinit will have already done that.
|
||||||
|
if [[ ! -f "$ZSH_CACHE_DIR/completions/_jj" ]]; then
|
||||||
|
typeset -g -A _comps
|
||||||
|
autoload -Uz _jj
|
||||||
|
_comps[jj]=_jj
|
||||||
|
fi
|
||||||
|
|
||||||
|
jj util completion zsh >| "$ZSH_CACHE_DIR/completions/_jj" &|
|
||||||
|
|
||||||
|
function __jj_prompt_jj() {
|
||||||
|
local -a flags
|
||||||
|
flags=("--no-pager")
|
||||||
|
if zstyle -t ':omz:plugins:jj' ignore-working-copy; then
|
||||||
|
flags+=("--ignore-working-copy")
|
||||||
|
fi
|
||||||
|
command jj $flags "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
# convenience functions for themes
|
||||||
|
function jj_prompt_template_raw() {
|
||||||
|
__jj_prompt_jj log --no-graph -r @ -T "$@" 2> /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
function jj_prompt_template() {
|
||||||
|
local out
|
||||||
|
out=$(jj_prompt_template_raw "$@") || return 1
|
||||||
|
echo "${out:gs/%/%%}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Aliases (sorted alphabetically)
|
||||||
|
alias jjc='jj commit'
|
||||||
|
alias jjcmsg='jj commit --message'
|
||||||
|
alias jjd='jj diff'
|
||||||
|
alias jjdmsg='jj desc --message'
|
||||||
|
alias jjds='jj desc'
|
||||||
|
alias jje='jj edit'
|
||||||
|
alias jjgcl='jj git clone'
|
||||||
|
alias jjgf='jj git fetch'
|
||||||
|
alias jjgp='jj git push'
|
||||||
|
alias jjl='jj log'
|
||||||
|
alias jjla='jj log -r "all()"'
|
||||||
|
alias jjn='jj new'
|
||||||
|
alias jjrb='jj rebase'
|
||||||
|
alias jjrs='jj restore'
|
||||||
|
alias jjrt='cd "$(jj root || echo .)"'
|
||||||
|
alias jjsp='jj split'
|
||||||
|
alias jjsq='jj squash'
|
Loading…
Reference in New Issue