forked from divad12/khan-dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Totally revamp the way we handle .bashrc.
Summary: I have spent some time groveling through the bash manpages, and am clearer now on the difference between .bashrc and .bash_profile -- basically, one is used for login shells and one for non-login shells. We want our code to run in both contexts, so I have moved everything to .bash_profile, which I now source from .bashrc. (I actually only source .bash_profile.khan, to keep any existing .bash_profile stuff out of it, since maybe the user *does* want that stuff to be login-only.) I also separate out .bash_profile -- which is bash-specific -- from .profile -- which runs on any sh-compatible shell, including zsh. This should make it easier for zsh users to do their setup. Test Plan: I created a new user on my machine, and ran make in the khan-dotfiles directory. It created all the files the way they should be. I then ran bash git rb and saw that the git alias was picked up; that is, the git command didn't say 'rb not found'. I then ran bash --login git rb and saw that it was picked up as well (it wasn't, before this change). Reviewers: marcos, alpert Reviewed By: alpert Subscribers: ayman Differential Revision: http://phabricator.khanacademy.org/D13071
- Loading branch information
Showing
7 changed files
with
129 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
################################################################################ | ||
# Khan Academy specific .bash_profile | ||
# | ||
# The difference between .bash_profile and .profile is that the latter | ||
# is called for all sh-compatible shells. So we put bashisms here | ||
# and non-bashisms in .profile. | ||
# | ||
# According to the bash manpage, if both .bash_profile and .profile | ||
# exist, bash only reads the first one. So we have to source .profile | ||
# manually. | ||
|
||
if [ -s ~/.profile ]; then | ||
source ~/.profile | ||
fi | ||
|
||
# Activate Python2.7 virtualenv | ||
source ~/.virtualenv/khan27/bin/activate | ||
|
||
# Figure out what directory we're *really* in (following symlinks). | ||
# We need this because *-completion.bash are siblings to this script. | ||
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in | ||
SOURCE="${BASH_SOURCE[0]}" | ||
while [ -h "$SOURCE" ]; do # follow symlinks | ||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" | ||
SOURCE="$(readlink "$SOURCE")" | ||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # resolve relative symlink | ||
done | ||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" | ||
|
||
# Enable autocompletion for git | ||
source "$DIR/git-completion.bash" | ||
|
||
# Make sure git (and other apps) prefer 'vim' to 'vi'. | ||
: ${EDITOR:=vim} | ||
|
||
# Set a high limit for open file descriptors per shell. | ||
# The default on OS X is 256; we increase it to 1024--the default value of | ||
# `sysctl kern.maxfilesperproc`, which `ulimit -n` must not exceed. | ||
ulimit -S -n 1024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,14 @@ | ||
################################################################################ | ||
# Khan Academy specific bashrc | ||
|
||
# Add Phabricator bins to PATH | ||
export PATH="$HOME/khan/devtools/arcanist/khan-bin:$PATH" | ||
|
||
# Add frankenserver bins to PATH | ||
export PATH="$HOME/khan/webapp/third_party/frankenserver:$PATH" | ||
|
||
# Add dotfiles scripts to PATH | ||
export PATH="$HOME/khan/devtools/khan-dotfiles/bin:$PATH" | ||
|
||
# Activate Python2.7 virtualenv | ||
source ~/.virtualenv/khan27/bin/activate | ||
|
||
# Figure out what directory we're *really* in (following symlinks). | ||
# We need this because *-completion.bash are siblings to this script. | ||
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in | ||
SOURCE="${BASH_SOURCE[0]}" | ||
while [ -h "$SOURCE" ]; do # follow symlinks | ||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" | ||
SOURCE="$(readlink "$SOURCE")" | ||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # resolve relative symlink | ||
done | ||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" | ||
|
||
# Enable autocompletion for git | ||
source "$DIR/git-completion.bash" | ||
|
||
# Make sure git (and other apps) prefer 'vim' to 'vi'. | ||
: ${EDITOR:=vim} | ||
|
||
# Set a high limit for open file descriptors per shell. | ||
# The default on OS X is 256; we increase it to 1024--the default value of | ||
# `sysctl kern.maxfilesperproc`, which `ulimit -n` must not exceed. | ||
ulimit -S -n 1024 | ||
# | ||
# We actually store all our rc-code in .profile and .bash_profile. | ||
# The difference between .*profile and .bashrc is that the former | ||
# are loaded for login shells and the latter for non-login shells. | ||
# (For more info, see http://hacktux.com/bash/bashrc/bash_profile.) | ||
# | ||
# We want our code to run for both types of shells, so we just include | ||
# .bash_profile from here. We source only .bash_profile.khan in case | ||
# you have code in your .bashrc_profile that you *don't* want executed | ||
# for non-login shells. | ||
|
||
source ~/.bash_profile.khan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
################################################################################ | ||
# Khan Academy specific .profile | ||
# | ||
# The difference between .bash_profile and .profile is that the latter | ||
# is called for all sh-compatible shells. So we put non-bashisms here | ||
# and bashisms in .bash_profile. | ||
|
||
# Add Phabricator bins to PATH | ||
export PATH="$HOME/khan/devtools/arcanist/khan-bin:$PATH" | ||
|
||
# Add frankenserver bins to PATH | ||
export PATH="$HOME/khan/webapp/third_party/frankenserver:$PATH" | ||
|
||
# Add dotfiles scripts to PATH | ||
export PATH="$HOME/khan/devtools/khan-dotfiles/bin:$PATH" | ||
|
||
# Make sure git (and other apps) prefer 'vim' to 'vi'. | ||
: ${EDITOR:=vim} | ||
|
||
# Set a high limit for open file descriptors per shell. | ||
# The default on OS X is 256; we increase it to 1024--the default value of | ||
# `sysctl kern.maxfilesperproc`, which `ulimit -n` must not exceed. | ||
ulimit -S -n 1024 | ||
|
||
|
||
# Mac-specific stuff. | ||
if [ `uname -s` = Darwin ]; then | ||
# We need /usr/local/bin to come before /usr/bin on the path, | ||
# to pick up brew files we install. | ||
if ! echo "$PATH" | egrep -q '(:|^)/usr/local/bin/?:(.*:)?/usr/bin/?(:|$)' | ||
then | ||
# This replaces /usr/bin with /usr/local/bin:/usr/bin | ||
PATH=`echo $PATH | sed -E 's,(^|:)(/usr/bin/?(:|$)),\1/usr/local/bin:\2,'` | ||
fi | ||
|
||
# Ideally we'd put /usr/local/sbin right before /usr/sbin, but | ||
# there's so little in it we figure it's ok to put it first. | ||
PATH=/usr/local/sbin:$PATH | ||
export PATH | ||
|
||
# Numpy/etc use flags clang doesn't know about. This is only | ||
# needed for mavericks. | ||
if expr "`sw_vers -productVersion`" : 10.9 >/dev/null; then | ||
CPPFLAGS="-Qunused-arguments $CPPFLAGS" | ||
CFLAGS="-Qunused-arguments $CFLAGS" | ||
# This ARCHFLAGS is needed until we have pyobjc 3.0, according to | ||
# https://bitbucket.org/ronaldoussoren/pyobjc/issue/66/cannot-locate-a-working-compiler-error | ||
ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future $ARCHFLAGS" | ||
export CPPFLAGS CFLAGS ARCHFLAGS | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
################################################################################ | ||
# Local .bash_profile. | ||
# Feel free to add whatever you like after the 'bash_profile.khan' line. | ||
# | ||
# Note that .bash_profile.khan automatically sources ~/.profile if it | ||
# exists, so you don't have to worry that the addition of this file | ||
# "hides" .profile (bash won't load a .profile file if it sees a | ||
# .bash_profile file instead). | ||
|
||
if [ -s ~/.bash_profile.khan ]; then | ||
source ~/.bash_profile.khan | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
################################################################################ | ||
# Local .profile. | ||
# Feel free to add whatever you like after the profile.khan' line. | ||
|
||
if [ -s ~/.profile.khan ]; then | ||
. ~/.profile.khan | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters