0

Granted they’re generally invisible files, but it’s like every application wants to store a million configuration files in my home directory. I like to keep my home directory neat and tidy. Ideally I’d like to make a folder called bash and store all the bash, shell, etc files in there. Like every app leaves a trail of one line files in my nice, clean home directory.

This is my working directory:

Where I want it to look like this with a nice, neat little folder for the shell to do whatever it wants.

Anyway... sorry if I sound pissy but I just got a new MacBook and I literally had to spend 40 minutes playing 52-pick-up in my home directory with all the files terminal apps left everywhere.

I’m actually surprised Apple allows this. It just let’s the shall spill it’s crap all over the nice, neat home directory. I wish Apple would make it so you need a password to even create a directory there.

  • My Desktop is clean, my home directory isn’t. This is what my home directory ~ looks like: imgur.com/a/FfSpalV I would like my Home Directory to remain like my Desktop. I labeled the folders “JUNK” because i’m reinstalling everything and i want to make sure nothing breaks before i delete that crap. – Chris May 24 '18 at 0:22
  • Please go into terminal, type the following command: ls -la $HOME | pbcopy the paste it into the original question by editing it. – Allan May 24 '18 at 0:26
  • I would suggest you get rid of the entire thing about the desktop, and just ask about the bash question in the title. Its a good question. – JBis May 24 '18 at 0:29
  • 2
    Why not just hide invisible files? The Mac idiom is for graphical users to look at documents or desktop and not the root home folder as well as let hidden files be hidden. – bmike May 24 '18 at 2:58
7

Is there any way to change the directory bash works out of.....

This is a misunderstanding of what Bash is. Bash is a Unix shell that's a command line interface to the operating system.

It doesn't "work out" of your Home folder. When you start a non-login, interactive shell, it starts you out in your HOME folder as a matter of convenience.

For simplicity sake, Bash is just a "portal" (Terminal window) into the operating system; nothing more.

...so as not to junk up my Home folder?

Your HOME folder is becoming "junked up" because whatever you're installing is using the default location $HOME for it's support files.

Just looking at a sample of the files/folders, things like JUNK, New Folder with Items, doc, core, layers, news, etc. are either files created by applications sourced from somewhere other than the App Store or created by the user.

...but it’s like every application wants to store a million configuration files in my home directory.

Apps usually store their files in ~/Library or more granular, in ~/Library/Application Support (this is the Library directory in the individual user's HOME directory). There are exceptions...iCloud, and Adobe Create Cloud store files in the HOME directory. I personally put my VirtualBox VM's in my HOME directory instead of my ~/Documents directory.

I’m actually surprised Apple allows this.

Thank goodness they do! I wouldn't welcome any OS that restricts me from modifying MY home directory the way I want it to.

That said, it's important to note that this is not an "Apple thing." This is a BSD and more generally a Unix thing. Your HOME directory is a predefined variable in the OS and many applications and scripts use this directory to store it's files.

As stated before, App Store apps (the ones with oversight by Apple) conform to a standard place for their support files. Things you download from Github...well, you're at their mercy.

...Where I want it to look like this with a nice, neat little folder for the shell to do whatever it wants.

You could do this, but bear in mind that the app you installed will be looking for it's support files in directory defined by the environment variable HOME. Move those files somewhere else and you could break the app.

To make this work, you would have to let the app know (by modifying it) that it's files are located in $HOME/bash.

TL;DR

You're expecting HOME to be a pristine place that doesn't get touched; that's an ill conceived expectation. Use the HOME directory for what it's designed for - a user support directory and focus on keeping ~/Documents, ~/Downloads, ~/Music, nice and clean.

  • Okay, I’ve used other environments, so yea, I know how the *NIX systems work. Bash works out of a directory. imgur.com/nElZZQ9 The directory it just so happens to work out of is ‘Macintosh HD’ /Users/chrisvaccaro` (Macintosh HD wouldn’t be labeled, although it is on Windows systems, making it C:/Users/chrisvaccaro/) So the “Home directory” is where the ~ tilde points. On macOS it’s just /Users/usernamehere. If I had a wife her Home Directory might be /Users/stephanie, and when she typed cd ~ that’s where it would go. – Chris May 24 '18 at 2:04
  • I mean i guess I get what you’re saying, but bash relies a lot of RELATIVE directories. Sure you can change the working directory, but ~ will always be home base. – Chris May 24 '18 at 2:08
  • “Thank goodness they do! I wouldn't welcome” macOS is the most locked down system on the planet, which is what makes it so incredible stable and awesome. Look up Apple's “System Integrity” system. Go trying to edit files in /usr/ or /var/. Apple locks down a LOT of stuff, But the folders named “JUNK” or “New Folder with Items” are ones I created or edited. Like when you edit a file “and save it as whatever.orig. I just didn’t wanna delete in case i needed it. I will in a few days. And when i say “Apps” I mean $bash apps that I’ve installed. Nvim, homebrew. Mac apps, I just use AppCleaner. – Chris May 24 '18 at 2:12
  • 1
    macOS is far from locked down. What you are experiencing is the different way macOS and Unix applications handle config files etc. macOS installs in ~/Library, Unix applications install in ~. Now files/folders starting with a dot aren't showing up in Finder usually anyway, and other directories I only need from Terminal I tend to hide with chflags hidden DIR. – nohillside May 24 '18 at 10:04
  • 3
    @Chris - No, no, and no; to each of your comments, in that order. I'm not saying it to be combative, but your understanding of Bash is very much incorrect. It's advisable that you review the FreeBSD manual (macOS uses a lot of BSD in it) as it gives a good foundation to how *nix systems work. I also recommend this book on Unix Administration – Allan May 24 '18 at 11:56
0

The short answer to your question is you cannot and the long answer is sort of. Let's lay some ground work. When you log on to your computer the loginwindow.app set up a basic environment setting HOME, PATH, TMPDIR, LOGNAME and USER.

The Terminal.app is a terminal emulator, in other words software that emulates a physical terminal. The environment variables set by the loginwindow.app are available to the Terminal.app. The Terminal.app then calls login which checks that HOME, PATH, LOGNAME and USER are set. Then starts the shell as a login shell reading the appropriate start up files. Up to this point HOME is static, set by the loginwindow.app, but within a terminal session the value of HOME can be changed.

Now, copy your .bash_profile and .bashrc (or whatever shell config files you have) to /Users/chrisvaccaro/bash. Now, issue the following command:

HOME=/Users/chrisvaccaro/bash; export HOME; exec bash -l

From this point on bash_history will be written inside /Users/chrisvaccaro/bash along with any typical "unix" dot file. The initial terminal session will still leave some "junk" in the original HOME directory.

This is way too complicated and subject to breaking.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .