Advertisement
arkanon

/etc/profile

May 9th, 2013
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 16.91 KB | None | 0 0
  1. # /etc/profile
  2.  
  3. # system-wide .profile file for the Bourne and Bourne compatible shells
  4. #
  5. # Arkanon <arkanon@lsd.org.br>
  6. # 2013/05/10 (Sex) 01:34:31 (BRS)
  7.  
  8.  
  9.  
  10. # [additional scripts]
  11.  
  12. #[ "$BASH" ] && [ -f /etc/bash.bashrc ] && . /etc/bash.bashrc
  13.  
  14. for profile_script in /etc/profile.d/*.sh
  15. do
  16.   [ -x $profile_script ] && . $profile_script
  17. done
  18. unset profile_script
  19.  
  20.  
  21.  
  22. # [environment variables]
  23.  
  24.                               FS=/fs
  25.  
  26.                             PATH=$FS/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:$HOME/bin
  27.                  LD_LIBRARY_PATH=$FS/lib:$HOME/lib
  28.  
  29.                             PATH=$PATH:/export/data/src/depot_tools
  30.  
  31. if [ $(id -u) = 0 ]
  32. then
  33.                             PATH=$FS/sbin:/usr/local/sbin:/usr/sbin:/sbin:$PATH
  34. else
  35.                             PATH=$PATH:.
  36.                  LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
  37. fi
  38.  
  39. #                         CDPATH=.:auto/clip/image/fotos/:/auto/i/.soft/common/:$FS/share/:/home/
  40. #                        MANPATH=/usr/local/share/man:/usr/share/man
  41.  
  42.  export                 HOSTNAME=$(cat /etc/hostname)
  43.  export                 WWW_HOME=http://www.google.com/
  44. #export                 LYNX_CFG=~/.lynxrc
  45.  
  46. # locale -a
  47.  utf=".utf8"
  48. # sudo locale-gen en_US$utf
  49. # sudo dpkg-reconfigure locales
  50.  
  51.  unset LC_ALL # Its value will override all the LC_* variable (but not LANG). After setting LC_ALL, modifications to any LC_* variables are not permitted.
  52.               # In general, it is then recommended to leave LC_ALL unset, set instead LANG, and change individual LC_* variables to suit your needs.
  53.  
  54.  export                     LANG="pt_BR$utf" # Set the value of all LC_* variables which are not explicitely set (those already set are not changed).
  55.                                              # Also, any LC_* variable can be modified after setting LANG.
  56.  
  57.  export               LC_ADDRESS="pt_BR$utf"
  58.  export               LC_COLLATE="C"         # Collation order used for comparing and sorting
  59.  export        LC_IDENTIFICATION="pt_BR$utf"
  60.  export           LC_MEASUREMENT="pt_BR$utf"
  61.  export              LC_MONETARY="pt_BR$utf" # Monetary formats
  62.  export                  LC_NAME="pt_BR$utf"
  63.  export                 LC_PAPER="pt_BR$utf" # Paper format
  64.  export             LC_TELEPHONE="pt_BR$utf"
  65.  export                 LC_CTYPE="pt_BR$utf" # Character classification and case conversion. Also indicates the language which should be used with XIM
  66.  export              LC_MESSAGES="pt_BR$utf" # Formats of informative and diagnostic messages and interactive responses (also for graphical user interfaces)
  67.  export               LC_NUMERIC="pt_BR$utf" # Non-monetary numeric formats
  68.  export                  LC_TIME="pt_BR$utf" # Date and time formats
  69.  export                       TZ="$FS/etc/tz/Brazil/East"
  70.  
  71. # locale -m
  72.  charset=UTF-8
  73. #charset=ISO-8859-1
  74.  export                     LESS=-MRS      # NF
  75.  export                  LESSKEY=/etc/lesskey
  76.  export                 LESSOPEN="|lesspipe.sh %s"
  77.  export              LESSCHARSET=$charset
  78.  export         GROFF_TYPESETTER=$charset
  79.  export          LESS_TERMCAP_mb=$'\e[01;31m'     # red          begin blinking
  80.  export          LESS_TERMCAP_md=$'\e[01;33m'     # yellow       begin bold
  81.  export          LESS_TERMCAP_me=$'\e[0m'         #              end   mode
  82.  export          LESS_TERMCAP_so=$'\e[01;44;33m'  # blue/yellow  begin standout-mode (info box)
  83.  export          LESS_TERMCAP_se=$'\e[0m'         #              end   standout-mode
  84.  export          LESS_TERMCAP_us=$'\e[01;32m'     # green        begin underline
  85.  export          LESS_TERMCAP_ue=$'\e[0m'         #              end   underline
  86.  unset charset
  87.  
  88.  export                IGNOREEOF=10 # logouts with ^D pressed 10 times
  89. #export                    TMOUT=300    # automaticaly logs out if idle is 300s (0 for never)
  90.  export             PERL_BADLANG=0
  91. #export        ALSA_OUTPUT_PORTS=128:0
  92.  
  93. #export                 RCX_PORT=/dev/ttyS0
  94.  
  95. #export                 MANPAGER="/usr/bin/most -s"
  96.  
  97. {
  98.  export                 HISTFILE=~/.history
  99.  export             HISTFILESIZE=50000
  100.  export                 HISTSIZE=50000
  101. } &> /dev/null
  102.  
  103.  export           HISTTIMEFORMAT="%Y/%m/%d %a %T %Z  "
  104.  export command_oriented_history=1              # bash attempts to save all lines of a multiple-line command in the same history entry. This allows easy re-editing of multi-line commands
  105.  export           PROMPT_COMMAND="history -a"           # append the "new" history lines (history lines entered since the beginning of the current bash session) to the history file.
  106. #export           PROMPT_COMMAND="history -n; $PROMPT_COMMAND"  # read the history lines not already read from the history file into the current history list. These are lines appended to the history file since the beginning of the current bash session.
  107. #export               HISTIGNORE="pwd:ls:ls -ltr:"      # patterns used to decide which command lines should be saved on the history list
  108. #export              HISTCONTROL="ignoredups"           # values controlling how commands are saved on the history list
  109.                 # ignorespace           # lines which begin with a space character are not saved in the history list
  110.                 # ignoredups            # lines matching the previous history entry to not be saved
  111.                 # ignoreboth            # shorthand for ignorespace and ignoredups
  112.                 # erasedups         # all previous lines matching the current line to be removed from the history list before that line is saved.
  113.  
  114.  shopt -s checkwinsize          # bash checks the window size after each command and, if necessary, updates the values of LINES and COLUMNS
  115.  shopt -s histappend            # the history list is appended to the file named by the value of the HISTFILE variable when the shell exits, rather than overwriting the file
  116.  shopt -s cmdhist           # bash attempts to save all lines of a multiple-line command in the same history entry. This allows easy re-editing of multi-line commands
  117.  shopt -s lithist           # If the cmdhist option is enabled, multi-line commands are saved to the history with embedded newlines rather than using semicolon separators where possible
  118.  
  119.  # if readline is being used
  120.  shopt -s hostcomplete          # bash will attempt to perform hostname completion when a word containing a @ is being completed. This is enabled by default
  121.  shopt -s histreedit            # a user is given the opportunity to re-edit a failed history substitution
  122.  shopt -s histverify            # the results of history substitution are not immediately passed to the shell parser. Instead, the resulting line is loaded into the readline editing buffer, allowing further modification
  123.  shopt -s no_empty_cmd_completion   # bash will not attempt to search the PATH for possible completions when completion is attempted on an empty line
  124.  
  125. # Set some vars read-only
  126.  typeset -r HISTFILE HISTFILESIZE HISTSIZE
  127.  
  128.  export NWS=$'\x0A'$'\x0D'  # no whitespace :=  line_feed   carriage_return
  129.  export  WS=$'\x20'$'\x09'  #    whitespace :=  space       tab
  130.  export DEF=${WS}${NWS}     #   default ifs :=  whitespace  no_whitespace
  131.  
  132. # If the user doesn't have a .inputrc, use the one in /etc.
  133. [ -r "$HOME/.inputrc" ] || export INPUTRC=/etc/inputrc
  134.  
  135. # I had problems with the backspace key using 'eval tset' instead of 'TERM=',
  136. # but you might want to try it anyway instead of the section below it.  I
  137. # think with the right /etc/termcap it would work.
  138. # eval $(tset -sQ "$TERM")
  139.  
  140. # Set TERM to linux for unknown type or unset variable:
  141. [ "$TERM" = "" -o "$TERM" = "unknown" ] && TERM=linux
  142.  
  143. # EDITOR="emacs"
  144. # EDITOR="gmacs"
  145. # EDITOR="$FS/bin/edit"
  146. # EDITOR="vi"
  147.  
  148.  
  149.  
  150. # [ls_options]
  151. ls --help 2>&1 | grep -q group-directories-first && LS_GDF="--group-directories-first"
  152. LS_OPTIONS='-lapbviT0 --color=always --time-style="+%Y/%m/%d %a %T %Z"'
  153. SL_OPTIONS='-lapbvT0  --color=always --time-style=+'
  154.  
  155. # [ls_colors]
  156. eval $(dircolors -b)
  157. [ -f /etc/DIR_COLORS   ] && eval $(dircolors -b /etc/DIR_COLORS)
  158. [ -f $HOME/.dir_colors ] && eval $(dircolors -b $HOME/.dir_colors)
  159.  
  160.  
  161.  
  162. # [functions]
  163.  
  164.  ps()
  165.  {
  166.    ps=/bin/ps
  167.    format="o start,tty,user,rss,pid,cmd"
  168.    if [ $# = 0 ]
  169.    then
  170.      $ps fwwx $format
  171.    else
  172.      [ "$1" = a ] && $ps fwwxa $format || $ps fww $format U $1
  173.    fi
  174.  }
  175.  
  176.  vi()
  177.  {
  178.    args="" && [ "$*" ] && args=$( for i in $(seq $#); do eval echo \\\"\${$i}\\\"; done )
  179.    { vi=$(which vi) && [ "$DISPLAY" ] && xping -n1 && which gvim && vi="gvim"; } &> /dev/null
  180.    eval $vi $args 2>> ~/.xsession-errors
  181.  }
  182.  export -f vi
  183.  
  184.  sl()
  185.  {
  186.    BLOCK_SIZE=\'1 ls $SL_OPTIONS $LS_GDF $* | cut -c12- | sed "/^$/d"
  187.  # LC_NUMERIC=en_US$utf BLOCK_SIZE=\'1 ls $SL_OPTIONS $LS_GDF $* | cut -c12- | sed "/^$/d"
  188.  }
  189.  
  190.  sla()
  191.  {
  192.    BLOCK_SIZE=\'1 ls $SL_OPTIONS         $* | cut -c12- | sed "/^$/d"
  193.  # LC_NUMERIC=en_US$utf BLOCK_SIZE=\'1 ls $SL_OPTIONS         $* | cut -c12- | sed "/^$/d"
  194.  }
  195.  
  196.  
  197.  
  198. # [prompt]
  199.  
  200.    black="\[\e[1;30m\]"
  201.      red="\[\e[1;31m\]"
  202.    green="\[\e[1;32m\]"
  203.   yellow="\[\e[1;33m\]"
  204.     blue="\[\e[1;34m\]"
  205.  magenta="\[\e[1;35m\]"
  206.     cyan="\[\e[1;36m\]"
  207.    white="\[\e[1;37m\]"
  208.      off="\[\e[0m\]"
  209.  
  210.   c__def=$red
  211.   c_numb=$red
  212.   c_user=$green
  213.   c_host=$yellow
  214.   c__tty=$cyan
  215.   c_path=$white
  216.  
  217. if [ "$(id -u)" = "0" ]
  218. then
  219.   char="#"
  220.     at=""
  221.    tat=""
  222. else
  223.   char="$"
  224.     at="$c_user\u$c__def@"
  225.    tat="\u@"
  226. fi
  227.  
  228.    ab='['
  229.    fe=']'
  230. # tty=t$(tty | awk -F "tty" '{print$2}') && [ "$tty" = "t" ] && tty=p$(tty | awk -F "/" '{print$NF}')
  231.   tty=$(tty | cut -d/ -f3-)
  232. # \!  history number of current command
  233. # \$  # for UID=0  and  $ othewise
  234. # \h  hostname
  235. # \s  name of shell
  236. # \t  time
  237. # \u  username
  238. # \w  working directory
  239. # \W  basename of working direktory
  240.  title="\[\e]0;$tat\h$ab$tty$fe\w\a\]"
  241. prompt="$c_numb\! $at$c_host\h$c__def$ab$c__tty$tty$c__def$fe$c_path\w$c__def$char$off "
  242. echo "$TERM" | grep -qi xterm && PS1="$title$prompt" || PS1="$prompt"
  243. #case "$TERM" in
  244. #  xterm*|rxvt*) export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"; '$PROMPT_COMMAND;;
  245. #  *);;
  246. #esac
  247. unset char at ab fe tty title prompt tat
  248. unset black red green yellow blue magenta cyan white off
  249. unset c__def c_numb c_user c_host c__tty c_path
  250.  
  251.  
  252.  
  253.  umask 0002     # default mode = 0664/0775
  254. #biff  y
  255.  mesg  y
  256. #stty  echo     # commente because locks WM startup in X
  257.  
  258.  ulimit -c 0        # disable coredumps creation
  259. #ulimit -u 64       # limits the maximum number of processes available to a single user
  260.  
  261.  set -o noclobber   # prevents overwrite of files with cp
  262.  set -o notify      # report the status of terminated background jobs immediately
  263.  
  264.  
  265.  
  266. export FS PATH CDPATH MANPATH LD_LIBRARY_PATH TERM PS1 PS2 VISUAL EDITOR LS_OPTIONS SL_OPTIONS LS_GDF
  267.  
  268.  
  269.  
  270. # [aliases]
  271.  
  272. #unalias d
  273. #unalias dir
  274. #unalias ls
  275. #unalias mc
  276. #unalias v
  277. #unalias vdir
  278.  
  279. #alias     l="LC_NUMERIC=en_US$utf BLOCK_SIZE=\'1 ls $LS_OPTIONS $LS_GDF"
  280. #alias    la="LC_NUMERIC=en_US$utf BLOCK_SIZE=\'1 ls $LS_OPTIONS"
  281.  alias     l="BLOCK_SIZE=\'1 ls $LS_OPTIONS $LS_GDF"
  282.  alias    la="BLOCK_SIZE=\'1 ls $LS_OPTIONS"
  283.  alias watch="watch -cbn1"
  284.  alias cgrep="grep --color=always"
  285.  alias     h="history"
  286.  alias    du="time du -chs"
  287.  alias    df="df -haT"
  288.  alias    wt="wordtrans"
  289.  alias  time="/usr/bin/time -f 'ELAPSED TIME: %E'"
  290.  alias  lynx="lynx -cfg=$HOME/.lynxrc"
  291.  
  292. #alias   put="nqc -d"
  293. #alias   run="nqc -run"
  294. #alias  wake="nqc -sleep 10"
  295. #alias   off="nqc -sleep 1"
  296. #alias  firm="nqc -firmfast /auto/share/Areas/Robotica/nqc/firmware/firm.lgo"
  297.  
  298.  
  299.  
  300. # [sudo hint]
  301. if [ ! -e $HOME/.sudo_as_admin_successful ]
  302. then
  303.   case " $(groups) " in *\ admin\ *)
  304.   if [ -x /usr/bin/sudo ]
  305.   then
  306.     cat << EOF
  307.       To run a command as administrator (user "root"), use "sudo <command>".
  308.       See "man sudo_root" for details.
  309. EOF
  310.   fi
  311.   esac
  312. fi
  313.  
  314. # if the command-not-found package is installed, use it
  315. if [ -x /usr/lib/command-not-found ]
  316. then
  317.   command_not_found_handle()
  318.   {
  319.     # check because c-n-f could've been removed in the meantime
  320.     if [ -x /usr/lib/command-not-found ]
  321.     then
  322.       python /usr/lib/command-not-found -- $1
  323.       return $?
  324.     else
  325.       return 127
  326.     fi
  327.   }
  328. fi
  329.  
  330.  
  331.  
  332. # [LWD - Last Working Directory]
  333.  
  334. # Em 19 de março de 2010 11:50, Julio C. Neves <julio.neves@gmail.com> escreveu:
  335. # > Bah Tchê,
  336. # > se eu entendi bem, em tempo de login vc quer voltar para o diretório em que
  337. # > estava qdo deu logout. se for isso coloque a seguinte linha no ~/.bashrc:
  338. #
  339. # Oi, Julio. Obrigado pela dica! :-)
  340. #
  341. # Inicialmente era exatamente isso que eu queria.
  342. #
  343. # > cd $(cat ~/.lwd 2> /dev/null)
  344. # > trap "echo $PWD > ~/.lwd" 0 15
  345. #
  346. # A sua solucao tem a simplicidade poetica dos bons scripts bash :-) ; com ela percebi que minha solucao inicial nao resolvia o problema proposto.
  347. #
  348. # [CUT, inclusive o aperfeicoamento da solucao acima :-p]
  349. #
  350. # Mas agora, alem de
  351. #
  352. # (1) nao havendo sessoes abertas, fazer a primeira nova sessao voltar para o ultimo (L) diretorio de trabalho (WD) da ultima sessao shell fechada,
  353. #
  354. # resolvi querer MAIS 2 coisas :-p
  355. #
  356. # (2) fazer as novas sessoes iniciarem no LWD definido no conjunto de sessoes abertas, ignorando as sessoes que vao sendo fechadas, ate que se feche a
  357. #     ultima;
  358. #
  359. # (3) implementar um caracter especial (no estilo do - e do ~) que diga ao comando cd para entrar nesse LWD, permitindo que as sessoes abertas "conversem"
  360. #     nesses termos de LWD.
  361. #
  362. # Juntando as nossas 2 solucoes, cheguei a essa:
  363. #
  364. # --
  365. #
  366. # lwd_cd()
  367. # {
  368. #   local LWD=$1
  369. #   [ "$LWD" = : ] && LWD=$(cat ~/.lwd 2> /dev/null)
  370. #   cd "${LWD:-$HOME}" && pwd >| ~/.lwd
  371. # }
  372. #
  373. # echo $$ >> ~/.lwp
  374. #
  375. # trap 'echo "$(grep -wv $$ ~/.lwp 2> /dev/null)" >| ~/.lwp; grep -qE "[0-9]" ~/.lwp || cd .' 0 15
  376. #
  377. # alias cd="lwd_cd"
  378. #
  379. # cd :
  380. #
  381. # --
  382. #
  383. # O que acontece aí?
  384. #
  385. # <http://en.wikipedia.org/wiki/Path_%28computing%29#Representations_of_paths_by_operating_system_and_shell>
  386. #
  387. # Colocando o codigo acima em algum dos arquivos de inicializacao do bash, ate onde eu pude testar, as 3 condicoes estipuladas sao satisfeitas.
  388. #
  389. # E SIM, eu percebi que PODE haver concorrencia na hora de gravar o arquivo ~/.lwp, mas nao me preocupei com essa possibilidade AINDA, hehe. Ja
  390. # vi que fatalmente vou cair no uso dos fifo's de novo...
  391. #
  392. # E a minha pergunta continua: voces tem alguma sugestao para simplificar o algoritmo acima, mantendo agora as 3 condicoes?
  393. #
  394. # A-bash-os, (puts, essa foi triste... :-p)
  395.  
  396. # Signal     Value      Acti   Comment
  397. # --------   --------   ----   -------
  398. #                0      n/a    Exit code indicates if a signal may be sent
  399. # SIG HUP        1      Term   Hangup detected on controlling terminal or death of controlling process
  400. # SIG INT        2      Term   Interrupt from keyboard
  401. # SIG QUIT       3      Core   Quit from keyboard
  402. # SIG ILL        4      Core   Illegal Instruction
  403. # SIG TRAP       5      Core   Trace/breakpoint trap
  404. # SIG ABRT       6      Core   Abort signal from abort(3)
  405. # SIG BUS    10  7 10   Core   Bus error (bad memory access)
  406. # SIG FPE        8      Core   Floating point exception
  407. # SIG KILL       9      Term   Kill signal
  408. # SIG SEGV      11      Core   Invalid memory reference
  409. # SIG PIPE      13      Term   Broken pipe: write to pipe with no readers
  410. # SIG ALRM      14      Term   Timer signal from alarm(2)
  411. # SIG TERM      15      Term   Termination signal
  412. # SIG USR1   30 10 16   Term   User-defined signal 1
  413. # SIG USR2   31 12 17   Term   User-defined signal 2
  414. # SIG CHLD   20 17 18   Ign    Child stopped or terminated
  415. # SIG CONT   19 18 25   Cont   Continue if stopped
  416. # SIG STOP   17 19 23   Stop   Stop process
  417. # SIG TSTP   18 20 24   Stop   Stop typed at tty
  418. # SIG TTIN   21 21 26   Stop   tty input  for background process
  419. # SIG TTOU   22 22 27   Stop   tty output for background process
  420.  
  421.   export LWDFILE="$HOME/.lwd"
  422.  
  423.   lwdcd()
  424.   {
  425.  
  426.     local WD
  427.     local TTY=$(tty)
  428.  
  429.     [ "$1" != : ] \
  430.     && WD=$1 \
  431.     || {
  432.          [ -s "$LWDFILE" ] && WD=$(grep -w "$TTY" "$LWDFILE" | cut -f3)
  433.        }
  434.  
  435.     builtin cd "${WD:-$HOME}" \
  436.     && {
  437.          [ -s "$LWDFILE" ] \
  438.          && {
  439.               grep -wv "$TTY" "$LWDFILE" >| "$LWDFILE-$$"
  440.               mv "$LWDFILE-$$" "$LWDFILE"
  441.             }
  442.          [ "$(readlink -f "$PWD")" != "$(readlink -f "$HOME")" ] && echo -e "$TTY\t$(date +'%Y/%m/%d %a %H:%M:%S %Z')\t$PWD" >> "$LWDFILE"
  443.        }
  444.  
  445.   }
  446.  
  447.   alias  cd="lwdcd"
  448.   alias lwd="[ -s \"$LWDFILE\" ] && sort -t/ -k4 -n \"$LWDFILE\""
  449.  
  450.   lwd
  451.   cd :
  452.  
  453. # cd $( [ -s $LWDFILE ] && grep "$TTY" $LWDFILE | cut -f2 && cat < $LWDFILE | $( grep -v "$TTY" >| $LWDFILE ) )
  454. # trap '[ $(readlink -f $PWD) != $(readlink -f $HOME) ] && echo -e "$TTY\t$PWD" >> $LWDFILE' 0 2 3 15
  455.  
  456. # cd $( [ -s $LWDFILE ] && grep "$TTY" $LWDFILE | cut -f2 && grep -v "$TTY" $LWDFILE >| $LWDFILE-$$ && mv $LWDFILE-$$ $LWDFILE )
  457. # trap "[ \$(readlink -f \$PWD) != \$(readlink -f $HOME) ] && echo -e \"$TTY\t\$PWD\" >> $LWDFILE" 0 HUP INT QUIT TERM
  458.  
  459.  
  460.  
  461. # [bash_completion]
  462.  
  463. [ -f /etc/bash_completion ] && . /etc/bash_completion
  464.  
  465. _compssh ()
  466. {
  467.   cur=${COMP_WORDS[COMP_CWORD]};
  468.   COMPREPLY=($(compgen -W '$(cat ${HOME}/.ssh/config)' -- $cur))
  469. }
  470. complete -F _compssh ssh
  471.  
  472.  
  473.  
  474. [ "$(readlink -f "$PWD")" = "$(readlink -f "$HOME")" ] && cd
  475.  
  476. # EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement