Add helper functions

This commit is contained in:
Martin Blazik
2022-10-01 09:28:16 +02:00
parent 024c55482b
commit 42bd496419
3 changed files with 18 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
# $LWS/rc/functions.sh
# Linux Workspace Functions
function xlog() {
if true_false "$LWS_DEBUG"; then
@@ -21,6 +21,18 @@ function utime() {
date '+%s.%N'
}
function sqltime() {
date '+%Y-%m-%d %H:%M:%S'
}
function lines() {
tr ":" "\n"
}
function path() {
echo "$PATH" | lines
}
function in_path() {
[[ "$PATH" =~ (^|:)"${1}"(:|$) ]]
}
@@ -49,6 +61,10 @@ function prepend_path_try() {
fi
}
function remove_path() {
PATH=$(path | grep -v "$1" | tr "\n" ":")
}
function uniq_path() {
echo "$PATH" | tr ":" "\n" | awk '!seen[$0]++' | tr "\n" ":" | sed -r 's/:+/:/g' | sed -r 's/^:|:$//g'
}