From 8694f97099567c29dad8664d5bea61388ef32fba Mon Sep 17 00:00:00 2001 From: Zeh Rizzatti Date: Wed, 12 Dec 2012 14:43:37 -0300 Subject: [PATCH 1/4] add zstyle for allowing alias definitions on modules --- runcoms/zpreztorc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/runcoms/zpreztorc b/runcoms/zpreztorc index 27aad49b49..d9bc049822 100644 --- a/runcoms/zpreztorc +++ b/runcoms/zpreztorc @@ -34,6 +34,16 @@ zstyle ':prezto:load' pmodule \ 'completion' \ 'prompt' +# +# Alias +# + +# Allow aliases defined in all loaded modules with 'all' +# Commenting out will disable aliases +# Specific modules can be loaded with: +# zstyle ':prezto:alias' pmodule 'git' 'ruby' 'osx' +zstyle ':prezto:alias' pmodule 'all' + # # Editor # From d2c14fecb9e6d2351e8fa380974e6f9c91fc1d14 Mon Sep 17 00:00:00 2001 From: Zeh Rizzatti Date: Wed, 12 Dec 2012 14:44:08 -0300 Subject: [PATCH 2/4] define aliases for git if :prezto:alias is set --- modules/git/alias.zsh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/git/alias.zsh b/modules/git/alias.zsh index 8d84d92387..bf922324f3 100644 --- a/modules/git/alias.zsh +++ b/modules/git/alias.zsh @@ -22,6 +22,11 @@ zstyle -s ':prezto:module:git:log:brief' format '_git_log_brief_format' \ zstyle -s ':prezto:module:git:status:ignore' submodules '_git_status_ignore_submodules' \ || _git_status_ignore_submodules='none' +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all git; then + return 1 +fi + # # Aliases # From b3f1d9ff2cba5fe953c8dcc310cdf3edaf9a3e47 Mon Sep 17 00:00:00 2001 From: Zeh Rizzatti Date: Wed, 12 Dec 2012 18:54:48 -0300 Subject: [PATCH 3/4] extend the conditionals for all modules except utility --- modules/directory/init.zsh | 5 +++ modules/dpkg/init.zsh | 5 +++ modules/fasd/init.zsh | 5 +++ modules/git/alias.zsh | 8 ++-- modules/history/init.zsh | 5 +++ modules/macports/init.zsh | 5 +++ modules/osx/init.zsh | 25 +++++++----- modules/pacman/init.zsh | 5 +++ modules/perl/init.zsh | 5 +++ modules/python/init.zsh | 5 +++ modules/rails/init.zsh | 5 +++ modules/rsync/init.zsh | 5 +++ modules/ruby/init.zsh | 5 +++ modules/screen/init.zsh | 5 +++ modules/tmux/init.zsh | 5 +++ modules/utility/init.zsh | 83 ++++++++++++++++++++------------------ modules/yum/init.zsh | 5 +++ 17 files changed, 133 insertions(+), 53 deletions(-) diff --git a/modules/directory/init.zsh b/modules/directory/init.zsh index 3be411b5a5..e63f885831 100644 --- a/modules/directory/init.zsh +++ b/modules/directory/init.zsh @@ -26,6 +26,11 @@ unsetopt CLOBBER # Do not overwrite existing files with > and >>. # Aliases # +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all directory; then + return 1 +fi + alias d='dirs -v' for index ({1..9}) alias "$index"="cd +${index}"; unset index diff --git a/modules/dpkg/init.zsh b/modules/dpkg/init.zsh index 939e9100b4..fa8de27f0d 100644 --- a/modules/dpkg/init.zsh +++ b/modules/dpkg/init.zsh @@ -16,6 +16,11 @@ fi # Aliases # +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all dpkg; then + return 1 +fi + # Cleans the cache. alias debc='sudo apt-get clean && sudo apt-get autoclean' diff --git a/modules/fasd/init.zsh b/modules/fasd/init.zsh index 7088e9c681..58beaf44d5 100644 --- a/modules/fasd/init.zsh +++ b/modules/fasd/init.zsh @@ -49,6 +49,11 @@ function fasd_cd { # Aliases # +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all fasd; then + return 1 +fi + # Changes the current working directory interactively. alias j='fasd_cd -i' diff --git a/modules/git/alias.zsh b/modules/git/alias.zsh index bf922324f3..6bd6de5fbc 100644 --- a/modules/git/alias.zsh +++ b/modules/git/alias.zsh @@ -22,15 +22,15 @@ zstyle -s ':prezto:module:git:log:brief' format '_git_log_brief_format' \ zstyle -s ':prezto:module:git:status:ignore' submodules '_git_status_ignore_submodules' \ || _git_status_ignore_submodules='none' +# +# Aliases +# + # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all git; then return 1 fi -# -# Aliases -# - # Git alias g='git' diff --git a/modules/history/init.zsh b/modules/history/init.zsh index 31db4c5b3a..012c7408f8 100644 --- a/modules/history/init.zsh +++ b/modules/history/init.zsh @@ -35,5 +35,10 @@ setopt HIST_BEEP # Beep when accessing non-existent history. # Aliases # +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all history; then + return 1 +fi + # Lists the ten most used commands. alias history-stat="history 0 | awk '{print \$2}' | sort | uniq -c | sort -n -r | head" diff --git a/modules/macports/init.zsh b/modules/macports/init.zsh index 4554ca1fb5..58e01b5b71 100644 --- a/modules/macports/init.zsh +++ b/modules/macports/init.zsh @@ -37,6 +37,11 @@ path=( # Aliases # +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all macports; then + return 1 +fi + alias portc='sudo port clean --all installed' alias porti='sudo port install' alias ports='port search' diff --git a/modules/osx/init.zsh b/modules/osx/init.zsh index 6acbfbc762..69b002e9a1 100644 --- a/modules/osx/init.zsh +++ b/modules/osx/init.zsh @@ -10,16 +10,6 @@ if [[ "$OSTYPE" != darwin* ]]; then return 1 fi -# -# Aliases -# - -# Change directory to the current Finder directory. -alias cdf='cd "$(pfd)"' - -# Push directory to the current Finder directory. -alias pushdf='pushd "$(pfd)"' - # # Functions # @@ -37,3 +27,18 @@ function rm-osx-cruft { \) -print0 | xargs -0 rm -rf } +# +# Aliases +# + +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all osx; then + return 1 +fi + +# Change directory to the current Finder directory. +alias cdf='cd "$(pfd)"' + +# Push directory to the current Finder directory. +alias pushdf='pushd "$(pfd)"' + diff --git a/modules/pacman/init.zsh b/modules/pacman/init.zsh index c6fdc451e3..5a720ee8dc 100644 --- a/modules/pacman/init.zsh +++ b/modules/pacman/init.zsh @@ -18,6 +18,11 @@ fi # Frontend # +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all pacman; then + return 1 +fi + # Get the Pacman frontend. zstyle -s ':prezto:module:pacman' frontend '_pacman_frontend' diff --git a/modules/perl/init.zsh b/modules/perl/init.zsh index 62701283ac..5c7a0df833 100644 --- a/modules/perl/init.zsh +++ b/modules/perl/init.zsh @@ -43,6 +43,11 @@ fi # Aliases # +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all perl; then + return 1 +fi + # General alias pl='perl' alias pld='perldoc' diff --git a/modules/python/init.zsh b/modules/python/init.zsh index 11875612b7..b3d63b800b 100644 --- a/modules/python/init.zsh +++ b/modules/python/init.zsh @@ -42,6 +42,11 @@ fi # Aliases # +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all python; then + return 1 +fi + alias py='python' # pythonz diff --git a/modules/rails/init.zsh b/modules/rails/init.zsh index e51185bb8c..71e7fb4a5d 100644 --- a/modules/rails/init.zsh +++ b/modules/rails/init.zsh @@ -16,6 +16,11 @@ fi # Aliases (Compatible with Rails 2) # +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all rails; then + return 1 +fi + alias ror='rails' alias rorc='_rails-command console' alias rordc='_rails-command dbconsole' diff --git a/modules/rsync/init.zsh b/modules/rsync/init.zsh index c3b3b577b3..4e07e9e723 100644 --- a/modules/rsync/init.zsh +++ b/modules/rsync/init.zsh @@ -14,6 +14,11 @@ fi # Aliases # +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all rsync; then + return 1 +fi + _rsync_cmd='rsync --verbose --progress --human-readable --compress --archive --hard-links --one-file-system' # Mac OS X and HFS+ Enhancements diff --git a/modules/ruby/init.zsh b/modules/ruby/init.zsh index b5ab77d0dd..566f179d75 100644 --- a/modules/ruby/init.zsh +++ b/modules/ruby/init.zsh @@ -40,6 +40,11 @@ fi # Aliases # +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all ruby; then + return 1 +fi + # General alias rb='ruby' diff --git a/modules/screen/init.zsh b/modules/screen/init.zsh index 424f6584f6..00588ff9cb 100644 --- a/modules/screen/init.zsh +++ b/modules/screen/init.zsh @@ -32,6 +32,11 @@ fi # Aliases # +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all screen; then + return 1 +fi + alias scr='screen' alias scrl='screen -list' alias scrn='screen -U -S' diff --git a/modules/tmux/init.zsh b/modules/tmux/init.zsh index a464827640..14d48b1938 100644 --- a/modules/tmux/init.zsh +++ b/modules/tmux/init.zsh @@ -40,5 +40,10 @@ fi # Aliases # +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all tmux; then + return 1 +fi + alias tmuxa='tmux attach-session' alias tmuxl='tmux list-sessions' diff --git a/modules/utility/init.zsh b/modules/utility/init.zsh index ea31138c33..2d043e1a8e 100644 --- a/modules/utility/init.zsh +++ b/modules/utility/init.zsh @@ -13,10 +13,54 @@ pmodload 'helper' 'spectrum' # Correct commands. setopt CORRECT +# +# Functions +# + +# Makes a directory and changes to it. +function mkdcd { + [[ -n "$1" ]] && mkdir -p "$1" && builtin cd "$1" +} + +# Changes to a directory and lists its contents. +function cdls { + builtin cd "$argv[-1]" && ls "${(@)argv[1,-2]}" +} + +# Pushes an entry onto the directory stack and lists its contents. +function pushdls { + builtin pushd "$argv[-1]" && ls "${(@)argv[1,-2]}" +} + +# Pops an entry off the directory stack and lists its contents. +function popdls { + builtin popd "$argv[-1]" && ls "${(@)argv[1,-2]}" +} + +# Prints columns 1 2 3 ... n. +function slit { + awk "{ print ${(j:,:):-\$${^@}} }" +} + +# Finds files and executes a command on them. +function find-exec { + find . -type f -iname "*${1:-}*" -exec "${2:-file}" '{}' \; +} + +# Displays user owned processes status. +function psu { + ps -U "${1:-$USER}" -o 'pid,%cpu,%mem,command' "${(@)argv[2,-1]}" +} + # # Aliases # +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all utility; then + return 1 +fi + # Disable correction. alias ack='nocorrect ack' alias cd='nocorrect cd' @@ -139,42 +183,3 @@ fi # Serves a directory via HTTP. alias http-serve='python -m SimpleHTTPServer' -# -# Functions -# - -# Makes a directory and changes to it. -function mkdcd { - [[ -n "$1" ]] && mkdir -p "$1" && builtin cd "$1" -} - -# Changes to a directory and lists its contents. -function cdls { - builtin cd "$argv[-1]" && ls "${(@)argv[1,-2]}" -} - -# Pushes an entry onto the directory stack and lists its contents. -function pushdls { - builtin pushd "$argv[-1]" && ls "${(@)argv[1,-2]}" -} - -# Pops an entry off the directory stack and lists its contents. -function popdls { - builtin popd "$argv[-1]" && ls "${(@)argv[1,-2]}" -} - -# Prints columns 1 2 3 ... n. -function slit { - awk "{ print ${(j:,:):-\$${^@}} }" -} - -# Finds files and executes a command on them. -function find-exec { - find . -type f -iname "*${1:-}*" -exec "${2:-file}" '{}' \; -} - -# Displays user owned processes status. -function psu { - ps -U "${1:-$USER}" -o 'pid,%cpu,%mem,command' "${(@)argv[2,-1]}" -} - diff --git a/modules/yum/init.zsh b/modules/yum/init.zsh index d7019cd060..80e40dc4fd 100644 --- a/modules/yum/init.zsh +++ b/modules/yum/init.zsh @@ -15,6 +15,11 @@ fi # Aliases # +# Return if conditions are unsatistied +if ! zstyle -t ':prezto:alias' pmodule all yum; then + return 1 +fi + alias yumc='sudo yum clean all' # Cleans the cache. alias yumh='yum history' # Displays history. alias yumi='sudo yum install' # Installs package(s). From 8d7383e5dd6e68394f59d3b6ceef5be77bdba9f2 Mon Sep 17 00:00:00 2001 From: Zeh Rizzatti Date: Wed, 12 Dec 2012 19:15:09 -0300 Subject: [PATCH 4/4] return 0 instead of 1 returning 1 would make :module:loaded set to no, undefining functions, which was not intended. not using the aliases is not an error, just an option, while other features of the module were loaded normally --- modules/directory/init.zsh | 2 +- modules/dpkg/init.zsh | 2 +- modules/fasd/init.zsh | 2 +- modules/git/alias.zsh | 2 +- modules/history/init.zsh | 2 +- modules/macports/init.zsh | 2 +- modules/osx/init.zsh | 2 +- modules/pacman/init.zsh | 2 +- modules/perl/init.zsh | 2 +- modules/python/init.zsh | 2 +- modules/rails/init.zsh | 2 +- modules/rsync/init.zsh | 2 +- modules/ruby/init.zsh | 2 +- modules/screen/init.zsh | 2 +- modules/tmux/init.zsh | 2 +- modules/utility/init.zsh | 2 +- modules/yum/init.zsh | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/modules/directory/init.zsh b/modules/directory/init.zsh index e63f885831..cc9a523140 100644 --- a/modules/directory/init.zsh +++ b/modules/directory/init.zsh @@ -28,7 +28,7 @@ unsetopt CLOBBER # Do not overwrite existing files with > and >>. # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all directory; then - return 1 + return 0 fi alias d='dirs -v' diff --git a/modules/dpkg/init.zsh b/modules/dpkg/init.zsh index fa8de27f0d..83a61aa1c3 100644 --- a/modules/dpkg/init.zsh +++ b/modules/dpkg/init.zsh @@ -18,7 +18,7 @@ fi # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all dpkg; then - return 1 + return 0 fi # Cleans the cache. diff --git a/modules/fasd/init.zsh b/modules/fasd/init.zsh index 58beaf44d5..ce188db60c 100644 --- a/modules/fasd/init.zsh +++ b/modules/fasd/init.zsh @@ -51,7 +51,7 @@ function fasd_cd { # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all fasd; then - return 1 + return 0 fi # Changes the current working directory interactively. diff --git a/modules/git/alias.zsh b/modules/git/alias.zsh index 6bd6de5fbc..d08d9d9ec7 100644 --- a/modules/git/alias.zsh +++ b/modules/git/alias.zsh @@ -28,7 +28,7 @@ zstyle -s ':prezto:module:git:status:ignore' submodules '_git_status_ignore_subm # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all git; then - return 1 + return 0 fi # Git diff --git a/modules/history/init.zsh b/modules/history/init.zsh index 012c7408f8..1e3fb464ca 100644 --- a/modules/history/init.zsh +++ b/modules/history/init.zsh @@ -37,7 +37,7 @@ setopt HIST_BEEP # Beep when accessing non-existent history. # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all history; then - return 1 + return 0 fi # Lists the ten most used commands. diff --git a/modules/macports/init.zsh b/modules/macports/init.zsh index 58e01b5b71..f3f587903c 100644 --- a/modules/macports/init.zsh +++ b/modules/macports/init.zsh @@ -39,7 +39,7 @@ path=( # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all macports; then - return 1 + return 0 fi alias portc='sudo port clean --all installed' diff --git a/modules/osx/init.zsh b/modules/osx/init.zsh index 69b002e9a1..9415bf84dc 100644 --- a/modules/osx/init.zsh +++ b/modules/osx/init.zsh @@ -33,7 +33,7 @@ function rm-osx-cruft { # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all osx; then - return 1 + return 0 fi # Change directory to the current Finder directory. diff --git a/modules/pacman/init.zsh b/modules/pacman/init.zsh index 5a720ee8dc..c3881705b3 100644 --- a/modules/pacman/init.zsh +++ b/modules/pacman/init.zsh @@ -20,7 +20,7 @@ fi # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all pacman; then - return 1 + return 0 fi # Get the Pacman frontend. diff --git a/modules/perl/init.zsh b/modules/perl/init.zsh index 5c7a0df833..294394f81a 100644 --- a/modules/perl/init.zsh +++ b/modules/perl/init.zsh @@ -45,7 +45,7 @@ fi # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all perl; then - return 1 + return 0 fi # General diff --git a/modules/python/init.zsh b/modules/python/init.zsh index b3d63b800b..0c6c2191c4 100644 --- a/modules/python/init.zsh +++ b/modules/python/init.zsh @@ -44,7 +44,7 @@ fi # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all python; then - return 1 + return 0 fi alias py='python' diff --git a/modules/rails/init.zsh b/modules/rails/init.zsh index 71e7fb4a5d..4fa07baac0 100644 --- a/modules/rails/init.zsh +++ b/modules/rails/init.zsh @@ -18,7 +18,7 @@ fi # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all rails; then - return 1 + return 0 fi alias ror='rails' diff --git a/modules/rsync/init.zsh b/modules/rsync/init.zsh index 4e07e9e723..1985f895a6 100644 --- a/modules/rsync/init.zsh +++ b/modules/rsync/init.zsh @@ -16,7 +16,7 @@ fi # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all rsync; then - return 1 + return 0 fi _rsync_cmd='rsync --verbose --progress --human-readable --compress --archive --hard-links --one-file-system' diff --git a/modules/ruby/init.zsh b/modules/ruby/init.zsh index 566f179d75..b4e696b97d 100644 --- a/modules/ruby/init.zsh +++ b/modules/ruby/init.zsh @@ -42,7 +42,7 @@ fi # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all ruby; then - return 1 + return 0 fi # General diff --git a/modules/screen/init.zsh b/modules/screen/init.zsh index 00588ff9cb..aa1c6fc933 100644 --- a/modules/screen/init.zsh +++ b/modules/screen/init.zsh @@ -34,7 +34,7 @@ fi # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all screen; then - return 1 + return 0 fi alias scr='screen' diff --git a/modules/tmux/init.zsh b/modules/tmux/init.zsh index 14d48b1938..5319d995d5 100644 --- a/modules/tmux/init.zsh +++ b/modules/tmux/init.zsh @@ -42,7 +42,7 @@ fi # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all tmux; then - return 1 + return 0 fi alias tmuxa='tmux attach-session' diff --git a/modules/utility/init.zsh b/modules/utility/init.zsh index 2d043e1a8e..6ffd05f1a1 100644 --- a/modules/utility/init.zsh +++ b/modules/utility/init.zsh @@ -58,7 +58,7 @@ function psu { # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all utility; then - return 1 + return 0 fi # Disable correction. diff --git a/modules/yum/init.zsh b/modules/yum/init.zsh index 80e40dc4fd..efa053ce6e 100644 --- a/modules/yum/init.zsh +++ b/modules/yum/init.zsh @@ -17,7 +17,7 @@ fi # Return if conditions are unsatistied if ! zstyle -t ':prezto:alias' pmodule all yum; then - return 1 + return 0 fi alias yumc='sudo yum clean all' # Cleans the cache.