Unverified Commit 18ee5dff authored by Marc Cornellà's avatar Marc Cornellà Committed by GitHub
Browse files

Merge branch 'master' into clipboard

parents d81cd753 368198b7
# Common Aliases Plugin
This plugin creates helpful shortcut aliases for many commonly used commands.
To use it add `common-aliases` to the plugins array in your zshrc file:
```zsh
plugins=(... common-aliases)
```
## Aliases
### ls command
| Alias | Command | Description |
|-------|---------------|--------------------------------------------------------------------------------|
| l | `ls -lFh` | List files as a long list, show size, type, human-readable |
| la | `ls -lAFh` | List almost all files as a long list show size, type, human-readable |
| lr | `ls -tRFh` | List files recursively sorted by date, show type, human-readable |
| lt | `ls -ltFh` | List files as a long list sorted by date, show type, human-readable |
| ll | `ls -l` | List files as a long list |
| ldot | `ls -ld .*` | List dot files as a long list |
| lS | `ls -1FSsh` | List files showing only size and name sorted by size |
| lart | `ls -1Fcart` | List all files sorted in reverse of create/modification time (oldest first) |
| lrt | `ls -1Fcrt` | List files sorted in reverse of create/modification time(oldest first) |
### File handling
| Alias | Command | Description |
|-------|-----------------------|------------------------------------------------------------------------------------|
| rm | `rm -i` | Remove a file |
| cp | `cp -i` | Copy a file |
| mv | `mv -i` | Move a file |
| zshrc | `${=EDITOR} ~/.zshrc` | Quickly access the ~/.zshrc file |
| dud | `du -d 1 -h` | Display the size of files at depth 1 in current location in human-readable form |
| duf | `du -sh` | Display the size of files in current location in human-readable form |
| t | `tail -f` | Shorthand for tail which outputs the last part of a file |
### find and grep
| Alias | Command | Description |
|-------|-----------------------------------------------------|-----------------------------------------|
| fd | `find . -type d -name` | Find a directory with the given name |
| ff | `find . -type f -name` | Find a file with the given name |
| grep | `grep --color` | Searches for a query string |
| sgrep | `grep -R -n -H -C 5 --exclude-dir={.git,.svn,CVS}` | Useful for searching within files |
### Other Aliases
| Alias | Command | Description |
|-----------|---------------------|-------------------------------------------------------------|
| h | `history` | Lists all recently used commands |
| hgrep | `fc -El 0 \| grep` | Searches for a word in the list of previously used commands |
| help | `man` | Opens up the man page for a command |
| p | `ps -f` | Displays currently executing processes |
| sortnr | `sort -n -r` | Used to sort the lines of a text file |
| unexport | `unset` | Used to unset an environment variable |
## Global aliases
These aliases are expanded in any position in the command line, meaning you can use them even at the
end of the command you've typed. Examples:
Quickly pipe to less:
```zsh
$ ls -l /var/log L
# will run
$ ls -l /var/log | less
```
Silences stderr output:
```zsh
$ find . -type f NE
# will run
$ find . -type f 2>/dev/null
```
| Alias | Command | Description |
|-------|-----------------------------|-------------------------------------------------------------|
| H | `\| head` | Pipes output to head which outputs the first part of a file |
| T | `\| tail` | Pipes output to tail which outputs the last part of a file |
| G | `\| grep` | Pipes output to grep to search for some word |
| L | `\| less` | Pipes output to less, useful for paging |
| M | `\| most` | Pipes output to more, useful for paging |
| LL | `2>&1 \| less` | Writes stderr to stdout and passes it to less |
| CA | `2>&1 \| cat -A` | Writes stderr to stdout and passes it to cat |
| NE | `2 > /dev/null` | Silences stderr |
| NUL | `> /dev/null 2>&1` | Silences both stdout and stderr |
| P | `2>&1\| pygmentize -l pytb` | Writes stderr to stdout and passes it to pygmentize |
## File extension aliases
These are special aliases that are triggered when a file name is passed as the command. For example,
if the pdf file extension is aliased to `acroread` (a popular Linux pdf reader), when running `file.pdf`
that file will be open with `acroread`.
### Reading Docs
| Alias | Command | Description |
|-------|-------------|-------------------------------------|
| pdf | `acroread` | Opens up a document using acroread |
| ps | `gv` | Opens up a .ps file using gv |
| dvi | `xdvi` | Opens up a .dvi file using xdvi |
| chm | `xchm` | Opens up a .chm file using xchm |
| djvu | `djview` | Opens up a .djvu file using djview |
### Listing files inside a packed file
| Alias | Command | Description |
|---------|-------------|-------------------------------------|
| zip | `unzip -l` | Lists files inside a .zip file |
| rar | `unrar l` | Lists files inside a .rar file |
| tar | `tar tf` | Lists files inside a .tar file |
| tar.gz | `echo` | Lists files inside a .tar.gz file |
| ace | `unace l` | Lists files inside a .ace file |
### Some other features
- Opens urls in terminal using browser specified by the variable `$BROWSER`
- Opens C, C++, Tex and text files using editor specified by the variable `$EDITOR`
- Opens images using image viewer specified by the variable `$XIVIEWER`
- Opens videos and other media using mplayer
......@@ -50,6 +50,7 @@ alias mv='mv -i'
# zsh is able to auto-do some kungfoo
# depends on the SUFFIX :)
autoload -Uz is-at-least
if is-at-least 4.2.0; then
# open browser on urls
if [[ -n "$BROWSER" ]]; then
......
# compleat plugin
This plugin looks for [compleat](https://github.com/mbrubeck/compleat) and loads its completion.
To use it, add compleat to the plugins array in your zshrc file:
```
plugins=(... compleat)
```
# copy the active line from the command line buffer
# onto the system clipboard (requires clipcopy plugin)
# onto the system clipboard
copybuffer () {
if which clipcopy &>/dev/null; then
echo $BUFFER | clipcopy
printf "%s" "$BUFFER" | clipcopy
else
echo "clipcopy function not found. Please make sure you have Oh My Zsh installed correctly."
fi
......
# Dash plugin
This plugin adds command line functionality for [Dash](https://kapeli.com/dash),
an API Documentation Browser for macOS. This plugin requires Dash to be installed
to work.
To use it, add `dash` to the plugins array in your zshrc file:
```zsh
plugins=(... dash)
```
## Usage
- Open and switch to the dash application.
```
dash
```
- Query for something in dash app: `dash query`
```
dash golang
```
- You can optionally provide a keyword: `dash [keyword:]query`
```
dash python:tuple
```
......@@ -35,36 +35,30 @@ _dash() {
if [[ "$locator" == "platform" ]]; then
# Since these are the only special cases right now, let's not do the
# expensive processing unless we have to
if [[ "$keyword" == "python" || "$keyword" == "java" || \
"$keyword" == "qt" || "$keyword" == "cocs2d" ]]; then
if [[ "$keyword" = (python|java|qt|cocos2d) ]]; then
docsetName=`echo $doc | grep -Eo "docsetName = .*?;" | sed -e "s/docsetName = \(.*\);/\1/" -e "s/[\":]//g"`
if [[ "$keyword" == "python" ]]; then
if [[ "$docsetName" == "Python 2" ]]; then
keyword="python2"
elif [[ "$docsetName" == "Python 3" ]]; then
keyword="python3"
fi
elif [[ "$keyword" == "java" ]]; then
if [[ "$docsetName" == "Java SE7" ]]; then
keyword="java7"
elif [[ "$docsetName" == "Java SE6" ]]; then
keyword="java6"
elif [[ "$docsetName" == "Java SE8" ]]; then
keyword="java8"
fi
elif [[ "$keyword" == "qt" ]]; then
if [[ "$docsetName" == "Qt 5" ]]; then
keyword="qt5"
elif [[ "$docsetName" == "Qt 4" ]]; then
keyword="qt4"
elif [[ "$docsetName" == "Qt" ]]; then
keyword="qt4"
fi
elif [[ "$keyword" == "cocos2d" ]]; then
if [[ "$docsetName" == "Cocos3D" ]]; then
keyword="cocos3d"
fi
fi
case "$keyword" in
python)
case "$docsetName" in
"Python 2") keyword="python2" ;;
"Python 3") keyword="python3" ;;
esac ;;
java)
case "$docsetName" in
"Java SE7") keyword="java7" ;;
"Java SE6") keyword="java6" ;;
"Java SE8") keyword="java8" ;;
esac ;;
qt)
case "$docsetName" in
"Qt 5") keyword="qt5" ;;
"Qt 4"|Qt) keyword="qt4" ;;
esac ;;
cocos2d)
case "$docsetName" in
Cocos3D) keyword="cocos3d" ;;
esac ;;
esac
fi
fi
......
......@@ -72,7 +72,7 @@ if [[ $use_sudo -eq 1 ]]; then
# commands using su #########
else
alias aac="su -ls '$apt_pref autoclean' root"
abd() {
function abd() {
cmd="su -lc '$apt_pref build-dep $@' root"
print "$cmd"
eval "$cmd"
......@@ -83,17 +83,17 @@ else
alias adu="su -lc '$apt_pref update && aptitude dist-upgrade' root"
alias afu="su -lc '$apt-file update'"
alias au="su -lc '$apt_pref $apt_upgr' root"
ai() {
function ai() {
cmd="su -lc 'aptitude -P install $@' root"
print "$cmd"
eval "$cmd"
}
ap() {
function ap() {
cmd="su -lc '$apt_pref -P purge $@' root"
print "$cmd"
eval "$cmd"
}
ar() {
function ar() {
cmd="su -lc '$apt_pref -P remove $@' root"
print "$cmd"
eval "$cmd"
......@@ -114,7 +114,7 @@ fi
# Registers a compdef for $1 that calls $apt_pref with the commands $2
# To do that it creates a new completion function called _apt_pref_$2
#
apt_pref_compdef() {
function apt_pref_compdef() {
local f fb
f="_apt_pref_${2}"
......@@ -151,7 +151,7 @@ alias mydeb='time dpkg-buildpackage -rfakeroot -us -uc'
# Functions #################################################################
# create a simple script that can be used to 'duplicate' a system
apt-copy() {
function apt-copy() {
print '#!/bin/sh'"\n" > apt-copy.sh
cmd='$apt_pref install'
......@@ -173,7 +173,7 @@ apt-copy() {
# apt-history rollback
# apt-history list
# Based On: https://linuxcommando.blogspot.com/2008/08/how-to-show-apt-log-history.html
apt-history () {
function apt-history() {
case "$1" in
install)
zgrep --no-filename 'install ' $(ls -rt /var/log/dpkg*)
......@@ -202,7 +202,7 @@ apt-history () {
}
# Kernel-package building shortcut
kerndeb () {
function kerndeb() {
# temporarily unset MAKEFLAGS ( '-j3' will fail )
MAKEFLAGS=$( print - $MAKEFLAGS | perl -pe 's/-j\s*[\d]+//g' )
print '$MAKEFLAGS set to '"'$MAKEFLAGS'"
......@@ -216,10 +216,9 @@ kerndeb () {
}
# List packages by size
function apt-list-packages {
function apt-list-packages() {
dpkg-query -W --showformat='${Installed-Size} ${Package} ${Status}\n' | \
grep -v deinstall | \
sort -n | \
awk '{print $1" "$2}'
}
......@@ -15,10 +15,10 @@ This plugin enables directory navigation similar to using back and forward on br
)
```
2. Reload the source file or restart your Terminal session:
2. Restart the shell or restart your Terminal session:
```console
$ source ~/.zshrc
$ exec zsh
$
```
......
......@@ -53,7 +53,8 @@ function push_future() {
}
# Called by zsh when directory changes
chpwd_functions+=(chpwd_dirhistory)
autoload -U add-zsh-hook
add-zsh-hook chpwd chpwd_dirhistory
function chpwd_dirhistory() {
push_past $PWD
# If DIRHISTORY_CD is not set...
......
......@@ -11,7 +11,8 @@ if [[ -f ${dirstack_file} ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then
[[ -d $dirstack[1] ]] && cd $dirstack[1] && cd $OLDPWD
fi
chpwd_functions+=(chpwd_dirpersist)
autoload -U add-zsh-hook
add-zsh-hook chpwd chpwd_dirpersist
chpwd_dirpersist() {
if (( $DIRSTACKSIZE <= 0 )) || [[ -z $dirstack_file ]]; then return; fi
local -ax my_stack
......
......@@ -374,7 +374,8 @@ _managepy-commands() {
_applist() {
local line
local -a apps
_call_program help-command "python -c \"import os.path as op, re, django.conf, sys;\\
_call_program help-command "python -c \"import sys; del sys.path[0];\\
import os.path as op, re, django.conf;\\
bn=op.basename(op.abspath(op.curdir));[sys\\
.stdout.write(str(re.sub(r'^%s\.(.*?)$' %
bn, r'\1', i)) + '\n') for i in django.conf.settings.\\
......
## Docker autocomplete plugin
# Docker plugin
A copy of the completion script from the
[docker/cli](https://github.com/docker/cli/blob/master/contrib/completion/zsh/_docker)
git repo.
This plugin adds auto-completion for [docker](https://www.docker.com/).
To use it add `docker` to the plugins array in your zshrc file.
```zsh
plugins=(... docker)
```
A copy of the completion script from the docker/cli git repo:
https://github.com/docker/cli/blob/master/contrib/completion/zsh/_docker
......@@ -32,6 +32,8 @@ PORT=3001
```
You can even mix both formats, although it's probably a bad idea.
## Plugin options
### ZSH_DOTENV_FILE
You can also modify the name of the file to be loaded with the variable `ZSH_DOTENV_FILE`.
......@@ -43,6 +45,10 @@ For example, this will make the plugin look for files named `.dotenv` and load t
ZSH_DOTENV_FILE=.dotenv
```
### ZSH_DOTENV_PROMPT
Set `ZSH_DOTENV_PROMPT=false` in your zshrc file if you don't want the confirmation message.
## Version Control
**It's strongly recommended to add `.env` file to `.gitignore`**, because usually it contains sensitive information such as your credentials, secret keys, passwords etc. You don't want to commit this file, it's supposed to be local only.
......
source_env() {
if [[ -f $ZSH_DOTENV_FILE ]]; then
if [ "$ZSH_DOTENV_PROMPT" != "false" ]; then
# confirm before sourcing file
local confirmation
# print same-line prompt and output newline character if necessary
echo -n "dotenv: source '$ZSH_DOTENV_FILE' file in the directory? (Y/n) "
read -k 1 confirmation; [[ "$confirmation" != $'\n' ]] && echo
# only bail out if confirmation character is n
if [[ "$confirmation" = [nN] ]]; then
return
fi
fi
# test .env syntax
zsh -fn $ZSH_DOTENV_FILE || echo "dotenv: error when sourcing '$ZSH_DOTENV_FILE' file" >&2
......
# .NET Core CLI plugin
This plugin provides completion and useful aliases for [.NET Core CLI](https://dotnet.microsoft.com/).
To use it, add `dotnet` to the plugins array in your zshrc file.
```
plugins=(... dotnet)
```
## Aliases
| Alias | Command | Description |
|-------|------------------|-------------------------------------------------------------------|
| dn | dotnet new | Create a new .NET project or file. |
| dr | dotnet run | Build and run a .NET project output. |
| dt | dotnet test | Run unit tests using the test runner specified in a .NET project. |
| dw | dotnet watch | Watch for source file changes and restart the dotnet command. |
| dwr | dotnet watch run | Watch for source file changes and restart the `run` command. |
| ds | dotnet sln | Modify Visual Studio solution files. |
| da | dotnet add | Add a package or reference to a .NET project. |
| dp | dotnet pack | Create a NuGet package. |
| dng | dotnet nuget | Provides additional NuGet commands. |
# This scripts is copied from (MIT License):
# https://github.com/dotnet/toolset/blob/master/scripts/register-completions.zsh
_dotnet_zsh_complete()
{
local completions=("$(dotnet complete "$words")")
# If the completion list is empty, just continue with filename selection
if [ -z "$completions" ]
then
_arguments '*::arguments: _normal'
return
fi
# This is not a variable assigment, don't remove spaces!
_values = "${(ps:\n:)completions}"
}
compdef _dotnet_zsh_complete dotnet
# Aliases bellow are here for backwards compatibility
# added by Shaun Tabone (https://github.com/xontab)
alias dn='dotnet new'
alias dr='dotnet run'
alias dt='dotnet test'
alias dw='dotnet watch'
alias dwr='dotnet watch run'
alias ds='dotnet sln'
alias da='dotnet add'
alias dp='dotnet pack'
alias dng='dotnet nuget'
# eecms plugin
This plugin adds auto-completion of console commands for [`eecms`](https://github.com/ExpressionEngine/ExpressionEngine).
To use it, add `eecms` to the plugins array of your `.zshrc` file:
```
plugins=(... eecms)
```
It also adds the alias `eecms` which finds the eecms file in the current project
and runs it with php.
......@@ -20,7 +20,8 @@ _emacsfun()
# tempfile. (first argument will be `--no-wait` passed in by the plugin.zsh)
if [ "$#" -ge "2" -a "$2" = "-" ]
then
tempfile="$(mktemp emacs-stdin-$USER.XXXXXXX --tmpdir)"
tempfile="$(mktemp --tmpdir emacs-stdin-$USER.XXXXXXX 2>/dev/null \
|| mktemp -t emacs-stdin-$USER)" # support BSD mktemp
cat - > "$tempfile"
_emacsfun --no-wait $tempfile
else
......
......@@ -2,7 +2,7 @@
# FILE: emoji-clock.plugin.zsh
# DESCRIPTION: The current time with half hour accuracy as an emoji symbol.
# Inspired by Andre Torrez' "Put A Burger In Your Shell"
# http://notes.torrez.org/2013/04/put-a-burger-in-your-shell.html
# https://notes.torrez.org/2013/04/put-a-burger-in-your-shell.html
# AUTHOR: Alexis Hildebrandt (afh[at]surryhill.net)
# VERSION: 1.0.0
# -----------------------------------------------------------------------------
......
# emotty plugin
This plugin returns an emoji for the current $TTY number so it can be used
in a prompt.
To use it, add emotty to the plugins array in your zshrc file:
```
plugins=(... emotty)
```
**NOTE:** it requires the [emoji plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/emoji).
## Usage
The function `emotty` displays an emoji from the current character set (default: `emoji`), based
on the number associated to the `$TTY`.
There are different sets of emoji characters available, to choose a different
set, set `$emotty_set` to the name of the set you would like to use, e.g.:
```
emotty_set=nature
```
### Character Sets
- emoji
- loral
- love
- nature
- stellar
- zodiac
Use the `display_emotty` function to list the emojis in the current character set, or
the character set passed as the first argument. For example:
```
$ display_emotty zodiac
<list of all the emojis in the zodiac character set>
```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment