# Great Practical Ideas for Computer Scientists .bashrc_gpi (F13) # DO NOT MODIFY THIS FILE; place your modifications in ~/.bashrc ### v5: Fixes minor bugs and adds the afsperms command ### v6: Removes annoying screen issue ### v7: Changes GPI_PATH to be full, checks if file exists before using it ### v8: Adds gpi_makemake (a way to automatically generate Makefiles) ### v9: Updates semester ### v10: Update semester to f12 ### v11: Adds afsperms to gpi helptext ### v12: Adds alias for coin that allows you to use arrow keys ### v13: Updates semester, moves "current" file to CS directory ### v14: Adds unicode support; 15-151 bin ### v15: Adds a command to get CS AFS access. ### v16: Adds better support for lern2unix problems, store more command history. ### v17: Fixes a bug with ls on Mac OS X # If not running interactively, don't do anything [ -z "$PS1" ] && return # Define Color Variables for later usage c_red=$(tput setaf 1) c_green=$(tput setaf 2) c_yellow=$(tput setaf 3) c_blue=$(tput setaf 4) c_purple=$(tput setaf 5) c_cyan=$(tput setaf 6) c_white=$(tput setaf 7) c_reset=$(tput sgr0) # Make .bash_history store more and not store duplicates export HISTCONTROL=ignoreboth export HISTSIZE=250000 export HISTFILESIZE=250000 # Append to the history file, don't overwrite it shopt -s histappend # Check the window size after each command and, if necessary, # Update the values of LINES and COLUMNS. shopt -s checkwinsize # Make cd correct minor spelling mistakes # This is now not a default as of v5, because we decided it has questionable behavior # shopt -s cdspell # Make less more friendly for non-text input files, see lesspipe(1) [ -x /usr/bin/lesspipe.sh ] && export LESSOPEN="|/usr/bin/lesspipe.sh %s" # Set the Prompt to be more reasonable #PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' # Alias definitions. alias killz='killall -9 ' alias hidden='ls -a | grep "^\..*"' alias rm='rm -i' alias shell='ps -p $$ -o comm=' alias math='rlwrap MathKernel' alias coin='rlwrap coin' # C Aliases alias cc='gcc -Wall -W -ansi -pedantic -O2 ' alias valgrind-leak='valgrind --leak-check=full --show-reachable=yes' # Enable color support of ls and also add handy aliases # Mac OS doesn't support --color flag for ls, needs -G instead. if [[ `uname` = "Darwin" ]] then alias ls='ls -G' else alias ls='ls --color=auto' fi alias grep='grep --color=auto' # Enable programmable completion features (you don't need to enable # this, if it's already enabled in /etc/bash.bashrc and /etc/profile # sources /etc/bash.bashrc). if [ -f /etc/bash_completion ]; then . /etc/bash_completion fi bind "set completion-ignore-case on" # Useful Functions afsperms(){ find $1 -type d -exec fs sa {} $2 $3 \; ; } qdict(){ grep $1 /usr/share/dict/words; } ldap(){ ldapsearch -b ou=person,dc=cmu,dc=edu cn=$1; } get_cs_afs_access() { # Script to give a user with an andrew.cmu.edu account access to cs.cmu.edu # See https://www.cs.cmu.edu/~help/afs/cross_realm.html for information. # Get tokens. This might create the user, but I'm not sure that that's # reliable, so we'll also try to do pts createuser. aklog cs.cmu.edu CUR_USER=`whoami` pts createuser $CUR_USER@ANDREW.CMU.EDU -cell cs.cmu.edu 2>&1 | grep -v "Entry for name already exists" aklog cs.cmu.edu echo "(aklog cs.cmu.edu &)" >> ~/.bashrc } # Turn off the ability for other people to message your terminal using wall mesg n gpi(){ echo "${c_red}Great Practical Ideas for Computer Scientists .bashrc_gpi${c_reset} (${GPI_VERSION})" echo "We provide a few (useful) aliases and scripts for you to get started:" echo " ${c_green}qdict${c_reset} -- Queries the unix dictionary" echo " ${c_green}afsperms${c_reset} -- Recursively runs fs sa on a directory" echo " ${c_green}cc${c_reset} -- Invokes gcc with the flags you will usually use" echo " ${c_green}valgrind-leak${c_reset} -- Invokes valgrind in the mode to show all leaks" echo " ${c_green}hidden${c_reset} -- Displays ONLY the hidden files" echo " ${c_green}killz${c_reset} -- Kills all programs with the given program name" echo " ${c_green}shell${c_reset} -- Displays the name of the shell being used" echo " ${c_green}gpi_install${c_reset} -- Installs a configuration package provided by GPI" echo " ${c_green}gpi_makemake${c_reset} -- Creates a Makefile for C, C0, or LaTeX projects in the current directory" echo " ${c_green}get_cs_afs_access${c_reset} -- Sets up cross-realm authentication with CS.CMU.EDU so you can access files stored there." echo "More features may be added later, as thought of or requested." } gpi_install() { echo "Choose a package to install:" ls $GPI_PATH/packages echo -n "Package: " read package if [ ! -e "$GPI_PATH/packages/$package" ] then echo "Bad package name: $package" return fi echo "Installing $package..." for f in `ls -A $GPI_PATH/packages/$package` do f=$GPI_PATH/packages/$package/$f cmd="cp --recursive --interactive $f $HOME/" echo "$cmd" $cmd done echo "Installed!" } gpi_makemake() { supported_extensions='tex java c c0' found=0 for ext in $supported_extensions; do files=$(ls *.$ext 2> /dev/null | wc -l) if [ "$files" != "0" ]; then found=1 break fi done if [ "$found" == "0" ]; then echo -e "You don't have any of the supported file types in this directory" return fi if [ "$ext" == "tex" ]; then echo -e "gpi_makemake is making you a LaTeX Makefile!" if [ "$files" == "1" ]; then file=$(echo *.${ext}) else echo -e "There is more than one LaTeX file in your directory..." echo -e "Choose one from the list to be the main source file." select file in *.$ext; do break; done fi if [ "$file" == "" ]; then echo -e "Aborting..." else cat ${GPI_PATH}/makefiles/latex.mk | sed -e "s/GPIMAKEMAKE/${file%.tex}/" > Makefile echo "gpi_makemake has installed a LaTeX Makefile for $file" echo "${c_green}make${c_reset} -- Compiles the LaTeX document into a PDF" echo "${c_green}make clean${c_reset} -- Removes aux and log files" echo "${c_green}make veryclean${c_reset} -- Removes pdf, aux, and log files" echo "${c_green}make view${c_reset} -- Display the generated PDF file" echo "${c_green}make print${c_reset} -- Sends the PDF to print" fi elif [ "$ext" == "java" ]; then echo "gpi_makemake doesn't support java yet. We will add it soon!" elif [ "$ext" == "c" ]; then echo -e "gpi_makemake is making you a C Makefile!" echo -n "What should the name of the target executable be? " read target cat ${GPI_PATH}/makefiles/c.mk | sed -e "s/GPIMAKEMAKE_TARGET/${target}/" > Makefile echo "gpi_makemake has installed a C Makefile!" echo "${c_green}make${c_reset} -- Compiles the C Program (no debug information)" echo "${c_green}make debug${c_reset} -- Compiles the C Program (with debugging information!)" echo "${c_green}make run${c_reset} -- Re-compiles (if necessary) and run the program" echo "${c_green}make clean${c_reset} -- Deletes the created object files" echo "${c_green}make veryclean${c_reset} -- Deletes the created object files and dependencies" elif [ "$ext" == "c0" ]; then echo -e "gpi_makemake is making you a C0 Makefile!" echo -n "List the C0 source files separated by spaces: " read sources echo -n "What should the name of the target executable be? " read target cat ${GPI_PATH}/makefiles/c0.mk | sed -e "s/GPIMAKEMAKE_TARGET/${target}/" | sed -e "s/GPIMAKEMAKE_SOURCE/${sources}/" > Makefile echo "gpi_makemake has installed a C0 Makefile" echo "${c_green}make${c_reset} -- Compiles the C0 Program (no debug information)" echo "${c_green}make debug${c_reset} -- Compiles the C0 Program (with debugging information!)" echo "${c_green}make run${c_reset} -- Re-compiles (if necessary) and run the program" echo "${c_green}make clean${c_reset} -- Deletes the created object files" echo "${c_green}make veryclean${c_reset} -- Deletes the created object files and dependencies" fi }