mirror of https://github.com/kazhala/dotbare
init
commit
eb9a88b246
@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Stage the selected file to git bare repo
|
||||
#
|
||||
# @params
|
||||
# Globals
|
||||
# ${new_file}: new file path to stage
|
||||
# ${new_folder}: new folder to stage
|
||||
# ${stage_file}: changed file to stage
|
||||
|
||||
function stage_file() {
|
||||
local file=$1
|
||||
if [[ -z "${file}" ]]
|
||||
then
|
||||
exit 0
|
||||
else
|
||||
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME add "${file}"
|
||||
echo "${file} staged successfully"
|
||||
fi
|
||||
}
|
||||
|
||||
new_file=''
|
||||
new_folder=''
|
||||
|
||||
while getopts ":fhd" opt
|
||||
do
|
||||
case "$opt" in
|
||||
f)
|
||||
new_file=$(fd -H -d 1 -t f | fzf --multi --exit-0 --preview "head -50 {}")
|
||||
[[ -z "${new_file}" ]] && exit 1
|
||||
break
|
||||
;;
|
||||
h)
|
||||
echo "Usage: fca [-h] [-f] [-d] ...\n"
|
||||
echo "Stage the selected file to the dotfile gitbare repo"
|
||||
echo "Press escape to stop staging file\n"
|
||||
echo "optional arguments:"
|
||||
echo " -h\t\tshow this help message and exit"
|
||||
echo " -f\t\tselect a file in current directory and stage it"
|
||||
echo " -d\t\tselect a entire folder to stage"
|
||||
exit 0
|
||||
;;
|
||||
d)
|
||||
# don't allow add directory from home folder to decrease errors
|
||||
[[ "$PWD" == "$HOME" ]] && exit 0
|
||||
new_folder=$(fd -H -d 1 -t d -E .git | fzf --exit-0 --preview "tree -L 1 -C --dirsfirst {}")
|
||||
[[ -z "${new_folder}" ]] && exit 1
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option: ${OPTARG}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -n "${new_file}" ]]; then
|
||||
while IFS= read -r line; do
|
||||
stage_file "${line}"
|
||||
done <<< "${new_file}"
|
||||
elif [[ -n "${new_folder}" ]]; then
|
||||
stage_file "${new_folder}"
|
||||
else
|
||||
selected_files=$(/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME diff --name-only | \
|
||||
fzf --multi --exit-0 --preview "/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME diff --color=always $HOME/{}" | \
|
||||
awk -v home=$HOME '{print home "/" $0}')
|
||||
while IFS= read -r line; do
|
||||
stage_file "${line}"
|
||||
done <<< "${selected_files}"
|
||||
fi
|
@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Untrack the selected file from the git bare repo
|
||||
#
|
||||
# @params
|
||||
# Globals
|
||||
# ${list_location}: location of where to list files, if empty, will list files from root
|
||||
# ${selected_files}: list of selected file to untrack
|
||||
|
||||
list_location=''
|
||||
|
||||
while getopts ":p:h" opt
|
||||
do
|
||||
case "$opt" in
|
||||
p)
|
||||
list_location="${OPTARG}"
|
||||
;;
|
||||
h)
|
||||
echo "Usage: fcr [-h] [-p PATH] ...\n"
|
||||
echo "Untrack the selected files from git bare repo"
|
||||
echo "Note: Although local files will be untracked without issue"
|
||||
echo "make sure to backup the untracked files in any other desktop"
|
||||
echo "because git will actually remove those files, after pulling the new changes"
|
||||
echo "copy the backup back to their original location\n"
|
||||
echo "optional arguments:"
|
||||
echo " -h\t\tshow this help message and exit"
|
||||
echo ' -p PATH\tspecify the path to list files, by default, files will be listed from $HOME'
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option: ${OPTARG}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "${list_location}" ]]; then
|
||||
cd
|
||||
else
|
||||
cd "${list_location}"
|
||||
fi
|
||||
|
||||
selected_files=$(/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME ls-files | \
|
||||
fzf --multi --exit-0 --preview "head -50 {}")
|
||||
|
||||
[[ -z "${selected_files}" ]] && exit 0
|
||||
|
||||
while IFS= read -r line; do
|
||||
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME rm --cached "${line}"
|
||||
done <<< "${selected_files}"
|
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
selected_stash=$(/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME stash list | \
|
||||
fzf --exit-0 --preview "echo {} | sed 's/://g' | awk '{print \$1}' | \
|
||||
xargs -I __ /usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME stash show -p __ --color" | \
|
||||
sed 's/://g' | awk '{print $1}')
|
||||
|
||||
[[ -z "$selected_stash" ]] && exit 0
|
||||
|
||||
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME stash apply "$selected_stash"
|
Loading…
Reference in New Issue