mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-08 00:50:44 +00:00
misc: .screenrc, config, functions & new scripts!
This commit is contained in:
57
local/bin/x-compare-versions.py
Executable file
57
local/bin/x-compare-versions.py
Executable file
@@ -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()
|
||||
5
local/bin/x-ip
Executable file
5
local/bin/x-ip
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# Source: https://github.com/thirtythreeforty/dotfiles/blob/master/bin/extip
|
||||
|
||||
curl icanhazip.com "${@}"
|
||||
|
||||
Reference in New Issue
Block a user