Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

lr: accept a line count

  • Loading branch information...
commit 4bbfda71bd2a9322f6df3fdd6903f0b32e1b65a4 1 parent 8771f50
@sshaw authored
Showing with 35 additions and 20 deletions.
  1. +1 −1  bash_profile
  2. +34 −19 bashrc
View
2  bash_profile
@@ -10,7 +10,7 @@ export RUBYOPT=-rubygems
export EDITOR="emacs --no-init"
export ESHELL=bash
export PAGER=less
-export PATH=$HOME/usr/bin:$PATH:/usr/sbin:/usr/local/sbin:$GOROOT/bin:$HOME/.cask/bin
+export PATH=$HOME/bin:$HOME/usr/bin:$PATH:/usr/sbin:/usr/local/sbin:$GOROOT/bin:$HOME/.cask/bin
export PERLDOC=-MPod::Text::Ansi
# Interpret ANSI codes and don't warn about a bin file
export PERLDOC_PAGER="less -fR"
View
53 bashrc
@@ -27,6 +27,11 @@ alias gp='git pull'
type -t pgrep > /dev/null || alias pgrep='ps ax | grep -v grep | egrep'
alias build='make && { make test || make check; }'
alias j=' jobs'
+
+alias ls=' ls -FG'
+# BSD vs GNU
+ls --color &> /dev/null && alias ls=' ls -F --color=auto'
+
alias ll=' ls -lh'
alias rg='egrep -R'
@@ -43,8 +48,8 @@ done
annoy()
{
if [ $# -lt 2 ]; then
- echo usage: $FUNCNAME USER MESSAGE
- return 1
+ echo usage: $FUNCNAME USER MESSAGE
+ return 1
fi
local user=$1; shift
@@ -52,13 +57,13 @@ annoy()
local ttys=$(who | perl -lane"print \$F[1] if /\b$user\b/")
if [ -z "$ttys" ]; then
- echo $user is not logged in
- return 2
+ echo $user is not logged in
+ return 2
fi
for tty in $ttys; do
- [ "$tty" == ":0" -o "$tty" == "console" ] && continue # Skip the console
- echo $message | write $user $tty || return
+ [ "$tty" == ":0" -o "$tty" == "console" ] && continue # Skip the console
+ echo "$message" | write $user $tty || return
done
}
@@ -91,14 +96,24 @@ bigfile()
# $* instead of $@
canspell()
{
- [ -n "$*" ] && { echo $@ | aspell -a | grep '^&'; } && return 1 || return 0;
+ [ -n "$*" ] && { echo "$@" | aspell -a | grep '^&'; } && return 1 || return 0;
}
# ls recent
-# usage: lr [DIR]
+# usage: lr [-N] [OPTIONS] [DIR]
lr()
{
- ls -lt "$@" | head
+ local n
+
+ if [[ $1 =~ ^-[0-9]+$ ]]
+ then
+ n=$1
+ shift
+ fi
+
+ # Force color and skip ls summary
+ # BSD; note GNU ls will need --color=force
+ CLICOLOR_FORCE=1 ls -lt "$@" | perl -ne'print unless $.==1' | head $n
}
# usage: newmod [PATTERN]
@@ -137,11 +152,11 @@ rake()
{
local r=$(which rake)
if [ -f "./.components" ]; then
- bundle exec padrino 'rake' "$@"
+ bundle exec padrino 'rake' "$@"
elif [ -f "./Gemfile" -a -f "./Rakefile" ]; then
- bundle exec 'rake' "$@"
+ bundle exec 'rake' "$@"
else
- "$r" "$@"
+ "$r" "$@"
fi
}
@@ -149,16 +164,16 @@ rake()
ri()
{
if [ -z "$1" ]; then
- command ri
- return
+ command ri
+ return
fi
-
+
# TODO: try to use whatever browser is currently open
url="http://localhost:8808/rdoc?q=$*"
- if [ $(uname -s) == "Darwin" ]; then
- open -a Opera "$url"
- else
- opera "$url" &
+ if [ $(uname -s) == "Darwin" ]; then
+ open -a Opera "$url"
+ else
+ opera "$url" &
fi
# Fallback if command failed
Please sign in to comment.
Something went wrong with that request. Please try again.