Last active
October 17, 2020 00:32
-
-
Save eikenb/323cf660d11f1fd578737809a5ca0079 to your computer and use it in GitHub Desktop.
zsh/terminal based application launcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Preamble. This is cobbled together as it is spread out a bit on my system. | |
# It might require some fiddling. | |
# Script to launch terminal/launcher window. Bind this to a key. | |
# ------------------------- | |
#!/bin/sh | |
export ZDOTDIR=$HOME/.zsh/zsilver | |
border="rgb:ff/d0/78" # yellow/orange | |
width=$(xwininfo -root | grep Width | awk -F ': ' '{print $2}') | |
placement=$(( ($width/2) - 304)) # 50 char wide ~= 608 pixels wide with font | |
urxvtcd -bl -b 6 -bd $border -geometry 50x1+${placement}+4 -name zsilver \ | |
-depth 32 -fg grey -bg '[70]#2d2d2d' \ | |
-fg white -fn terminus-bold-24 -e zsh -t -i | |
# (zsh options: -t single use, -i interactive) | |
# ------------------------- | |
# ~/home/.zsh/zsilver/.zshrc - (zsh looks for .zshrc in ZDOTDIR when set) | |
# ------------------------- | |
# History settings | |
HISTSIZE=1000 | |
SAVEHIST=1000 | |
HISTFILE=$HOME/.zsh/zsilver/history | |
# Set all background jobs to a lower priority (on by default) | |
unsetopt bgnice | |
# Remove (old) duplicates from history | |
setopt hist_ignore_all_dups | |
# commands starting with spaces don't go in history | |
setopt histignorespace | |
# Remove superfluous blanks from history | |
setopt hist_reduceblanks | |
# Compact display of completion list. | |
setopt list_packed | |
# So backgrounded jobs don't get terminated when the shell is. | |
setopt nohup | |
# enable completion | |
zmodload zsh/complist | |
autoload -U compinit; compinit | |
# predictive completion | |
autoload -U predict-on | |
zle-line-init() { predict-on } | |
zle -N zle-line-init | |
# complete beginnings/middles of words | |
setopt completeinword | |
# Up-arrow history completion | |
autoload -U up-line-or-beginning-search | |
zle -N up-line-or-beginning-search | |
bindkey '\e[A' up-line-or-beginning-search | |
autoload -U colors; colors | |
# no prompt | |
PROMPT= | |
## Set up keys and command processing | |
set singlelinezle | |
# override key bindings | |
autoload -U up-line-or-beginning-search down-line-or-beginning-search | |
zle -N up-line-or-beginning-search | |
zle -N down-line-or-beginning-search | |
bindkey "$key[up]" up-line-or-beginning-search | |
bindkey "$key[down]" down-line-or-beginning-search | |
# override backspace to clear/reset | |
reset-prompt() { | |
if [[ "${BUFFER}" == *' '* ]] ; then | |
zle backward-delete-char | |
else | |
zle kill-buffer; zle .accept-line; zle clear-screen | |
fi | |
} | |
zle -N reset-prompt | |
bindkey "" reset-prompt | |
# list of apps that need to run in terminals | |
typeset -U in_terminal | |
in_terminal=( python htop ncmpcpp ncmpc e1000e mpdplay wyrd htop steam ) | |
in_terminal+=( edpwd zsh sudo ssh bash ) | |
# keep history clean | |
setopt inc_append_history | |
function zshaddhistory() | |
{ | |
emulate -L zsh | |
if ! [[ -z "${_HISTLINE}" ]] ; then | |
print -sr -- "${_HISTLINE}" | |
unset _HISTLINE | |
fc -W | |
fi | |
return 1 | |
} | |
# exand aliases in BUFFER line but not history or terminal | |
# needed as aliases are not expanded otherwise | |
function expand-aliases-in-buffer() { | |
# functions[] is a magic array | |
#unset 'functions[_expand-aliases-in-buffer]' # empty old values | |
functions[_expand-aliases-in-buffer]="${BUFFER}" # assign BUFFER contents | |
(($+functions[_expand-aliases-in-buffer])) && # if not empty | |
BUFFER=${functions[_expand-aliases-in-buffer]#$'\t'} # normalize | |
} | |
# https://unix.stackexchange.com/questions/372811/better-understand-a-function-expanding-aliases-in-zsh | |
# this is set to 'accept-line' below, so it processes the command when you hit enter | |
function auto-bg { | |
export ZDOTDIR=$HOME/.zsh | |
_HISTLINE=${BUFFER%% } | |
expand-aliases-in-buffer | |
[[ -n ${(M)in_terminal:#${BUFFER%% *}} ]] && \ | |
BUFFER="x-terminal-emulator -name '${BUFFER}' -e ${BUFFER}" | |
exec &> ~/.tmp/zsilver.log | |
[[ ${BUFFER} =~ "&&" ]] || [[ ${BUFFER} =~ ";" ]] && \ | |
BUFFER="sh -c '${BUFFER}'" | |
echo "(exec) $BUFFER" | |
BUFFER="exec ${BUFFER} &|" | |
zle .accept-line | |
} | |
zle -N accept-line auto-bg | |
# ------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment