summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgarhve <git@garhve.com>2023-01-02 06:25:43 +0800
committergarhve <git@garhve.com>2023-01-02 06:25:43 +0800
commit2a9ade7cf6080d1649dbd0a03de61f3387325ae9 (patch)
treeb8cd8c5d424209148d2336928b0cac9d31d134e6
parentdf131ff5044691a9c417478063a8c9de93c92e43 (diff)
bash cheatsheet
-rwxr-xr-xblog.sh79
-rw-r--r--content/post/mess with bash(2).md1
-rw-r--r--public/post/mess-with-bash-2/index.html3
3 files changed, 82 insertions, 1 deletions
diff --git a/blog.sh b/blog.sh
new file mode 100755
index 0000000..573506d
--- /dev/null
+++ b/blog.sh
@@ -0,0 +1,79 @@
+#!/usr/bin/env sh
+
+######################################################################
+# @author : garhve (dev@garhve.com)
+# @file : blog
+# @created : Friday Dec 09, 2022 16:09:42 CST
+#
+# @description : simplify blog publishing, it only can use in blog dir
+######################################################################
+
+# usage: prog funct
+
+push() {
+ read -r -p "Do you want to push?[y/n] " ans
+ if [ "$ans" == 'y' ]; then
+ zola build
+ git add .
+ if [ ! -z "$(git status | grep 'Changes to be committed')" ]; then
+ read -r -p "commit message: " msg
+ git commit -m "$msg"
+ git push origin main
+ fi
+ echo -e "push done"
+ fi
+}
+
+edit() {
+ path="content/post"
+
+ # --- get editing file
+ choice=1
+ declare -a arr
+ for file in $path/*; do
+ [[ "$file" == *"_index.md" ]] && continue
+ echo -ne "($choice)\x1b[0;32m${file##*/}\x1b[0m " # n get rid of trailing new line, e strip backslash
+ arr[$choice]="$file"
+ choice=$((choice+1))
+ done
+ echo ""
+ read -r -p "please choose file by number you want to edit from above: " num
+ [[ "$num" == "q" ]] && exit 0
+ vim "${arr[$num]}"
+ # --- end
+ echo -e "edit done\n"
+
+ push
+ echo -e "\nall done"
+}
+
+new() {
+ read -r -p "blog name: " name
+ path="content/post/$name"
+
+ vim "$path".md
+ [ "$?" -eq 0 ] && echo "creation done"
+ [ "$?" -ne 0 ] && echo "creation fail, please check error" && exit 1
+
+ read -r -p "do you want to edit now?[y/n] " ans
+ [ "${ans,,}" == 'y' ] && vim "$path/$name.md" && echo "edit done"
+
+ push
+
+ echo -e "\nall done"
+}
+
+list() {
+ echo -e "\x1b[1;34mList content:\x1b[0m"
+ tree ./content/post
+}
+
+
+funct="new/edit/push/ls"
+
+[ $# -lt 1 ] && echo "usage: $(basename $0) $funct"
+
+[ $1 == "new" ] && new
+[ $1 == "edit" ] && edit
+[ $1 == "push" ] && push
+[ $1 == "ls" ] && list
diff --git a/content/post/mess with bash(2).md b/content/post/mess with bash(2).md
index 1e3b744..3ce13f0 100644
--- a/content/post/mess with bash(2).md
+++ b/content/post/mess with bash(2).md
@@ -8,6 +8,7 @@ tags = ["bash"]
math = false
+++
> More info is in this [tutorial](https://https://guide.bash.academy)
+> Bash scripting [cheatsheet](https://devhints.io/bash)
> all value expansions (ie. all syntax with a `$` prefix) can only expand inside quoted arguments if the argument was *double-quoted* . Single quotes will turn the dollar-syntax into literal characters, causing bash to output the dollar rather than expand its value in-place!
diff --git a/public/post/mess-with-bash-2/index.html b/public/post/mess-with-bash-2/index.html
index 5064a1d..867eca3 100644
--- a/public/post/mess-with-bash-2/index.html
+++ b/public/post/mess-with-bash-2/index.html
@@ -53,7 +53,8 @@
<p>
<blockquote>
-<p>More info is in this <a href="https://https://guide.bash.academy">tutorial</a></p>
+<p>More info is in this <a href="https://https://guide.bash.academy">tutorial</a>
+Bash scripting <a href="https://devhints.io/bash">cheatsheet</a></p>
</blockquote>
<blockquote>
<p>all value expansions (ie. all syntax with a <code>$</code> prefix) can only expand inside quoted arguments if the argument was <em>double-quoted</em> . Single quotes will turn the dollar-syntax into literal characters, causing bash to output the dollar rather than expand its value in-place!</p>