Tag Info

New answers tagged

0

Solved by the following: Placed a guard around my PATH manipulation code in .profile if [ "$PATHS" != "true" ]; then export PATHS="true" #Manipulate and export PATH over here fi Removed file-level guards around .bash_profile and .bashrc IMPORTANT: RESTARTED the tmux server. (killall tmux) -- the manual indicates the server maintains its ...


1

It's as simple as shopt -s autocd 2>/dev/null If you want to see whether an option is available but not change its value, call shopt without -s or -u: if shopt autocd >/dev/null 2>/dev/null; then …


3

autocd was introduced into bash with version 4. So, a general cross-platform solution should be: [ "${BASH_VERSINFO[0]}" -ge 4 ] && shopt -s autocd ${BASH_VERSINFO[0]} is bash's major version. The minor version, should you ever need it, is ${BASH_VERSINFO[1]}. See man bash for more on BASH_VERSINFO.


0

A simple approach would be to check the OS name and act accordingly. I don't know what uname will return on OSX but presumably it will be different. You can therefore do something like this: [[ $(uname) = Linux ]] && shopt -s autocd That said, are you sure you need to do this? OSX runs login shells by default and the ~/.bashrc is ignored unless ...


0

I use the parse_git_branch function myself and I've found the following works well and gives me lots of info (and a carriage return!): parse_git_branch () { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' } PS1='\033[01;31m\]\t\033[00m\]:' PS1=$PS1'\[\033[01;32m\]\u@\h\[\033[00m\]:' ...


0

This is a perfect use-case for ${parameter+substitution} since we're talking about parameters after all. _src_release() { . ${RELEASE:=/path/to/fallback} } <<GET_RELEASE ${PREFERRED="$(whatever gets you /path/to/preferred)"} ${NEXT_BEST="$(something else gets you /path/to/next/best)"} ${IF_YOU_MUST="$(get ...


1

Using the lsb_release command (should be in most distros by default): shopt -s nocasematch if [ -x "$(which lsb_release)" ]; then case "$(lsb_release -si)" in *centos*) case "$(lsb_release -sr)" in 5.7*) source ~/.bashrc.centos5.7 ;; 5*) # source something for any other version 5 minor release ...


2

I realize you mentioned not to edit .bashrc. However, I hope this might help someone else. I have been looking for a good answer to a similar problem for many years. I like to use vi but don't want to change the default for everyone else. Edit /etc/ssh/ssh_config in your local configuration and add the following line: SendEnv EDITOR You can use any ...


6

No, there isn't. Yes, this is a design defect. Use the following content in ~/.bash_profile: if [ -e ~/.profile ]; then . ~/.profile; fi if [[ -e ~/.bashrc && $- = *i* ]]; then . ~/.bashrc; fi Beware that bash has an even weirder quirk: when it is a non-interactive login shell and the parent process is rshd or sshd, bash sources ~/.bashrc (but ...


-1

There are several files that run when you login to your shell including ~/.bash_profile and possibly ~/.bashrc and ~/.bash_aliases if those are referenced in your ~/.bash_profile file. To have an alias available every time you login, just put the command that creates the alias in one of those files. ...


2

Here is my workaround, the function palias (aka permanent alias): function palias () { if [ $# -ne "2" ] ; then error "Usage: palias short-alias \"long-alias\"" return fi alias $1="$2" echo -e "alias $1='$2'" >> ~/.bash_aliases }


3

The Arch Wiki has some example aliases and generic commands that will work in the majority of .bashrc files providing you are using systemd and have sudo installed. This highlights the problem with the approach you are seeking, and one of the undesirable side effects of copying and pasting someone else's idea of a standard configuration into your shell 's ...


1

I think it's not a property of bash (or zsh, csh... and other shell). It's property of terminal which showed the output. You can use expand command to convert tab to number of spaces. From expand man page: -t, --tabs=NUMBER have tabs NUMBER characters apart, not 8 So you will do like this: $ cat test.tabs a b c $ expand -t 4 ...


2

from man less: -xn,... or --tabs=n,... Sets tab stops. If only one n is specified, tab stops are set at multiples of n. If multiple values separated by commas are specified, tab stops are set at those positions, and then continue with the same spacing as the last two. For example, -x9,17 will set tabs at ...


0

Not a direct answer to your question, but I have wrapper scripts to handle things like this rather than extra complication in the .bashrc For example here is my l script that handles your case here in a cross platform way: http://www.pixelbeat.org/scripts/l


3

Littering the code with if statements to perform a switch on the type of coreutils does work, however the clean programming solution for handling different types is to use polymorphism. Since this is Bash, we don't have polymorphism per se, but I've been messing around with a way to fake it. The only requirement is that your .bashrc file etc. be organized ...



Top 50 recent answers are included