From 7e68ca61fc7aff1318a21e25659f177ba2eb5995 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 29 Jul 2015 00:06:58 +0100 Subject: [PATCH] change profile paths --- bin/nb-update | 6 ++- etc/profile | 14 ++++-- etc/profile.d/0default.sh | 52 -------------------- etc/profile.d/default.sh | 0 etc/{bashrc => profile.d/envs} | 11 +++-- etc/{bashrc.function => profile.d/functions} | 51 ++++++++++++++++++- 6 files changed, 70 insertions(+), 64 deletions(-) delete mode 100644 etc/profile.d/0default.sh create mode 100644 etc/profile.d/default.sh rename etc/{bashrc => profile.d/envs} (86%) rename etc/{bashrc.function => profile.d/functions} (70%) diff --git a/bin/nb-update b/bin/nb-update index 93b668c8..9576ec3c 100755 --- a/bin/nb-update +++ b/bin/nb-update @@ -37,12 +37,16 @@ for repo in \ cd "$repo" || continue [ -z "$user" ] && user=`ls -dl "$repo" |awk '{print $3}'` + cmd="git pull" echo ">git pull $repo (user=$user)" if [ "$USER" == "$user" ]; then timeout 30 git pull - else + elif [ "$USER" == "root" ]; then timeout 30 su $user -c "GIT_SSH=$TMP cd \"$repo\" && git pull" + else + echo "Ignore $repo: current user=$USER repo user=$user" + continue fi ret=$? diff --git a/etc/profile b/etc/profile index b84c3060..6964d3ca 100644 --- a/etc/profile +++ b/etc/profile @@ -1,10 +1,14 @@ -case "$BASH_SOURCE" in */*) path_profile="${BASH_SOURCE%/*}";; *) path_profile='.' ;; esac -[ -r "${path_profile}/bashrc" ] && . "${path_profile}/bashrc" -[ -r "${path_profile}/aliases" ] && . "${path_profile}/aliases" +# +# ROOT PATH +# +case "$BASH_SOURCE" in */*) path="${BASH_SOURCE%/*}";; *) path='.' ;; esac +[ -e "$path/profile.d/functions" ] && . "$path/profile.d/functions" +NB_ROOT=$(realpath ${path}/..) +unset path -for i in $NB_ROOT/etc/profile.d/*.sh; do +for i in ${NB_ROOT}/etc/profile.d/envs ${NB_ROOT}/etc/profile.d/aliases $NB_ROOT/etc/profile.d/*.sh; do [ -r "$i" ] && . "$i" done -unset i path_profile +unset i tmp true diff --git a/etc/profile.d/0default.sh b/etc/profile.d/0default.sh deleted file mode 100644 index 5a9fe88e..00000000 --- a/etc/profile.d/0default.sh +++ /dev/null @@ -1,52 +0,0 @@ -radio_play() { -#1 | FranceInter | http://www.tv-radio.com/station/france_inter_mp3/france_inter_mp3-128k.m3u -#3 | FranceInfo | http://players.creacast.com/creacast/france_info/playlist.m3u -#4 | FranceCulture | http://www.tv-radio.com/station/france_culture_mp3/france_culture_mp3-128k.m3u - local radios="\ -1 | FranceInter | http://audio.scdn.arkena.com/11008/franceinter-midfi128.mp3 -2 | Indie | http://107.155.126.42:17160/listen.pls -3 | FranceInfo | http://audio.scdn.arkena.com/11006/franceinfo-midfi128.mp3 -4 | FranceCulture | http://audio.scdn.arkena.com/11010/franceculture-midfi128.mp3 -5 | BBC 1 | http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1_mf_p -6 | BBC 2 | http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio2_mf_p -7 | BBC 3 | http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/http-icy-aac-lc-a/format/pls/vpid/bbc_radio_three.pls -8 | BBC 4 | http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4fm_mf_p -9 | BBC 5 live | http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio5live_mf_p -10 | BBC 6 | http://bbcmedia.ic.llnwd.net/stream/bbcmedia_6music_mf_p - -Choose one > \ -" - if [ -z "$@" ]; then - read -p "$radios" - else - REPLY="$@" - fi - - test -z "$REPLY" 2>/dev/null && return - echo "$radios" | awk -F '|' '$1 == '$REPLY' {print $3; exit}' | sed 's/^ //' | xargs mplayer 2>/dev/null -} - -_getexp_pcregrep="" -getexp() { - [ -z "$*" -o "$1" == "-h" -o "$1" == "--help" ] && echo "Usage: $FUNCNAME [capture number|default 0] PERL_REGEXP FILES..." && return - declare exp num - num=0; case "$1" in [0-9]*) num=$1; shift ;; esac - exp=$1; shift - - if [ -z "$_getexp_pcregrep" ]; then - _getexp_pcregrep=0 - which pcregrep > /dev/null && _getexp_pcregrep=1 - fi - - if [ $_getexp_pcregrep = 1 ]; then - pcregrep -o${num} "$exp" $@ - else - perl -ne 'BEGIN{$e=shift @ARGV; $n=shift(@ARGV) or 0; $e="($e)" and $n=1 if $n==0} (@_=m{$e}) and ($n<=scalar(@_)) and print ($n==0 ? $_[0] : $_[$n-1].chr(10))' "$exp" "$num" $@ - fi - return -} - -hl(){ - #cat | grep --color=always -E "(^|($@))" - perl -MTerm::ANSIColor -pe 's/('$@')/color("red").$1.color("reset")/ge' -} diff --git a/etc/profile.d/default.sh b/etc/profile.d/default.sh new file mode 100644 index 00000000..e69de29b diff --git a/etc/bashrc b/etc/profile.d/envs similarity index 86% rename from etc/bashrc rename to etc/profile.d/envs index 718fc1fe..a38dd6e8 100644 --- a/etc/bashrc +++ b/etc/profile.d/envs @@ -3,10 +3,13 @@ # ENVS # ################################################################################# -case "$BASH_SOURCE" in */*) path="${BASH_SOURCE%/*}";; *) path='.' ;; esac -[ -e "$path/bashrc.function" ] && . "$path/bashrc.function" -NB_ROOT=$(realpath ${path}/..) -unset path +# NB 28.07.15 case "$BASH_SOURCE" in */*) path="${BASH_SOURCE%/*}";; *) path='.' ;; esac +# NB 28.07.15 # +# NB 28.07.15 # ROOT PATH +# NB 28.07.15 # +# NB 28.07.15 [ -e "$path/bashrc.function" ] && . "$path/bashrc.function" +# NB 28.07.15 NB_ROOT=$(realpath ${path}/..) +# NB 28.07.15 unset path # # BASE diff --git a/etc/bashrc.function b/etc/profile.d/functions similarity index 70% rename from etc/bashrc.function rename to etc/profile.d/functions index 2ec01783..51a74d1a 100644 --- a/etc/bashrc.function +++ b/etc/profile.d/functions @@ -165,8 +165,9 @@ yaml2perl() { # FUNCTIONS - BASH # ################################################################################# -hl() { - cat | grep --color=auto -E "(^|($@))" +hl(){ + #cat | grep --color=always -E "(^|($@))" + perl -MTerm::ANSIColor -pe 's/('$@')/color("red").$1.color("reset")/ge' } ls_tree() { @@ -203,3 +204,49 @@ if (/^$t1$/ .. /^$t2$/) { END { print "$content" if $content; } ' "$tag" "$content" } + +_getexp_pcregrep="" +getexp() { + [ -z "$*" -o "$1" == "-h" -o "$1" == "--help" ] && echo "Usage: $FUNCNAME [capture number|default 0] PERL_REGEXP FILES..." && return + declare exp num + num=0; case "$1" in [0-9]*) num=$1; shift ;; esac + exp=$1; shift + + if [ -z "$_getexp_pcregrep" ]; then + _getexp_pcregrep=0 + which pcregrep > /dev/null && _getexp_pcregrep=1 + fi + + if [ $_getexp_pcregrep = 1 ]; then + pcregrep -o${num} "$exp" $@ + else + perl -ne 'BEGIN{$e=shift @ARGV; $n=shift(@ARGV) or 0; $e="($e)" and $n=1 if $n==0} (@_=m{$e}) and ($n<=scalar(@_)) and print ($n==0 ? $_[0] : $_[$n-1].chr(10))' "$exp" "$num" $@ + fi + return +} + +radio_play() { +perl -e ' +@_=grep{$_} split("\n"," +FranceInter | http://audio.scdn.arkena.com/11008/franceinter-midfi128.mp3 +Indie | http://107.155.126.42:17160/listen.pls +FranceInfo | http://audio.scdn.arkena.com/11006/franceinfo-midfi128.mp3 +FranceCulture | http://audio.scdn.arkena.com/11010/franceculture-midfi128.mp3 +BBC 1 | http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1_mf_p +BBC 2 | http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio2_mf_p +BBC 3 | http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/http-icy-aac-lc-a/format/pls/vpid/bbc_radio_three.pls +BBC 4 | http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio4fm_mf_p +BBC 5 live | http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio5live_mf_p +BBC 6 | http://bbcmedia.ic.llnwd.net/stream/bbcmedia_6music_mf_p +"); +if (@ARGV) { $play=shift @ARGV; } else { + $i=1; + map{printf("%2d | %s\n",$i++,$_)} @_; + print "\nChoose one > "; + chomp($play=<>); +} +$play eq "" && exit; @_ = $_[$play-1] =~ /^(.*?)\s*\|\s*(.*?)$/ or exit; +print "[ $play - ".$_[0]." ]\n\n"; +exec "mplayer",$_[1]; +' "$@" +} -- 2.47.3