]> git.nbdom.net Git - nb.git/commitdiff
optimise profile
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 8 Sep 2016 21:59:54 +0000 (22:59 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 8 Sep 2016 21:59:54 +0000 (22:59 +0100)
etc/profile [changed mode: 0644->0755]
etc/profile.d/aliases
etc/profile.d/functions
etc/profile.d/mac.sh

old mode 100644 (file)
new mode 100755 (executable)
index 78b9c39..7b2a812
@@ -1,21 +1,25 @@
 #
 # Avoid infinit loop. Eg: profile -> .bashrc -> profile
 #
-#[ "$1" = "--debug" ] && NB_DEBUG='eval echo 1>&2 "$(basename $BASH_SOURCE): "' && shift
-[ "$1" = "--debug" ] && NB_DEBUG='echo NB_DEBUG:' && shift
-#NB_DEBUG='echo NB_DEBUG:'
+[ "$1" = "--debug" ] && export NB_DEBUG="echo " && shift
+#NB_DEBUG='echo '
 if [ -n "$NB_LOOP" ]; then
-  [ -n "$NB_DEBUG" ] && $NB_DEBUG "NB_LOOP=$NB_LOOP: BASH_SOURCE=$BASH_SOURCE \$0=$0"
+  [ -n "$NB_DEBUG" ] && $NB_DEBUG "WARN: NB_LOOP=$NB_LOOP: BASH_SOURCE=$BASH_SOURCE \$0=$0"
+  echo "WARN: NB_LOOP=$NB_LOOP: BASH_SOURCE=$BASH_SOURCE \$0=$0"
   NB_LOOP=$(($NB_LOOP+1))
-  return
+  unset NB_LOOP
+  return 2>/dev/null || exit # if executable
 fi
+[ -n "$NB_DEBUG" ] && $NB_DEBUG "OK: BASH_SOURCE=$BASH_SOURCE \$0=$0"
+
+#trap 'unset NB_LOOP' EXIT
 export NB_LOOP=1
-#set | grep profile
 
 #
 # SEARCH ROOT
 #
 dir=''
+#NB_DEBUG="echo $0:"
 case "$BASH_SOURCE" in
   */*) dir="${BASH_SOURCE%/*}";;
   *)
@@ -30,16 +34,13 @@ case "$BASH_SOURCE" in
 esac
 
 if [ -z "$dir" ]; then
-  [ -n "$NB_DEBUG" ] && $NB_DEBUG "Can't find NB_ROOT"
+  [ -n "$NB_DEBUG" ] && $NB_DEBUG "ERR: Can't find NB_ROOT"
   return 0
 fi
 [ -e "$dir/profile.d/functions" ] && . "$dir/profile.d/functions"
 NB_ROOT=$(realpath ${dir}/.. 2>/dev/null)
-#echo $NB_ROOT
-#echo $NB_ROOT
 
 #echo "$NB_ROOT: `pwd`"
-unset dir
 
 #
 # Profiles
@@ -49,14 +50,14 @@ if [ -n "$NB_ROOT" ]; then
 
   for i in \
     ${NB_ROOT}/etc/profile.d/aliases \
-    ${NB_ROOT}/etc/profile.d/*.sh \
-    $(nb-repo-dirs "etc/profile" "etc/profile.d/*.sh" | grep -vF "${NB_ROOT}/etc/profile") \
+    $(nb-repo-dirs "etc/profile" "etc/profile.d/*.sh" | grep -vFx "${NB_ROOT}/etc/profile") \
   ;do
-    [ -n "$NB_DEBUG" ] && $NB_DEBUG ". $i"
+    [ -n "$NB_DEBUG" ] && $NB_DEBUG "OK: . $i"
     [ -r "$i" -a -f "$i" ] && . "$i"
   done
 
 fi
 
-unset i tmp NB_LOOP NB_DEBUG
+unset i tmp dir NB_DEBUG NB_LOOP
+#unset NB_LOOP
 true
index 94912f1c734f2318daaab9da4bd8f652d291d0e4..35f3011ca6f9ef395d14b8208ed9076ea7132f19 100644 (file)
@@ -26,15 +26,7 @@ alias grep='grep --color=auto'
 # Etherwake
 # Cable: alias advent-on="etherwake -i eth0 00:22:68:7b:fb:99 -D -b"
 #
-#which etherwake &> /dev/null && alias advent-on="etherwake -i eth0 48:5b:39:eb:db:8a -D -b"
-
-#--------------------------------------------------------------------------------
-# seq / jot
-#
-case "$OSTYPE" in 
-       darwin*) alias seq='jot' ;;
-       *) alias jot='seq' ;;
-esac
+#alias advent-on="etherwake -i eth0 48:5b:39:eb:db:8a -D -b"
 
 #--------------------------------------------------------------------------------
 # Beep
@@ -49,13 +41,8 @@ test "$TERM_PROGRAM" = "iTerm.app" && export PROMPT_COMMAND='printf "\033]0;%s\0
 #--------------------------------------------------------------------------------
 # Get / Head
 #
-if which lynx &> /dev/null; then
-  alias Head="lynx -dump -head -width=0"
-  alias Get="lynx -source -width=0"
-elif which curl &> /dev/null; then
-  alias Head="curl -s --head"
-  alias Get="curl -s --get -L"
-fi
+alias Get='wget --no-check-certificate --quiet -O -'
+alias Head='wget --server-response --spider --no-check-certificate --quiet -O -'
 # NB 15.07.15 function nbGet() {
 # NB 15.07.15   declare host port uri
 # NB 15.07.15   eval $(perl -ne 'm,^\s*\w+://([^/:]+)(?::(\d+))?(/.*)?\s*$, and print qq|host=$1 port=$2 uri=$3\n|' <<< "$@")
@@ -89,42 +76,16 @@ alias vi=vim
 #--------------------------------------------------------------------------------
 # Torrent
 #
-opt="--max_upload_rate 1 --minport 6881 --maxport 6999"
-if which btlaunchmanycurses.py &> /dev/null; then
-
-       opt="$opt --max_download_rate 150 --max_files_open 0"
-
-       alias torrent="btdownloadcurses.py $opt"
-       alias torrentdir="btlaunchmanycurses.py $opt"
-
-elif which btdownloadcurses &> /dev/null; then
 
-       alias torrent="btdownloadcurses $opt"
-       alias torrentdir="btlaunchmanycurses $opt"
+# btlaunchmanycurses.py
+#alias torrent="btdownloadcurses.py --max_download_rate 150 --max_files_open 0"
+#alias torrentdir="btlaunchmanycurses.py --max_download_rate 150 --max_files_open 0"
 
-fi
-unset opt
+# btdownloadcurses
+alias torrent="btdownloadcurses --max_upload_rate 1 --minport 6881 --maxport 6999"
+alias torrentdir="btlaunchmanycurses --max_upload_rate 1 --minport 6881 --maxport 6999"
 
 #--------------------------------------------------------------------------------
 # debian upgrade
 #
 alias servers-upgrade='server-package.pl update,upgrade $((printf "big.cascais.loc\n";mysql -h mysql izi -NBe "select host from server where not hidden") | sort -u)'
-
-#--------------------------------------------------------------------------------
-# Mac OS
-#
-case "$OSTYPE" in darwin*) 
-
-  alias strace='dtruss'
-  alias updatedb='bash -c "cd / && /usr/libexec/locate.updatedb &"'
-  alias mac-dns-flush='dscacheutil -flushcache'
-  #alias mac-wakeup-screen="pmset schedule wake '\$(date +\"%d/%m/%Y %T\")'"
-  #alias mac-wakeup-screen2='osascript -e \'tell application "System Events" to key code 123\''
-  alias mac-sleep='pmset sleepnow'
-  alias mac-halt='halt=1 && bash -c "(sleep 3 && halt) &" && logout'
-  alias mac-top-proc="echo 'TOP PROCESSES:'; ps -Aro'%cpu, ucomm, user' | grep $USER | grep -v ' 0.0 '"
-  alias mac-automount='sudo automount -v'
-  alias mac-vlc-playlists="open -a vlc --args /home/nico/Music/*/*.m3u"
-  alias mac-mount-nfs="sudo mount -o resvport -t nfs"
-
-esac
index 20090e19d63ac88cde7a158cbf6b445b085436d0..3cbe36334b38affbfb45abc1a54444d9163d04db 100644 (file)
@@ -3,11 +3,10 @@
 # FUNCTIONS - SH
 #
 #################################################################################
-if ! which timeout 1>/dev/null; then
 timeout() {
+  which timeout 1>/dev/null && exec timeout -- $@
   perl -e 'BEGIN{$|=1}; $SIG{ALRM}=sub{exit 1}; alarm(shift @ARGV); system join(" ",@ARGV)' -- $@
 }
-fi
 
 shell_help() {
   #
@@ -253,7 +252,7 @@ getexp() {
 }
 
 radio_play() {
-  local prog=`which player`
+  local prog=`which mplayer`
   if [ -z "$prog" ]; then
     case $OSTYPE in
       darwin*) prog="open" ;;
index 4baf2f2040e680c0def6da5ad64cf88b8f171f8d..cb4cf145f3bcc13593ec693fa613ddbc1d6239d9 100644 (file)
@@ -10,14 +10,22 @@ mac_pbcopy() {
 # Darwin only !
 #
 ##############################################################################
-[ -z "$DARWIN" ] && return 0
-function ls_users() {
-  dscacheutil -q user|perl -ne '/^\w+:\s+(.*)?$/; push @_,$1; print join(":",$_[0],"*",@_[2,3,6,4,5])."\n" and @_=() if /^\s*$/'|sort -u|sort -t : -k3,4 -n |head|csv2human -nh -s :
-}
+#[ -z "$DARWIN" ] && return 0
+case "$OSTYPE" in 
+       darwin*) [ 1 ];;
+  *) return ;;
+esac
 [ -x /opt/local/bin/mysqld_safe5 ] && alias mac_mysqlstart='sudo /opt/local/bin/mysqld_safe5 &'
 [ -x /opt/local/bin/mysqladmin5 ] && alias mac_mysqlstop='sudo /opt/local/bin/mysqladmin5 -u root -p shutdown'
 [ -x /Applications/iTunes.app/Contents/MacOS/iTunes ] && alias iTunes=/Applications/iTunes.app/Contents/MacOS/iTunes
 [ -x /Applications/VLC.app/Contents/MacOS/VLC ] && alias vlc=/Applications/VLC.app/Contents/MacOS/VLC
+alias strace='dtruss'
+alias updatedb='bash -c "cd / && /usr/libexec/locate.updatedb &"'
+
+#--------------------------------------------------------------------------------
+# seq / jot
+#
+alias seq='jot'
 
 alias mac_vlc_playlists='open -a vlc --args /home/nico/Music/*/*.m3u'
 alias mac_top_proc="echo 'TOP PROCESSES:'; ps -Aro'%cpu, ucomm, user' | grep root | grep -v ' 0.0 '"
@@ -25,8 +33,16 @@ alias mac_sleep='pmset sleepnow'
 alias mac_mount_nfs='sudo mount -o resvport -t nfs'
 alias mac_automount='sudo automount -v'
 alias mac_dns_flush='sudo dscacheutil -flushcache'
+
+alias mac_sleep='pmset sleepnow'
 alias mac_halt='halt=1 && bash -c "(sleep 3 && halt) &" && logout'
 
+#alias mac-wakeup-screen="pmset schedule wake '\$(date +\"%d/%m/%Y %T\")'"
+#alias mac-wakeup-screen2='osascript -e \'tell application "System Events" to key code 123\''
+alias macps_top="echo 'TOP PROCESSES:'; ps -Aro'%cpu, ucomm, user' | grep $USER | grep -v ' 0.0 '"
+alias mac_vlc_playlists="open -a vlc --args /home/nico/Music/*/*.m3u"
+alias mac_mount_nfs="sudo mount -o resvport -t nfs"
+
 mac_config() {
   declare run r; run="
 echo 'Finder path           : YES'
@@ -66,3 +82,7 @@ mac_keychain_add() {
   [ -n "$*" ] && in="echo $*";
   eval $in | sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain
 }
+
+function ls_users() {
+  dscacheutil -q user|perl -ne '/^\w+:\s+(.*)?$/; push @_,$1; print join(":",$_[0],"*",@_[2,3,6,4,5])."\n" and @_=() if /^\s*$/'|sort -u|sort -t : -k3,4 -n |head|csv2human -nh -s :
+}