diff --git a/apps/shell/bash/bashrc b/apps/shell/bash/rc similarity index 98% rename from apps/shell/bash/bashrc rename to apps/shell/bash/rc index 137550e..38c4f7f 100644 --- a/apps/shell/bash/bashrc +++ b/apps/shell/bash/rc @@ -17,7 +17,6 @@ NICE_HOME="$HOME" [[ -e "${EDFP}/.nice_home" ]] && NICE_HOME="$(cat "${EDFP}/.nice_home")" export NICE_HOME -export NOTES_DIR="$NICE_HOME/doc/notes" # set our PATH source "$DOTFILES_PATH/apps/shell/bash/paths" diff --git a/apps/shell/fish/aliases.fish b/apps/shell/fish/aliases.fish new file mode 100644 index 0000000..6d053d3 --- /dev/null +++ b/apps/shell/fish/aliases.fish @@ -0,0 +1,164 @@ +#!/usr/bin/env fish + +# ls aliases +alias lx 'ls -lXB' # order by filetype +alias lk 'ls -lSr' # order by filesize reversed +alias lt 'ls -ltr' # order by file modified time +alias lc 'ls -ltcr' # order by filectime +alias lu 'ls -ltur' # order by file access time +alias ls 'ls -h --color --group-directories-first' # flat view w/ directories first +alias l 'ls -h --color --group-directories-first' # same as above +alias ll 'ls -lv --group-directories-first' # non-flat view +alias lm 'll | more' +alias lr 'll -R' # please don't - why is this even here...? +alias la 'll -A' # show all + +# other file aliases +alias tree 'tree -Csuh' +alias f fzf +alias cp 'rsync -ah --progress' + +# gets the newest file in the current directory (or the specified directory +# if one is provided) +function ltl + set d $argv[1] . + set -l l "" + for f in $d[1]/* + if test -z $l; set l $f; continue; end + if command test $f -nt $l; and test ! -d $f + set l $f + end + end + echo $l +end + +function ltld + set d $argv[1] . + set -l l "" + for f in $d[1]/* + if test -z $l; set l $f; continue; end + if command test $f -nt $l; and test -d $f + set l $f + end + end + echo $l +end + +alias vltl "vim (ltl)" +alias cdltl "cd (ltld)" +alias ltlv vltl + +# navigation aliases +function c + if count $argv + cd $NICE_HOME && cd $argv[1] || exit 1 + else + cd $NICE_HOME || exit 1 + end +end +alias cd.. "cd .." +alias cdd "cd $DOTFILES_PATH" # go to dotfiles +alias cde "cd $ENV_DOTFILES_PATH" # go to env dotfiles +alias cdc "cd $XDG_CONFIG_HOME" # go to ~/.config +alias cdn "cd $NOTES_PATH" +alias cdl "cd $NICE_HOME/dl" +alias cdg "cd $NICE_HOME/games" + +# quick parent-directory aliases +alias .. "cd .." +alias ... "cd ../.." +alias .... "cd ../../.." +alias ..... "cd ../../../.." +alias ...... "cd ../../../../.." +alias ....... "cd ../../../../../.." +alias ........ "cd ../../../../../../.." +alias ......... "cd ../../../../../../../.." + +# tmux aliases +# TODO: see if this can be worked around? +alias tmux 'env TERM=screen-256color-bce tmux' # syntax higlighting for vim in tmux +alias tmnew "tmux new -s" +alias tmls "tmux list-sessions" +alias tmatt "tmux attach -t" +alias tu "tmux attach -t utils || tmux new -s utils" +alias tdf "tmux attach -t dotfiles || tmux new -s dotfiles -c $DOTFILES_PATH" +alias tmon "tmux attach -t monitoring || tmux new -s monitoring" +alias tcom "tmux attach -t comms || tmux new -s comms" +alias tn "tmux attach -t notes || tmux new -s notes -c $NOTES_PATH" +alias tm "tmux attach -t music || tmux new -s music" + +# git aliases +# TODO: make these git aliases in the gitconfig? +function g + if count $argv >/dev/null + git $argv + else + git status + end +end +alias gs "git status" +alias gd "git diff" +alias gds "git diff --staged" +# alias gdv "git dv" # TODO: what is this? +alias gpl "git pull" +alias gp "git push" +alias gpa "git push --all && git push --tags" +alias gpt "git push && git push --tags" +alias gpf "git push --force-with-lease" +alias gac "git add -A && git commit" +alias gacnv "git add -A && git commit --no-verify" +alias gsur "git submodule update --remote" +alias glf "git ls-files" +alias gl "git log --pretty=format:\"%h %ad%x09%an%x09%s\" --date=short" + +# docker aliases +alias dlf "docker logs --tail=500 -f" +alias dclf "docker-compose logs --tail=500 -f" +alias ctop "docker run --rm -ti -v /var/run/docker.sock:/var/run/docker.sock quay.io/vektorlab/ctop:latest" + +# misc aliases +alias p "ping 8.8.8.8" +alias C "clear && clear" +alias r "ranger" +alias rn "/usr/bin/watch -n 1" +alias sctl "sudo systemctl" +alias sctlu "systemctl --user" +alias logs "sudo journalctl" +alias logsr "sudo journalctl -r" +alias logsf "sudo journalctl -f" +alias bt "sudo bluetoothctl" +alias btctl "bt" +alias btctl "sudo bluetoothctl" +alias pbcopy "clip" +alias pt "htop -t" # experimental htop tree-view-by-default +alias resrc "source $HOME/.bashrc" +alias redshift "redshift -r -l 39.0997:-94.5786 -t 6500K:2500K" +alias gpmdpe "electron --app=/usr/share/gpmdp/resources/app.asar" +alias t "task" +alias sc "sc-im" +alias scs "sc-im $NOTES_PATH/_scratch.sc" +alias disks "lsblk && df -h" +alias dd "dd status=progress" +alias wifi "sudo nmtui" +alias year 'cal (date +%Y)' +alias y year + +# games aliases +# this sometimes fixes steam dynamic library issues? +alias lsteam "env LD_PRELOAD='/usr/$LIB/libstdc++.so.6 /usr/$LIB/libgcc_s.so.1 /usr/$LIB/libxcb.so.1 /usr/$LIB/libgpg-error.so' steam" + +# override the man commands with vim +alias _man "\\man" +alias man "vman" + +# neomutt is better +alias mutt "neomutt" + +# fsw aliases +alias fsw-mix-test 'fsw "mix test" ./**/*.{ex,exs,erl,hrl,xrl,yrl}' + +# weechat aliases +function chat + set -l pass (pass weechat-passphrase | head -n 1) + env WEECHAT_PASSPHRASE $pass weechat +end diff --git a/apps/shell/fish/colors.fish b/apps/shell/fish/colors.fish new file mode 100755 index 0000000..992915b --- /dev/null +++ b/apps/shell/fish/colors.fish @@ -0,0 +1,28 @@ +#!/usr/bin/env fish + +set -U fish_color_autosuggestion 555\x1ebrblack +set -U fish_color_cancel \x2dred +set -U fish_color_command white +set -U fish_color_comment brblack +set -U fish_color_cwd magenta +set -U fish_color_cwd_root red +set -U fish_color_end green +set -U fish_color_error red +set -U fish_color_escape yellow +set -U fish_color_history_current white +set -U fish_color_host normal +set -U fish_color_match \x2d\x2dbackground\x3dbrblue +set -U fish_color_normal normal +set -U fish_color_operator blue +set -U fish_color_param white +set -U fish_color_quote yellow +set -U fish_color_redirection blue +set -U fish_color_search_match bryellow\x1e\x2d\x2dbackground\x3dbrblack +set -U fish_color_selection white\x1e\x2d\x2dbackground\x3dbrblack +set -U fish_color_user blue +set -U fish_color_valid_path \x2d\x2dunderline + +set -U fish_pager_color_completion \x1d +set -U fish_pager_color_description yellow\x1eyellow +set -U fish_pager_color_prefix white\x1e\x2d\x2dunderline +set -U fish_pager_color_progress brwhite\x1e\x2d\x2dbackground\x3dcyan diff --git a/apps/shell/fish/config.fish b/apps/shell/fish/config.fish new file mode 100644 index 0000000..a8a4eb9 --- /dev/null +++ b/apps/shell/fish/config.fish @@ -0,0 +1,62 @@ +set -U XDG_CONFIG_HOME "$HOME/.config" +set -U DOTFILES_PATH "$XDG_CONFIG_HOME/dotfiles" +set -U ENV_DOTFILES_PATH "$DOTFILES_PATH/env" +set -U EDFP "$ENV_DOTFILES_PATH" + +# TODO: better logic for auto-detecting alternative home directories? +# 1. check dirname(basename $HOME)) matches username +# 2. check if /home/$username +set -U NICE_HOME $HOME +test (basename $HOME) = .home && set -U NICE_HOME (realpath $HOME/..) +test -e $HOME/.nice_home && set -U NICE_HOME (cat $HOME/.nice_home) +test -e $EDFP/.nice_home && set -U NICE_HOME (cat $EDFP/.nice_home) + +# setup paths +source $DOTFILES_PATH/apps/shell/fish/paths.fish + +# stop parsing here on a non-interactive shell +status --is-interactive || exit + +# TODO: autocompletions? +# TODO: ctrl-r history fzf +# TODO: ctrl-p files fzf +# TODO: forever history ignoring certain commands +# TODO: per-env configuration + +source $DOTFILES_PATH/apps/shell/fish/key-bindings.fish +source $DOTFILES_PATH/apps/shell/fish/colors.fish +source $DOTFILES_PATH/apps/shell/fish/prompt.fish +source $DOTFILES_PATH/apps/shell/fish/aliases.fish + +set -U _JAVA_AWT_WM_NONREPARENTING 1 +set -U LS_COLORS 'ow=01;36;40' +set -U LESS -x2 # less tab size of 2 spaces +set -U TERMINAL urxvtc +set -U BROWSER firefox-developer-edition +set -U ERL_AFLAGS "-kernel shell_history enabled -kernel shell_history_file_bytes 1024000" # iex history + +# set our EDITOR to neovim if we've got it +set -U EDITOR vim +if command -v nvim 2>&1 >/dev/null + alias vim nvim + alias ovim 'command vim' + set -U EDITOR nvim +end + +_make_paths + +command -v fd 2>&1 >/dev/null && set -U FZF_DEFAULT_COMMAND 'fd --type f --hidden --follow --exclude .git' + +# we assume the user uses "$HOME" to just store their mess of dotfiles and other +# nonsense that clutters it up and that they have a preferred starting +# directory where they keep the stuff they actually care about +# we only do this if the user is opening a shell at $HOME +test $PWD = $HOME && cd $NICE_HOME || cd || exit + +test -f ~/.fzf/shell/key-bindings.fish && source ~/.fzf/shell/key-bindings.fish + +if test -d $HOME/.asdf/; and test -f $HOME/.asdf/asdf.sh + source $HOME/.asdf/asdf.sh +else if test -d /opt/asdf-vm/; and test -f /opt/asdf-vm/asdf.sh + source $HOME/opt/asdf-vm/asdf.sh +end diff --git a/apps/shell/fish/fish_variables b/apps/shell/fish/fish_variables new file mode 100644 index 0000000..59e06f1 --- /dev/null +++ b/apps/shell/fish/fish_variables @@ -0,0 +1,47 @@ +# This file contains fish universal variable definitions. +# VERSION: 3.0 +SETUVAR BROWSER:firefox\x2ddeveloper\x2dedition +SETUVAR --path DOTFILES_PATH:/home/daniel/\x2ehome/\x2econfig/dotfiles +SETUVAR EDFP:/home/daniel/\x2ehome/\x2econfig/dotfiles/\x2eenv +SETUVAR EDITOR:nvim +SETUVAR --path ENV_DOTFILES_PATH:/home/daniel/\x2ehome/\x2econfig/dotfiles/env +SETUVAR ERL_AFLAGS:\x2dkernel\x20shell_history\x20enabled\x20\x2dkernel\x20shell_history_file_bytes\x201024000 +SETUVAR FZF_DEFAULT_COMMAND:fd\x20\x2d\x2dtype\x20f\x20\x2d\x2dhidden\x20\x2d\x2dfollow\x20\x2d\x2dexclude\x20\x2egit +SETUVAR LESS:\x2dx2 +SETUVAR LS_COLORS:ow\x3d01\x3b36\x3b40 +SETUVAR NICE_HOME:/home/daniel +SETUVAR --path NOTES_PATH:/home/daniel/doc/notes +SETUVAR TERMINAL:urxvtc +SETUVAR XDG_CONFIG_HOME:/home/daniel/\x2ehome/\x2econfig +SETUVAR _JAVA_AWT_WM_NONREPARENTING:1 +SETUVAR __fish_init_2_39_8:\x1d +SETUVAR __fish_init_2_3_0:\x1d +SETUVAR __fish_init_3_x:\x1d +SETUVAR fish_color_autosuggestion:555\x1ebrblack +SETUVAR fish_color_cancel:\x2dred +SETUVAR fish_color_command:white +SETUVAR fish_color_comment:brblack +SETUVAR fish_color_cwd:magenta +SETUVAR fish_color_cwd_root:red +SETUVAR fish_color_end:green +SETUVAR fish_color_error:red +SETUVAR fish_color_escape:yellow +SETUVAR fish_color_history_current:white +SETUVAR fish_color_host:normal +SETUVAR fish_color_match:\x2d\x2dbackground\x3dbrblue +SETUVAR fish_color_normal:normal +SETUVAR fish_color_operator:blue +SETUVAR fish_color_param:white +SETUVAR fish_color_quote:yellow +SETUVAR fish_color_redirection:blue +SETUVAR fish_color_search_match:bryellow\x1e\x2d\x2dbackground\x3dbrblack +SETUVAR fish_color_selection:white\x1e\x2d\x2dbackground\x3dbrblack +SETUVAR fish_color_user:blue +SETUVAR fish_color_valid_path:\x2d\x2dunderline +SETUVAR fish_greeting:Welcome\x20to\x20fish\x2c\x20the\x20friendly\x20interactive\x20shell +SETUVAR fish_key_bindings:fish_vi_key_bindings +SETUVAR fish_pager_color_completion:\x1d +SETUVAR fish_pager_color_description:yellow\x1eyellow +SETUVAR fish_pager_color_prefix:white\x1e\x2d\x2dunderline +SETUVAR fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan +SETUVAR fish_user_paths:/home/daniel/\x2ehome/\x2elocal/bin\x1e/home/daniel/\x2ehome/\x2elocal/bin\x1e/home/daniel/\x2ehome/\x2elocal/bin\x1e/home/daniel/\x2ehome/\x2ego\x1e/home/daniel/\x2ehome/\x2ego/bin\x1e/home/daniel/\x2ehome/\x2econfig/dotfiles/bin\x1e/home/daniel/\x2ehome/\x2econfig/dotfiles/\x2eenv/bin\x1e/home/daniel/\x2ehome/\x2ebin\x1e/home/daniel/\x2ehome/\x2ecargo/bin\x1e/home/daniel/\x2ehome/\x2eyarn/bin diff --git a/apps/shell/fish/key-bindings.fish b/apps/shell/fish/key-bindings.fish new file mode 100755 index 0000000..f6705c5 --- /dev/null +++ b/apps/shell/fish/key-bindings.fish @@ -0,0 +1,17 @@ +#!/usr/bin/env fish + +function fish_user_key_bindings + fish_vi_key_bindings + fzf_key_bindings + + set vi_esc "if commandline -P; commandline -f cancel; else; set fish_bind_mode default; commandline -f backward-char force-repaint; end" + bind -M insert jk $vi_esc + bind -M insert Jk $vi_esc + bind -M insert JK $vi_esc + bind -M insert jj $vi_esc + bind -M insert Jj $vi_esc + bind -M insert JJ $vi_esc + bind -M insert JJ $vi_esc + + bind -M insert \cf 'fzf-cd-widget' +end diff --git a/apps/shell/fish/paths.fish b/apps/shell/fish/paths.fish new file mode 100644 index 0000000..ccb3c33 --- /dev/null +++ b/apps/shell/fish/paths.fish @@ -0,0 +1,12 @@ +#!/usr/bin/env fish + +set -U fish_user_paths $HOME/.go $GOPATH/bin $DOTFILES_PATH/bin $EDFP/bin $HOME/.bin $HOME/.cargo/bin $HOME/.yarn/bin +test -d $HOME/.local/bin && set -U fish_user_paths $HOME/.local/bin $fish_user_paths +test -d $HOME/.bin && set -U fish_user_paths $HOME/.local/bin $fish_user_paths + +command -v python 2>&1 >/dev/null && set -U fish_user_paths (python -m site --user-base)"/bin" $fish_user_paths +command -v ruby 2>&1 >/dev/null && set -U fish_user_paths (ruby -e 'print Gem.user_dir')"/bin" $fish_user_paths + +set -U NOTES_PATH $NICE_HOME/doc/notes + +function _make_paths; mkdir -p $NOTES_PATH; end diff --git a/apps/shell/fish/prompt.fish b/apps/shell/fish/prompt.fish new file mode 100644 index 0000000..e3bd8b0 --- /dev/null +++ b/apps/shell/fish/prompt.fish @@ -0,0 +1,43 @@ +#!/usr/bin/env fish + +# TODO: if root, background instead? + +set MAX_PATH_PIECE_CHARS $BASH_PROMPT_MAX_PATH_PIECE_CHARS 3 + +# prompt rendering functions +function preprocess_pwd + test (pwd) = / && echo "/" && return 1 + test (pwd) = $NICE_HOME && echo "~" && return 0 + # with ellipsis + #echo "$(<<< "$p" cut -c2- | awk '{split($0,p,"/");for(k in p){if(k==length(p)){printf "/%s",p[k]}else{if(length(p[k])>'"$((MAX_PATH_PIECE_CHARS+1))"'){printf "/%.'"$((MAX_PATH_PIECE_CHARS))"'s…",p[k]}else{printf "/%s",p[k]}}}}')" + # without ellipsis + echo (pwd) | cut -c2- | awk '{split($0,p,"/");for(k in p){if(k==length(p)){printf "/%s",p[k]}else{printf "/%.'$MAX_PATH_PIECE_CHARS[1]'s",p[k]}}}' +end + +function fish_prompt + if test $status -eq 0 + set_color blue + else + set_color red + end + printf $USER"@"$hostname" " + set_color magenta + printf (preprocess_pwd)" " +end + +function fish_mode_prompt + set_color brblack + switch $fish_bind_mode + case default + echo 'N' + case insert + echo 'I' + case replace_one + echo 'R' + case replace + echo 'R' + case visual + echo 'V' + end + echo -n ' ' + end diff --git a/setup b/setup index 5ff2e5f..aa48de4 100755 --- a/setup +++ b/setup @@ -45,10 +45,11 @@ links=( "$dfp/bin/lib/colors/xresources" "$HOME/.Xresources.colors" # shell files - "$dfp/apps/shell/bash/bashrc" "$HOME/.bashrc" + "$dfp/apps/shell/bash/rc" "$HOME/.bashrc" "$dfp/apps/shell/bash/bash_profile" "$HOME/.bash_profile" "$dfp/apps/shell/tmux/tmux.conf" "$HOME/.tmux.conf" "$dfp/apps/shell/tmux/layouts" "$HOME/.tmux/layouts" + "$dfp/apps/shell/fish/" "$XDG_CONFIG_HOME/fish" # text editor files "$dfp/apps/neovim/" "$XDG_CONFIG_HOME/nvim"