summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2013-11-06 17:18:47 +0100
committerJan Pokorný <jpokorny@redhat.com>2013-11-06 17:18:47 +0100
commit2e6351eedb374b7a377de0128c6b06ad905100e8 (patch)
tree5c00268533b3ee386814a2121c536e8ff9a7b5f4
parent538f3f349fb05abdf8b7afcbf0d33acd426946e9 (diff)
downloaddotfiles-2e6351eedb374b7a377de0128c6b06ad905100e8.tar.gz
dotfiles-2e6351eedb374b7a377de0128c6b06ad905100e8.tar.xz
dotfiles-2e6351eedb374b7a377de0128c6b06ad905100e8.zip
Bash: add .bashrc-xml for some XML-related functions
first one being xml-xpath that uses 3 (2 under the hood) implementations to perform an XPath query Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rw-r--r--.bashrc2
-rw-r--r--.bashrc-xml22
2 files changed, 23 insertions, 1 deletions
diff --git a/.bashrc b/.bashrc
index 37a2ac7..322e3ee 100644
--- a/.bashrc
+++ b/.bashrc
@@ -19,7 +19,7 @@ _linkalias () {
linkalias () { alias "$1=_linkalias $2"; }
# Source the other common definitions
-for f in /etc/bashrc ~/.bashrc-dotfiles ~/.bashrc-fedora ~/.bashrc-work ~/.bashrc-priv; do
+for f in /etc/bashrc ~/.bashrc-dotfiles ~/.bashrc-fedora ~/.bashrc-work ~/.bashrc-xml ~/.bashrc-priv; do
[ -f "${f}" ] && source "${f}" || :
done
diff --git a/.bashrc-xml b/.bashrc-xml
new file mode 100644
index 0000000..17027e3
--- /dev/null
+++ b/.bashrc-xml
@@ -0,0 +1,22 @@
+# .bashrc-xml
+
+# run different implementation to select data from XML file per XPath expression
+# $1 ... XPath expr
+# $2 ... file
+xml-xpath() {
+ [ $# -ne 2 ] && int-usage "XPath" "XML" && return
+ local clrstart=$(test -t && echo -e '\x1b[1;34m' || echo -n)
+ local clrmiddle=$(test -t && echo -e '\x1b[1;30m' || echo -n)
+ local clrend=$(test -t && echo -e '\x1b[0m' || echo -n)
+ # yum install libxml2
+ echo -e "\n${clrstart}--- xmllint: ${clrmiddle}xmllint --noout --xpath '$1' '$2'${clrstart} ---${clrend}"
+ xmllint --noout --xpath "$1" "$2"
+
+ # yum install xmlstarlet
+ echo -e "\n${clrstart}--- XMLStarlet: ${clrmiddle}xmlstarlet sel -t -v '$1' '$2'${clrstart} ---${clrend}"
+ xmlstarlet sel -t -v "$1" "$2"
+
+ # yum install xqilla
+ echo -e "\n${clrstart}--- XQilla: ${clrmiddle}xqilla -P <(echo '$1') -i '$2'${clrstart} ---${clrend}"
+ xqilla -P <(echo "$1") -i "$2"
+}