From 8fbacc6392f34dc49546c3064efc9c69fba7c169 Mon Sep 17 00:00:00 2001 From: Derek Taylor Date: Mon, 2 Nov 2020 18:56:51 -0600 Subject: [PATCH] Major edits to my fish config --- .bashrc | 4 + .config/fish/config.fish | 381 +++++++++++++++++++++++++++++++++++++++ .doom.d/aliases | 4 + .doom.d/config.el | 39 +++- .doom.d/config.org | 64 ++++++- .doom.d/init.el | 2 +- .doom.d/packages.el | 2 + 7 files changed, 484 insertions(+), 12 deletions(-) create mode 100644 .config/fish/config.fish diff --git a/.bashrc b/.bashrc index fdc76ad..e6e637d 100644 --- a/.bashrc +++ b/.bashrc @@ -102,6 +102,10 @@ alias .5='cd ../../../../..' alias vim="nvim" alias em="/usr/bin/emacs -nw" alias emacs="emacsclient -c -a 'emacs'" +alias doomsync="~/.emacs.d/bin/doom sync" +alias doomdoctor="~/.emacs.d/bin/doom doctor" +alias doomupgrade="~/.emacs.d/bin/doom upgrade" +alias doompurge="~/.emacs.d/bin/doom purge" # pacman and yay alias pacsyu='sudo pacman -Syyu' # update only standard pkgs diff --git a/.config/fish/config.fish b/.config/fish/config.fish new file mode 100644 index 0000000..c5eab11 --- /dev/null +++ b/.config/fish/config.fish @@ -0,0 +1,381 @@ +# ____ _____ +# | _ \_ _| Derek Taylor (DistroTube) +# | | | || | http://www.youtube.com/c/DistroTube +# | |_| || | http://www.gitlab.com/dwt1/ +# |____/ |_| +# +# My fish config. Not much to see here. Some pretty standard stuff. +set -U fish_user_paths $fish_user_paths $HOME/.local/bin/ +set fish_greeting # Supresses fish's intro message +set TERM "xterm-256color" # Sets the terminal type +set EDITOR "emacsclient -t -a ''" # $EDITOR use Emacs in terminal +set VISUAL "emacsclient -c -a emacs" # $VISUAL use Emacs in GUI mode + + +### PROMPT ### +# This was the 'sashimi' prompt from oh-my-fish. +function fish_prompt + set -l last_status $status + set -l cyan (set_color -o 98be65) + set -l yellow (set_color -o yellow) + set -g red (set_color -o 98be65) + set -g blue (set_color -o blue) + set -l green (set_color -o green) + set -g normal (set_color magenta) + + set -l ahead (_git_ahead) + set -g whitespace ' ' + + if test $last_status = 0 + set initial_indicator "$green◆" + set status_indicator "$normal❯$cyan❯$green❯" + else + set initial_indicator "$red✖ $last_status" + set status_indicator "$red❯$red❯$red❯" + end + set -l cwd $cyan(basename (prompt_pwd)) + + if [ (_git_branch_name) ] + if test (_git_branch_name) = 'master' + set -l git_branch (_git_branch_name) + set git_info "$normal git:($red$git_branch$normal)" + else + set -l git_branch (_git_branch_name) + set git_info "$normal git:($blue$git_branch$normal)" + end + if [ (_is_git_dirty) ] + set -l dirty "$yellow ✗" + set git_info "$git_info$dirty" + end + end + # Notify if a command took more than 5 minutes + if [ "$CMD_DURATION" -gt 300000 ] + echo The last command took (math "$CMD_DURATION/1000") seconds. + end + + echo -n -s $initial_indicator $whitespace $cwd $git_info $whitespace $ahead $status_indicator $whitespace +end + +function _git_ahead + set -l commits (command git rev-list --left-right '@{upstream}...HEAD' ^/dev/null) + if [ $status != 0 ] + return + end + set -l behind (count (for arg in $commits; echo $arg; end | grep '^<')) + set -l ahead (count (for arg in $commits; echo $arg; end | grep -v '^<')) + switch "$ahead $behind" + case '' # no upstream + case '0 0' # equal to upstream + return + case '* 0' # ahead of upstream + echo "$blue↑$normal_c$ahead$whitespace" + case '0 *' # behind upstream + echo "$red↓$normal_c$behind$whitespace" + case '*' # diverged from upstream + echo "$blue↑$normal$ahead $red↓$normal_c$behind$whitespace" + end +end + +function _git_branch_name + echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||') +end + +function _is_git_dirty + echo (command git status -s --ignore-submodules=dirty ^/dev/null) +end + +function fish_mode_prompt + switch $fish_bind_mode + case default + set_color --bold red + echo '(N) ' + case insert + set_color --bold green + echo '(I) ' + case replace_one + set_color --bold green + echo '(R) ' + case visual + set_color --bold brmagenta + echo '(V) ' + case '*' + set_color --bold red + echo '(?) ' + end + set_color normal +end +### END OF PROMPT ### + + +### DEFAULT EMACS MODE OR VI MODE ### +function fish_user_key_bindings + fish_default_key_bindings + # fish_vi_key_bindings +end +### END OF VI MODE ### + + +### SPARK ### +set -g spark_version 1.0.0 + +complete -xc spark -n __fish_use_subcommand -a --help -d "Show usage help" +complete -xc spark -n __fish_use_subcommand -a --version -d "$spark_version" +complete -xc spark -n __fish_use_subcommand -a --min -d "Minimum range value" +complete -xc spark -n __fish_use_subcommand -a --max -d "Maximum range value" + +function spark -d "sparkline generator" + if isatty + switch "$argv" + case {,-}-v{ersion,} + echo "spark version $spark_version" + case {,-}-h{elp,} + echo "usage: spark [--min= --max=] Draw sparklines" + echo "examples:" + echo " spark 1 2 3 4" + echo " seq 100 | sort -R | spark" + echo " awk \\\$0=length spark.fish | spark" + case \* + echo $argv | spark $argv + end + return + end + + command awk -v FS="[[:space:],]*" -v argv="$argv" ' + BEGIN { + min = match(argv, /--min=[0-9]+/) ? substr(argv, RSTART + 6, RLENGTH - 6) + 0 : "" + max = match(argv, /--max=[0-9]+/) ? substr(argv, RSTART + 6, RLENGTH - 6) + 0 : "" + } + { + for (i = j = 1; i <= NF; i++) { + if ($i ~ /^--/) continue + if ($i !~ /^-?[0-9]/) data[count + j++] = "" + else { + v = data[count + j++] = int($i) + if (max == "" && min == "") max = min = v + if (max < v) max = v + if (min > v ) min = v + } + } + count += j - 1 + } + END { + n = split(min == max && max ? "▅ ▅" : "▁ ▂ ▃ ▄ ▅ ▆ ▇ █", blocks, " ") + scale = (scale = int(256 * (max - min) / (n - 1))) ? scale : 1 + for (i = 1; i <= count; i++) + out = out (data[i] == "" ? " " : blocks[idx = int(256 * (data[i] - min) / scale) + 1]) + print out + } + ' +end +### END OF SPARK ### + + +### FUNCTIONS ### +# Spark functions +function letters + cat $argv | awk -vFS='' '{for(i=1;i<=NF;i++){ if($i~/[a-zA-Z]/) { w[tolower($i)]++} } }END{for(i in w) print i,w[i]}' | sort | cut -c 3- | spark | lolcat + printf '%s\n' 'abcdefghijklmnopqrstuvwxyz' ' ' | lolcat +end + +function commits + git log --author="$argv" --format=format:%ad --date=short | uniq -c | awk '{print $1}' | spark | lolcat +end + +# Functions needed for !! and !$ +# Will only work in default (emacs) mode. +# Will NOT work in vi mode. +function __history_previous_command + switch (commandline -t) + case "!" + commandline -t $history[1]; commandline -f repaint + case "*" + commandline -i ! + end +end + +function __history_previous_command_arguments + switch (commandline -t) + case "!" + commandline -t "" + commandline -f history-token-search-backward + case "*" + commandline -i '$' + end +end +# The bindings for !! and !$ +bind ! __history_previous_command +bind '$' __history_previous_command_arguments + +# Function for creating a backup file +# ex: backup file.txt +# result: copies file as file.txt.bak +function backup --argument filename + cp $filename $filename.bak +end + +# Function for copying files and directories, even recursively. +# ex: copy DIRNAME LOCATIONS +# result: copies the directory and all of its contents. +function copy + set count (count $argv | tr -d \n) + if test "$count" = 2; and test -d "$argv[1]" + set from (echo $argv[1] | trim-right /) + set to (echo $argv[2]) + command cp -r $from $to + else + command cp $argv + end +end + +# Function for printing a column (splits input on whitespace) +# ex: echo 1 2 3 | coln 3 +# output: 3 +function coln + while read -l input + echo $input | awk '{print $'$argv[1]'}' + end +end + +# Function for printing a row +# ex: seq 3 | rown 3 +# output: 3 +function rown --argument index + sed -n "$index p" +end + +# Function for ignoring the first 'n' lines +# ex: seq 10 | skip 5 +# results: prints everything but the first 5 lines +function skip --argument n + tail +(math 1 + $n) +end + +# Function for taking the first 'n' lines +# ex: seq 10 | take 5 +# results: prints only the first 5 lines +function take --argument number + head -$number +end +### END OF FUNCTIONS ### + + +### ALIASES ### +# spark aliases +alias clear='clear; echo; echo; seq 1 (tput cols) | sort -R | spark | lolcat; echo; echo' + +# root privileges +alias doas="doas --" + +# navigation +alias ..='cd ..' +alias ...='cd ../..' +alias .3='cd ../../..' +alias .4='cd ../../../..' +alias .5='cd ../../../../..' + +# vim and emacs +alias vim='nvim' +alias em='/usr/bin/emacs -nw' +alias emacs="emacsclient -c -a 'emacs'" +alias doomsync="~/.emacs.d/bin/doom sync" +alias doomdoctor="~/.emacs.d/bin/doom doctor" +alias doomupgrade="~/.emacs.d/bin/doom upgrade" +alias doompurge="~/.emacs.d/bin/doom purge" + +# broot +alias br='broot -dhp' +alias bs='broot --sizes' + +# Changing "ls" to "exa" +alias ls='exa -al --color=always --group-directories-first' # my preferred listing +alias la='exa -a --color=always --group-directories-first' # all files and dirs +alias ll='exa -l --color=always --group-directories-first' # long format +alias lt='exa -aT --color=always --group-directories-first' # tree listing + +# pacman and yay +alias pacsyu='sudo pacman -Syyu' # update only standard pkgs +alias yaysua='yay -Sua --noconfirm' # update only AUR pkgs +alias yaysyu='yay -Syu --noconfirm' # update standard pkgs and AUR pkgs +alias unlock='sudo rm /var/lib/pacman/db.lck' # remove pacman lock +alias cleanup='sudo pacman -Rns (pacman -Qtdq)' # remove orphaned packages + +# get fastest mirrors +alias mirror="sudo reflector -f 30 -l 30 --number 10 --verbose --save /etc/pacman.d/mirrorlist" +alias mirrord="sudo reflector --latest 50 --number 20 --sort delay --save /etc/pacman.d/mirrorlist" +alias mirrors="sudo reflector --latest 50 --number 20 --sort score --save /etc/pacman.d/mirrorlist" +alias mirrora="sudo reflector --latest 50 --number 20 --sort age --save /etc/pacman.d/mirrorlist" + +# Colorize grep output (good for log files) +alias grep='grep --color=auto' +alias egrep='egrep --color=auto' +alias fgrep='fgrep --color=auto' + +# confirm before overwriting something +alias cp="cp -i" +alias mv='mv -i' +alias rm='rm -i' + +# adding flags +alias df='df -h' # human-readable sizes +alias free='free -m' # show sizes in MB +alias lynx='lynx -cfg=~/.lynx/lynx.cfg -lss=~/.lynx/lynx.lss -vikeys' +alias vifm='./.config/vifm/scripts/vifmrun' + +## get top process eating memory +alias psmem='ps auxf | sort -nr -k 4' +alias psmem10='ps auxf | sort -nr -k 4 | head -10' + +## get top process eating cpu ## +alias pscpu='ps auxf | sort -nr -k 3' +alias pscpu10='ps auxf | sort -nr -k 3 | head -10' + +# shutdown or reboot +alias ssn="sudo shutdown now" +alias sr="sudo reboot" + +# Merge Xresources +alias merge='xrdb -merge ~/.Xresources' + +# get error messages from journalctl +alias jctl="journalctl -p 3 -xb" + +# gpg encryption +# verify signature for isos +alias gpg-check="gpg2 --keyserver-options auto-key-retrieve --verify" +# receive the key of a developer +alias gpg-retrieve="gpg2 --keyserver-options auto-key-retrieve --receive-keys" + +# youtube-dl +alias yta-aac="youtube-dl --extract-audio --audio-format aac " +alias yta-best="youtube-dl --extract-audio --audio-format best " +alias yta-flac="youtube-dl --extract-audio --audio-format flac " +alias yta-m4a="youtube-dl --extract-audio --audio-format m4a " +alias yta-mp3="youtube-dl --extract-audio --audio-format mp3 " +alias yta-opus="youtube-dl --extract-audio --audio-format opus " +alias yta-vorbis="youtube-dl --extract-audio --audio-format vorbis " +alias yta-wav="youtube-dl --extract-audio --audio-format wav " +alias ytv-best="youtube-dl -f bestvideo+bestaudio " + +# switch between shells +alias tobash="sudo chsh $USER -s /bin/bash && echo 'Now log out.'" +alias tozsh="sudo chsh $USER -s /bin/zsh && echo 'Now log out.'" +alias tofish="sudo chsh $USER -s /bin/fish && echo 'Now log out.'" + +# the terminal rickroll +alias rr='curl -s -L https://raw.githubusercontent.com/keroserene/rickrollrc/master/roll.sh | bash' + +# bare git repo alias for dotfiles +alias config="/usr/bin/git --git-dir=$HOME/dotfiles --work-tree=$HOME" + +# termbin +alias tb="nc termbin.com 9999" + +# force all kakoune windows into one session +alias kak="/usr/bin/kak -c mysession" +alias kaks="/usr/bin/kak -s mysession" +alias kakd="/usr/bin/kak -d -s mysession &" + +### RANDOM COLOR SCRIPT ### +# Get this script from my GitLab: gitlab.com/dwt1/shell-color-scripts +# Or install it from the Arch User Repository: shell-color-scripts +/opt/shell-color-scripts/colorscript.sh random diff --git a/.doom.d/aliases b/.doom.d/aliases index 10f0915..1991d0d 100644 --- a/.doom.d/aliases +++ b/.doom.d/aliases @@ -1,2 +1,6 @@ alias ls exa -al --color=always --group-directories-first alias ff find-file $1 +alias doomsync ~/.emacs.d/bin/doom sync +alias doomdoctor ~/.emacs.d/bin/doom doctor +alias doomupgrade ~/.emacs.d/bin/doom upgrade +alias doompurge ~/.emacs.d/bin/doom purge diff --git a/.doom.d/config.el b/.doom.d/config.el index b1c9dea..d3f4af6 100644 --- a/.doom.d/config.el +++ b/.doom.d/config.el @@ -15,10 +15,10 @@ (map! :leader :desc "Toggle tabs on/off" "t c" #'centaur-tabs-local-mode) -(evil-define-key 'normal centaur-tabs-mode-map (kbd "g ") 'centaur-tabs-forward ; default Doom binding is 'g t' - (kbd "g ") 'centaur-tabs-backward ; default Doom binding is 'g T' - (kbd "g ") 'centaur-tabs-forward-group - (kbd "g ") 'centaur-tabs-backward-group) +(evil-define-key 'normal centaur-tabs-mode-map (kbd "g ") 'centaur-tabs-forward ; default Doom binding is 'g t' + (kbd "g ") 'centaur-tabs-backward ; default Doom binding is 'g T' + (kbd "g ") 'centaur-tabs-forward-group + (kbd "g ") 'centaur-tabs-backward-group) (map! :leader :desc "Dired" @@ -128,6 +128,25 @@ '(font-lock-comment-face :slant italic) '(font-lock-keyword-face :slant italic)) +(require 'ivy-posframe) +(setq ivy-posframe-display-functions-alist + '((swiper . ivy-posframe-display-at-point) + (complete-symbol . ivy-posframe-display-at-point) + (counsel-M-x . ivy-display-function-fallback) + (counsel-esh-history . ivy-posframe-display-at-window-center) + (counsel-describe-function . ivy-display-function-fallback) + (counsel-describe-variable . ivy-display-function-fallback) + (counsel-find-file . ivy-display-function-fallback) + (counsel-recentf . ivy-display-function-fallback) + (counsel-register . ivy-posframe-display-at-frame-bottom-window-center) + (dmenu . ivy-posframe-display-at-frame-top-center) + (nil . ivy-posframe-display)) + ivy-posframe-height-alist + '((swiper . 20) + (dmenu . 20) + (t . 10))) +(ivy-posframe-mode 1) ; 1 enables posframe-mode, 0 disables it. + (map! :leader :desc "Ivy push view" "v p" #'ivy-push-view @@ -273,7 +292,17 @@ "\\ n" #'(lambda () (interactive) (find-file "/scp:derek@distrotube.net"))) (setq shell-file-name "/bin/fish" - eshell-aliases-file "~/.doom.d/aliases") + eshell-aliases-file "~/.doom.d/aliases" + eshell-history-size 5000 + eshell-buffer-maximum-lines 5000 + eshell-hist-ignoredups t + eshell-scroll-to-bottom-on-input t + eshell-destroy-buffer-when-process-dies t + eshell-visual-commands'("bash" "fish" "htop" "ssh" "zsh") + vterm-max-scrollback 5000) +(map! :leader + :desc "Counsel eshell history" + "e h" #'counsel-esh-history) (defun prefer-horizontal-split () (set-variable 'split-height-threshold nil t) diff --git a/.doom.d/config.org b/.doom.d/config.org index 2fc46ad..08dbdc3 100644 --- a/.doom.d/config.org +++ b/.doom.d/config.org @@ -15,6 +15,8 @@ - [[#eww][EWW]] - [[#fonts][FONTS]] - [[#ivy][IVY]] + - [[#ivy-posframe][IVY-POSFRAME]] + - [[#ivy-keybindings][IVY KEYBINDINGS]] - [[#line-settings][LINE SETTINGS]] - [[#manpages][MANPAGES]] - [[#mastodon][MASTODON]] @@ -67,10 +69,10 @@ To use tabs in Doom Emacs, be sure to uncomment "tabs" in Doom's init.el. Displ (map! :leader :desc "Toggle tabs on/off" "t c" #'centaur-tabs-local-mode) -(evil-define-key 'normal centaur-tabs-mode-map (kbd "g ") 'centaur-tabs-forward ; default Doom binding is 'g t' - (kbd "g ") 'centaur-tabs-backward ; default Doom binding is 'g T' - (kbd "g ") 'centaur-tabs-forward-group - (kbd "g ") 'centaur-tabs-backward-group) +(evil-define-key 'normal centaur-tabs-mode-map (kbd "g ") 'centaur-tabs-forward ; default Doom binding is 'g t' + (kbd "g ") 'centaur-tabs-backward ; default Doom binding is 'g T' + (kbd "g ") 'centaur-tabs-forward-group + (kbd "g ") 'centaur-tabs-backward-group) #+END_SRC * DIRED @@ -247,7 +249,47 @@ Settings related to fonts within Doom Emacs: #+END_SRC * IVY -Ivy is a generic completion mechanism for Emacs. By default, Doom Emacs does not use 'SPC v', so the format I use for these bindings is 'SPC v' plus 'key'. +Ivy is a generic completion mechanism for Emacs. + +** IVY-POSFRAME +Ivy-posframe is an ivy extension, which lets ivy use posframe to show its candidate menu. Some of the settings below involve: ++ ivy-posframe-display-functions-alist -- sets the display position for specific programs ++ ivy-posframe-height-alist -- sets the height of the list displayed for specific programs + +Available functions (positions) for 'ivy-posframe-display-functions-alist' ++ ivy-posframe-display-at-frame-center ++ ivy-posframe-display-at-window-center ++ ivy-posframe-display-at-frame-bottom-left ++ ivy-posframe-display-at-window-bottom-left ++ ivy-posframe-display-at-frame-bottom-window-center ++ ivy-posframe-display-at-point ++ ivy-posframe-display-at-frame-top-center + +=NOTE:= If the setting for 'ivy-posframe-display' is set to 'nil' (false), anything that is set to 'ivy-display-function-fallback' will just default to their normal position in Doom Emacs (usually a bottom split). However, if this is set to 't' (true), then the fallback position will be centered in the window. + +#+BEGIN_SRC emacs-lisp +(require 'ivy-posframe) +(setq ivy-posframe-display-functions-alist + '((swiper . ivy-posframe-display-at-point) + (complete-symbol . ivy-posframe-display-at-point) + (counsel-M-x . ivy-display-function-fallback) + (counsel-esh-history . ivy-posframe-display-at-window-center) + (counsel-describe-function . ivy-display-function-fallback) + (counsel-describe-variable . ivy-display-function-fallback) + (counsel-find-file . ivy-display-function-fallback) + (counsel-recentf . ivy-display-function-fallback) + (counsel-register . ivy-posframe-display-at-frame-bottom-window-center) + (dmenu . ivy-posframe-display-at-frame-top-center) + (nil . ivy-posframe-display)) + ivy-posframe-height-alist + '((swiper . 20) + (dmenu . 20) + (t . 10))) +(ivy-posframe-mode 1) ; 1 enables posframe-mode, 0 disables it. +#+END_SRC + +** IVY KEYBINDINGS +By default, Doom Emacs does not use 'SPC v', so the format I use for these bindings is 'SPC v' plus 'key'. #+BEGIN_SRC emacs-lisp (map! :leader @@ -478,7 +520,17 @@ Settings for the various shells and terminal emulators within Emacs. #+BEGIN_SRC emacs-lisp (setq shell-file-name "/bin/fish" - eshell-aliases-file "~/.doom.d/aliases") + eshell-aliases-file "~/.doom.d/aliases" + eshell-history-size 5000 + eshell-buffer-maximum-lines 5000 + eshell-hist-ignoredups t + eshell-scroll-to-bottom-on-input t + eshell-destroy-buffer-when-process-dies t + eshell-visual-commands'("bash" "fish" "htop" "ssh" "zsh") + vterm-max-scrollback 5000) +(map! :leader + :desc "Counsel eshell history" + "e h" #'counsel-esh-history) #+END_SRC * SPLITS diff --git a/.doom.d/init.el b/.doom.d/init.el index 47cb537..2bc6e34 100644 --- a/.doom.d/init.el +++ b/.doom.d/init.el @@ -25,7 +25,7 @@ company ; the ultimate code completion backend ;;helm ; the *other* search engine for love and life ;;ido ; the other *other* search engine... - ivy ; a search engine for love and life + (ivy +fuzzy) ; a search engine for love and life :ui ;;deft ; notational velocity for Emacs diff --git a/.doom.d/packages.el b/.doom.d/packages.el index 91ad137..52f9a0d 100644 --- a/.doom.d/packages.el +++ b/.doom.d/packages.el @@ -53,6 +53,7 @@ (package! emms) (package! emojify) (package! evil-tutor) +(package! ivy-posframe) (package! mastodon) (package! md4rd) (package! org-bullets) @@ -60,5 +61,6 @@ (package! rainbow-mode) (package! sublimity) (package! tldr) +(package! virtualenvwrapper) (package! wc-mode) (package! writeroom-mode)