Lots of stuff. Working on refactoring

This commit is contained in:
Thomas Loven
2017-10-14 09:47:18 +02:00
parent 8230d22739
commit 1b5423997e
23 changed files with 620 additions and 12 deletions

20
fish/config.fish Executable file
View File

@@ -0,0 +1,20 @@
if test "$SHLVL" -le 1
set -x DOTFILES {$HOME}/dotfiles
set -x PATH /usr/local/bin /usr/local/sbin $PATH
set -x PATH $DOTFILES/bin $PATH
if test -d $HOME/bin
set -x PATH $HOME/bin $PATH
end
set -x PATH . $PATH
set -x FISH_SETUP_PATH 'yes'
end
set -x LANG sv_SE.UTF-8
set -x LC_ALL sv_SE.UTF-8
set -x EDITOR nvim
alias v nvim
eval (python3 -m virtualfish)

6
fish/functions/bubu.fish Executable file
View File

@@ -0,0 +1,6 @@
function bubu --description="Update, upgrade and clean up homebrew packages"
brew update
and brew outdated
and brew upgrade
and brew cleanup
end

View File

@@ -0,0 +1,4 @@
function fish_greeting
end

29
fish/functions/fish_prompt.fish Executable file
View File

@@ -0,0 +1,29 @@
function fish_prompt
set -l status_copy $status
if set -q VIRTUAL_ENV
echo -sn "(" (basename "$VIRTUAL_ENV") ")"
end
# Hostname with unique color
set_color (hostname -s | md5 | cut -c-6)
echo -sn (hostname -s)
# A yellow separator
# The color of this could be used to signify something
set_color yellow
echo -sn ':'
# Contracted path to PWD
set_color normal
echo -sn (prompt_pwd)
# A green or red >, depending on exit status of last command
if test "$status_copy" -ne 0
set_color red
else
set_color green
end
echo -sn ' > '
end

View File

@@ -0,0 +1,34 @@
function fish_right_prompt
# Check if we are inside a version controlled directory (git only)
set -l ref (git symbolic-ref HEAD ^/dev/null)
if test -z $ref
return
end
# Check if any files have changes
git diff --no-ext-diff --quiet --exit-code ^/dev/null
or set -l dirty 'yes'
# Check if any files are staged
git diff-index --cached --quiet HEAD -- ^/dev/null
or set -l staged 'yes'
set_color normal
echo -sn '['
# Print branch name
# red if dirty
# yellow if staged
# green otherwise
if set -q staged
set_color yellow
else if set -q dirty
set_color red
else
set_color green
end
echo -sn (string replace refs/heads/ '' -- $ref)
set_color normal
echo -sn ']'
end

View File

@@ -0,0 +1,4 @@
function fish_user_key_bindings
bind \t try_subst
end

10
fish/functions/g.fish Executable file
View File

@@ -0,0 +1,10 @@
function g
# shortcut to git
# If no arguments are given, run git status and git l
if count $argv >/dev/null
git $argv
else
git status
git l -5
end
end

3
fish/functions/greb.fish Executable file
View File

@@ -0,0 +1,3 @@
function greb --description "Git rebase entire history, interactively"
git rebase --interactive (git rev-list --max-parents=0 HEAD)
end

40
fish/functions/man.fish Executable file
View File

@@ -0,0 +1,40 @@
function man --description "Format and display the on-line manual pages"
# Work around the "builtin" manpage that everything symlinks to,
# by prepending our fish datadir to man. This also ensures that man gives fish's
# man pages priority, without having to put fish's bin directories first in $PATH
# My changes (Thomas Lovén)
# Add color to the man pager
#
# blink
set -lx LESS_TERMCAP_mb (set_color -o red)
# bold
set -lx LESS_TERMCAP_md (set_color -o purple)
set -lx LESS_TERMCAP_me (set_color normal)
# standout
set -lx LESS_TERMCAP_so (set_color -b blue) (set_color yellow)
set -lx LESS_TERMCAP_se (set_color normal)
# underline
set -lx LESS_TERMCAP_us (set_color -u green)
set -lx LESS_TERMCAP_ue (set_color normal)
set -l manpath
if set -q MANPATH
set manpath $MANPATH
else if command -qs manpath
set manpath (command manpath)
end
# Notice local exported copy of the variable.
set -lx MANPATH $manpath
set -l fish_manpath (dirname $__fish_datadir)/fish/man
if test -d "$fish_manpath" -a -n "$MANPATH"
set MANPATH $fish_manpath:$MANPATH
# Invoke man with this manpath, and we're done.
command man $argv
return
end
# If fish's man pages could not be found, just invoke man normally
command man $argv
end

4
fish/functions/mcd.fish Executable file
View File

@@ -0,0 +1,4 @@
function mcd --description "Make directory and enter it"
mkdir -p $argv
and cd $argv
end

14
fish/functions/try_subst.fish Executable file
View File

@@ -0,0 +1,14 @@
function try_subst
# Use s/word/replacement<tab> to replace word with replacement
# in last command
commandline | read -l saved_commandline
set -l pattern '^s/..*/.*$'
if commandline -t | grep -E -q "$pattern"
commandline -tr (echo -n "$history[1]" | sed -e (commandline -t)/g)
else
commandline -f complete
end
end

21
fish/setup.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env bash
function setup_fish()
{
brew install fish
if ! grep /usr/local/bin/fish < /etc/shells >/dev/null; then
echo /usr/local/bin/fish | sudo tee -a /etc/shells
chsh -s /usr/local/bin/fish
fi
}
function link_config()
{
mkdir ${HOME}/.config
ln -s ${DOTFILES}/fish ${HOME}/.config/.
}
export DOTFILES=/Users/thomas/dotfiles
setup_fish
link_config