View previous topic :: View next topic |
Author |
Message |
Bones McCracker Veteran
Joined: 14 Mar 2006 Posts: 1611 Location: U.S.A.
|
Posted: Thu Dec 13, 2007 4:20 am Post subject: |
|
|
ppurka wrote: | eww! Who reads all that |
People who used to say "duh!" when offering someone a tip? _________________
patrix_neo wrote: | The human thought: I cannot win.
The ratbrain in me : I can only go forward and that's it. |
|
|
Back to top |
|
|
swimmer Veteran
Joined: 15 Jul 2002 Posts: 1330 Location: Netherlands
|
Posted: Thu Dec 13, 2007 2:20 pm Post subject: |
|
|
ppurka wrote: | duh! Code: | echo "bindkey \"^R\" history-incremental-search-backward
bindkey \"^S\" history-incremental-search-forward" >> .zshrc
. .zshrc |
|
Luckily I don't know what "duh!" means and I think I don't want to know
Thanks for the tip ppurka |
|
Back to top |
|
|
Alanceil n00b
Joined: 14 Aug 2007 Posts: 36 Location: Regensburg, Germany
|
Posted: Sat Dec 15, 2007 12:41 am Post subject: |
|
|
Why didn't I find this thread earlier ? *beats himself*
There were some really nice gems in here. ( Feels like "You just gained a level in Bash Magic!" )
In return, part of my bash config:
Code: |
shopt -s cdspell
shopt -u extdebug
complete -d cd
complete -c which
complete -c man
complete -c killall
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias l='ls -lF --color=always'
alias la='ls -la --color=always'
alias lh='ls -lh --color=always'
alias ll='ls -l --color=always'
alias ls='ls --color=always'
alias lS='ls -lS'
alias c='cd'
alias o='/usr/bin/less'
alias vo='/usr/bin/vim'
alias bi='/usr/bin/vim'
alias vu='/usr/bin/vim'
alias suvi='sudo /usr/bin/vim'
alias xc='/usr/bin/xv'
PS1='\[\033[0;32m\]\u@\h\[\033[0m\]:\[\033[0;36m\]\A\[\033[0m\]:\[\033[1;30m\]${?}\[\033[0m\]:\[\033[1;34m\]\w\[\033[0m\]>\[\033[0m\] '
|
I sometimes hit the wrong keys when I want to start vi, so there are some aliases to catch that. (In case you ask) |
|
Back to top |
|
|
ppurka Advocate
Joined: 26 Dec 2004 Posts: 3256
|
Posted: Sat Dec 15, 2007 3:11 am Post subject: |
|
|
Alanceil wrote: | I sometimes hit the wrong keys when I want to start vi, so there are some aliases to catch that. (In case you ask) | I believe there is some shell setting which makes the shell suggest you the correct alternative if you had a typo in the previous command. _________________ emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/ |
|
Back to top |
|
|
purpler n00b
Joined: 11 Jan 2007 Posts: 38 Location: /v*/l*/p*/world
|
|
Back to top |
|
|
Alanceil n00b
Joined: 14 Aug 2007 Posts: 36 Location: Regensburg, Germany
|
Posted: Thu Dec 20, 2007 12:13 am Post subject: |
|
|
Then I'll still have to use my vi aliases
I tried zsh several times, and never liked it.
... and sth. for the topic:
Code: | function path(){
test -e "$1" && echo "`pwd`/${1}"
} |
|
|
Back to top |
|
|
Dralnu Veteran
Joined: 24 May 2006 Posts: 1919
|
Posted: Sat Dec 22, 2007 6:27 am Post subject: |
|
|
purpler wrote: | oh yes, that setting is called ZSH
/etc/zsh/zshrc:
setopt correctall |
bash has a similar feature. _________________ The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner. |
|
Back to top |
|
|
arcanex n00b
Joined: 10 Jun 2007 Posts: 1
|
|
Back to top |
|
|
MartyParish n00b
Joined: 08 Oct 2004 Posts: 40 Location: Maryland-US
|
Posted: Sun Mar 09, 2008 8:09 pm Post subject: |
|
|
Hey, here's a list that contains plenty of stuff that's been mentioned already but some stuff that I did not see. I read the whole thread too! It was great.
Ctrl + A - Go to the beginning of the line you are currently typing on
Ctrl + E - Go to the end of the line you are currently typing on
Ctrl + L - Clears the Screen, similar to the clear command
Ctrl + U - Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H - Same as backspace
Ctrl + R - Let’s you search through previously used commands
Ctrl + C - Kill whatever you are running
Ctrl + D - Exit the current shell
Ctrl + Z - Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + W - Delete the word before the cursor
Ctrl + K - Clear the line after the cursor
Ctrl + T - Swap the last two characters before the cursor
Esc + T - Swap the last two words before the cursor
Alt + F - Move cursor forward one word on the current line
Alt + B - Move cursor backward one word on the current line
Tab - Auto-complete files and folder names
Ctrl + W - erase word before cursor
Ctrl + Y - to paste it (as in delete and copy) all text in front of the cursor
Esc + . (or Esc + Underscore) - Insert Last Argument
Ctrl + b - Move back a character
Ctrl + f - Move forward a character
Ctrl + r - Search the history backwards
Ctrl + xx - Move between EOL and current cursor position
Ctrl + x @ - Show possible hostname completions
Alt + < - Move to the first line in the history
Alt + > - Move to the last line in the history
Alt + ? - Show current completion list
Alt + * - Insert all possible completions
Alt + / - Attempt to complete filename
Alt + . - Yank last argument to previous command
Alt + c - Capitalize the word
Alt + d - Delete word
Alt + l - Make word lowercase
Alt + n - Search the history forwards non-incremental
Alt + p - Search the history backwards non-incremental
Alt + r - Recall command
Alt + t - Move words around
Alt + u - Make word uppercase
Alt + back-space - Delete backward from cursor
Here "2T" means Press TAB twice
$ 2T - All available commands(common)
$ (string) 2T - All available commands starting with (string)
$ /2T - Entire directory structure including Hidden one
$ 2T - Only Sub Dirs inside including Hidden one
$ *2T - Only Sub Dirs inside without Hidden one
$ ~2T - All Present Users on system from "/etc/passwd"
$ $2T - All Sys variables
$ @2T - Entries from "/etc/hosts"
$ =2T - Output like ls or dir |
|
Back to top |
|
|
devsk Advocate
Joined: 24 Oct 2003 Posts: 3003 Location: Bay Area, CA
|
Posted: Sat Mar 29, 2008 5:48 am Post subject: |
|
|
put this in your ~/.bashrc if you just want to override part of the DIR_COLORS and don't want to copy the full file to ~/.dir_colors and maintain it in future if /etc/DIR_COLORS changes:
Code: | eval `cat /etc/DIR_COLORS ~/.dir_colors | dircolors - |
|
|
Back to top |
|
|
David Serrano n00b
Joined: 26 Mar 2008 Posts: 16
|
Posted: Mon Apr 14, 2008 2:43 pm Post subject: |
|
|
Great thread!!
tam1138 wrote: | Also, using the ":p" option on any potentially-dangerous bash replacement tricks is useful: it prints out the command that WOULD be run and also appends it to your history. That is, if you think you want to run the last command starting with 'r' in your history but don't want to hose yourself before verifying the command:
|
I use:
Code: | shopt -s histverify |
With this, you get confirmation for all history expansions. That's useful not only for verifying potentially harmful 'rm' commands, but also to change some parameters, files and whatever before actually running the command.
Here are my aliases and functions:
Code: | function del() {
/bin/mv -f "$@" $HOME/.trash/;
}
alias cd='cd -P'
alias ls='ls -F -N --color=tty --time-style="+%Y%m%d:%H%M%S%z"'
alias ll='ls -l'
alias cl='clear; logout'
alias cv='clear; vlock -a'
alias lless='ll -R --color=always | less -r'
## allows 'h emerge -s' without quoting the space
function h() { HISTTIMEFORMAT= history | grep "$*"; }
alias ltrace='ltrace -S -tt -C'
alias strace='strace -s 500 -tt -ff'
alias vim='vim -X -o'
alias bc='bc ~/.bcrc' ## set up default number of decimals, .bcrc contains "scale=4"
alias perl='perl -Mstrict -w'
alias pf='perldoc -f'
alias pd='perldoc'
alias pq='perldoc -q'
alias xev='xev | grep keycode'
function rmoz() {
## ripped from https://bugzilla.mozilla.org/attachment.cgi?id=151958
## which appears in https://bugzilla.mozilla.org/show_bug.cgi?id=246168
if [ "$1" ]; then
if [ -f "$PWD/$1" ]; then
LOCAL="file://$PWD/$1"
elif [ -f "$1" ]; then
LOCAL="file://$1"
else
LOCAL="$1"
[[ $LOCAL =~ ^http:// ]] || LOCAL="http://$LOCAL"
fi
DISPLAY=:0 mozilla -remote "openurl($LOCAL,new-tab)"
fi
}
## show version of specified perl modules
function pmver() { perl -le "eval { require ${1} } and print qq{${1}: },\$${1}::VERSION or print qq{${1}: none}"; }
function ls-() { ls -"$@"; } |
Environment variables:
Code: | export HISTCONTROL=ignoredups:erasedups
export HISTIGNORE="date:df:fg:jd:jobs:ll:ls"
export HISTTIMEFORMAT="%Y%m%d:%H%M%S%z"
export IGNOREEOF=1
export LESS='-c -h1 -y1 -j2 -S'
export LESS="$LESS -P B%bt-%bB?B/%B.?pt(%pt\%). ?ltL%lt-%lb.?L/%L.?Pt(%Pt\%). .?f%f:-.?e (END).?m (file %i of %m).%t"
unset LESSOPEN ## hate this
## use with 'ps -eH' or 'ps -e f'
export PS_FORMAT="pid,pgid,euid,egid,nlwp:2=NT,ni:2,rtprio:2=RT,cls:2,vsz:6,rss:6,pcpu,pmem,stat:3=ST,tname:6,stime,bsdtime,args"
export TIMEFORMAT=$'\nreal: %3R, user: %3U, sys: %S'
export TMPDIR=~/tmp
export TMP=$TMPDIR
unset PERL5LIB;
DIRS=(~/em/perl-modules/{lib,share}/perl/*);
local IFS=":";
export PERL5LIB="${DIRS[*]}"; |
Misc:
Code: | shopt -s cdable_vars checkhash checkwinsize cmdhist extquote histappend histreedit histverify
shopt -u force_fignore
if [[ "`tty`" =~ ^/dev/tty ]]; then ## things for console only
setterm -blength 10 -bfreq 10000 ## barely hearable, prevents waking up people
fi |
.inputrc:
Code: | set horizontal-scroll-mode off
## 'audible' or 'visible'
set bell-style audible
set meta-flag on
set input-meta on
set output-meta on
set convert-meta off
set history-preserve-point on
set editing-mode vi-command
set keymap vi-command
set page-completions off
set visible-stats on
## todo: yank-nth-arg
## todo: yank-last-arg |
.xbindkeysrc:
Code: | "xkbcomp /home/hue/.hue-xkb/es-qwerty-hue :0"
control+F1
"xkbcomp /home/hue/.hue-xkb/es-dvorak-hue :0"
control+F2
"xwd -root -silent | convert xwd:- png:/home/hue/xwd-$(date +%Y%m%d:%H%M%S.png)"
Print |
The ~/.hue-xkb files were generated by using xkbcomp; then further tweaked. It's like using xmodmap.
Last, I'd like to bump this excellent tip (not for obtaining the IP, but for its use of 'set'):
dub.wav wrote: | Code: | alias currentip='set `/sbin/ifconfig eth0` && echo ${7#*:}' |
|
_________________ David Serrano |
|
Back to top |
|
|
faux n00b
Joined: 26 Oct 2007 Posts: 61 Location: Linz, Austria
|
Posted: Tue Apr 29, 2008 2:14 pm Post subject: |
|
|
Nice thread. Read the whole one, really useful!
Job Management
recalls a running or suspended job.
lists jobs of current session.
Ctrl+Z suspends current job and sends it to background.
starts a job in backgroud.
screen usage in my .bashrc
Code: | if [ $SHLVL -eq 1 ]; then
/usr/bin/screen -xRR
fi |
Resumes the last screen session (or starts a new one, if nothing to resume) if using an tty (not a terminal like xterm) or SSH session. Very useful on SSH sessions if connection times out.
view ebuild of package
Code: | eview() {
FILE=$(equery which $1)
if [ -f "$FILE" ]; then
view $FILE
fi
} |
|
|
Back to top |
|
|
notHerbert Advocate
Joined: 11 Mar 2008 Posts: 2228 Location: 45N 73W
|
Posted: Fri Oct 03, 2008 2:38 pm Post subject: |
|
|
It has happened that I mistyped an append command in an important file.
My desire is to do something like this Code: | echo "some configuration" >> /etc/somefile | But instead I type Code: | echo "some configuration" > /etc/somefile |
Consider Code: | # echo "something something" > /etc/passwd |
This command would overwrite /etc/passwd, and would be a real pain to repair - even if the error is caught before logging out.
If I add this to .bashrc (then source .bashrc)Then I can do this Code: | # echo "a bunch of crap" > /etc/passwd
-su: /etc/passwd: cannot overwrite existing file |
Now I caught my typo before making a mess.
Now if my intention really is to overwrite a file, a pipe character will allow me to do that.
To clear the contents of $HOME/.xsession-errors, type Code: | $ :>| $HOME/.xsession-errors |
|
|
Back to top |
|
|
a.b. Apprentice
Joined: 23 Mar 2008 Posts: 218 Location: Anus Mundi, Germany
|
Posted: Fri Oct 03, 2008 5:17 pm Post subject: |
|
|
The only interesting things in my .zshrc are:
Code: | # With -p, Paludis should have normal niceness
# Else, it should be extremly friendly
function paludis(){
if echo $@ | egrep '\-.*p\ ' > /dev/null; then
/usr/bin/paludis $@
else
nice -n19 /usr/bin/paludis $@
fi
} |
and
Code: | # For the really bullish processes
function murder(){
while [[ $? = 0 ]]; do
kill -9 $@
done
} |
The rest:
http://shellium.org/~aeebee/dotfiles/zshrc |
|
Back to top |
|
|
a.b. Apprentice
Joined: 23 Mar 2008 Posts: 218 Location: Anus Mundi, Germany
|
Posted: Fri Oct 03, 2008 5:19 pm Post subject: |
|
|
notHerbert wrote: | It has happened that I mistyped an append command in an important file. |
That has happened to me several times as well. Backups more or less solve that |
|
Back to top |
|
|
notHerbert Advocate
Joined: 11 Mar 2008 Posts: 2228 Location: 45N 73W
|
Posted: Sun Oct 19, 2008 10:02 pm Post subject: |
|
|
A bash command prompt that prints the return value in the prompt if it is not equal to zero.
Code: | PS1='\w \u$(r=$?; test $r -ne 0 && echo " \[\e[1;31m\]ret:$r")\e[0m\] \$ ' |
|
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6749
|
Posted: Mon Oct 20, 2008 7:50 am Post subject: |
|
|
notHerbert wrote: | A bash command prompt that prints the return value in the prompt |
This is once more an example why it is wiser to use zsh as the interactive shell. There you can just include %? or (for analogous behaviour to your case) %(?||ret:%?) within PS1 (coloring omitted for simplicity). Or even simpler and IMHO more convenient for daily usage: setopt print_exit_value. |
|
Back to top |
|
|
Dralnu Veteran
Joined: 24 May 2006 Posts: 1919
|
Posted: Sat Jan 03, 2009 12:40 pm Post subject: |
|
|
renice <nice_value> `pgrep <proccess to renice>`
Or
renice <nice_val> $(pgrep <proc>) if you don't want the folks in #bash to yell at you _________________ The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner. |
|
Back to top |
|
|
a.b. Apprentice
Joined: 23 Mar 2008 Posts: 218 Location: Anus Mundi, Germany
|
Posted: Sat Jan 03, 2009 2:02 pm Post subject: |
|
|
Code: | function wi() { vi $(equery which $@) |
Code: | function usegrep() { grep $@ /var/repos/*/profiles/use.* } |
and a couple of functions like
Code: | function bugz() { if [[ $1 == get ]]; then =bugz $@ | less; else =bugz $@; fi } |
|
|
Back to top |
|
|
Dralnu Veteran
Joined: 24 May 2006 Posts: 1919
|
Posted: Sat Jan 03, 2009 2:05 pm Post subject: |
|
|
a.b. wrote: | Code: | function usegrep() { grep $@ /var/repos/*/profiles/use.* } |
|
I don't have a var/repos dir on my system. Are you talking about /usr/portage/profiles/use.desc? _________________ The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner. |
|
Back to top |
|
|
a.b. Apprentice
Joined: 23 Mar 2008 Posts: 218 Location: Anus Mundi, Germany
|
Posted: Sat Jan 03, 2009 3:04 pm Post subject: |
|
|
Dralnu wrote: | a.b. wrote: | Code: | function usegrep() { grep $@ /var/repos/*/profiles/use.* } |
|
I don't have a var/repos dir on my system. Are you talking about /usr/portage/profiles/use.desc? |
I've put the stuff in more logical places:
Code: | # Folders
REPODIR="/var/repos"
PORTDIR="$REPODIR/gentoo"
PORTDIR_OVERLAY="$REPODIR/local $REPODIR/imported"
source "/var/repos/.layman/make.conf"
DISTDIR="/var/cache/distfiles" |
In the default setup it's of course /usr/portage/etc.. |
|
Back to top |
|
|
Ormaaj Guru
Joined: 28 Jan 2008 Posts: 319
|
Posted: Sat Apr 11, 2009 3:30 pm Post subject: |
|
|
deleteme
Last edited by Ormaaj on Wed Oct 20, 2010 3:49 am; edited 2 times in total |
|
Back to top |
|
|
loudmax n00b
Joined: 30 Mar 2005 Posts: 7
|
Posted: Mon Apr 13, 2009 10:33 pm Post subject: smileys |
|
|
Here's my prompt string:
Code: | PS1='\[\033[01;32m\]\u@\[\033[01;31m\]\h[\w]:`if [[ $? != 0 ]]; then echo "( "; else echo ") "; fi`\[\033[00m\]' |
If the previous command succeeds it shows me it's happy:
Code: | user@host[~]:) /bin/true
user@host[~]:) |
If the previous command fails, it's sad
Code: | user@host[~]:) /bin/false
user@host[~]:( |
|
|
Back to top |
|
|
nendzd n00b
Joined: 10 Apr 2006 Posts: 68
|
Posted: Fri Apr 24, 2009 4:45 pm Post subject: |
|
|
^^^^ That is great!
Unfortunately I don't have any tips and tricks to post, although I am getting a lot of use out of this thread, thanks! |
|
Back to top |
|
|
coolsnowmen Veteran
Joined: 30 Jun 2004 Posts: 1479 Location: No.VA
|
Posted: Fri Apr 24, 2009 5:04 pm Post subject: Re: smileys |
|
|
loudmax wrote: | Here's my prompt string:
Code: | PS1='\[\033[01;32m\]\u@\[\033[01;31m\]\h[\w]:`if [[ $? != 0 ]]; then echo "( "; else echo ") "; fi`\[\033[00m\]' |
If the previous command succeeds it shows me it's happy:
Code: | user@host[~]:) /bin/true
user@host[~]:) |
If the previous command fails, it's sad
Code: | user@host[~]:) /bin/false
user@host[~]:( |
|
HAHAHAHAHHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA
edit: my most recent alias -
Code: |
alias ghistory="history | grep"
alias gh="ghistory"
|
_________________ emerge: there are no ebuilds to satisfy "moo" |
|
Back to top |
|
|
|