]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Edit accepting params
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 31 Dec 2017 02:53:02 +0000 (00:53 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 31 Dec 2017 02:53:02 +0000 (00:53 -0200)
TODO.md
kvmx

diff --git a/TODO.md b/TODO.md
index 7fc8e6067cdaa48de18c759228348fc98a3cb7f4..f06b0cea16dbdc8efdf10690bde7c2d4bfb48289 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -19,4 +19,3 @@
 * Makefile and debian package.
 * Patch for spice-client-gtk for menuless windows (spicec usecase).
 * Accept args into monitor action.
-* Support for key=value options at `init` action to populate the `kvmxfile` with custom values.
diff --git a/kvmx b/kvmx
index 979620e27280a6792814ef72c3780abd357c51ca..6ef49925ecb1a2064a0adcd66c34167854c7807c 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -1033,14 +1033,30 @@ function kvmx_copy {
 
 # Edit guest config
 function kvmx_edit {
-  if [ -z "$EDITOR" ]; then
-    EDITOR="vi"
-  fi
+  if [ -z "$1" ]; then
+    if [ -z "$EDITOR" ]; then
+      EDITOR="vi"
+    fi
 
-  if [ -e "$GLOBAL_USER_CONFIG_FOLDER/$VM" ]; then
-    $EDITOR $GLOBAL_USER_CONFIG_FOLDER/$VM
+    if [ -e "$GLOBAL_USER_CONFIG_FOLDER/$VM" ]; then
+      $EDITOR $GLOBAL_USER_CONFIG_FOLDER/$VM
+    else
+      echo "$BASENAME: $GLOBAL_USER_CONFIG_FOLDER/$VM: file not found."
+    fi
   else
-    echo "$BASENAME: $GLOBAL_USER_CONFIG_FOLDER/$VM: file not found."
+    if [ -z "$2" ]; then
+      echo "usage: $BASENAME $VM edit $1 <value>"
+      exit 1
+    fi
+
+    param="$1"
+    shift
+
+    if ! grep -q "^$param=" $GLOBAL_USER_CONFIG_FOLDER/$VM; then
+      echo "$param=\"$*\"" >> $GLOBAL_USER_CONFIG_FOLDER/$VM
+    else
+      sed -i -e "s#^$param=.*#$param=\"$*\"#" $GLOBAL_USER_CONFIG_FOLDER/$VM
+    fi
   fi
 }