From 0fd227776229ddf21253b1e3cb8aa782c827e353 Mon Sep 17 00:00:00 2001 From: Jean-Michel Fayard Date: Mon, 21 Oct 2013 19:07:24 +0200 Subject: [PATCH 1/3] 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 From 907f7ceaa928f67dcfc981c3d3060f7438faea0a Mon Sep 17 00:00:00 2001 From: Jean-Michel Fayard Date: Mon, 21 Oct 2013 23:50:16 +0200 Subject: [PATCH 2/3] Creating template/FILES.template so that baash_it users can get started more quickly with `$ edit ` Plus small bug in edit --- install.sh | 4 ++++ lib/helpers.bash | 2 +- template/FILES.template | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 template/FILES.template diff --git a/install.sh b/install.sh index 46edcf22..408ce4ea 100755 --- a/install.sh +++ b/install.sh @@ -9,6 +9,10 @@ cp $HOME/.bash_it/template/bash_profile.template.bash $HOME/.bash_profile echo "Copied the template .bash_profile into ~/.bash_profile, edit this file to customize bash-it" +# TODO: this should be tested more. +cp $BASH_IT/template/FILES.template $BASH_IT/custom/FILES +echo "Copied the template FILES into $BASH_IT/custom/FILES, edit this file to have bookmarks to file you 'edit' often" + while true do read -p "Do you use Jekyll? (If you don't know what Jekyll is, answer 'n') [Y/N] " RESP diff --git a/lib/helpers.bash b/lib/helpers.bash index b04ea6c2..43107a1d 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -357,7 +357,7 @@ edit () { FILES=$1 if [ -z "$FILES" ] then - $EDITOR $HOME/.bash-it/custom/FILES + $EDITOR $BASH_IT/custom/FILES else $EDITOR $FILES fi diff --git a/template/FILES.template b/template/FILES.template new file mode 100644 index 00000000..ae80ce2c --- /dev/null +++ b/template/FILES.template @@ -0,0 +1,32 @@ +# This file is opened with you type 'edit' without argument +# $ edit + +# Simply edit this file and put you have bookmarks to the files you edit most +# +# You don't need anymore to go to the same directory and open the same files again and again +# How to open the file is then trivial +# - With vim, see :help gf +# - With xxx, do yyyy +# - If your text editor doesn't have that feature, simply copy and paste + +# When you call edit with arguments, edit is simply a shortcut to EDITOR +# $ edit /etc/fstab + +# edit those files as root +/etc/apt/sources.list +/etc/fstab +/etc/hosts +/etc/hosts +/etc/nginx/conf.d/nginx.conf +/etc/profile + +# edit those files as a user +$BASH_IT/aliases/custom.aliases.bash +$BASH_IT/lib/custom.bash +$BASH_IT/plugins/custom.plugins.bash +$HOME/.bash_profile +$HOME/.vimrc +$HOME/.emacs + +# See here for inspiration of what you can put here +http://en.wikibooks.org/wiki/Guide_to_Unix/Files From eddb356feeeb35e630f9f6cd024e9ce4a6e0a08b Mon Sep 17 00:00:00 2001 From: Jean-Michel Fayard Date: Mon, 21 Oct 2013 23:54:18 +0200 Subject: [PATCH 3/3] Documeting the "edit" bookmarking magic --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 527034c4..97db0caa 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Includes autocompletion, themes, aliases, custom functions, a few stolen pieces 1. Check a clone of this repo: `git clone https://github.com/revans/bash-it.git ~/.bash_it` 2. Run `~/.bash_it/install.sh` (it automatically backs up your `~/.bash_profile`) 3. Edit your `~/.bash_profile` file in order to customize bash-it. +4. Run `$ edit` and edit this file to have bookmarks to the files you edit over and over again **NOTE:** The install script will also prompt you asking if you use [Jekyll](https://github.com/mojombo/jekyll).