mirror of
https://github.com/kazhala/dotbare
synced 2024-11-02 09:40:27 +00:00
refactor comman git commands into single file
This commit is contained in:
parent
44a254d5b4
commit
0f79f0c0a1
17
helper/git_data.sh
Normal file
17
helper/git_data.sh
Normal file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# helper functions to obtain git related information
|
||||
|
||||
#######################################
|
||||
# let user select a commit interactively
|
||||
# Outputs:
|
||||
# the selected commit 6 char code
|
||||
# e.g. b60b330
|
||||
#######################################
|
||||
function get_commit() {
|
||||
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" \
|
||||
log --oneline --color=always --decorate=short | \
|
||||
fzf --no-multi --header='select which commit to reset' --preview "echo {} | awk '{print \$1}' | \
|
||||
xargs -I __ /usr/bin/git --git-dir=${DOTBARE_DIR} --work-tree=${DOTBARE_TREE} show --color=always __" | \
|
||||
awk '{print $1}'
|
||||
}
|
@ -20,6 +20,7 @@ set -e
|
||||
mydir="${0%/*}"
|
||||
source "${mydir}"/../helper/set_variable.sh
|
||||
source "${mydir}"/../helper/get_confirmation.sh
|
||||
source "${mydir}"/../helper/git_data.sh
|
||||
|
||||
function usage() {
|
||||
echo -e "Usage: dotbare fcheckout [-h] [-a] [-b] [-c] ...\n"
|
||||
@ -84,10 +85,7 @@ if [[ -n "${branch}" ]]; then
|
||||
exit 0
|
||||
elif [[ -n "${commits}" ]]; then
|
||||
# checkout commits
|
||||
selected_commits=$(/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" log --oneline --color=always --decorate=short | \
|
||||
fzf --no-multi --header='select which commit to reset' --preview "echo {} | awk '{print \$1}' | \
|
||||
xargs -I __ /usr/bin/git --git-dir=${DOTBARE_DIR} --work-tree=${DOTBARE_TREE} show --color=always __" | \
|
||||
awk '{print $1}')
|
||||
selected_commits=$(get_commit)
|
||||
[[ -z "${selected_commits}" ]] && exit 0
|
||||
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout "${selected_commits}"
|
||||
exit 0
|
||||
|
@ -15,6 +15,7 @@ set -e
|
||||
mydir="${0%/*}"
|
||||
source "${mydir}"/../helper/set_variable.sh
|
||||
source "${mydir}"/../helper/get_confirmation.sh
|
||||
source "${mydir}"/../helper/git_data.sh
|
||||
|
||||
function usage() {
|
||||
echo -e "Usage: dotbare freset [-h] [-c] [-S] [-H] ...\n"
|
||||
@ -55,10 +56,7 @@ do
|
||||
done
|
||||
|
||||
if [[ -n "${search_commits}" ]]; then
|
||||
selected_commits=$(/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" log --oneline --color=always --decorate=short | \
|
||||
fzf --no-multi --header='select which commit to reset' --preview "echo {} | awk '{print \$1}' | \
|
||||
xargs -I __ /usr/bin/git --git-dir=${DOTBARE_DIR} --work-tree=${DOTBARE_TREE} show --color=always __" | \
|
||||
awk '{print $1}')
|
||||
selected_commits=$(get_commit)
|
||||
[[ -z "${selected_commits}" ]] && exit 0
|
||||
confirm=$(get_confirmation "Reset HEAD to ${selected_commits} ${reset_option}?")
|
||||
[[ "${confirm}" != 'y' ]] && exit 0
|
||||
|
Loading…
Reference in New Issue
Block a user