Completions for backup_*
This commit is contained in:
parent
e186fdf7db
commit
41f13f65d3
17
.bashrc
17
.bashrc
|
@ -54,7 +54,7 @@ hash -r
|
|||
unalias -a
|
||||
unset POSIXLY_CORRECT
|
||||
|
||||
################################# ENVIRONMENT ##################################
|
||||
################################# environment ##################################
|
||||
export EDITOR="$({ type -P nvim ||
|
||||
type -P vim ||
|
||||
type -P vi ||
|
||||
|
@ -291,7 +291,7 @@ write_history () {
|
|||
rm -f -- "${HISTFILE}"
|
||||
} && trap 'write_history' EXIT
|
||||
|
||||
############################# VIM ALIASES (posix) ##############################
|
||||
############################# vim aliases (posix) ##############################
|
||||
if _have nvim ; then
|
||||
alias vi="$(_path_lookup nvim)"
|
||||
elif _have vim ; then
|
||||
|
@ -602,7 +602,7 @@ clone42 () {
|
|||
} || { printf '%s\n' "Could not clone repo!" ; }
|
||||
}
|
||||
|
||||
################################ BASH PRE-EXEC #################################
|
||||
################################ bash pre-exec #################################
|
||||
if [ ! -f "${HOME}"/.bash-preexec.sh ] ; then
|
||||
curl -sfkSL "https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh" -o "${HOME}"/.bash-preexec.sh
|
||||
fi
|
||||
|
@ -634,7 +634,7 @@ precmd() {
|
|||
fi
|
||||
}
|
||||
|
||||
#################################### PROMPT ####################################
|
||||
#################################### prompt ####################################
|
||||
GIT_PS1_SHOWDIRTYSTATE='1'
|
||||
GIT_PROMPT='1'
|
||||
if [ ! -f "${HOME}"/git-prompt.sh ] && [ "${GIT_PROMPT-}" -eq "1" ] ; then
|
||||
|
@ -679,7 +679,7 @@ fi
|
|||
# Show shell level
|
||||
# PS1='[${SHLVL}] '"${PS1}"
|
||||
|
||||
# ##################################### AOC ######################################
|
||||
# ##################################### aoc ######################################
|
||||
AOC_DIR="${HOME}/projects/aoc" # remember to change this to whatever your AOC directory is
|
||||
alias aos='< in.txt python3 solution.py'
|
||||
alias aot='< test.txt printf '\033[34m' ; python3 solution.py ; printf '\033[m''
|
||||
|
@ -790,7 +790,7 @@ aocload () {
|
|||
tmux send-keys "nvim './solution.py'" ENTER
|
||||
}
|
||||
|
||||
############################## TERMINAL SETTINGS ###############################
|
||||
############################## terminal settings ###############################
|
||||
tabs -4
|
||||
set -o emacs
|
||||
_have lesspipe && eval "$(SHELL=/bin/sh lesspipe)"
|
||||
|
@ -802,7 +802,10 @@ _have xset && 2>/dev/null xset r rate 200 60
|
|||
# Disable bell
|
||||
_have xset && 2>/dev/null xset -b
|
||||
|
||||
################################# COMPLETIONS ##################################
|
||||
################################# completions ##################################
|
||||
complete -F _command vimw
|
||||
complete -C backup_dir backup_dir
|
||||
complete -C backup_file backup_file
|
||||
|
||||
################################### sources ####################################
|
||||
_source_if "${HOME}/.userbashrc"
|
||||
|
|
|
@ -1,18 +1,57 @@
|
|||
#! /bin/sh -
|
||||
# Depends on GNU cp, basename, log.err
|
||||
# Depends on GNU cp, log.err
|
||||
|
||||
[ "${#}" -ne "2" ] && { log.err "Usage: backup_dir BACKUP_DIR DIR" ; exit 1 ; }
|
||||
############################### completion start ###############################
|
||||
options='--no-chattr --no-sudo'
|
||||
if [ -n "${COMP_LINE}" ] ; then
|
||||
if [ "${1}" = "${3}" ] && [ ! "${2#-}" = "${2}" ] ; then
|
||||
for option in $options ; do
|
||||
case "${option}" in
|
||||
"${2}"*) printf '%s\n' "${option}" ;;
|
||||
esac
|
||||
done
|
||||
elif [ "${2#-}" = "${2}" ] ; then
|
||||
find "$(dirname -- "${2}")" -mindepth 1 -maxdepth 1 -path "$(dirname -- "${2}")/$(basename -- "${2}")*"
|
||||
fi
|
||||
exit
|
||||
fi
|
||||
################################ completion end ################################
|
||||
|
||||
############################ argument parsing start ############################
|
||||
no_chattr=0
|
||||
no_sudo=0
|
||||
while : ; do
|
||||
case "${1}" in
|
||||
--no-chattr|-c) no_chattr=1 ;;
|
||||
--no-sudo|-s) no_sudo=1 ;;
|
||||
-*) log.err "Invalid option argument: '${1}'" ; exit 1 ;;
|
||||
*) break ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
test "${#}" -ne "2" && { log.err "Usage: backup_dir [--no-chattr] [--no-sudo] BACKUP_DIR DIR" ; exit 1 ; }
|
||||
|
||||
backupdir="${1:-${HOME}/backups}"
|
||||
srcdir="${2}"
|
||||
############################# argument parsing end #############################
|
||||
|
||||
if [ "${no_sudo}" = "1" ] ; then
|
||||
sudo_cmd=""
|
||||
else
|
||||
sudo_cmd="sudo --"
|
||||
fi
|
||||
|
||||
backupname="$(basename -- "$srcdir")"
|
||||
|
||||
[ -d "${srcdir}" ] || { log.err "Directory '${srcdir}' does not exist" ; exit 2 ; }
|
||||
[ -d "${backupdir}" ] || mkdir -p -- "${backupdir}" || { log.err "Backup Directory '${backupdir}' couldn't be created" ; exit 3 ; }
|
||||
|
||||
if [ -e "${backupdir}/${backupname}" ]; then
|
||||
chattr -i "${backupdir}/${backupname}" || { log.err "Can't chattr -i '${backupdir}/${backupname}'" ; exit 4 ; }
|
||||
if [ -e "${backupdir}/${backupname}" ] && [ "${no_chattr}" = "0" ] ; then
|
||||
$sudo_cmd chattr -i "${backupdir}/${backupname}" || { log.err "Can't chattr -i '${backupdir}/${backupname}'" ; exit 4 ; }
|
||||
fi
|
||||
tar --backup=t -cvzf "${backupdir}/${backupname}" "${srcdir}" || { log.err "Can't tar --backup=t -cvzf '${backupdir}/${backupname}' '${srcdir}'" ; exit 5 ; }
|
||||
|
||||
find "${backupdir}" -mindepth 1 -exec chattr +i {} + || { log.err "Can't chattr +i some files" ; exit 6 ; }
|
||||
if [ "${no_chattr}" = "0" ] ; then
|
||||
$sudo_cmd find "${backupdir}" -mindepth 1 -exec chattr +i {} + || { log.err "Can't chattr +i some files" ; exit 6 ; }
|
||||
fi
|
||||
|
|
|
@ -1,18 +1,57 @@
|
|||
#! /bin/sh -
|
||||
# Depends on GNU cp, basename, log.err
|
||||
# Depends on GNU cp, log.err
|
||||
|
||||
[ "${#}" -ne "2" ] && { log.err "Usage: backup_dir BACKUP_DIR FILE" ; exit 1 ; }
|
||||
############################### completion start ###############################
|
||||
options='--no-chattr --no-sudo'
|
||||
if [ -n "${COMP_LINE}" ] ; then
|
||||
if [ "${1}" = "${3}" ] && [ ! "${2#-}" = "${2}" ] ; then
|
||||
for option in $options ; do
|
||||
case "${option}" in
|
||||
"${2}"*) printf '%s\n' "${option}" ;;
|
||||
esac
|
||||
done
|
||||
elif [ "${2#-}" = "${2}" ] ; then
|
||||
find "$(dirname -- "${2}")" -mindepth 1 -maxdepth 1 -path "$(dirname -- "${2}")/$(basename -- "${2}")*"
|
||||
fi
|
||||
exit
|
||||
fi
|
||||
################################ completion end ################################
|
||||
|
||||
############################ argument parsing start ############################
|
||||
no_chattr=0
|
||||
no_sudo=0
|
||||
while : ; do
|
||||
case "${1}" in
|
||||
--no-chattr|-c) no_chattr=1 ;;
|
||||
--no-sudo|-s) no_sudo=1 ;;
|
||||
-*) log.err "Invalid option argument: '${1}'" ; exit 1 ;;
|
||||
*) break ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
test "${#}" -ne "2" && { log.err "Usage: backup_dir [--no-chattr] [--no-sudo] BACKUP_DIR DIR" ; exit 1 ; }
|
||||
|
||||
backupdir="${1:-${HOME}/backups}"
|
||||
srcfile="${2}"
|
||||
############################# argument parsing end #############################
|
||||
|
||||
if [ "${no_sudo}" = "1" ] ; then
|
||||
sudo_cmd=""
|
||||
else
|
||||
sudo_cmd="sudo --"
|
||||
fi
|
||||
|
||||
backupname="$(basename -- "$srcfile")"
|
||||
|
||||
[ -f "${srcfile}" ] || { log.err "Regular File '${srcfile}' does not exist" ; exit 2 ; }
|
||||
[ -d "${backupdir}" ] || mkdir -p -- "${backupdir}" || { log.err "Backup Directory '${backupdir}' couldn't be created" ; exit 3 ; }
|
||||
|
||||
if [ -e "${backupdir}/${backupname}" ]; then
|
||||
chattr -i "${backupdir}/${backupname}" || { log.err "Can't chattr -i '${backupdir}/${backupname}'" ; exit 4 ; }
|
||||
if [ -e "${backupdir}/${backupname}" ] && [ "${no_chattr}" = "0" ] ; then
|
||||
$sudo_cmd chattr -i "${backupdir}/${backupname}" || { log.err "Can't chattr -i '${backupdir}/${backupname}'" ; exit 4 ; }
|
||||
fi
|
||||
cp --backup=t "${srcfile}" "${backupdir}/${backupname}" || { log.err "Can't cp --backup=t '${srcfile}' '${backupdir}/${backupname}'" ; exit 5 ; }
|
||||
|
||||
find "${backupdir}" -mindepth 1 -exec chattr +i {} + || { log.err "Can't chattr +i some files" ; exit 6 ; }
|
||||
if [ "${no_chattr}" = "0" ] ; then
|
||||
$sudo_cmd find "${backupdir}" -mindepth 1 -exec chattr +i {} + || { log.err "Can't chattr +i some files" ; exit 6 ; }
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue