Skip to content

Instantly share code, notes, and snippets.

@hvmonteiro
Last active January 24, 2018 11:32
Show Gist options
  • Save hvmonteiro/118a04718a2a43aa317dbf0e662826b2 to your computer and use it in GitHub Desktop.
Save hvmonteiro/118a04718a2a43aa317dbf0e662826b2 to your computer and use it in GitHub Desktop.
Get 'less'' command to display highlighted content
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
umask 0002
eval "$( dircolors -b "$HOME/.LS_COLORS" )"
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# Shell prompt setup
#export PS1="[\\[\\033[01;32m\\]\\u@\\h\\[\\033[01;34m\\] \\w\\[\\033[00m\\]]\$ \\[\\033[00m\\]"
export PS1="\n\\[\\033[00m\\][\[\\033[01;37m\\]\\w\\[\\033[00m\\]]\\n[\\[\\033[01;32m\\]\\u\\[\\033[01;37m\\]@\\[\\033[01;33m\\]\h\\[\\033[00m\\]]\\\$ "
# Shell environment setup
export EDITOR="vim"
export ATOM_NODE_URL="http://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist"
export PATH="$PATH:/HOME/bin"
# ignorespace: lines which begin with a space character are not saved in the history list.
# ignoredups: causes lines matching the previous history entry to not be saved.
# ignoreboth: shorthand for ignorespace and ignoredups
# erasedups: causes all previous lines matching the current line to be removed from the history list before that line is saved.
export HISTCONTROL=ignoredups:erasedups
export LESS='-R'
export LESSOPEN='|$HOME/.lessfilter %s'
# Maven options to add to every "mvn" command executed
export MAVEN_OPTS="-DskipTests"
# User specific proxy settings
#export https_proxy="http://proxy:8080"
#export http_proxy="http://proxy:8080"
#export ftp_proxy="http://proxy:8080"
#export no_proxy="localdomain localhost"
# User specific aliases and functions
alias vi="vim"
alias ll="ls -l --color"
alias ls="ls --color"
alias mroe="more"
# Ignore external repositories in SVN
svn() {
case "$1" in
st|stat|status)
svnargs1=""
svnargs2="--ignore-externals"
for i in "$@"; do
if [ "--examine-externals" == "$i" ]; then
svnargs2=""
else
svnargs1="$svnargs1 $i"
fi
done
echo "Executing: svn $svnargs1 $svnargs2"
command svn "$svnargs1" "$svnargs2"
;;
*)
command svn "$@"
;;
esac
}
svndiff() {
svn diff "$@" | vim -R -c "color darkblue" -
}
colordiff() {
diff "$@" | vim -R -c "color darkblue" -
}
diffcolor() {
diff "$@" | vim -R -c "color darkblue" -
}
# Automatic authentication using the password specified in ~/.ssh/sshpass
ssh() {
sshpass -f $HOME/.ssh/sshpass ssh "$@"
}
git() {
unset SSH_ASKPASS
unset GIT_ASKPASS
command git "$@"
}
man() {
env \
LESS_TERMCAP_mb="$(printf "\e[1;31m")" \
LESS_TERMCAP_md="$(printf "\e[1;31m")" \
LESS_TERMCAP_me="$(printf "\e[0m")" \
LESS_TERMCAP_se="$(printf "\e[0m")" \
LESS_TERMCAP_so="$(printf "\e[1;44;33m")" \
LESS_TERMCAP_ue="$(printf "\e[0m")" \
LESS_TERMCAP_us="$(printf "\e[1;32m")" \
man "$@"
}
# added by travis gem
[ -f $HOME/.travis/travis.sh ] && source $HOME/.travis/travis.sh
#!/bin/bash
#
# Description: This script allows unix command 'less' to display prettified source code
# by highlighting displayed content using http://pygments.org.
# You must have pigmentize command installed on your system for it to function.
# If no colors are displayed, you don't have the command 'pygmentize' available
# in your $PATH.
#
# Notes: This files should have executable attribute set (ex: chmod u+x ~/.lessfilter)
#
# Source: https://gist.github.com/hvmonteiro/118a04718a2a43aa317dbf0e662826b2
#
case "$1" in
*.awk|*.groff|*.java|*.js|*.m4|*.php|*.pl|*.pm|*.pod|*.sh|\
*.ad[asb]|*.asm|*.inc|*.[ch]|*.[ch]pp|*.[ch]xx|*.cc|*.hh|\
*.lsp|*.l|*.pas|*.p|*.xml|*.xps|*.xsl|*.axp|*.ppd|*.pov|\
*.diff|*.patch|*.py|*.rb|*.sql|*.ebuild|*.eclass)
[ $(which pygmentize 2> /dev/null) ] && pygmentize -f 256 "$1";;
.bashrc|.bash_aliases|.bash_environment)
[ $(which pygmentize 2> /dev/null) ] && pygmentize -f 256 -l sh "$1"
;;
*)
grep "#\!/bin/bash" "$1" > /dev/null
if [ "$?" -eq "0" ]; then
[ $(which pygmentize 2> /dev/null) ] && pygmentize -f 256 -l sh "$1"
else
exit 1
fi
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment