Browse Source

Initial commit

main
Cédric Marie 9 years ago
commit
29010b42e9
  1. 2
      .gitignore
  2. 2
      INSTALL
  3. 21
      bash/alias
  4. 20
      bash/init
  5. 39
      bash/setproject
  6. 26
      bash/setprompt
  7. 28
      scripts/myunzip
  8. 47
      scripts/myzip

2
.gitignore

@ -0,0 +1,2 @@
alias.local
scripts.local/

2
INSTALL

@ -0,0 +1,2 @@
Add this line in your ~/.bashrc file:
source <path_to_painted_shell>/bash/init

21
bash/alias

@ -0,0 +1,21 @@
#!/bin/bash
#(to be sourced)
# Override default options
alias rm='rm -i'
if [ "$TERM" != "" ]; then
alias ls='ls --color=always'
fi
# Aliases for specific options
alias ll="ls -l"
alias lll="ls -al"
alias llf="ls -l --full-time"
# Aliases for new commands
alias ..='cd ..'
alias ...='cd ../..'
# Aliases for setting commands (to be sourced)
alias setproject='source $PAINTED_SHELL_PATH/bash/setproject'

20
bash/init

@ -0,0 +1,20 @@
#!/bin/bash
#(to be sourced)
export PAINTED_SHELL_PATH=$(dirname $(dirname $BASH_SOURCE))
# Define aliases
source $PAINTED_SHELL_PATH/bash/alias
# Set colorful prompt
source $PAINTED_SHELL_PATH/bash/setprompt
# Add the path to scripts if not yet present
echo $PATH | grep -q "$PAINTED_SHELL_PATH/scripts" || PATH=$PATH:$PAINTED_SHELL_PATH/scripts
# Define local aliases (specific to this environment)
if [ -f $PAINTED_SHELL_PATH/bash/alias.local ]; then
source $PAINTED_SHELL_PATH/bash/alias.local
fi
# Add the path to local scripts (specific to this environment)
if [ -d $PAINTED_SHELL_PATH/scripts.local ]; then
echo $PATH | grep -q "$PAINTED_SHELL_PATH/scripts.local" || PATH=$PATH:$PAINTED_SHELL_PATH/scripts.local
fi

39
bash/setproject

@ -0,0 +1,39 @@
#!/bin/bash
#(to be sourced)
usage()
{
echo "Usage: setproject [HOME_DIR]"
echo "Select a project with current directory as project root directory, and HOME_DIR (optional) as project home directory."
echo "Define new aliases: pcdr = cd ROOT_DIR, pcdh = cd HOME_DIR."
}
project_is_set="n"
if [ $# = 0 ]; then
# root directory = home directory = current directory
project_root_dir=`pwd`
project_home_dir=$project_root_dir
project_is_set="y"
elif [ $# = 1 ]; then
# root directory = current directory
# home directory = parameter
if [ -d "$1" ]; then
project_root_dir=`pwd`
cd $1
project_home_dir=`pwd`
project_is_set="y"
else
usage
fi
else
usage
fi
if [ "$project_is_set" = "y" ]; then
project_name=${project_root_dir##*/}
source $PAINTED_SHELL_PATH/bash/setprompt $project_name
alias pcdr="cd $project_root_dir"
alias pcdh="cd $project_home_dir"
cd $project_home_dir
fi

26
bash/setprompt

@ -0,0 +1,26 @@
#!/bin/bash
#(to be sourced)
usage()
{
echo "Usage: setprompt [STRING]"
echo "Set prompt with user name, STRING (optional) and working directory."
}
if [ "$TERM" != "" ]; then
prompt_usr="\[\e[1;33;41m\]\u "
prompt_str="\[\e[1;37;42m\]$1 "
prompt_pwd="\[\e[1;36;44m\]\w "
prompt_end="\[\e[0m\]\[\e[1;31m\] >\[\e[0m\] "
if [ $# = 0 ]; then
# user + directory
PS1=$prompt_usr$prompt_pwd$prompt_end
#PS1=$prompt_pwd$prompt_end
elif [ $# = 1 ]; then
# user + parameter + directory
PS1=$prompt_usr$prompt_str$prompt_pwd$prompt_end
else
usage
fi
fi

28
scripts/myunzip

@ -0,0 +1,28 @@
#!/bin/sh
exit_with_usage()
{
command=$(basename $0)
printf "Usage: $command FILE\n"
printf "Unzip a zipped directory.\n"
exit 1
}
option_crypt=0
if [ "$1" = "" -o ! -f "$1" ]; then exit_with_usage; fi
file=${1%.crypt}
if [ "$file" != "$1" ]; then
option_crypt=1
[ -e "$file" ] && printf "$file already exists\n" && exit 1
fi
dir=${file%.tar.xz}
[ "$dir" = "$file" ] && exit_with_usage
dir=${dir%.*-*-*.*h*m*s}
[ -e "$dir" ] && printf "$dir already exists\n" && exit 1
if [ $option_crypt -eq 1 ]; then
openssl bf-cbc -d -a -in $1 -out $file
fi
tar -Jxvf $file
[ $option_crypt -eq 1 ] && rm -f $file
printf "\033[1mOutput directory:\033[0m $dir\n"

47
scripts/myzip

@ -0,0 +1,47 @@
#!/bin/sh
exit_with_usage()
{
command=$(basename $0)
printf "Usage: $command [OPTION]... DIRECTORY\n"
printf "Zip a directory.\n"
printf " -c : encrypt output file with password\n"
printf " -t : timestamp output file\n"
exit 1
}
option_crypt=0
option_timestamp=0
# Get options from command line
while getopts ct OPT
do
case $OPT in
c) option_crypt=1;;
t) option_timestamp=1;;
*) exit_with_usage;;
esac
done
shift $(($OPTIND - 1))
if [ "$1" = "" -o ! -d "$1" ]; then exit_with_usage; fi
dir=${1%/}
if [ $option_timestamp -eq 1 ]; then
file=$dir.`date +%F.%Hh%Mm%Ss`.tar.xz
else
file=$dir.tar.xz
fi
[ -e "$file" ] && printf "$file already exists\n" && exit 1
if [ $option_crypt -eq 1 ]; then
output_file=${file}.crypt
[ -e "$output_file" ] && printf "$output_file already exists\n" && exit 1
else
output_file=$file
fi
tar -Jcvf $file $dir
if [ $option_crypt -eq 1 ]; then
openssl bf-cbc -e -a -salt -in $file -out $output_file
rm -f $file
[ -f $output_file ] || exit 1
fi
chmod 444 $output_file
printf "\033[1mOutput file:\033[0m $output_file\n"
Loading…
Cancel
Save