From d504fc5f2b5d02ad4b1a9b58e31250f4feee0ad8 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Thu, 13 Apr 2023 08:41:14 +0300 Subject: [PATCH] misc: .screenrc, config, functions & new scripts! --- config/alias | 3 ++ config/exports-apps | 2 ++ config/functions | 17 ++++++++++ config/misc/screenrc | 16 +++++++++ local/bin/x-compare-versions.py | 57 +++++++++++++++++++++++++++++++++ local/bin/x-ip | 5 +++ 6 files changed, 100 insertions(+) create mode 100644 config/misc/screenrc create mode 100755 local/bin/x-compare-versions.py create mode 100755 local/bin/x-ip diff --git a/config/alias b/config/alias index 168ecb1..4a26596 100755 --- a/config/alias +++ b/config/alias @@ -56,6 +56,9 @@ alias watchx='watch -dpbc' # watch with: differences, precise, beep and color alias zapds='find . -name ".DS_Store" -print -delete' alias t='tail -f' # tail with follow flag on alias dn='du -chd1' # directory usage, return only the total +alias mirrorsite='wget -m -k -K -E -e robots=off' # Mirror site +# Mirror stdout to stderr, useful for seeing data going through a pipe +alias peek='tee >(cat 1>&2)' alias code_scanner='docker run --env SOURCE_CODE="$PWD" diff --git a/config/exports-apps b/config/exports-apps index 369e724..fff9206 100755 --- a/config/exports-apps +++ b/config/exports-apps @@ -103,3 +103,5 @@ export _Z_DATA="$XDG_STATE_HOME/z" # Misc export ANDROID_HOME="$XDG_DATA_HOME/android" export GNUPGHOME="$XDG_DATA_HOME/gnupg" +export SCREENRC="$XDG_CONFIG_HOME/misc/screenrc" + diff --git a/config/functions b/config/functions index 8041a75..113e444 100755 --- a/config/functions +++ b/config/functions @@ -66,6 +66,23 @@ function silent "$@" >&/dev/null } +function path_remove +{ + PATH=$(echo -n "$PATH" | awk -v RS=: -v ORS=: "\$0 != \"$1\"" | sed 's/:$//') +} + +function path_append +{ + path_remove "$1" + PATH="${PATH:+"$PATH:"}$1" +} + +function path_prepend +{ + path_remove "$1" + PATH="$1${PATH:+":$PATH"}" +} + # Defines default antigen bundles function x-default-antigen-bundles { diff --git a/config/misc/screenrc b/config/misc/screenrc new file mode 100644 index 0000000..b483947 --- /dev/null +++ b/config/misc/screenrc @@ -0,0 +1,16 @@ +# Disable the startup message +startup_message off + +# Set a large scrollback buffer +defscrollback 32000 + +# Always start `screen` with UTF-8 enabled (`screen -U`) +defutf8 on + +# Scroll with mouse wheel (http://stackoverflow.com/a/1125947) +termcapinfo xterm* ti@:te@ + +# Some settings for screen + vim +term xterm-256color +maptimeout 10 + diff --git a/local/bin/x-compare-versions.py b/local/bin/x-compare-versions.py new file mode 100755 index 0000000..f7647d7 --- /dev/null +++ b/local/bin/x-compare-versions.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +""" +Version Comparison tool for the CLI. + +Adapted from script found in anishathalye's dotfiles. +https://github.com/anishathalye/dotfiles/blob/master/bin/vercmp +""" + +import operator +import sys + +from packaging import version + +str_to_operator = { + "==": operator.eq, + "!=": operator.ne, + "<": operator.lt, + "<=": operator.le, + ">": operator.gt, + ">=": operator.ge, +} + + +def vercmp(expr): + """Version Comparison function.""" + words = expr.split() + comparisons = [words[i: i + 3] for i in range(0, len(words) - 2, 2)] + for left, op_str, right in comparisons: + compare_op = str_to_operator[op_str] + if not compare_op(version.parse(left), version.parse(right)): + return False + return True + + +def main(): + """Triggers version comparison if line is provided.""" + for line in sys.stdin: + if not vercmp(line): + sys.exit(1) + sys.exit(0) + + +def test(): + """Basic functionality tests.""" + assert not vercmp("1.9 >= 2.4") + assert vercmp("2.4 >= 2.4") + assert vercmp("2.5 >= 2.4") + assert vercmp("3 >= 2.999") + assert vercmp("2.9 < 2.9a") + assert vercmp("2.9a >= 2.8") + + +if __name__ == "__main__": + if len(sys.argv) == 2 and sys.argv[1] == "test": + test() + else: + main() diff --git a/local/bin/x-ip b/local/bin/x-ip new file mode 100755 index 0000000..39d240e --- /dev/null +++ b/local/bin/x-ip @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +# Source: https://github.com/thirtythreeforty/dotfiles/blob/master/bin/extip + +curl icanhazip.com "${@}" +