2018-09-05 07:57:17 +02:00
|
|
|
#This program is free software: you can redistribute it and/or modify
|
|
|
|
#it under the terms of the GNU General Public License as published by
|
|
|
|
#the Free Software Foundation, either version 3 of the License, or
|
|
|
|
#(at your option) any later version.
|
|
|
|
#
|
|
|
|
#This program is distributed in the hope that it will be useful,
|
|
|
|
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
#GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
#You should have received a copy of the GNU General Public License
|
|
|
|
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2020-05-30 00:24:53 +02:00
|
|
|
|
2021-01-06 20:30:47 +01:00
|
|
|
|
|
|
|
#set important shell variables
|
2021-04-03 08:53:27 +02:00
|
|
|
#fancy way of testing if a command exists
|
|
|
|
(($+command[ruby])) && export PATH="$PATH:$(ruby -e 'puts Gem.user_dir' 2> /dev/null)/bin"
|
2021-04-03 09:03:10 +02:00
|
|
|
#test that these nonstandard paths exist before adding to PATH.
|
2021-04-03 08:53:27 +02:00
|
|
|
testPath="$HOME/.local/bin"
|
2021-04-13 17:13:07 +02:00
|
|
|
[ -d "$testPath" ] && export PATH="$PATH:$testPath"
|
2021-07-12 18:22:07 +02:00
|
|
|
export PATH="$PATH:/opt"
|
2021-01-06 20:30:47 +01:00
|
|
|
#set default editor and pager.
|
|
|
|
export EDITOR=nvim
|
|
|
|
export VISUAL=nvim
|
|
|
|
export PAGER=less
|
|
|
|
#default options for less
|
|
|
|
export LESS="-R"
|
|
|
|
export LESSHISTFILE="/dev/null"
|
|
|
|
#set the w3m homepage
|
|
|
|
export WWW_HOME="duckduckgo.com/lite/"
|
|
|
|
|
2020-05-30 00:24:53 +02:00
|
|
|
#web_search from terminal
|
|
|
|
function web_search() {
|
|
|
|
emulate -L zsh
|
|
|
|
|
|
|
|
# define search engine URLS
|
|
|
|
typeset -A urls
|
|
|
|
urls=(
|
|
|
|
ddg "https://www.duckduckgo.com/?q="
|
|
|
|
github "https://github.com/search?q="
|
|
|
|
)
|
|
|
|
|
|
|
|
# check whether the search engine is supported
|
|
|
|
if [[ -z "$urls[$1]" ]]; then
|
|
|
|
echo "Search engine $1 not supported."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# search or go to main page depending on number of arguments passed
|
|
|
|
if [[ $# -gt 1 ]]; then
|
|
|
|
# build search url:
|
|
|
|
# join arguments passed with '+', then append to search engine URL
|
|
|
|
url="${urls[$1]}${(j:+:)@[2,-1]}"
|
|
|
|
else
|
|
|
|
# build main page url:
|
|
|
|
# split by '/', then rejoin protocol (1) and domain (2) parts with '//'
|
|
|
|
url="${(j://:)${(s:/:)urls[$1]}[1,2]}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
open_command "$url"
|
|
|
|
}
|
|
|
|
|
|
|
|
#prompt
|
|
|
|
autoload -U promptinit
|
|
|
|
promptinit
|
|
|
|
autoload -U colors
|
|
|
|
colors
|
|
|
|
|
|
|
|
#stuff to show git things.
|
|
|
|
autoload -Uz vcs_info
|
|
|
|
|
|
|
|
setopt prompt_subst
|
|
|
|
|
|
|
|
precmd_vcs() {vcs_info}
|
|
|
|
|
|
|
|
#when not in a repo, show full path to current directory. when in one, show path from base direcory of the repo.
|
|
|
|
zstyle ':vcs_info:*' nvcsformats '%~'
|
|
|
|
zstyle ':vcs_info:*' formats '%r/%S %F{green}[%b]%f'
|
|
|
|
|
|
|
|
#the precmd function, called just before printing the prompt.
|
|
|
|
function precmd() {
|
|
|
|
precmd_vcs
|
|
|
|
}
|
|
|
|
|
|
|
|
#Make the right prompt blank, just to be sure.
|
|
|
|
RPROMPT=
|
|
|
|
|
|
|
|
#on the top line, show a whole bunch of info. botton line should be as minimal as possilbe (just a single char to input next to...)
|
2021-04-03 09:03:10 +02:00
|
|
|
PROMPT=$'%F{cyan}[%n@%m]%f%F{red}├────┤%f${vcs_info_msg_0_}\n»'
|
2020-05-30 00:24:53 +02:00
|
|
|
|
|
|
|
#show dots while waiting for tab-completion
|
|
|
|
expand-or-complete-with-dots() {
|
|
|
|
# toggle line-wrapping off and back on again
|
|
|
|
[[ -n "$terminfo[rmam]" && -n "$terminfo[smam]" ]] && echoti rmam
|
|
|
|
print -Pn "%{%F{red}......%f%}"
|
|
|
|
[[ -n "$terminfo[rmam]" && -n "$terminfo[smam]" ]] && echoti smam
|
|
|
|
|
|
|
|
zle expand-or-complete
|
|
|
|
zle redisplay
|
|
|
|
}
|
|
|
|
zle -N expand-or-complete-with-dots
|
|
|
|
bindkey "^I" expand-or-complete-with-dots
|
|
|
|
|
|
|
|
#misc
|
2018-07-10 11:33:58 +02:00
|
|
|
# Enable the ZLE line editor, which is default behavior, but to be sure
|
|
|
|
setopt ZLE
|
2018-07-17 05:02:50 +02:00
|
|
|
#Enable vi mode for the ZLE. it should be set by default due to our EDITOR and VISUAL, but this is just to be safe.
|
|
|
|
bindkey -v
|
2018-07-10 11:33:58 +02:00
|
|
|
# Sends cd commands without the need for 'cd'
|
|
|
|
setopt AUTO_CD
|
|
|
|
# Kill all child processes when we exit, dont leave them running
|
|
|
|
unsetopt NO_HUP
|
|
|
|
#Allows comments in interactive shell.
|
|
|
|
setopt INTERACTIVE_COMMENTS
|
|
|
|
# Ctrl+S and Ctrl+Q usually disable/enable tty input. This disables those inputs
|
|
|
|
unsetopt FLOW_CONTROL
|
2020-05-30 00:24:53 +02:00
|
|
|
mkdir -p ~/.cache/zsh
|
|
|
|
local zshCache=~/.cache/zsh
|
|
|
|
|
|
|
|
#ZSH history
|
|
|
|
#make a history file outside our home directory
|
|
|
|
HISTFILE=$zshCache/history
|
|
|
|
#save a lot of history
|
|
|
|
SAVEHIST=1000
|
|
|
|
HISTSIZE=1000
|
|
|
|
#save more information in history
|
|
|
|
setopt EXTENDED_HISTORY
|
|
|
|
#share history among zsh sessions
|
|
|
|
setopt APPEND_HISTORY
|
|
|
|
setopt SHARE_HISTORY
|
|
|
|
#skip dupes when going through history
|
|
|
|
setopt HIST_FIND_NO_DUPS
|
|
|
|
#delete dupes first when histsize becomes full
|
|
|
|
setopt HIST_EXPIRE_DUPS_FIRST
|
|
|
|
#dont write dupes of the last command to histfile
|
|
|
|
setopt HIST_IGNORE_DUPS
|
|
|
|
#write history file as we type
|
|
|
|
setopt INC_APPEND_HISTORY
|
|
|
|
#remove extra whitespace from history
|
|
|
|
setopt HIST_REDUCE_BLANKS
|
|
|
|
|
|
|
|
#autocomplete
|
2018-07-10 11:33:58 +02:00
|
|
|
autoload -Uz compinit
|
2020-05-30 00:24:53 +02:00
|
|
|
compinit
|
|
|
|
#have the menu highlight while we cycle through options
|
|
|
|
zstyle ':completion:*' menu select
|
|
|
|
#case insensitive completion
|
|
|
|
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
|
|
|
|
#allow completion from midword
|
|
|
|
setopt COMPLETE_IN_WORD
|
|
|
|
#move cursor to end of word after completing
|
|
|
|
setopt ALWAYS_TO_END
|
|
|
|
#complete aliases as well
|
|
|
|
setopt COMPLETE_ALIASES
|
2020-05-31 18:27:00 +02:00
|
|
|
#select first item when you press tab the first time.
|
|
|
|
setopt MENU_COMPLETE
|
2020-05-30 00:24:53 +02:00
|
|
|
|
|
|
|
#globbing
|
|
|
|
#case insensitive globbing
|
|
|
|
setopt NO_CASE_GLOB
|
|
|
|
#sort globs that expand to numbers by number rather than alphabeticly
|
|
|
|
setopt NUMERIC_GLOB_SORT
|
|
|
|
|
|
|
|
#aliases
|
2021-11-14 18:37:40 +01:00
|
|
|
alias msfconsole="msfconsole --quiet -x \"db_connect ${USER}@msf\""
|
2018-07-10 11:33:58 +02:00
|
|
|
alias vim="nvim"
|
2018-10-15 19:02:44 +02:00
|
|
|
alias vimdiff="nvim -d"
|
2018-07-25 03:35:53 +02:00
|
|
|
alias mutt="neomutt"
|
2021-06-05 20:46:56 +02:00
|
|
|
alias please='sudo $(fc -ln -1)'
|
2020-05-31 18:27:00 +02:00
|
|
|
alias la='ls -la'
|
|
|
|
alias ll='ls -l'
|
2021-06-06 06:10:35 +02:00
|
|
|
alias say='espeak -v default -p 10 -s 150 -a 200 2> /dev/null'
|
2021-10-01 00:59:54 +02:00
|
|
|
alias tmux='tmux -u'
|
2022-01-07 02:53:52 +01:00
|
|
|
# needs to have a number immediately after it.
|
|
|
|
alias slideshow='feh --full-screen --randomize --auto-zoom --recursive --slideshow-delay'
|
2020-05-31 18:27:00 +02:00
|
|
|
|
2018-07-10 11:33:58 +02:00
|
|
|
|
2020-05-30 00:24:53 +02:00
|
|
|
#web searches
|
2018-07-10 11:33:58 +02:00
|
|
|
alias ddg='web_search ddg'
|
|
|
|
alias github='web_search github'
|
|
|
|
alias wiki='web_search ddg \!w'
|
|
|
|
alias news='web_search ddg \!n'
|
|
|
|
alias youtube='web_search ddg \!yt'
|
|
|
|
alias map='web_search ddg \!m'
|
|
|
|
alias image='web_search ddg \!i'
|
|
|
|
|
2020-05-30 00:24:53 +02:00
|
|
|
#setup grep to be a bit more nice
|
2018-07-10 11:33:58 +02:00
|
|
|
local GREP_OPTIONS=""
|
|
|
|
|
|
|
|
# color grep results
|
2020-05-30 00:24:53 +02:00
|
|
|
GREP_OPTIONS+=" --color=auto"
|
2018-07-10 11:33:58 +02:00
|
|
|
|
|
|
|
# ignore VCS folders (if the necessary grep flags are available)
|
|
|
|
local VCS_FOLDERS="{.bzr,CVS,.git,.hg,.svn}"
|
|
|
|
|
2020-05-30 00:24:53 +02:00
|
|
|
GREP_OPTIONS+=" --exclude-dir=$VCS_FOLDERS"
|
|
|
|
GREP_OPTIONS+=" --exclude=$VCS_FOLDERS"
|
2018-07-10 11:33:58 +02:00
|
|
|
|
|
|
|
# export grep settings
|
|
|
|
alias grep="grep $GREP_OPTIONS"
|
2021-03-15 23:42:36 +01:00
|
|
|
|
|
|
|
#fzf stuff
|
2021-03-15 23:49:56 +01:00
|
|
|
#zsh key bindings (different distros put these in different places.)
|
2021-04-03 08:53:27 +02:00
|
|
|
testPath=$(find /usr/share -path '*fzf/*key-bindings.zsh' -print -quit 2> /dev/null)
|
2021-04-07 23:01:08 +02:00
|
|
|
[ -f "$testPath" ] && source $testPath
|
2021-03-15 23:42:36 +01:00
|
|
|
#zsh completions, if it exists.
|
2021-03-16 08:30:07 +01:00
|
|
|
testPath=$(find /usr/share -path '*fzf/*completion.zsh' -print -quit 2> /dev/null)
|
2021-04-07 23:01:08 +02:00
|
|
|
[ -f "$testPath" ] && source $testPath
|