Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # /etc/profile
- # system-wide .profile file for Bourne (and compatible) Shells.
- #
- # Arkanon <arkanon@lsd.org.br>
- # 2013/08/02 (Sex) 13:48:22 (BRS)
- # 2013/08/01 (Thu) 14:17:29 (BRS)
- # 2013/07/31 (Qua) 16:43:54 (BRS)
- # 2013/07/24 (Qua) 15:13:05 (BRS)
- # 2013/05/10 (Sex) 01:34:31 (BRS)
- # 2012/05/18 (Sex) 18:41:47 (BRS)
- #
- # 1st revision: 1993, @euler.mat.ufrgs.br
- #
- # O conteudo abaixo estara disponivel em dois arquivos: /etc/profile e /etc/bash.bashrc
- # Quatro ambientes o utilizarao: terminais no modo login shell, screen, ssh e scp.
- # para os terminais, basta o arquivo profile.
- # para o screen, devem existir os dois arquivos.
- #
- # Dependencias
- # - screen
- # - colordiff
- # - most
- # - libtrash.so.3.2
- echo "$TERM" | grep -q "dumb" ||
- {
- export TTY=$(tty)
- sw()
- {
- one='screen -wipe | grep -v There | sort -t. -k2'
- [ $(id -u) = 0 ] && ls -1 /var/run/screen/ | cut -d- -f2 | grep -v $USER | while read user; do eval sudo -u $user $one; done
- eval $one
- echo
- }
- cat << EOT
- TTY: $TTY
- TERM: $TERM
- BASH_SOURCE: ${BASH_SOURCE[0]}
- $(sw)
- EOT
- if ! echo $TERM | grep -q "screen"
- then
- N=30
- echo -n "Starting screen in $N seconds, press C to Cancel, Q to Quit or any other key to start immediately... ";
- for i in $(eval echo {$N..1})
- do
- echo -n "$i "
- read -n 1 -t 1 -s key && break
- done
- key=$(echo $key | tr A-Z a-z)
- case "$key" in
- "c" )
- echo -e "canceled.\n"
- ;;
- "q" )
- echo -n "quiting."
- exit
- ;;
- * )
- detached=$(screen -ls | grep detached | sort)
- first=$(echo "$detached" | head -n1)
- [ "$detached" ] && screen -r $first || screen -R -t $(tty|cut -d/ -f3-|tr / -)
- exit
- ;;
- esac
- fi
- # [additional scripts]
- # [ "$BASH" ] && [ -f /etc/bash.bashrc ] && . /etc/bash.bashrc
- for profile_script in /etc/profile.d/*.sh
- do
- [ -x $profile_script ] && . $profile_script
- done
- unset profile_script
- # [environment variables]
- FS=/fs
- export LD_PRELOAD=/fs/lib/libtrash.so.3.2
- PATH=$FS/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:$HOME/bin
- LD_LIBRARY_PATH=$FS/lib:$HOME/lib
- # CDPATH=.:auto/clip/image/fotos/:/auto/i/.soft/common/:$FS/share/:/home/
- MANPATH=$FS/man:/usr/local/share/man:/usr/share/man
- PATH=$PATH:/export/data/src/depot_tools
- if [ $(id -u) = 0 ]
- then
- PATH=$FS/sbin:/usr/local/sbin:/usr/sbin:/sbin:$PATH
- else
- PATH=$PATH:.
- LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
- fi
- export HOSTNAME=$(cat /etc/hostname)
- export WWW_HOME=http://www.google.com/
- # export LYNX_CFG=~/.lynxrc
- # locale -a
- loc="pt_BR"
- utf=".utf8"
- # sudo locale-gen en_US$utf
- # sudo dpkg-reconfigure locales
- 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.
- # In general, it is then recommended to leave LC_ALL unset, set instead LANG, and change individual LC_* variables to suit your needs.
- export LANGUAGE="$loc$utf"
- export LANG="$loc$utf" # Set the value of all LC_* variables which are not explicitely set (those already set are not changed).
- # Also, any LC_* variable can be modified after setting LANG.
- export LC_ADDRESS="$loc$utf"
- export LC_COLLATE="C" # Collation order used for comparing and sorting
- export LC_IDENTIFICATION="$loc$utf"
- export LC_MEASUREMENT="$loc$utf"
- export LC_MONETARY="$loc$utf" # Monetary formats
- export LC_NAME="$loc$utf"
- export LC_PAPER="$loc$utf" # Paper format
- export LC_TELEPHONE="$loc$utf"
- export LC_CTYPE="$loc$utf" # Character classification and case conversion. Also indicates the language which should be used with XIM
- export LC_MESSAGES="$loc$utf" # Formats of informative and diagnostic messages and interactive responses (also for graphical user interfaces)
- export LC_NUMERIC="$loc$utf" # Non-monetary numeric formats
- export LC_TIME="$loc$utf" # Date and time formats
- export TZ="$FS/etc/tz/Brazil/East"
- # locale -m
- charset=UTF-8
- # charset=ISO-8859-1
- export LESS=-MRS # NF
- export LESSKEY=/etc/lesskey
- export LESSOPEN="|lesspipe.sh %s"
- export LESSCHARSET=$charset
- export GROFF_TYPESETTER=$charset
- export LESS_TERMCAP_mb=$'\e[01;31m' # red begin blinking
- export LESS_TERMCAP_md=$'\e[01;33m' # yellow begin bold
- export LESS_TERMCAP_me=$'\e[0m' # end mode
- export LESS_TERMCAP_so=$'\e[01;44;33m' # blue/yellow begin standout-mode (info box)
- export LESS_TERMCAP_se=$'\e[0m' # end standout-mode
- export LESS_TERMCAP_us=$'\e[01;32m' # green begin underline
- export LESS_TERMCAP_ue=$'\e[0m' # end underline
- unset charset
- export IGNOREEOF=2 # logouts with ^D pressed 3 times
- # export TMOUT=300 # automaticaly logs out if idle is 300s (0 for never)
- export PERL_BADLANG=0
- # export ALSA_OUTPUT_PORTS=128:0
- # export RCX_PORT=/dev/ttyS0
- # export MANPAGER="most -s"
- export PAGER="bash -c \"col -b -x | $FS/bin/vi -R -S /etc/vim/man.vim -\"" # <http://vim.wikia.com/wiki/Using_vim_as_a_man-page_viewer_under_Unix>
- {
- export HISTFILE=~/.history
- export HISTFILESIZE=50000
- export HISTSIZE=50000
- } &> /dev/null
- export HISTTIMEFORMAT="%Y/%m/%d %a %T %Z "
- 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
- 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.
- # 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.
- # export HISTIGNORE="pwd:ls:ls -ltr:" # patterns used to decide which command lines should be saved on the history list
- # export HISTCONTROL="ignoredups" # values controlling how commands are saved on the history list
- # ignorespace # lines which begin with a space character are not saved in the history list
- # ignoredups # lines matching the previous history entry to not be saved
- # ignoreboth # shorthand for ignorespace and ignoredups
- # erasedups # all previous lines matching the current line to be removed from the history list before that line is saved.
- [ "$DISPLAY" ] && xhost +SI:localuser:root
- shopt -s checkwinsize # bash checks the window size after each command and, if necessary, updates the values of LINES and COLUMNS
- 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
- 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
- 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
- # if readline is being used
- shopt -s hostcomplete # bash will attempt to perform hostname completion when a word containing a @ is being completed. This is enabled by default
- shopt -s histreedit # a user is given the opportunity to re-edit a failed history substitution
- 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
- 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
- # Set some vars read-only
- typeset -r HISTFILE HISTFILESIZE HISTSIZE
- umask 0002 # default mode = 0664/0775
- # biff y
- mesg y
- # stty echo # commente because locks WM startup in X
- ulimit -c 0 # disable coredumps creation
- # ulimit -u 64 # limits the maximum number of processes available to a single user
- set -o noclobber # prevents overwrite of files with cp
- set -o notify # report the status of terminated background jobs immediately
- export NWS=$'\x0A'$'\x0D' # no whitespace := line_feed carriage_return
- export WS=$'\x20'$'\x09' # whitespace := space tab
- export DEF=${WS}${NWS} # default ifs := whitespace no_whitespace
- # If the user doesn't have a .inputrc, use the one in /etc.
- [ -r "$HOME/.inputrc" ] || export INPUTRC=/etc/inputrc
- # I had problems with the backspace key using 'eval tset' instead of 'TERM=',
- # but you might want to try it anyway instead of the section below it. I
- # think with the right /etc/termcap it would work.
- # eval $(tset -sQ "$TERM")
- # Set TERM to linux for unknown type or unset variable:
- [ "$TERM" = "" -o "$TERM" = "unknown" ] && TERM=linux
- # EDITOR="emacs"
- # EDITOR="gmacs"
- # EDITOR="$FS/bin/edit"
- # EDITOR="vi"
- # [ls_options]
- ls --help 2>&1 | grep -q group-directories-first && LS_GDF="--group-directories-first"
- LS_OPTIONS='-lapbviT0 --color=always --time-style="+%Y/%m/%d %a %T %Z"'
- SL_OPTIONS='-lapbvT0 --color=always --time-style=+'
- # [ls_colors]
- eval $(dircolors -b)
- [ -f /etc/DIR_COLORS ] && eval $(dircolors -b /etc/DIR_COLORS)
- [ -f $HOME/.dir_colors ] && eval $(dircolors -b $HOME/.dir_colors)
- # [functions]
- ps()
- {
- ps=/bin/ps
- format="o start,tty,user,rss,pid,cmd"
- if [ $# = 0 ]
- then
- $ps fwwx $format
- else
- [ "$1" = a ] && $ps fwwxa $format || $ps fww $format U $1
- fi
- }
- # # replaced with $FS/bin/vi because of $PAGER variable
- # vi()
- # {
- # args="" && [ "$*" ] && args=$( for i in $(seq $#); do eval echo \\\"\${$i}\\\"; done )
- # { vi=$(which vim) && [ "$DISPLAY" ] && xping -n1 && which gvim && vi="gvim"; } &> /dev/null
- # # { vi=$(which vim) && [ "$DISPLAY" ] && which gvim && vi="gvim"; } &> /dev/null
- # eval $vi $args 2>> ~/.xsession-errors
- # }
- # export -f vi
- sl()
- {
- BLOCK_SIZE=\'1 ls $SL_OPTIONS $LS_GDF $* | cut -c12- | sed "/^$/d"
- # LC_NUMERIC=en_US$utf BLOCK_SIZE=\'1 ls $SL_OPTIONS $LS_GDF $* | cut -c12- | sed "/^$/d"
- }
- sla()
- {
- BLOCK_SIZE=\'1 ls $SL_OPTIONS $* | cut -c12- | sed "/^$/d"
- # LC_NUMERIC=en_US$utf BLOCK_SIZE=\'1 ls $SL_OPTIONS $* | cut -c12- | sed "/^$/d"
- }
- prompt()
- {
- local black="\[\e[1;30m\]"
- local red="\[\e[1;31m\]"
- local green="\[\e[1;32m\]"
- local yellow="\[\e[1;33m\]"
- local blue="\[\e[1;34m\]"
- local magenta="\[\e[1;35m\]"
- local cyan="\[\e[1;36m\]"
- local white="\[\e[1;37m\]"
- local off="\[\e[0m\]"
- local c__def=$red
- local c_numb=$red
- local c_user=$green
- local c_host=$yellow
- local c__tty=$cyan
- local c_path=$white
- local char at tat
- if [ "$(id -u)" = "0" ]
- then
- char="#"
- at=""
- tat=""
- else
- char="$"
- at="$c_user\u$c__def@"
- tat="\u@"
- fi
- local ab='['
- local fe=']'
- # local tty=t$(tty | awk -F "tty" '{print$2}') && [ "$tty" = "t" ] && tty=p$(tty | awk -F "/" '{print$NF}')
- local tty=$(tty | cut -d/ -f3-)
- # \! history number of current command
- # \$ # for UID=0 and $ othewise
- # \h hostname
- # \s name of shell
- # \t time
- # \u username
- # \w working directory
- # \W basename of working direktory
- local title="\[\e]0;$tat\h$ab$tty$fe\w\a\]"
- local prompt="$c_numb\! $at$c_host\h$c__def$ab$c__tty$tty$c__def$fe$c_path\w$c__def$char$off "
- echo "$TERM" | grep -qi xterm && echo "$title$prompt" || echo "$prompt"
- }
- PS1=$(prompt)
- export FS PATH CDPATH MANPATH LD_LIBRARY_PATH TERM VISUAL EDITOR PS1 LS_OPTIONS SL_OPTIONS LS_GDF
- # [aliases]
- # unalias d
- # unalias dir
- # unalias ls
- # unalias mc
- # unalias v
- # unalias vdir
- # alias l="LC_NUMERIC=en_US$utf BLOCK_SIZE=\'1 ls $LS_OPTIONS $LS_GDF"
- # alias la="LC_NUMERIC=en_US$utf BLOCK_SIZE=\'1 ls $LS_OPTIONS"
- alias l="BLOCK_SIZE=\'1 ls $LS_OPTIONS $LS_GDF"
- alias la="BLOCK_SIZE=\'1 ls $LS_OPTIONS"
- alias watch="watch -cbn1"
- alias cgrep="grep --color=always"
- alias h="history"
- alias du="time du -chs"
- alias df="df -haT"
- alias wt="wordtrans"
- alias time="/usr/bin/time -f 'ELAPSED TIME: %E'"
- alias lynx="lynx -cfg=$HOME/.lynxrc"
- # alias put="nqc -d"
- # alias run="nqc -run"
- # alias wake="nqc -sleep 10"
- # alias off="nqc -sleep 1"
- # alias firm="nqc -firmfast /auto/share/Areas/Robotica/nqc/firmware/firm.lgo"
- # [sudo hint]
- if [ ! -e $HOME/.sudo_as_admin_successful ]
- then
- case " $(groups) " in *\ admin\ *)
- if [ -x /usr/bin/sudo ]
- then
- cat << EOF
- To run a command as administrator (user "root"), use "sudo <command>".
- See "man sudo_root" for details.
- EOF
- fi
- esac
- fi
- # if the command-not-found package is installed, use it
- if [ -x /usr/lib/command-not-found ]
- then
- command_not_found_handle()
- {
- # check because c-n-f could've been removed in the meantime
- if [ -x /usr/lib/command-not-found ]
- then
- python /usr/lib/command-not-found -- $1
- return $?
- else
- return 127
- fi
- }
- fi
- # [LWD - Last Working Directory]
- # Em 19 de março de 2010 11:50, Julio C. Neves <julio.neves@gmail.com> escreveu:
- # > Bah Tchê,
- # > se eu entendi bem, em tempo de login vc quer voltar para o diretório em que
- # > estava qdo deu logout. se for isso coloque a seguinte linha no ~/.bashrc:
- #
- # Oi, Julio. Obrigado pela dica! :-)
- #
- # Inicialmente era exatamente isso que eu queria.
- #
- # > cd $(cat ~/.lwd 2> /dev/null)
- # > trap "echo $PWD > ~/.lwd" 0 15
- #
- # A sua solucao tem a simplicidade poetica dos bons scripts bash :-) ; com ela percebi que minha solucao inicial nao resolvia o problema proposto.
- #
- # [CUT, inclusive o aperfeicoamento da solucao acima :-p]
- #
- # Mas agora, alem de
- #
- # (1) nao havendo sessoes abertas, fazer a primeira nova sessao voltar para o ultimo (L) diretorio de trabalho (WD) da ultima sessao shell fechada,
- #
- # resolvi querer MAIS 2 coisas :-p
- #
- # (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
- # ultima;
- #
- # (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"
- # nesses termos de LWD.
- #
- # Juntando as nossas 2 solucoes, cheguei a essa:
- #
- # --
- #
- # lwd_cd()
- # {
- # local LWD=$1
- # [ "$LWD" = : ] && LWD=$(cat ~/.lwd 2> /dev/null)
- # cd "${LWD:-$HOME}" && pwd >| ~/.lwd
- # }
- #
- # echo $$ >> ~/.lwp
- #
- # trap 'echo "$(grep -wv $$ ~/.lwp 2> /dev/null)" >| ~/.lwp; grep -qE "[0-9]" ~/.lwp || cd .' 0 15
- #
- # alias cd="lwd_cd"
- #
- # cd :
- #
- # --
- #
- # O que acontece aí?
- #
- # <http://en.wikipedia.org/wiki/Path_%28computing%29#Representations_of_paths_by_operating_system_and_shell>
- #
- # Colocando o codigo acima em algum dos arquivos de inicializacao do bash, ate onde eu pude testar, as 3 condicoes estipuladas sao satisfeitas.
- #
- # 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
- # vi que fatalmente vou cair no uso dos fifo's de novo...
- #
- # E a minha pergunta continua: voces tem alguma sugestao para simplificar o algoritmo acima, mantendo agora as 3 condicoes?
- #
- # A-bash-os, (puts, essa foi triste... :-p)
- # Signal Value Acti Comment
- # -------- -------- ---- -------
- # 0 n/a Exit code indicates if a signal may be sent
- # SIG HUP 1 Term Hangup detected on controlling terminal or death of controlling process
- # SIG INT 2 Term Interrupt from keyboard
- # SIG QUIT 3 Core Quit from keyboard
- # SIG ILL 4 Core Illegal Instruction
- # SIG TRAP 5 Core Trace/breakpoint trap
- # SIG ABRT 6 Core Abort signal from abort(3)
- # SIG BUS 10 7 10 Core Bus error (bad memory access)
- # SIG FPE 8 Core Floating point exception
- # SIG KILL 9 Term Kill signal
- # SIG SEGV 11 Core Invalid memory reference
- # SIG PIPE 13 Term Broken pipe: write to pipe with no readers
- # SIG ALRM 14 Term Timer signal from alarm(2)
- # SIG TERM 15 Term Termination signal
- # SIG USR1 30 10 16 Term User-defined signal 1
- # SIG USR2 31 12 17 Term User-defined signal 2
- # SIG CHLD 20 17 18 Ign Child stopped or terminated
- # SIG CONT 19 18 25 Cont Continue if stopped
- # SIG STOP 17 19 23 Stop Stop process
- # SIG TSTP 18 20 24 Stop Stop typed at tty
- # SIG TTIN 21 21 26 Stop tty input for background process
- # SIG TTOU 22 22 27 Stop tty output for background process
- export LWDFILE="$HOME/.lwd"
- lwdcd()
- {
- local WD
- local TTY=$(tty)
- [ "$1" != : ] \
- && WD=$1 \
- || {
- [ -s "$LWDFILE" ] && WD=$(grep -w "$TTY" "$LWDFILE" | cut -f3)
- }
- builtin cd "${WD:-$HOME}" \
- && {
- [ -s "$LWDFILE" ] \
- && {
- grep -wv "$TTY" "$LWDFILE" >| "$LWDFILE-$$"
- mv "$LWDFILE-$$" "$LWDFILE"
- }
- [ "$(readlink -f "$PWD")" != "$(readlink -f "$HOME")" ] && echo -e "$TTY\t$(date +'%Y/%m/%d %a %H:%M:%S %Z')\t$PWD" >> "$LWDFILE"
- }
- }
- alias cd="lwdcd"
- alias lwd="[ -s \"$LWDFILE\" ] && sort -t/ -k4 -n \"$LWDFILE\""
- # cd $( [ -s $LWDFILE ] && grep "$TTY" $LWDFILE | cut -f2 && cat < $LWDFILE | $( grep -v "$TTY" >| $LWDFILE ) )
- # trap '[ $(readlink -f $PWD) != $(readlink -f $HOME) ] && echo -e "$TTY\t$PWD" >> $LWDFILE' 0 2 3 15
- # cd $( [ -s $LWDFILE ] && grep "$TTY" $LWDFILE | cut -f2 && grep -v "$TTY" $LWDFILE >| $LWDFILE-$$ && mv $LWDFILE-$$ $LWDFILE )
- # trap "[ \$(readlink -f \$PWD) != \$(readlink -f $HOME) ] && echo -e \"$TTY\t\$PWD\" >> $LWDFILE" 0 HUP INT QUIT TERM
- # [bash_completion]
- [ -f /etc/bash_completion ] && . /etc/bash_completion
- _compssh ()
- {
- cur=${COMP_WORDS[COMP_CWORD]};
- COMPREPLY=($(compgen -W '$(cat ${HOME}/.ssh/config)' -- $cur))
- }
- complete -F _compssh ssh
- }
- # Funcoes ZZ
- [ -f /usr/bin/funcoeszz ] && . /usr/bin/funcoeszz
- if alias | grep -q lwd
- then
- echo -e "\nLast Working Directories: "
- lwd || echo "none."
- echo
- cd :
- fi
- [ "$(readlink -f '$PWD')" = "$(readlink -f '$HOME')" ] && cd
- # EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement