3

Every time I open a new shell window, I'm brought to my home directory rather than the current directory I was in when I gave the command to open a new Terminal.app window. I am under the impression that each new shell instance is a login shell on macOS, in case this is any help. I've made some recent .bashrc changes, but nothing I can tell should influence this. I've also added an .inputrc (readline rc file). All of the new configuration I've added I found from solid resources online. In any case, here are the new configs I've added to my .bashrc:

## BETTER BASH HISTORY
# tells readline to perform filename completion case-insensitively
#bind "set completion-ignore-case on"
# filename matching during completion will treat hyphens and underscores as equivalent; 
#+ requires completion-ignore-case on
#bind "set completion-map-case on"
# readline will display all possible matches for an ambiguous pattern at first 
#+ <tab> instead of 2x
#bind "set show-all-if-ambiguous on"
# Append to the history file, don't overwrite it
shopt -s histappend
# Save multi-line commands as one command
shopt -s cmdhist
# Record each line as it gets issued (aka "parallel history"?)
PROMPT_COMMAND='history -a'
# Yuge history. Doesn't appear to slow things down, so why not?
HISTSIZE=500000
HISTFILESIZE=100000
# Avoid duplicate entries
HISTCONTROL="erasedups:ignoreboth"
# Don't record some commands
export HISTIGNORE="&:[  ]*:exit:ls:history:cd:pwd"
# Useful timestamp format
HISTTIMEFORMAT='%F %T '
#
## Better, faster directory navigation
# don't need to type cd, just path to cd; works for .., but not -
#shopt -s autocd    # invalid shell option name
# dirspell and cdspell get bash to autocorrect minor spelling mistakes:
# the former during tab completion, the latter in arguments already supplied to cd
#shopt -s dirspell   # invalid shell option name
shopt -s cdspell
#
# by default, cd will look in the curdir for possible targets you might want to move into.
# this behavior is defined by the environment variable CDPATH="." by default.
# add more paths to this variable by separating them with a colon.
#
# native "jump" to directory from anywhere: we can define and export variables
# containing paths to our most important directories and cd into them
shopt -s cdable_vars

Additionally, here is the inputrc file I'm using from the source: https://github.com/mrzool/dotfiles/blob/master/readline/.inputrc

# set editing-mode vi
# set keymap vi
set bell-style none

$if mode=vi
    set keymap vi-command
    "gg": beginning-of-history
    "G": end-of-history
    set keymap vi-insert
    "jj": vi-movement-mode
    "\C-w": backward-kill-word
    "\C-p": history-search-backward
$endif

# Use the text that has already been typed as the prefix for searching through
# commands (i.e. more intelligent Up/Down behavior)
"\e[A": history-search-backward
"\e[B": history-search-forward

# Completion tweaks
set completion-ignore-case on
set completion-map-case on
set show-all-if-ambiguous on
set mark-symlinked-directories on
set match-hidden-files on
# set visible-stats on
set skip-completed-text on
set colored-stats on

# Allow UTF-8 input and output
set input-meta on
set output-meta on
set convert-meta off

# Bash-specific mappings and settings
$if Bash
  Space: magic-space
  \C-w: backward-kill-word
$endif
  • 2
    I have to imagine this is an Ask Different question more so than here, though it's borderline. There's nothing in your .bashrc that changes the directory. – Michael Homer Mar 29 '17 at 8:15
  • I disagree. It's a Unix and bash question. The OS should be irrelevant, I only mentioned it to be (a little) diligent. It's an issue that only came about, presumably, because I was messing about with new options; I noticed this behavior the following day. – GH05T Mar 29 '17 at 12:41
  • 1
    How do you start the terminal? Unless you have something weird in your bash configuration (.bash_profile or .profile, the files you posted are not relevant here), the terminal emulator is the culprit, not bash. – Gilles Mar 29 '17 at 21:59
  • The only thing in .bash_profile is a check for .bashrc, and to source it if it exists. – GH05T Mar 31 '17 at 5:07
  • Since you have posted an answer, and mentioned the lines to commented out in it, there's no reason to edit the question in this way to single out those lines. – muru Apr 3 '17 at 9:39
0

Remove/comment out these lines:

PROMPT_COMMAND='history -a'

HISTCONTROL="erasedups:ignoreboth"

export HISTIGNORE="&:[ ]*:exit:ls:history:cd:pwd"

Commenting out the above lines seems to have solved the problem. I suspect that the application or the shell determines where you previously were by parsing the latest cd in history.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.