From c3e5eddfcde26168bb324d10f309dce07fff0738 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 25 Feb 2010 23:35:16 +0100 Subject: split up bashrc and put it in ~/.config/bash --- .bashrc | 125 +------------------------- .bashrc.functions | 197 ----------------------------------------- .config/bash/.bashrc.swp | Bin 0 -> 12288 bytes .config/bash/alias.sh | 19 ++++ .config/bash/bashrc | 11 +++ .config/bash/environment.sh | 76 ++++++++++++++++ .config/bash/functions.sh | 208 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 315 insertions(+), 321 deletions(-) delete mode 100644 .bashrc.functions create mode 100644 .config/bash/.bashrc.swp create mode 100644 .config/bash/alias.sh create mode 100644 .config/bash/bashrc create mode 100644 .config/bash/environment.sh create mode 100644 .config/bash/functions.sh diff --git a/.bashrc b/.bashrc index f792c0c..6f478c3 100644 --- a/.bashrc +++ b/.bashrc @@ -1,124 +1 @@ -# /etc/skel/.bashrc -# -# This file is sourced by all *interactive* bash shells on startup, -# including some apparently interactive shells such as scp and rcp -# that can't tolerate any output. So make sure this doesn't display -# anything or bad things will happen ! - -[[ -d ~/bin/ ]] && PATH="~/bin/:$PATH" -[[ -d ~/.bin/ ]] && PATH="~/.bin/:$PATH" - -# Test for an interactive shell. There is no need to set anything -# past this point for scp and rcp, and it's important to refrain from -# outputting anything in those cases. -if [[ $- != *i* ]] ; then - # Shell is non-interactive. Be done now! - return -fi -# enable bashcompletion -alias ebc="[[ -f /etc/profile.d/bash-completion.sh ]] && source /etc/profile.d/bash-completion.sh" - -alias player="/home/ben/coding/cpp/audio/player" -alias packages="eix -I --format \" \" | grep --color=never Found.*matches." -alias gplay="gnome-mplayer" - -max() { [[ $# -eq 2 ]] && ( [[ $1 -ge $2 ]] && echo $1 || echo $2 ) } - -resize_to_min() { -# eval $(resize -s $(max $LINES $2) $(max $COLUMNS $1)) - printf "\e[8;%d;%dt" $(max $LINES $2) $(max $COLUMNS $1) -} -# list hidden files - if directory do NOT show contents and dont display ".." -alias lh="ls -d .[^.]*" -alias r="resize_to_min 100 35" -#export PAGER="col -b 2>/dev/null | view -c 'set ft=man' -c 'set titlestring=[view]man' -c 'set number!' -" -#export PAGER="sed 's/\[[^m]*m//g; s/.//g' | view -c 'set ft=man' -c 'set titlestring=[view]man' -c 'set number!' -" -#export MANWIDTH=4294967296 -#export PAGER="sed 's/\[[^m]*m//g' | view -c 'set ft=man' -c 'set titlestring=[view]man' -c 'set number!' -" - -# since vim has support - use built in ones.. -export MANPAGER="vimmanpager" -export PAGER="vimpager" - -alias vim="r; vim" -alias man="r; man" - -alias ccat="highlight --ansi" -alias hhtml="highlight --wrap --xhtml --linenumbers --anchors --linenumbers --anchor-prefix=line" - -alias use="quse -D" -alias tv="~/.scripts/tv.sh" -# if files are requested to open, open in existing in tabs. -gvim() { - /usr/bin/gvim $([[ $# > 0 ]] && echo --remote-tab-silent $@) -} - -[[ -f ~/.bashrc.functions ]] && source ~/.bashrc.functions - -if [[ ${EUID} == 0 ]]; then - DELIM_COL='\[\e[0;31m\]' - DIR_COL='\[\e[0;34m\]' - UNAME_COL='\[\e[0;31m\]' -else - DELIM_COL='\[\e[0;34m\]' - DIR_COL='\[\e[0;32m\]' - UNAME_COL='\[\e[1;32m\]' -fi -NOR_COL='\[\e[0m\]' - -PS1="${DELIM_COL}[${DIR_COL}\W${DELIM_COL}] \\\$ ${NOR_COL}" -[[ -n $SSH_CLIENT ]] && PS1="${UNAME_COL}`[[ ${EUID} != 0 ]] && echo '\u@'`\h $PS1" - -unset BRACKET_COL DIR_COL PROMPT_COL NOR_COL UNAME_COL - -#if [[ ${EUID} == 0 ]] ; then -# PS1='\[\e[0;31m\][\[\e[0;34m\]\W\[\e[0;31m\]] \$\[\e[0m\] ' -# [[ -n $SSH_CLIENT ]] && PS1="\[\e[0;31m\]\h\[\e[0m\] $PS1" -#else -# PS1='\[\e[0;34m\][\[\e[0;32m\]\W\[\e[0;34m\]] \$\[\e[0m\] ' -# [[ -n $SSH_CLIENT ]] && PS1="\[\e[1;32m\]\u@\h\[\e[0m\] $PS1" - -#fi - -##PS1="\$(test \$(~/coding/c/get_cursor_pos) -gt 1 && echo '\[\n\]')${PS1}" - -##PS1="\$([[ \$(get_cursor_y) -gt 1 ]] && echo -n '\[\n\]')$PS1" -##PS1="\$(prompt_nl_needed && echo '\[\n\]')${PS1}" - -#PS1="\$(print_prompt_nl_if_needed)${PS1}" - -#PS1="\$(~/coding/c/nl_if_needed)$PS1" - -#inspired by http://www.xfce-look.org/content/show.php/My+Destkop+(December)?content=50362 -#PS1="\[\e[\$((COLUMNS-\$(echo -n '\W' | wc -c)-2))G\] [\W]\[\e[0G\]\$ " -CMD="\$(date +%H:%M)" - -#PS1="\[\e[\$((COLUMNS-\$(echo -n $CMD | wc -c)-2))G\] \[\e[0;34m\][\[\e[0;32m\]$CMD\[\e[0;34m\]]\[\e[0G\]${PS1}" -#PS1="$PS1\[\e[s\[\e[\$((COLUMNS-\$(echo -n $CMD | wc -c)-2))G\]abc\[\e[u\]" - -#if [[ ${EUID} != 0 ]] ; then - #PS1='\[\033[1;34m\]\W \$\[\033[00m\] ' - #PS1='[\[\e[0;31m\]\W\[\e[0m\]] \$ ' - #PS1='\[\033[01;32m\]\u\[\033[00m\]@\[\033[01;31m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$ ' - #PS1='\[\e[1;31m\][\[\e[1;32m\]\W\[\e[1;31m\]]\[\e[1;34m\] \$\[\e[0m\] ' - #PS1='\[\e[0;34m\][\[\e[0;32m\]\W\[\e[0;34m\]] \$\[\e[0m\] ' - #PS1='\[\033[01;32m\]\u\[\033[00m\]@\[\033[01;31m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$ ' - #PS1='[\[\e[36;40m\]\u\[\e[0m\]] \[\e[32;40m\]\W \[\e[0m\]\$ ' - #PS1='[\u \w]\$ ' - #PS1="\[\033[0;36m\]\t\[\033[1;35m\]^\ - #\[\033[0;32m\]\u\[\033[1;34m\]@\[\033[0;32m\]\ - #\h\[\033[1;35m\]:\[\033[1;33m\]\w\[\033[0m\]\ - #\[\033[1;34m\]$\[\033[0m\] " -#fi - -#for matlab - wont start with out this -#export LIBXCB_ALLOW_SLOPPY_LOCK=true - -#for sdl -export SDL_AUDIODRIVER=alsa -export AUDIODEV=plug:upmix - - -export XDG_DATA_HOME="${HOME}/.config" -export XDG_CONFIG_HOME="${HOME}/.config" -export INPUTRC="${XDG_CONFIG_HOME}/readline/inputrc" +source ~/.config/bash/bashrc diff --git a/.bashrc.functions b/.bashrc.functions deleted file mode 100644 index 60f59c2..0000000 --- a/.bashrc.functions +++ /dev/null @@ -1,197 +0,0 @@ -print_prompt_nl_if_needed() { - local pos - local char - local ok=0 - local save=$(stty -g) - - stty -echo -icanon - echo -en '\e[6n' 1>&2 - #response format: \e[n;mR (m is needed) - while true - do - #char=$(dd bs=1 count=1 2>/dev/null) - char=$(head -c1) - [[ $char == 'R' ]] && break - [[ $ok -eq 1 ]] && pos="${pos}${char}" - [[ $char == ';' ]] && ok=1 - done - - stty $save - [[ $pos -gt 1 ]] && echo 1>&2 -} - -qjoypad() { - $(which qjoypad) --device /dev/input $@ -} - -jdownloader() { - $(java-config --java) -jar ~/Desktop/jdownloader/JDownloader.jar -} - -start() { - #local dir=/home/ben/coding/cpp/starter/ - #"${dir}"start "${dir}"command.sh $@ >> /dev/null 2>&1 -# nohup "$@" &>/dev/null & - /home/ben/coding/cpp/starter/start \ - bash -c "source ~/.bashrc.functions; ${@} >> /dev/null 2>&1" -} - -ts() { - start /opt/bin/TeamSpeak $@ -} - -eworld() { - local packages=$(/usr/bin/eix -u --only-names) - [[ -n $packages ]] && /usr/bin/sudo /usr/bin/emerge --verbose --ask --update --oneshot $packages -} - - - -uflag() { - local use=`echo ${1} | sed -n "s/[^a-Z0-9\-]//g; p"` - # [[ -n $use ]] && sed -n "/\(^\|:\)$use -/p" /usr/portage/profiles/use* | grep --color $use - files="/usr/portage/profiles/use.desc /usr/portage/profiles/desc/*" - echo "global use flags (searching: ${use})" - [[ -n $use ]] && sed -n "s~^\(\(.*/.*\):\)\?\(${use} \)\(.*\)$~&~p" $files - - echo -e "\nlocal useflags (searching: ${use})" - [[ -n $use ]] && sed -n "s~^\(\(.*/.*\):\)\?\(${use}\)[[:space:]]*-[[:space:]]*\(.*\)$~\3 (\2):\n\4~p" /usr/portage/profiles/use.local.desc -} - -tstart() { - [[ -n `ps -C $1 | sed -n 's/^.\([0-9][0-9]*\).*$/\1/p'` ]] && killall $1 || $1 -} - -up() { - local server=netdirekt - - if [[ -f $1 ]]; then - local rand=`date +%s | md5sum | sed -n 's/^\(...\).*$/\1/p'` - local name="${rand}-`basename $1`" - scp -q $1 $server:"/home/benjamin/uploads/${name}" || exit - - local cmd="sudo chown lighttpd:lighttpd /home/benjamin/uploads/${name}" - ssh -q $server $cmd || exit - - local ext=$(echo $1 | sed "s/^.*\.\([^\.]*\)$/\\1/") - local types="dummy txt $(sed -n "s/^\$ext(\(.*\))=\(.*\)$/\\1 \\2/p" /etc/highlight/filetypes.conf) dummy" - - [[ -n $(echo $types | grep " $ext ") ]] && \ - local url="http://89.149.199.86/highlight/${name}" || \ - local url="http://89.149.199.86/filebase/files/${name}" - - echo -n $url | xclip -selection clipboard - echo -n $url | xclip -selection primary - echo $url - fi -} - -function calc() { echo "$*" | bc; } - -pdftojpeg() { - if [ -z $2 ] || [ $1 = "--help" ] || [ $1 = "-h" ]; then - echo "Usage: pdftojpeg " - elif [ -e $2 ]; then - echo "Error: $2 existiert bereits!" - else - pdftoppm -l 1 "$1" | convert - -resize "176x248" "$2" - #pdftoppm -l 1 -scale-to 248 "$1" -- | cjpeg > "$2" - fi -} - -unpack() { - local srcdir - local x - local y - local myfail - local tar_opts="" - [ -z "$*" ] && die "Nothing passed to the 'unpack' command" - - for x in "$@"; do - echo ">>> Unpacking ${x} to ${PWD}" - y=${x%.*} - y=${y##*.} - -# if [[ ${x} == "./"* ]] ; then -# srcdir="" -# elif [[ ${x} == ${DISTDIR%/}/* ]] ; then -# die "Arguments to unpack() cannot begin with \${DISTDIR}." -# elif [[ ${x} == "/"* ]] ; then -# die "Arguments to unpack() cannot be absolute" -# else -# srcdir="${DISTDIR}/" -# fi - [[ ! -s ${x} ]] && die "${x} does not exist" - - myfail="failure unpacking ${x}" - case "${x##*.}" in - tar) - tar xof "${x}" ${tar_opts} || die "$myfail" - ;; - tgz) - tar xozf "${x}" ${tar_opts} || die "$myfail" - ;; - tbz|tbz2) - bzip2 -dc "${x}" | tar xof - ${tar_opts} - #assert "$myfail" - ;; - ZIP|zip|jar) - unzip -qo "${x}" || die "$myfail" - ;; - gz|Z|z) - if [ "${y}" == "tar" ]; then - tar zoxf "${x}" ${tar_opts} || die "$myfail" - else - gzip -dc "${x}" > ${x%.*} || die "$myfail" - fi - ;; - bz2|bz) - if [ "${y}" == "tar" ]; then - bzip2 -dc "${x}" | tar xof - ${tar_opts} - assert "$myfail" - else - bzip2 -dc "${x}" > ${x%.*} || die "$myfail" - fi - ;; - 7Z|7z) - local my_output - my_output="$(7z x -y "${x}")" - if [ $? -ne 0 ]; then - echo "${my_output}" >&2 - die "$myfail" - fi - ;; - RAR|rar) - unrar x -idq -o+ "${x}" || die "$myfail" - ;; - LHa|LHA|lha|lzh) - lha xfq "${x}" || die "$myfail" - ;; - a|deb) - ar x "${x}" || die "$myfail" - ;; - lzma) - if [ "${y}" == "tar" ]; then - lzma -dc "${x}" | tar xof - ${tar_opts} - assert "$myfail" - else - lzma -dc "${x}" > ${x%.*} || die "$myfail" - fi - ;; - *) - echo "unpack ${x}: file format not recognized. Ignoring." - ;; - esac - done -# # Do not chmod '.' since it's probably ${WORKDIR} and PORTAGE_WORKDIR_MODE -# # should be preserved. -# find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \ -# ${XARGS} -0 chmod -fR a+rX,u+w,g-w,o-w -} - - - -die() { - echo " * ${*:-(no error message)}" -} - diff --git a/.config/bash/.bashrc.swp b/.config/bash/.bashrc.swp new file mode 100644 index 0000000..3ce3a05 Binary files /dev/null and b/.config/bash/.bashrc.swp differ diff --git a/.config/bash/alias.sh b/.config/bash/alias.sh new file mode 100644 index 0000000..06bb069 --- /dev/null +++ b/.config/bash/alias.sh @@ -0,0 +1,19 @@ +# enable bashcompletion +alias ebc="[[ -f /etc/profile.d/bash-completion.sh ]] && source /etc/profile.d/bash-completion.sh" + +alias player="/home/ben/coding/cpp/audio/player" +alias packages="eix -I --format \" \" | grep --color=never Found.*matches." +alias gplay="gnome-mplayer" + +# list hidden files - if directory do NOT show contents and dont display ".." +alias lh="ls -d .[^.]*" +alias r="resize_to_min 100 35" +alias vim="r; vim" +alias man="r; man" + +alias ccat="highlight --ansi" +alias hhtml="highlight --wrap --xhtml --linenumbers --anchors --linenumbers --anchor-prefix=line" + +alias use="quse -D" +alias tv="~/.scripts/tv.sh" + diff --git a/.config/bash/bashrc b/.config/bash/bashrc new file mode 100644 index 0000000..3fd0fcb --- /dev/null +++ b/.config/bash/bashrc @@ -0,0 +1,11 @@ +[[ -d ~/bin/ ]] && PATH="~/bin/:$PATH" +[[ -d ~/.bin/ ]] && PATH="~/.bin/:$PATH" + +if [[ $- != *i* ]] ; then + # Shell is non-interactive. Be done now! + return +fi + +source ~/.config/bash/environment.sh +source ~/.config/bash/functions.sh +source ~/.config/bash/alias.sh diff --git a/.config/bash/environment.sh b/.config/bash/environment.sh new file mode 100644 index 0000000..8781e92 --- /dev/null +++ b/.config/bash/environment.sh @@ -0,0 +1,76 @@ +#export PAGER="col -b 2>/dev/null | view -c 'set ft=man' -c 'set titlestring=[view]man' -c 'set number!' -" +#export PAGER="sed 's/\[[^m]*m//g; s/.//g' | view -c 'set ft=man' -c 'set titlestring=[view]man' -c 'set number!' -" +#export MANWIDTH=4294967296 +#export PAGER="sed 's/\[[^m]*m//g' | view -c 'set ft=man' -c 'set titlestring=[view]man' -c 'set number!' -" + +# since vim has support - use built in ones.. +export MANPAGER="vimmanpager" +export PAGER="vimpager" + +if [[ ${EUID} == 0 ]]; then + DELIM_COL='\[\e[0;31m\]' + DIR_COL='\[\e[0;34m\]' + UNAME_COL='\[\e[0;31m\]' +else + DELIM_COL='\[\e[0;34m\]' + DIR_COL='\[\e[0;32m\]' + UNAME_COL='\[\e[1;32m\]' +fi +NOR_COL='\[\e[0m\]' + +PS1="${DELIM_COL}[${DIR_COL}\W${DELIM_COL}] \\\$ ${NOR_COL}" +[[ -n $SSH_CLIENT ]] && PS1="${UNAME_COL}`[[ ${EUID} != 0 ]] && echo '\u@'`\h $PS1" + +unset BRACKET_COL DIR_COL PROMPT_COL NOR_COL UNAME_COL + +#if [[ ${EUID} == 0 ]] ; then +# PS1='\[\e[0;31m\][\[\e[0;34m\]\W\[\e[0;31m\]] \$\[\e[0m\] ' +# [[ -n $SSH_CLIENT ]] && PS1="\[\e[0;31m\]\h\[\e[0m\] $PS1" +#else +# PS1='\[\e[0;34m\][\[\e[0;32m\]\W\[\e[0;34m\]] \$\[\e[0m\] ' +# [[ -n $SSH_CLIENT ]] && PS1="\[\e[1;32m\]\u@\h\[\e[0m\] $PS1" + +#fi + +##PS1="\$(test \$(~/coding/c/get_cursor_pos) -gt 1 && echo '\[\n\]')${PS1}" + +##PS1="\$([[ \$(get_cursor_y) -gt 1 ]] && echo -n '\[\n\]')$PS1" +##PS1="\$(prompt_nl_needed && echo '\[\n\]')${PS1}" + +#PS1="\$(print_prompt_nl_if_needed)${PS1}" + +#PS1="\$(~/coding/c/nl_if_needed)$PS1" + +#inspired by http://www.xfce-look.org/content/show.php/My+Destkop+(December)?content=50362 +#PS1="\[\e[\$((COLUMNS-\$(echo -n '\W' | wc -c)-2))G\] [\W]\[\e[0G\]\$ " +CMD="\$(date +%H:%M)" + +#PS1="\[\e[\$((COLUMNS-\$(echo -n $CMD | wc -c)-2))G\] \[\e[0;34m\][\[\e[0;32m\]$CMD\[\e[0;34m\]]\[\e[0G\]${PS1}" +#PS1="$PS1\[\e[s\[\e[\$((COLUMNS-\$(echo -n $CMD | wc -c)-2))G\]abc\[\e[u\]" + +#if [[ ${EUID} != 0 ]] ; then + #PS1='\[\033[1;34m\]\W \$\[\033[00m\] ' + #PS1='[\[\e[0;31m\]\W\[\e[0m\]] \$ ' + #PS1='\[\033[01;32m\]\u\[\033[00m\]@\[\033[01;31m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$ ' + #PS1='\[\e[1;31m\][\[\e[1;32m\]\W\[\e[1;31m\]]\[\e[1;34m\] \$\[\e[0m\] ' + #PS1='\[\e[0;34m\][\[\e[0;32m\]\W\[\e[0;34m\]] \$\[\e[0m\] ' + #PS1='\[\033[01;32m\]\u\[\033[00m\]@\[\033[01;31m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$ ' + #PS1='[\[\e[36;40m\]\u\[\e[0m\]] \[\e[32;40m\]\W \[\e[0m\]\$ ' + #PS1='[\u \w]\$ ' + #PS1="\[\033[0;36m\]\t\[\033[1;35m\]^\ + #\[\033[0;32m\]\u\[\033[1;34m\]@\[\033[0;32m\]\ + #\h\[\033[1;35m\]:\[\033[1;33m\]\w\[\033[0m\]\ + #\[\033[1;34m\]$\[\033[0m\] " +#fi + +#for matlab - wont start with out this +#export LIBXCB_ALLOW_SLOPPY_LOCK=true + +#for sdl +export SDL_AUDIODRIVER=alsa +export AUDIODEV=plug:upmix + + +export XDG_DATA_HOME="${HOME}/.config" +export XDG_CONFIG_HOME="${HOME}/.config" +export INPUTRC="${XDG_CONFIG_HOME}/readline/inputrc" diff --git a/.config/bash/functions.sh b/.config/bash/functions.sh new file mode 100644 index 0000000..34bd71b --- /dev/null +++ b/.config/bash/functions.sh @@ -0,0 +1,208 @@ +max() { [[ $# -eq 2 ]] && ( [[ $1 -ge $2 ]] && echo $1 || echo $2 ) } + +resize_to_min() { +# eval $(resize -s $(max $LINES $2) $(max $COLUMNS $1)) + printf "\e[8;%d;%dt" $(max $LINES $2) $(max $COLUMNS $1) +} + +gvim() { + /usr/bin/gvim $([[ $# > 0 ]] && echo --remote-tab-silent $@) +} + +print_prompt_nl_if_needed() { + local pos + local char + local ok=0 + local save=$(stty -g) + + stty -echo -icanon + echo -en '\e[6n' 1>&2 + #response format: \e[n;mR (m is needed) + while true + do + #char=$(dd bs=1 count=1 2>/dev/null) + char=$(head -c1) + [[ $char == 'R' ]] && break + [[ $ok -eq 1 ]] && pos="${pos}${char}" + [[ $char == ';' ]] && ok=1 + done + + stty $save + [[ $pos -gt 1 ]] && echo 1>&2 +} + +qjoypad() { + $(which qjoypad) --device /dev/input $@ +} + +jdownloader() { + $(java-config --java) -jar ~/Desktop/jdownloader/JDownloader.jar +} + +start() { + #local dir=/home/ben/coding/cpp/starter/ + #"${dir}"start "${dir}"command.sh $@ >> /dev/null 2>&1 +# nohup "$@" &>/dev/null & + /home/ben/coding/cpp/starter/start \ + bash -c "source ~/.bashrc.functions; ${@} >> /dev/null 2>&1" +} + +ts() { + start /opt/bin/TeamSpeak $@ +} + +eworld() { + local packages=$(/usr/bin/eix -u --only-names) + [[ -n $packages ]] && /usr/bin/sudo /usr/bin/emerge --verbose --ask --update --oneshot $packages +} + + + +uflag() { + local use=`echo ${1} | sed -n "s/[^a-Z0-9\-]//g; p"` + # [[ -n $use ]] && sed -n "/\(^\|:\)$use -/p" /usr/portage/profiles/use* | grep --color $use + files="/usr/portage/profiles/use.desc /usr/portage/profiles/desc/*" + echo "global use flags (searching: ${use})" + [[ -n $use ]] && sed -n "s~^\(\(.*/.*\):\)\?\(${use} \)\(.*\)$~&~p" $files + + echo -e "\nlocal useflags (searching: ${use})" + [[ -n $use ]] && sed -n "s~^\(\(.*/.*\):\)\?\(${use}\)[[:space:]]*-[[:space:]]*\(.*\)$~\3 (\2):\n\4~p" /usr/portage/profiles/use.local.desc +} + +tstart() { + [[ -n `ps -C $1 | sed -n 's/^.\([0-9][0-9]*\).*$/\1/p'` ]] && killall $1 || $1 +} + +up() { + local server=netdirekt + + if [[ -f $1 ]]; then + local rand=`date +%s | md5sum | sed -n 's/^\(...\).*$/\1/p'` + local name="${rand}-`basename $1`" + scp -q $1 $server:"/home/benjamin/uploads/${name}" || exit + + local cmd="sudo chown lighttpd:lighttpd /home/benjamin/uploads/${name}" + ssh -q $server $cmd || exit + + local ext=$(echo $1 | sed "s/^.*\.\([^\.]*\)$/\\1/") + local types="dummy txt $(sed -n "s/^\$ext(\(.*\))=\(.*\)$/\\1 \\2/p" /etc/highlight/filetypes.conf) dummy" + + [[ -n $(echo $types | grep " $ext ") ]] && \ + local url="http://89.149.199.86/highlight/${name}" || \ + local url="http://89.149.199.86/filebase/files/${name}" + + echo -n $url | xclip -selection clipboard + echo -n $url | xclip -selection primary + echo $url + fi +} + +function calc() { echo "$*" | bc; } + +pdftojpeg() { + if [ -z $2 ] || [ $1 = "--help" ] || [ $1 = "-h" ]; then + echo "Usage: pdftojpeg " + elif [ -e $2 ]; then + echo "Error: $2 existiert bereits!" + else + pdftoppm -l 1 "$1" | convert - -resize "176x248" "$2" + #pdftoppm -l 1 -scale-to 248 "$1" -- | cjpeg > "$2" + fi +} + +unpack() { + local srcdir + local x + local y + local myfail + local tar_opts="" + [ -z "$*" ] && die "Nothing passed to the 'unpack' command" + + for x in "$@"; do + echo ">>> Unpacking ${x} to ${PWD}" + y=${x%.*} + y=${y##*.} + +# if [[ ${x} == "./"* ]] ; then +# srcdir="" +# elif [[ ${x} == ${DISTDIR%/}/* ]] ; then +# die "Arguments to unpack() cannot begin with \${DISTDIR}." +# elif [[ ${x} == "/"* ]] ; then +# die "Arguments to unpack() cannot be absolute" +# else +# srcdir="${DISTDIR}/" +# fi + [[ ! -s ${x} ]] && die "${x} does not exist" + + myfail="failure unpacking ${x}" + case "${x##*.}" in + tar) + tar xof "${x}" ${tar_opts} || die "$myfail" + ;; + tgz) + tar xozf "${x}" ${tar_opts} || die "$myfail" + ;; + tbz|tbz2) + bzip2 -dc "${x}" | tar xof - ${tar_opts} + #assert "$myfail" + ;; + ZIP|zip|jar) + unzip -qo "${x}" || die "$myfail" + ;; + gz|Z|z) + if [ "${y}" == "tar" ]; then + tar zoxf "${x}" ${tar_opts} || die "$myfail" + else + gzip -dc "${x}" > ${x%.*} || die "$myfail" + fi + ;; + bz2|bz) + if [ "${y}" == "tar" ]; then + bzip2 -dc "${x}" | tar xof - ${tar_opts} + assert "$myfail" + else + bzip2 -dc "${x}" > ${x%.*} || die "$myfail" + fi + ;; + 7Z|7z) + local my_output + my_output="$(7z x -y "${x}")" + if [ $? -ne 0 ]; then + echo "${my_output}" >&2 + die "$myfail" + fi + ;; + RAR|rar) + unrar x -idq -o+ "${x}" || die "$myfail" + ;; + LHa|LHA|lha|lzh) + lha xfq "${x}" || die "$myfail" + ;; + a|deb) + ar x "${x}" || die "$myfail" + ;; + lzma) + if [ "${y}" == "tar" ]; then + lzma -dc "${x}" | tar xof - ${tar_opts} + assert "$myfail" + else + lzma -dc "${x}" > ${x%.*} || die "$myfail" + fi + ;; + *) + echo "unpack ${x}: file format not recognized. Ignoring." + ;; + esac + done +# # Do not chmod '.' since it's probably ${WORKDIR} and PORTAGE_WORKDIR_MODE +# # should be preserved. +# find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \ +# ${XARGS} -0 chmod -fR a+rX,u+w,g-w,o-w +} + + + +die() { + echo " * ${*:-(no error message)}" +} + -- cgit