hexo-helper

Hexo をGUI で支援するスクリプトをzenity で書いてみました。

シェルスクリプト

コマンドラインでHEXO を操作できる環境が整っていることが前提です。

/PATH/TO/hexo-helper.sh
#!/bin/bash

[[ -s "$HOME/.nvm/nvm.sh" ]] && . "$HOME/.nvm/nvm.sh"
nvm use v0.10 > /dev/null
export NODE_PATH=${NVM_PATH}_modules

SOURCE_REPOSITORY=bitbucket

if [ $# -lt 1 ] ; then
zenity --error --text="Usage: hexo-helper.sh hexo_path"
exit 1
fi
HEXODIR=$1
if ! [ -d $HEXODIR ] ; then
zenity --error --text="Bad directory."
exit 1
fi
cd $HEXODIR

while :
do
count=`ps -ef | grep "hexo server" | grep -v grep | wc -l`
if [ $count = 0 ]; then
hexoserverstatus="[DOWN]"
else
hexoserverstatus="[UP]"
fi
pick=$(zenity --list --radiolist \
--title "Hexo Helper" --text "$HEXODIR" \
--width=240 --height=320 \
--column Pick --column dummy --column Action --hide-column 2 --print-column=2 \
true 0 "New Post" \
false 1 "New Page" \
false 2 "Generate" \
false 3 "Deploy" \
false 4 "Start Server" \
false 5 "$hexoserverstatus Preview" \
false 6 "Stop Server" \
false 7 "Open Posts Folder" \
false 8 "Push Source");
case $pick in
"0")
post_title=`zenity --entry --title="New Post" --text="Enter Title."`
if [ $? -ne 0 ] ; then
continue
fi
if [ ${#post_title} > 0 ] ; then
hexo new "$post_title" | \
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | \
zenity --text-info --title="New Post" --width=640 --height=480 --auto-scroll
fi
;;
"1")
page_title=$(zenity --entry --title="New Page" --text="Enter Title." )
if [ ${#page_title} > 0 ] ; then
hexo new page "$page_title" | \
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | \
zenity --text-info --title="New Page" --width=640 --height=480 --auto-scroll
fi
;;
"2")
(echo "Generating..." ; hexo generate ) | \
zenity --text-info --title="Generate" --width=640 --height=480 --auto-scroll
;;
"3")
(echo "Deploying..." ; hexo deploy ) | \
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | \
zenity --text-info --title="Deploy" --width=640 --height=480 --auto-scroll
;;
"4")
count=`ps -ef | grep "hexo server" | grep -v grep | wc -l`
if [ $count = 0 ]; then
hexo server &
for i in `seq 0 5 100`; do echo $i; sleep 0.25; done | zenity --progress --text "Starting Server..." --auto-close --no-cancel
fi
;;
"5")
xdg-open http://localhost:4000/ &
;;
"6")
count=`ps -ef | grep "hexo server" | grep -v grep | wc -l`
if [ $count != 0 ]; then
kill -9 `ps -ef | grep "hexo server" | grep -v grep | awk '{print $2}'`
for i in `seq 0 5 100`; do echo $i; sleep 0.25; done | zenity --progress --text "Stopping Server..." --auto-close --no-cancel
fi
;;
"7")
xdg-open $HEXODIR/source/_posts/ &
;;
"8")
git add . && git commit -m 'update' && git push -u $SOURCE_REPOSITORY source | \
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | \
zenity --text-info --title="Push Source" --width=640 --height=480 --auto-scroll
;;
*)
exit 0
;;
esac
done

アプリケーションメニュー

~/.local/share/applications/hexo-helper.desktop
[Desktop Entry]
Encoding=UTF-8
Name=Hexo Helper
Exec=/PATH/TO/hexo-helper.sh /PATH/TO/HEXODIR
Icon=/PATH/TO/hexo-helper-icon.png
Terminal=false
Type=Application
Categories=Application;
StartupNotify=false

アイコン

hexo-helper-icon

Generate 画面

hexo-helper-generate