Merge branch 'feature/git' into develop
commit
96a9cd8325
|
@ -12,6 +12,7 @@ function _memo {
|
|||
show\:'show a topic'
|
||||
edit\:'edit a topic'
|
||||
list\:'print a list of all topics'
|
||||
git\:'run git command'
|
||||
))" \
|
||||
"*::arg:->args"
|
||||
|
||||
|
@ -19,6 +20,9 @@ function _memo {
|
|||
add|copy|show|edit)
|
||||
_memo_topics
|
||||
;;
|
||||
git)
|
||||
_git
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
@ -31,3 +35,17 @@ function _memo_topics {
|
|||
compadd -X "A vailable Topics" $topics
|
||||
}
|
||||
|
||||
function _git {
|
||||
local -a subcommands
|
||||
subcommands=(
|
||||
"init:Initialize git repository"
|
||||
"status:Status of git repository"
|
||||
"push:Push to remote repository"
|
||||
"pull:Pull from remote repository"
|
||||
"config:Show git config"
|
||||
"log:Show git log"
|
||||
"reflog:Show git reflog"
|
||||
)
|
||||
_describe -t commands 'git' subcommands
|
||||
}
|
||||
|
||||
|
|
55
memo
55
memo
|
@ -9,9 +9,11 @@
|
|||
ack_cmd=ack
|
||||
man_cmd=man
|
||||
tree_cmd=tree
|
||||
git_cmd=git
|
||||
# comment pandoc_cmd to fall back to cat
|
||||
pandoc_cmd=pandoc
|
||||
|
||||
|
||||
# Script
|
||||
|
||||
MEMO_FOLDER="${MEMO_DIR:-$HOME/memo}"
|
||||
|
@ -37,7 +39,48 @@ function precondition::provide_topic(){
|
|||
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
|
||||
|
@ -56,6 +99,8 @@ function edit_memo() {
|
|||
|
||||
${EDITOR} ${topic_file}
|
||||
|
||||
git:add_all_topics
|
||||
git:commit "edit : ${topic_name}"
|
||||
}
|
||||
|
||||
#
|
||||
|
@ -83,6 +128,9 @@ EOF
|
|||
cat >>${topic_file} -
|
||||
fi
|
||||
|
||||
git:add_all_topics
|
||||
git:commit "add : ${topic_name}"
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -118,6 +166,9 @@ function copy_file(){
|
|||
echo "copy '${path}' to '${topic_name}'"
|
||||
cp -r "${path}" ${topic_path}/
|
||||
|
||||
git:add_all_topics
|
||||
git:commit "copy $( dirname ${path} ): ${topic_name}"
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -254,6 +305,7 @@ command=$1
|
|||
shift
|
||||
|
||||
precondition::provide_memo_folder
|
||||
git:status
|
||||
|
||||
case $command in
|
||||
add) add_memo $@
|
||||
|
@ -273,6 +325,9 @@ case $command in
|
|||
list)
|
||||
list_topics
|
||||
;;
|
||||
git)
|
||||
git:run_commands $@
|
||||
;;
|
||||
*) show_help
|
||||
;;
|
||||
esac
|
||||
|
|
Loading…
Reference in New Issue