diff --git a/bin/columnize b/bin/columnize new file mode 100755 index 0000000..73f9209 --- /dev/null +++ b/bin/columnize @@ -0,0 +1,80 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# The MIT License (MIT) + +# Copyright (c) 2015 Thomas Lovén + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +'Columnize text with ANSI escape codes' + +from __future__ import print_function +import getopt +from os import path +import re +import sys + +try: + # Python 3 + from itertools import zip_longest +except ImportError: + # Python 2 + from itertools import izip_longest as zip_longest + +progname = path.basename(sys.argv[0]) + +def getlength(s): + 'Find length of a string, ignoring escape sequences' + s = re.sub('\x1b\[[0-9;]*m', '', s) + return len(s) + +def usage(): + print('Columnize text with ANSI escape codes') + print('usage:', progname, '[-s sep]') + + +try: + opts,args = getopt.getopt(sys.argv[1:], 'ts:') + opts = dict(opts) +except getopt.GetoptError as err: + print(progname, ':', str(err)) + usage() + sys.exit(2) + +splitchar = opts.get('-s', '\t') + +lines = [] +lengths = [] +# Read each line from stdin +for line in sys.stdin: + cols = line.strip().split(splitchar) + lines.append(cols) + # Calculate the widths of each column + width = [getlength(col) for col in cols] + # Save the longest columns' lengths + lengths = map(max, zip_longest(lengths, width, fillvalue=0)) + +lengths = list(lengths) +for line in lines: + thisline = '' + for i,col in enumerate(line): + spaces = ' '*(lengths[i]-getlength(col)+1) + thisline += col + spaces + print(thisline.rstrip()) diff --git a/bin/prettygit b/bin/prettygit new file mode 100755 index 0000000..7d81205 --- /dev/null +++ b/bin/prettygit @@ -0,0 +1,19 @@ +#!/bin/bash + +HASH="%C(yellow)%h%C(reset)" +RELATIVE_TIME="%C(green)%ar%C(reset)" +AUTHOR="%C(blue)<%an>%C(reset)" +REFS="%C(red)%d%C(reset)" +SUBJECT="%C(reset)%s%C(reset)" + +FORMAT="}$HASH}$RELATIVE_TIME}$AUTHOR}$REFS $SUBJECT" + +function pretty_git_log() { + git log --graph --all --color=always --pretty="tformat:$FORMAT" $* | + sed -Ee 's/(^[^<]*) ago}/\1}/' | + columnize -t -s '}' | + less -FXR +} + + # grep -v Merge | +pretty_git_log $@ diff --git a/fish/config.fish b/fish/config.fish new file mode 100644 index 0000000..30943b0 --- /dev/null +++ b/fish/config.fish @@ -0,0 +1,11 @@ +set -x DOTFILES $HOME/DOTFILES + +if test -z "$FISH_SETUP_PATH" + set -x PATH $HOME/dotfiles/bin $PATH + set -x PATH . $PATH + + set -x FISH_SETUP_PATH +end + +set -x LANG sv_SE.UTF-8 +set -x LC_ALL sv_SE.UTF-8 \ No newline at end of file diff --git a/fish/functions/fish_greeting.fish b/fish/functions/fish_greeting.fish new file mode 100644 index 0000000..de9e5d4 --- /dev/null +++ b/fish/functions/fish_greeting.fish @@ -0,0 +1,3 @@ +function fish_greeting + +end \ No newline at end of file diff --git a/fish/functions/fish_prompt.fish b/fish/functions/fish_prompt.fish new file mode 100644 index 0000000..758b789 --- /dev/null +++ b/fish/functions/fish_prompt.fish @@ -0,0 +1,23 @@ +function fish_prompt + set -l status_copy $status + + set -l host (hostname -s) + if set -q DEVCONTAINER + set host DEV + end + set_color (echo "$host" | md5sum | cut -c-6) + echo -sn $host + + set_color yellow + echo -sn ':' + + set_color normal + echo -sn (prompt_pwd) + + if test "$status_copy" -ne 0 + set_color red + else + set_color green + end + echo -sn ' > ' +end \ No newline at end of file diff --git a/fish/functions/fish_right_prompt.fish b/fish/functions/fish_right_prompt.fish new file mode 100644 index 0000000..7e237f4 --- /dev/null +++ b/fish/functions/fish_right_prompt.fish @@ -0,0 +1,27 @@ +function fish_right_prompt + set -l ref (git symbolic-ref HEAD ^/dev/null) + if test -z $ref + return + end + + git diff --no-ext-diff --quiet --exit-code ^/dev/null + or set -l dirty 'yes' + + git diff-index --cached --quiet HEAD -- ^/dev/null + or set -l staged 'yes' + + set_color normal + echo -sn '[' + + 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 \ No newline at end of file diff --git a/fish/functions/g.fish b/fish/functions/g.fish new file mode 100644 index 0000000..e37b208 --- /dev/null +++ b/fish/functions/g.fish @@ -0,0 +1,8 @@ +function g --wraps git + if count $argv >/dev/null + git $argv + else + git status + git l -5 + end +end \ No newline at end of file diff --git a/git/gitconfig b/git/gitconfig new file mode 100644 index 0000000..0fa1801 --- /dev/null +++ b/git/gitconfig @@ -0,0 +1,47 @@ +[user] + name = Thomas Lovén + email = thomasloven@gmail.com +[credential] + helper = cache +[color] + ui = auto + branch = auto + diff = auto + status = auto +[color "branch"] + current = yellow reverse + local = yellow + remote = green +[color "diff"] + meta = yellow + frag = magenta + old = red + new = green +[color "status"] + added = yellow + changed = green + untracked = cyan + +[push] + default = current +[core] + pager = less -F -X + +[alias] + st = status + ci = commit + co = checkout + di = diff + dc = diff --cached + wd = diff --word-diff=color + amend = commit --amend + aa = add --all + b = branch + updateall = submodule foreach 'git pull' + l = !prettygit + p = "!echo $PATH" + la = !git l --all + r = !git l -30 + ra = !git r --all +[merge] + tool = vimdiff diff --git a/git/gitignore_global b/git/gitignore_global new file mode 100644 index 0000000..7875fa7 --- /dev/null +++ b/git/gitignore_global @@ -0,0 +1,38 @@ +*.com +*.class +*.dll +*.exe +*.o +*.so + +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +*.log +*.sql +*.sqlite + +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +Icon? +ehthumbs.db +Thumbs.db + +#Latex files +*.aux +*.bcf +*.blg +*.fdb_latexmk +*.fls +*.out + +tags diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..2af7458 --- /dev/null +++ b/install.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +sudo -n apt-get update +sudo -n DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends fish vim + +USER=`whoami` +sudo -n chsh $USER -s $(which fish) + +echo "sv_SE.UTF-8 UTF-8" | sudo tee -a /etc/locale.gen +locale-gen + +cat << EOF > ~/.gitconfig +[include] + path = ${HOME}/dotfiles/git/gitconfig +[core] + excludesfile = ${HOME}/dotfiles/git/gitignore_global +EOF + +mkdir -p ~/.config/ +ln -s ~/dotfiles/fish ~/.config/fish diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 0000000..b72ad10 --- /dev/null +++ b/test/Dockerfile @@ -0,0 +1,10 @@ +FROM mcr.microsoft.com/vscode/devcontainers/python:0-3.8 + +ENV DEVCONTAINER=1 + +WORKDIR /workspaces + +COPY . /root/dotfiles +RUN /root/dotfiles/install.sh + +CMD fish \ No newline at end of file diff --git a/test/run_test b/test/run_test new file mode 100755 index 0000000..b957178 --- /dev/null +++ b/test/run_test @@ -0,0 +1,9 @@ +#!/bin/bash +set -e +cd "$(dirname "$0")/.." + +docker build . -t dotfiles -f test/Dockerfile --force-rm + +docker run --rm -it dotfiles + +docker rmi dotfiles \ No newline at end of file