From 0fd227776229ddf21253b1e3cb8aa782c827e353 Mon Sep 17 00:00:00 2001 From: Jean-Michel Fayard Date: Mon, 21 Oct 2013 19:07:24 +0200 Subject: [PATCH] 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. --- aliases/available/general.aliases.bash | 1 - lib/helpers.bash | 45 ++++++++++++++++++++++++++ template/bash_profile.template.bash | 15 +++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index 2439eb08..f33280cb 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -25,7 +25,6 @@ alias c='clear' alias k='clear' alias cls='clear' -alias edit="$EDITOR" alias pager="$PAGER" alias q='exit' diff --git a/lib/helpers.bash b/lib/helpers.bash index b99ae3d3..b04ea6c2 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -353,3 +353,48 @@ all_groups () cat $file | sort | uniq 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 " + 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" +} + diff --git a/template/bash_profile.template.bash b/template/bash_profile.template.bash index 60cac9ea..43c249f7 100644 --- a/template/bash_profile.template.bash +++ b/template/bash_profile.template.bash @@ -1,5 +1,19 @@ #!/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 [[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm @@ -39,5 +53,6 @@ export TODO="t" # https://github.com/xvzf/vcprompt #export VCPROMPT_EXECUTABLE=~/.vcprompt/bin/vcprompt + # Load Bash It source $BASH_IT/bash_it.sh