add git commands
This commit is contained in:
parent
af35ffabac
commit
aea3d9152e
55
memo
55
memo
|
@ -9,9 +9,11 @@
|
||||||
ack_cmd=ack
|
ack_cmd=ack
|
||||||
man_cmd=man
|
man_cmd=man
|
||||||
tree_cmd=tree
|
tree_cmd=tree
|
||||||
|
git_cmd=git
|
||||||
# comment pandoc_cmd to fall back to cat
|
# comment pandoc_cmd to fall back to cat
|
||||||
pandoc_cmd=pandoc
|
pandoc_cmd=pandoc
|
||||||
|
|
||||||
|
|
||||||
# Script
|
# Script
|
||||||
|
|
||||||
MEMO_FOLDER="${MEMO_DIR:-$HOME/memo}"
|
MEMO_FOLDER="${MEMO_DIR:-$HOME/memo}"
|
||||||
|
@ -37,7 +39,48 @@ function precondition::provide_topic(){
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# git commands
|
||||||
|
#
|
||||||
|
|
||||||
|
IS_GIT_REPO=0
|
||||||
|
# check if it is a gitrepository
|
||||||
|
# use the IS_GIT_REPO variable to
|
||||||
|
# verify later if it is a git repo
|
||||||
|
function git:status(){
|
||||||
|
cd ${MEMO_FOLDER}
|
||||||
|
${git_cmd} status &> /dev/null
|
||||||
|
if [[ $? -eq 0 ]]
|
||||||
|
then
|
||||||
|
IS_GIT_REPO=1
|
||||||
|
else
|
||||||
|
IS_GIT_REPO=0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# run before commit
|
||||||
|
function git:add_all_topics(){
|
||||||
|
if [[ ${IS_GIT_REPO} -eq 1 ]]
|
||||||
|
then
|
||||||
|
cd ${MEMO_FOLDER}
|
||||||
|
${git_cmd} add .
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# make a commit
|
||||||
|
function git:commit(){
|
||||||
|
local message="${1:-blind commit}"
|
||||||
|
if [[ ${IS_GIT_REPO} -eq 1 ]]
|
||||||
|
then
|
||||||
|
cd ${MEMO_FOLDER}
|
||||||
|
${git_cmd} commit -m "${message}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function git:run_commands(){
|
||||||
|
cd ${MEMO_FOLDER}
|
||||||
|
${git_cmd} $@
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# edit command
|
# edit command
|
||||||
|
@ -56,6 +99,8 @@ function edit_memo() {
|
||||||
|
|
||||||
${EDITOR} ${topic_file}
|
${EDITOR} ${topic_file}
|
||||||
|
|
||||||
|
git:add_all_topics
|
||||||
|
git:commit "edit : ${topic_name}"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -83,6 +128,9 @@ EOF
|
||||||
cat >>${topic_file} -
|
cat >>${topic_file} -
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
git:add_all_topics
|
||||||
|
git:commit "add : ${topic_name}"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,6 +166,9 @@ function copy_file(){
|
||||||
echo "copy '${path}' to '${topic_name}'"
|
echo "copy '${path}' to '${topic_name}'"
|
||||||
cp -r "${path}" ${topic_path}/
|
cp -r "${path}" ${topic_path}/
|
||||||
|
|
||||||
|
git:add_all_topics
|
||||||
|
git:commit "copy $( dirname ${path} ): ${topic_name}"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -254,6 +305,7 @@ command=$1
|
||||||
shift
|
shift
|
||||||
|
|
||||||
precondition::provide_memo_folder
|
precondition::provide_memo_folder
|
||||||
|
git:status
|
||||||
|
|
||||||
case $command in
|
case $command in
|
||||||
add) add_memo $@
|
add) add_memo $@
|
||||||
|
@ -273,6 +325,9 @@ case $command in
|
||||||
list)
|
list)
|
||||||
list_topics
|
list_topics
|
||||||
;;
|
;;
|
||||||
|
git)
|
||||||
|
git:run_commands $@
|
||||||
|
;;
|
||||||
*) show_help
|
*) show_help
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in a new issue