aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2021-11-11 14:09:28 -0700
committerJosh Rahm <rahm@google.com>2021-11-11 14:09:28 -0700
commit509b3462c5957b705ef02d8364b50e8c25c9d0dd (patch)
treec643161769f45825d95b3c427d16bb8c35fc5101
parentde29509eefa8caeeacd68d6cdfeaadbf207b369a (diff)
downloadzshrcd-509b3462c5957b705ef02d8364b50e8c25c9d0dd.tar.gz
zshrcd-509b3462c5957b705ef02d8364b50e8c25c9d0dd.tar.bz2
zshrcd-509b3462c5957b705ef02d8364b50e8c25c9d0dd.zip
Add abbreviations to zsh
-rw-r--r--04-functions.zsh49
-rw-r--r--05-functions.zsh10
-rw-r--r--05-options.zsh (renamed from 04-options.zsh)1
-rw-r--r--98-bindkeys.zsh4
-rw-r--r--99-plugins.zsh2
-rw-r--r--zshrc2
6 files changed, 57 insertions, 11 deletions
diff --git a/04-functions.zsh b/04-functions.zsh
new file mode 100644
index 0000000..0539b2f
--- /dev/null
+++ b/04-functions.zsh
@@ -0,0 +1,49 @@
+if [ -n '$TMUX' ]; then
+ function refresh {
+ export SSH_AUTH_SOCK="$(tmux show-environment | grep '^SSH_AUTH_SOCK' | cut -d '=' -f 2)"
+ export SSH_AUTH_KEY="$(tmux show-environment | grep '^SSH_AUTH_KEY' | cut -d '=' -f 2)"
+ export SSH_CONNECTION="$(tmux show-environment | grep '^SSH_CONNECTION' | cut -d '=' -f 2)"
+ export DISPLAY="$(tmux show-environment | grep '^DISPLAY' | cut -d '=' -f 2)"
+ }
+else
+ function refresh { }
+fi
+
+# declare a list of expandable aliases to fill up later
+typeset -a ealiases
+ealiases=()
+
+# write a function for adding an alias to the list mentioned above
+function abbrev-alias() {
+ alias $1
+ ealiases+=(${1%%\=*})
+}
+
+# expand any aliases in the current line buffer
+function expand-ealias() {
+ if [[ $LBUFFER =~ "\<(${(j:|:)ealiases})\$" ]]; then
+ zle _expand_alias
+ zle expand-word
+ fi
+ zle magic-space
+}
+zle -N expand-ealias
+
+# Bind the space key to the expand-alias function above, so that space will expand any expandable aliases
+bindkey ' ' expand-ealias
+bindkey '^ ' magic-space # control-space to bypass completion
+bindkey -M isearch " " magic-space # normal space during searches
+
+# A function for expanding any aliases before accepting the line as is and executing the entered command
+expand-alias-and-accept-line() {
+ expand-ealias
+ zle .backward-delete-char
+ zle .accept-line
+}
+
+zle -N accept-line expand-alias-and-accept-line
+
+abbrev-alias g="git"
+abbrev-alias gst="git status"
+abbrev-alias gcb="git checkout --branch"
+abbrev-alias ll="ls -l"
diff --git a/05-functions.zsh b/05-functions.zsh
deleted file mode 100644
index d69acf3..0000000
--- a/05-functions.zsh
+++ /dev/null
@@ -1,10 +0,0 @@
-if [ -n '$TMUX' ]; then
- function refresh {
- export SSH_AUTH_SOCK="$(tmux show-environment | grep '^SSH_AUTH_SOCK' | cut -d '=' -f 2)"
- export SSH_AUTH_KEY="$(tmux show-environment | grep '^SSH_AUTH_KEY' | cut -d '=' -f 2)"
- export SSH_CONNECTION="$(tmux show-environment | grep '^SSH_CONNECTION' | cut -d '=' -f 2)"
- export DISPLAY="$(tmux show-environment | grep '^DISPLAY' | cut -d '=' -f 2)"
- }
-else
- function refresh { }
-fi
diff --git a/04-options.zsh b/05-options.zsh
index 480657f..1b80a18 100644
--- a/04-options.zsh
+++ b/05-options.zsh
@@ -32,3 +32,4 @@ HISTFILE=~/.zsh_history
HISTSIZE=100000
SAVEHIST=100000
setopt appendhistory
+setopt histverify
diff --git a/98-bindkeys.zsh b/98-bindkeys.zsh
index 5be333a..b6d5255 100644
--- a/98-bindkeys.zsh
+++ b/98-bindkeys.zsh
@@ -10,3 +10,7 @@ bindkey '' backward-delete-word
bindkey -v '^?' backward-delete-char
bindkey -v '' backward-delete-char
+
+autoload edit-command-line
+zle -N edit-command-line
+bindkey '' edit-command-line
diff --git a/99-plugins.zsh b/99-plugins.zsh
index bba5cb7..466ba90 100644
--- a/99-plugins.zsh
+++ b/99-plugins.zsh
@@ -8,3 +8,5 @@ fpath=(~/.zshrc.d/plugins/completions/ $fpath)
for f in ~/.zshrc.d/local/*.zsh ; do
source "$f"
done 2>/dev/null
+
+/bin/true
diff --git a/zshrc b/zshrc
index f7a0522..69769b6 100644
--- a/zshrc
+++ b/zshrc
@@ -2,4 +2,4 @@ source /etc/profile
for f in $HOME/.zshrc.d/*.zsh ; do
source "$f"
-done
+done || true