adding archive command + XDG_* environnment variables (not finished)

In its essence, the archive command does this :
  archive /tmp/TEST.png
  mv /tmp/2013-10-20--TEST.png

I follow here the principle from gmail that you should 98% of the time,
archiving is better of deleting.

XDG Base Directory Specification
http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

Please review this patch, I'm not a real bash programmer.
pull/232/head
Jean-Michel Fayard 2013-10-21 19:07:24 +02:00
parent 8c03cc4297
commit 0fd2277762
3 changed files with 60 additions and 1 deletions

View File

@ -25,7 +25,6 @@ alias c='clear'
alias k='clear' alias k='clear'
alias cls='clear' alias cls='clear'
alias edit="$EDITOR"
alias pager="$PAGER" alias pager="$PAGER"
alias q='exit' alias q='exit'

View File

@ -353,3 +353,48 @@ all_groups ()
cat $file | sort | uniq cat $file | sort | uniq
rm $file rm $file
} }
edit () {
FILES=$1
if [ -z "$FILES" ]
then
$EDITOR $HOME/.bash-it/custom/FILES
else
$EDITOR $FILES
fi
}
archive () {
FILE=$1
BASEFILE=$(basename "$FILE")
TODAY=$(date --rfc-3339=date)
TARGET="$TODAY--$BASEFILE"
if [ -z "$FILE" ]
then
echo "move a file in the '$ARCHIVE' directory, timestamping it with $TODAY"
echo "Syntaxe : archive <file>"
return 1
fi
if [ -d "$FILE" ]
then
echo "sorry, archive doesn't work for directories"
return 2
fi
if [ ! -r "$FILE" ]
then
echo "Cannot read file '$FILE'"
return 3
fi
if [ -z "$ARCHIVE" ]
then
ARCHIVE=$HOME/archive
fi
if [ ! -r "$ARCHIVE" ]
then
mkdir -p "$ARCHIVE"
fi
echo "Archiving '$FILE' in '$ARCHIVE'"
/bin/mv -- "$FILE" "$ARCHIVE"/"$TARGET"
}

View File

@ -1,5 +1,19 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Set where your want to archive your files with the archive command
export ARCHIVE=$HOME/archive # default
# Set the XDG_* environnment variable
# See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
export XDG_DATA_HOME=$HOME/.local/share
export XDG_CONFIG_HOME=$HOME/.config
export XDG_CONFIG_DIRS=/etc/xdg
export XDG_CACHE_HOME=$HOME/.cache
# export XDG_RUNTIME_DIR=we won t set this for you, read the spec
# export XDG_DATA_DIRS=we won t set this for you, read the spec
# TODO : those directories should be created if they don't exist
# Load RVM, if you are using it # Load RVM, if you are using it
[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm [[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm
@ -39,5 +53,6 @@ export TODO="t"
# https://github.com/xvzf/vcprompt # https://github.com/xvzf/vcprompt
#export VCPROMPT_EXECUTABLE=~/.vcprompt/bin/vcprompt #export VCPROMPT_EXECUTABLE=~/.vcprompt/bin/vcprompt
# Load Bash It # Load Bash It
source $BASH_IT/bash_it.sh source $BASH_IT/bash_it.sh