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

Merge branch 'master' into fabric_task_description

parents 225425fe 40df67bc
# command-not-found plugin
This plugin uses the command-not-found package for zsh to provide suggested packages to be installed if a command cannot be found.
To use it, add `command-not-found` to the plugins array of your zshrc file:
```zsh
plugins=(... command-not-found)
```
An example of how this plugin works in Ubuntu:
```
$ mutt
The program 'mutt' can be found in the following packages:
* mutt
* mutt-kz
* mutt-patched
Try: sudo apt install <selected package>
```
### Supported platforms
It works out of the box with the command-not-found packages for:
- [Ubuntu](https://www.porcheron.info/command-not-found-for-zsh/)
- [Debian](https://packages.debian.org/search?keywords=command-not-found)
- [Arch Linux](https://wiki.archlinux.org/index.php/Pkgfile#Command_not_found)
- [macOS (Homebrew)](https://github.com/Homebrew/homebrew-command-not-found)
- [Fedora](https://fedoraproject.org/wiki/Features/PackageKitCommandNotFound)
- [NixOS](https://github.com/NixOS/nixpkgs/tree/master/nixos/modules/programs/command-not-found)
You can add support for other platforms by submitting a Pull Request.
# Uses the command-not-found package zsh support
# as seen in http://www.porcheron.info/command-not-found-for-zsh/
# as seen in https://www.porcheron.info/command-not-found-for-zsh/
# this is installed in Ubuntu
[[ -e /etc/zsh_command_not_found ]] && source /etc/zsh_command_not_found
......@@ -31,3 +31,10 @@ if type brew &> /dev/null; then
eval "$(brew command-not-found-init)";
fi
fi
# NixOS command-not-found support
if [ -x /run/current-system/sw/bin/command-not-found ]; then
command_not_found_handler () {
/run/current-system/sw/bin/command-not-found $@
}
fi
# 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
......@@ -13,7 +13,7 @@ alias lS='ls -1FSsh'
alias lart='ls -1Fcart'
alias lrt='ls -1Fcrt'
alias zshrc='$EDITOR ~/.zshrc' # Quick access to the ~/.zshrc file
alias zshrc='${=EDITOR} ~/.zshrc' # Quick access to the ~/.zshrc file
alias grep='grep --color'
alias sgrep='grep -R -n -H -C 5 --exclude-dir={.git,.svn,CVS} '
......@@ -44,8 +44,6 @@ alias p='ps -f'
alias sortnr='sort -n -r'
alias unexport='unset'
alias whereami=display_info
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
......@@ -54,17 +52,21 @@ alias mv='mv -i'
# depends on the SUFFIX :)
if is-at-least 4.2.0; then
# open browser on urls
_browser_fts=(htm html de org net com at cx nl se dk dk php)
for ft in $_browser_fts ; do alias -s $ft=$BROWSER ; done
if [[ -n "$BROWSER" ]]; then
_browser_fts=(htm html de org net com at cx nl se dk)
for ft in $_browser_fts; do alias -s $ft=$BROWSER; done
fi
_editor_fts=(cpp cxx cc c hh h inl asc txt TXT tex)
for ft in $_editor_fts ; do alias -s $ft=$EDITOR ; done
for ft in $_editor_fts; do alias -s $ft=$EDITOR; done
if [[ -n "$XIVIEWER" ]]; then
_image_fts=(jpg jpeg png gif mng tiff tif xpm)
for ft in $_image_fts ; do alias -s $ft=$XIVIEWER; done
for ft in $_image_fts; do alias -s $ft=$XIVIEWER; done
fi
_media_fts=(ape avi flv mkv mov mp3 mpeg mpg ogg ogm rm wav webm)
for ft in $_media_fts ; do alias -s $ft=mplayer ; done
_media_fts=(ape avi flv m4a mkv mov mp3 mpeg mpg ogg ogm rm wav webm)
for ft in $_media_fts; do alias -s $ft=mplayer; done
#read documents
alias -s pdf=acroread
......@@ -83,4 +85,3 @@ fi
# Make zsh know about hosts already accessed by SSH
zstyle -e ':completion:*:(ssh|scp|sftp|rsh|rsync):hosts' hosts 'reply=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null)"}%%[# ]*}//,/ })'
# 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)
```
# composer
This plugin provides completion for [composer](https://getcomposer.org/), as well as aliases
for frequent composer commands. It also adds Composer's global binaries to the PATH, using
Composer if available.
To use it add `composer` to the plugins array in your zshrc file.
```zsh
plugins=(... composer)
```
## Aliases
| Alias | Command | Description |
| ------ | -------------------------------------------- | -------------------------------------------------------------------------------------- |
| `c` | composer | Starts composer |
| `csu` | composer self-update | Updates composer to the latest version |
| `cu` | composer update | Updates composer dependencies and `composer.lock` file |
| `cr` | composer require | Adds new packages to `composer.json` |
| `crm` | composer remove | Removes packages from `composer.json` |
| `ci` | composer install | Resolves and installs dependencies from `composer.json` |
| `ccp` | composer create-project | Create new project from an existing package |
| `cdu` | composer dump-autoload | Updates the autoloader |
| `cdo` | composer dump-autoload --optimize-autoloader | Converts PSR-0/4 autoloading to classmap for a faster autoloader (good for production) |
| `cgu` | composer global update | Allows update command to run on COMPOSER_HOME directory |
| `cgr` | composer global require | Allows require command to run on COMPOSER_HOME directory |
| `cgrm` | composer global remove | Allows remove command to run on COMPOSER_HOME directory |
| `cget` | `curl -s https://getcomposer.org/installer` | Installs composer in the current directory |
......@@ -39,14 +39,22 @@ alias c='composer'
alias csu='composer self-update'
alias cu='composer update'
alias cr='composer require'
alias crm='composer remove'
alias ci='composer install'
alias ccp='composer create-project'
alias cdu='composer dump-autoload'
alias cdo='composer dump-autoload --optimize-autoloader'
alias cgu='composer global update'
alias cgr='composer global require'
alias cgrm='composer global remove'
# install composer in the current directory
alias cget='curl -s https://getcomposer.org/installer | php'
# Add Composer's global binaries to PATH
export PATH=$PATH:~/.composer/vendor/bin
# Add Composer's global binaries to PATH, using Composer if available.
if (( $+commands[composer] )); then
export PATH=$PATH:$(composer global config bin-dir --absolute 2>/dev/null)
else
[ -d $HOME/.composer/vendor/bin ] && export PATH=$PATH:$HOME/.composer/vendor/bin
[ -d $HOME/.config/composer/vendor/bin ] && export PATH=$PATH:$HOME/.config/composer/vendor/bin
fi
# copydir plugin
Copies the path of your current folder to the system clipboard.
To use, add `copydir` to your plugins array:
```
plugins=(... copydir)
```
Then use the command `copydir` to copy the $PWD.
# copyfile plugin
Puts the contents of a file in your system clipboard so you can paste it anywhere.
To use, add `copyfile` to your plugins array:
```
plugins=(... copyfile)
```
Then you can run the command `copyfile <filename>` to copy the file named `filename`.
# cp plugin
This plugin defines a `cpv` function that uses `rsync` so that you
get the features and security of this command.
To enable, add `cp` to your `plugins` array in your zshrc file:
```zsh
plugins=(... cp)
```
## Description
The enabled options for rsync are:
- `-p`: preserves permissions.
- `-o`: preserves owner.
* `-g`: preserves group.
* `-b`: make a backup of the original file instead of overwriting it, if it exists.
* `-r`: recurse directories.
* `-hhh`: outputs numbers in human-readable format, in units of 1024 (K, M, G, T).
* `--backup-dir=/tmp/rsync`: move backup copies to "/tmp/rsync".
* `-e /dev/null`: only work on local files (disable remote shells).
* `--progress`: display progress.
#Show progress while file is copying
# Rsync options are:
# -p - preserve permissions
# -o - preserve owner
# -g - preserve group
# -h - output in human-readable format
# --progress - display progress
# -b - instead of just overwriting an existing file, save the original
# --backup-dir=/tmp/rsync - move backup copies to "/tmp/rsync"
# -e /dev/null - only work on local files
# -- - everything after this is an argument, even if it looks like an option
alias cpv="rsync -poghb --backup-dir=/tmp/rsync -e /dev/null --progress --"
cpv() {
rsync -pogbr -hhh --backup-dir=/tmp/rsync -e /dev/null --progress "$@"
}
compdef _files cpv
# Cpanm
This plugin provides completion for [Cpanm](https://github.com/miyagawa/cpanminus) ([docs](https://metacpan.org/pod/App::cpanminus)).
To use it add cpanm to the plugins array in your zshrc file.
```bash
plugins=(... cpanm)
```
......@@ -6,9 +6,6 @@
#
# Current supported cpanm version: 1.4000 (Tue Mar 8 01:00:49 PST 2011)
#
# The latest code is always located at:
# https://github.com/rshhh/cpanminus/blob/master/etc/_cpanm
#
local arguments curcontext="$curcontext"
typeset -A opt_args
......
# 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
```
# Usage: dash [keyword:]query
dash() { open dash://"$*" }
compdef _dash dash
_dash() {
# No sense doing this for anything except the 2nd position and if we haven't
# specified which docset to query against
if [[ $CURRENT -eq 2 && ! "$words[2]" =~ ":" ]]; then
local -a _all_docsets
_all_docsets=()
# Use defaults to get the array of docsets from preferences
# Have to smash it into one big line so that each docset is an element of
# our DOCSETS array
DOCSETS=("${(@f)$(defaults read com.kapeli.dashdoc docsets | tr -d '\n' | grep -oE '\{.*?\}')}")
# remove all newlines since defaults prints so pretty like
# Now get each docset and output each on their own line
for doc in "$DOCSETS[@]"; do
# Only output docsets that are actually enabled
if [[ "`echo $doc | grep -Eo \"isEnabled = .*?;\" | sed 's/[^01]//g'`" == "0" ]]; then
continue
fi
keyword=''
# Order of preference as explained to me by @kapeli via email
KEYWORD_LOCATORS=(keyword suggestedKeyword platform)
for locator in "$KEYWORD_LOCATORS[@]"; do
# Echo the docset, try to find the appropriate keyword
# Strip doublequotes and colon from any keyword so that everything has the
# same format when output (we'll add the colon in the completion)
keyword=`echo $doc | grep -Eo "$locator = .*?;" | sed -e "s/$locator = \(.*\);/\1/" -e "s/[\":]//g"`
if [[ ! -z "$keyword" ]]; then
# if we fall back to platform, we should do some checking per @kapeli
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|java|qt|cocos2d) ]]; then
docsetName=`echo $doc | grep -Eo "docsetName = .*?;" | sed -e "s/docsetName = \(.*\);/\1/" -e "s/[\":]//g"`
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
# Bail once we have a match
break
fi
done
# If we have a keyword, add it to the list!
if [[ ! -z "$keyword" ]]; then
_all_docsets+=($keyword)
fi
done
# special thanks to [arx] on #zsh for getting me sorted on this piece
compadd -qS: -- "$_all_docsets[@]"
return
fi
}
# debian
This plugin provides Debian-related aliases and functions for zsh.
To use it add `debian` to the plugins array in your zshrc file.
```zsh
plugins=(... debian)
```
## Settings
- `$apt_pref`: use apt or aptitude if installed, fallback is apt-get.
- `$apt_upgr`: use upgrade or safe-upgrade (for aptitude).
Set `$apt_pref` and `$apt_upgr` to whatever command you want (before sourcing Oh My Zsh) to override this behavior.
## Common Aliases
| Alias | Command | Description |
| ------ | ---------------------------------------------------------------------- | ---------------------------------------------------------- |
| `age` | `apt-get` | Command line tool for handling packages |
| `api` | `aptitude` | Same functionality as `apt-get`, provides extra options |
| `acs` | `apt-cache search` | Command line tool for searching apt software package cache |
| `aps` | `aptitude search` | Searches installed packages using aptitude |
| `as` | `aptitude -F '* %p -> %d \n(%v/%V)' --no-gui --disable-columns search` | Print searched packages using a custom format |
| `afs` | `apt-file search --regexp` | Search file in packages |
| `asrc` | `apt-get source` | Fetch source packages through `apt-get` |
| `app` | `apt-cache policy` | Displays priority of package sources |
## Superuser Operations Aliases
| Alias | Command | Description |
| -------- | -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| `aac` | `sudo $apt_pref autoclean` | Clears out the local repository of retrieved package files |
| `abd` | `sudo $apt_pref build-dep` | Installs all dependencies for building packages |
| `ac` | `sudo $apt_pref clean` | Clears out the local repository of retrieved package files except lock files |
| `ad` | `sudo $apt_pref update` | Updates the package lists for upgrades for packages |
| `adg` | `sudo $apt_pref update && sudo $apt_pref $apt_upgr` | Update and upgrade packages |
| `adu` | `sudo $apt_pref update && sudo $apt_pref dist-upgrade` | Smart upgrade that handles dependencies |
| `afu` | `sudo apt-file update` | Update the files in packages |
| `au` | `sudo $apt_pref $apt_upgr` | Install package upgrades |
| `ai` | `sudo $apt_pref install` | Command-line tool to install package |
| `ail` | `sed -e 's/ */ /g' -e 's/ *//' \| cut -s -d ' ' -f 1 \| xargs sudo $apt_pref install` | Install all packages given on the command line while using only the first word of each line |
| `ap` | `sudo $apt_pref purge` | Removes packages along with configuration files |
| `ar` | `sudo $apt_pref remove` | Removes packages, keeps the configuration files |
| `ads` | `sudo apt-get dselect-upgrade` | Installs packages from list and removes all not in the list |
| `dia` | `sudo dpkg -i ./*.deb` | Install all .deb files in the current directory |
| `di` | `sudo dpkg -i` | Install all .deb files in the current directory |
| `kclean` | `sudo aptitude remove -P ?and(~i~nlinux-(ima\|hea) ?not(~n$(uname -r)))` | Remove ALL kernel images and headers EXCEPT the one in use |
## Aliases - Commands using `su`
| Alias | Command |
| ----- | --------------------------------------------------------- |
| `aac` | `su -ls "$apt_pref autoclean" root` |
| `ac` | `su -ls "$apt_pref clean" root` |
| `ad` | `su -lc "$apt_pref update" root` |
| `adg` | `su -lc "$apt_pref update && aptitude $apt_upgr" root` |
| `adu` | `su -lc "$apt_pref update && aptitude dist-upgrade" root` |
| `afu` | `su -lc "apt-file update"` |
| `au` | `su -lc "$apt_pref $apt_upgr" root` |
| `dia` | `su -lc "dpkg -i ./*.deb" root` |
## Miscellaneous Aliases
| Alias | Command | Description |
| --------- | ---------------------------------------------- | ------------------------------ |
| `allpkgs` | `aptitude search -F "%p" --disable-columns ~i` | Display all installed packages |
| `mydeb` | `time dpkg-buildpackage -rfakeroot -us -uc` | Create a basic .deb package |
## Functions
| Function | Description |
| ------------------- | --------------------------------------------------------------- |
| `apt-copy` | Create a simple script that can be used to 'duplicate' a system |
| `apt-history` | Displays apt history for a command |
| `kerndeb` | Builds kernel packages |
| `apt-list-packages` | List packages by size |
## Authors
- [@AlexBio](https://github.com/AlexBio)
- [@dbb](https://github.com/dbb)
- [@Mappleconfusers](https://github.com/Mappleconfusers)
# Authors:
# https://github.com/AlexBio
# https://github.com/dbb
# https://github.com/Mappleconfusers
#
# Debian-related zsh aliases and functions for zsh
# Use aptitude if installed, or apt-get if not.
# Use apt or aptitude if installed, fallback is apt-get
# You can just set apt_pref='apt-get' to override it.
if [[ -e $( which -p aptitude 2>&1 ) ]]; then
if [[ -z $apt_pref || -z $apt_upgr ]]; then
if [[ -e $commands[apt] ]]; then
apt_pref='apt'
apt_upgr='upgrade'
elif [[ -e $commands[aptitude] ]]; then
apt_pref='aptitude'
apt_upgr='safe-upgrade'
else
else
apt_pref='apt-get'
apt_upgr='upgrade'
fi
fi
# Use sudo by default if it's installed
if [[ -e $( which -p sudo 2>&1 ) ]]; then
if [[ -e $commands[sudo] ]]; then
use_sudo=1
fi
......@@ -29,8 +28,7 @@ alias api='aptitude'
# Some self-explanatory aliases
alias acs="apt-cache search"
alias aps='aptitude search'
alias as="aptitude -F \"* %p -> %d \n(%v/%V)\" \
--no-gui --disable-columns search" # search package
alias as="aptitude -F '* %p -> %d \n(%v/%V)' --no-gui --disable-columns search"
# apt-file
alias afs='apt-file search --regexp'
......@@ -43,60 +41,59 @@ alias app='apt-cache policy'
# superuser operations ######################################################
if [[ $use_sudo -eq 1 ]]; then
# commands using sudo #######
alias aac='sudo $apt_pref autoclean'
alias abd='sudo $apt_pref build-dep'
alias ac='sudo $apt_pref clean'
alias ad='sudo $apt_pref update'
alias adg='sudo $apt_pref update && sudo $apt_pref $apt_upgr'
alias adu='sudo $apt_pref update && sudo $apt_pref dist-upgrade'
alias afu='sudo apt-file update'
alias ag='sudo $apt_pref $apt_upgr'
alias ai='sudo $apt_pref install'
alias aac="sudo $apt_pref autoclean"
alias abd="sudo $apt_pref build-dep"
alias ac="sudo $apt_pref clean"
alias ad="sudo $apt_pref update"
alias adg="sudo $apt_pref update && sudo $apt_pref $apt_upgr"
alias adu="sudo $apt_pref update && sudo $apt_pref dist-upgrade"
alias afu="sudo apt-file update"
alias au="sudo $apt_pref $apt_upgr"
alias ai="sudo $apt_pref install"
# Install all packages given on the command line while using only the first word of each line:
# acs ... | ail
alias ail="sed -e 's/ */ /g' -e 's/ *//' | cut -s -d ' ' -f 1 | "' xargs sudo $apt_pref install'
alias ap='sudo $apt_pref purge'
alias ar='sudo $apt_pref remove'
alias ail="sed -e 's/ */ /g' -e 's/ *//' | cut -s -d ' ' -f 1 | xargs sudo $apt_pref install"
alias ap="sudo $apt_pref purge"
alias ar="sudo $apt_pref remove"
# apt-get only
alias ads='sudo apt-get dselect-upgrade'
alias ads="sudo apt-get dselect-upgrade"
# Install all .deb files in the current directory.
# Warning: you will need to put the glob in single quotes if you use:
# glob_subst
alias dia='sudo dpkg -i ./*.deb'
alias di='sudo dpkg -i'
alias dia="sudo dpkg -i ./*.deb"
alias di="sudo dpkg -i"
# Remove ALL kernel images and headers EXCEPT the one in use
alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) \
?not(~n`uname -r`))'
alias kclean='sudo aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n$(uname -r)))'
# commands using su #########
else
alias aac='su -ls \'$apt_pref autoclean\' root'
abd() {
alias aac="su -ls '$apt_pref autoclean' root"
function abd() {
cmd="su -lc '$apt_pref build-dep $@' root"
print "$cmd"
eval "$cmd"
}
alias ac='su -ls \'$apt_pref clean\' root'
alias ad='su -lc \'$apt_pref update\' root'
alias adg='su -lc \'$apt_pref update && aptitude $apt_upgr\' root'
alias adu='su -lc \'$apt_pref update && aptitude dist-upgrade\' root'
alias afu='su -lc "apt-file update"'
alias ag='su -lc \'$apt_pref $apt_upgr\' root'
ai() {
alias ac="su -ls '$apt_pref clean' root"
alias ad="su -lc '$apt_pref update' root"
alias adg="su -lc '$apt_pref update && aptitude $apt_upgr' root"
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"
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"
......@@ -108,8 +105,7 @@ else
alias di='su -lc "dpkg -i" root'
# Remove ALL kernel images and headers EXCEPT the one in use
alias kclean='su -lc '\''aptitude remove -P ?and(~i~nlinux-(ima|hea) \
?not(~n`uname -r`))'\'' root'
alias kclean='su -lc "aptitude remove -P ?and(~i~nlinux-(ima|hea) ?not(~n$(uname -r)))" root'
fi
# Completion ################################################################
......@@ -118,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}"
......@@ -138,7 +134,7 @@ apt_pref_compdef abd "build-dep"
apt_pref_compdef ac "clean"
apt_pref_compdef ad "update"
apt_pref_compdef afu "update"
apt_pref_compdef ag "$apt_upgr"
apt_pref_compdef au "$apt_upgr"
apt_pref_compdef ai "install"
apt_pref_compdef ail "install"
apt_pref_compdef ap "purge"
......@@ -155,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'
......@@ -176,8 +172,8 @@ apt-copy() {
# apt-history remove
# apt-history rollback
# apt-history list
# Based On: http://linuxcommando.blogspot.com/2008/08/how-to-show-apt-log-history.html
apt-history () {
# Based On: https://linuxcommando.blogspot.com/2008/08/how-to-show-apt-log-history.html
function apt-history() {
case "$1" in
install)
zgrep --no-filename 'install ' $(ls -rt /var/log/dpkg*)
......@@ -192,7 +188,7 @@ apt-history () {
awk '{print $4"="$5}'
;;
list)
zcat $(ls -rt /var/log/dpkg*)
zgrep --no-filename '' $(ls -rt /var/log/dpkg*)
;;
*)
echo "Parameters:"
......@@ -206,11 +202,11 @@ 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'"
appendage='-custom' # this shows up in $ (uname -r )
appendage='-custom' # this shows up in $(uname -r )
revision=$(date +"%Y%m%d") # this shows up in the .deb file name
make-kpkg clean
......@@ -220,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}'
}
# dircycle
Plugin for cycling through the directory stack
This plugin enables directory navigation similar to using back and forward on browsers or common file explorers like Finder or Nautilus. It uses a small zle trick that lets you cycle through your directory stack left or right using <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Left</kbd> / <kbd>Right</kbd> . This is useful when moving back and forth between directories in development environments, and can be thought of as kind of a nondestructive pushd/popd.
## Enabling the plugin
1. Open your `.zshrc` file and add `dircycle` in the plugins section:
```zsh
plugins=(
# all your enabled plugins
dircycle
)
```
2. Reload the source file or restart your Terminal session:
```console
$ source ~/.zshrc
$
```
## Usage Examples
Say you opened these directories on the terminal:
```console
~$ cd Projects
~/Projects$ cd Hacktoberfest
~/Projects/Hacktoberfest$ cd oh-my-zsh
~/Projects/Hacktoberfest/oh-my-zsh$ dirs -v
0 ~/Projects/Hacktoberfest/oh-my-zsh
1 ~/Projects/Hacktoberfest
2 ~/Projects
3 ~
```
By pressing <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Left</kbd>, the current working directory or `$CWD` will be from `oh-my-zsh` to `Hacktoberfest`. Press it again and it will be at `Projects`.
And by pressing <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Right</kbd>, the `$CWD` will be from `Projects` to `Hacktoberfest`. Press it again and it will be at `oh-my-zsh`.
Here's a example history table with the same accessed directories like above:
| Current `$CWD` | Key press | New `$CWD` |
| --------------- | ----------------------------------------------------- | --------------- |
| `oh-my-zsh` | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Left</kbd> | `Hacktoberfest` |
| `Hacktoberfest` | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Left</kbd> | `Projects` |
| `Projects` | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Left</kbd> | `~` |
| `~` | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Right</kbd> | `Projects` |
| `Projects` | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Right</kbd> | `Hacktoberfest` |
| `Hacktoberfest` | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Right</kbd> | `oh-my-zsh` |
| `oh-my-zsh` | <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Right</kbd> | `~` |
Note the last traversal, when pressing <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Right</kbd> on a last known `$CWD`, it will change back to the first known `$CWD`, which in the example is `~`.
Here's an asciinema cast demonstrating the example above:
[![asciicast](https://asciinema.org/a/204406.png)](https://asciinema.org/a/204406)
## Functions
| Function | Description |
| -------------------- | --------------------------------------------------------------------------------------------------------- |
| `insert-cycledleft` | Change `$CWD` to the previous known stack, binded on <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Left</kbd> |
| `insert-cycledright` | Change `$CWD` to the next known stack, binded on <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Right</kbd> |
## Rebinding keys
You can bind these functions to other key sequences, as long as you know the bindkey sequence. For example, these commands bind to <kbd>Alt</kbd> + <kbd>Shift</kbd> + <kbd>Left</kbd> / <kbd>Right</kbd> in `xterm-256color`:
```zsh
bindkey '^[[1;4D' insert-cycledleft
bindkey '^[[1;4C' insert-cycledright
```
You can get the bindkey sequence by pressing <kbd>Ctrl</kbd> + <kbd>V</kbd>, then pressing the keyboard shortcut you want to use.
......@@ -9,29 +9,36 @@
# pushd -N: start counting from right of `dirs' output
switch-to-dir () {
setopt localoptions nopushdminus
[[ ${#dirstack} -eq 0 ]] && return 1
while ! builtin pushd -q $1 &>/dev/null; do
# We found a missing directory: pop it out of the dir stack
builtin popd -q $1
# Stop trying if there are no more directories in the dir stack
[[ ${#dirstack} -eq 0 ]] && break
[[ ${#dirstack} -eq 0 ]] && return 1
done
}
insert-cycledleft () {
emulate -L zsh
setopt nopushdminus
switch-to-dir +1 || return
switch-to-dir +1
local fn
for fn (chpwd $chpwd_functions precmd $precmd_functions); do
(( $+functions[$fn] )) && $fn
done
zle reset-prompt
}
zle -N insert-cycledleft
insert-cycledright () {
emulate -L zsh
setopt nopushdminus
switch-to-dir -0 || return
switch-to-dir -0
local fn
for fn (chpwd $chpwd_functions precmd $precmd_functions); do
(( $+functions[$fn] )) && $fn
done
zle reset-prompt
}
zle -N insert-cycledright
......
# Dirhistory plugin
This plugin adds keyboard shortcuts for navigating directory history and hierarchy.
To use it, add `dirhistory` to the plugins array in your zshrc file:
```zsh
plugins=(... dirhistory)
```
## Keyboard Shortcuts
| Shortcut | Description |
|-----------------------------------|-----------------------------------------------------------|
| <kbd>alt</kbd> + <kbd>left</kbd> | Go to previous directory |
| <kbd>alt</kbd> + <kbd>right</kbd> | Undo <kbd>alt</kbd> + <kbd>left</kbd> |
| <kbd>alt</kbd> + <kbd>up</kbd> | Move into the parent directory |
| <kbd>alt</kbd> + <kbd>down</kbd> | Move into the first child directory by alphabetical order |
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