mirror of
https://github.com/notwa/rc
synced 2024-05-08 06:13:22 -07:00
add some scripts that act on shell variables
these are kinda experimental.
This commit is contained in:
parent
13149ff607
commit
2fb9bbe24f
25
sh/v_domap
Normal file
25
sh/v_domap
Normal file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env sh
|
||||
# YES_ZSH
|
||||
# YES_BASH
|
||||
# YES_DASH
|
||||
# YES_ASH
|
||||
|
||||
v_domap() {
|
||||
argc $# -eq 1 "$0" || return
|
||||
# TODO: sanity-check on characters of the variable name.
|
||||
local _k_="$1" _v_= _new_= _next_= _i_= _o_=
|
||||
eval "_v_=\"\$$_k_\""
|
||||
while [ -n "$_v_" ]; do
|
||||
_next_="${_v_#[! ]}"
|
||||
[ "$_next_" != "$_v_" ] || _next_="${_v_# }"
|
||||
_i_="${_v_%"$_next_"}"; _v_="$_next_"
|
||||
map
|
||||
_new_="$_new_$_o_"
|
||||
#printf 'new: %s\n' "$_new_"
|
||||
done
|
||||
eval "$_k_=\"\$_new_\""
|
||||
}
|
||||
|
||||
[ -n "${preload+-}" ] || . ~/sh/preload || exit 2
|
||||
eval ${preload:-preload} argc
|
||||
[ -n "${preload+-}" ] || v_domap "$@"
|
22
sh/v_lower
Normal file
22
sh/v_lower
Normal file
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env sh
|
||||
# YES_ZSH
|
||||
# YES_BASH
|
||||
# YES_DASH
|
||||
# YES_ASH
|
||||
|
||||
v_lower() { ### @- transform the contents of a variable to lowercase.
|
||||
argc $# -eq 1 "$0" || return
|
||||
map() {
|
||||
case "$_i_" in
|
||||
(A) _o_=a;; (B) _o_=b;; (C) _o_=c;; (D) _o_=d;; (E) _o_=e;; (F) _o_=f;; (G) _o_=g;;
|
||||
(H) _o_=h;; (I) _o_=i;; (J) _o_=j;; (K) _o_=k;; (L) _o_=l;; (M) _o_=m;; (N) _o_=n;;
|
||||
(O) _o_=o;; (P) _o_=p;; (Q) _o_=q;; (R) _o_=r;; (S) _o_=s;; (T) _o_=t;; (U) _o_=u;;
|
||||
(V) _o_=v;; (W) _o_=w;; (X) _o_=x;; (Y) _o_=y;; (Z) _o_=z;; (*) _o_="$_i_";;
|
||||
esac
|
||||
}
|
||||
v_domap "$1"
|
||||
}
|
||||
|
||||
[ -n "${preload+-}" ] || . ~/sh/preload || exit 2
|
||||
eval ${preload:-preload} argc v_domap
|
||||
[ -n "${preload+-}" ] || v_lower "$@"
|
22
sh/v_upper
Normal file
22
sh/v_upper
Normal file
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env sh
|
||||
# YES_ZSH
|
||||
# YES_BASH
|
||||
# YES_DASH
|
||||
# YES_ASH
|
||||
|
||||
v_upper() { ### @- transform the contents of a variable to uppercase.
|
||||
argc $# -eq 1 "$0" || return
|
||||
map() {
|
||||
case "$_i_" in
|
||||
(a) _o_=A;; (b) _o_=B;; (c) _o_=C;; (d) _o_=D;; (e) _o_=E;; (f) _o_=F;; (g) _o_=G;;
|
||||
(h) _o_=H;; (i) _o_=I;; (j) _o_=J;; (k) _o_=K;; (l) _o_=L;; (m) _o_=M;; (n) _o_=N;;
|
||||
(o) _o_=O;; (p) _o_=P;; (q) _o_=Q;; (r) _o_=R;; (s) _o_=S;; (t) _o_=T;; (u) _o_=U;;
|
||||
(v) _o_=V;; (w) _o_=W;; (x) _o_=X;; (y) _o_=Y;; (z) _o_=Z;; (*) _o_="$_i_";;
|
||||
esac
|
||||
}
|
||||
v_domap "$1"
|
||||
}
|
||||
|
||||
[ -n "${preload+-}" ] || . ~/sh/preload || exit 2
|
||||
eval ${preload:-preload} argc v_domap
|
||||
[ -n "${preload+-}" ] || v_upper "$@"
|
Loading…
Reference in New Issue
Block a user