(Emacs+Bash) bash: update_terminal_cwd: command not found resolution

When you run Bash under shell in Emacs on macOS then update_terminal_cwd is never defined and after every command you get the error message bash: update_terminal_cwd: command not found making the shell unusable.

The simplest solution is to define update_terminal_cwd when it isn’t defined.

Here is the code:

if [ -z "$(type -t update_terminal_cwd)" ] || [ "$(type -t update_terminal_cwd)" != "function" ]; then
  update_terminal_cwd() {
    true
  }
fi

Fix For When Bash Can’t Find Its Debugger On macOS

Sometimes Bash needs its debugger but it can’t find it. It looks like this:

/usr/share/bashdb/bashdb-main.inc: No such file or directory
-bash: warning: cannot start debugger

For example when you start bashdb yourself with bash --debugger or set shopt -s extdebug. Another example is when your terminal turns it on.

Here is the fix that worked on my box:

brew install bashdb
bashhome=$(brew --prefix bash)
bdbhome=$(brew --prefix bashdb)
ln -s $bdbhome/share/bashdb $bashhome/share/bashdb
unset bashhome
unset bdbhome

Easily Allowing and Forbidding Distractions on OS X macOS

Facebook and Instagram are better than television and like any good thing it is nice to have a break. Real televisions have an on/off switch but computers don’t really. Technical folks: here is one way to make it easy to give your OS X macOS box an on/off switch for your social sites:

#!/usr/bin/env bash
# -*- mode: sh; -*-

if [ $# -eq 0 ]; then
    sudo cp /etc/hosts.distractions /etc/hosts
    printf "...forbidding distractions.\n"
else
    sudo cp /etc/hosts.org /etc/hosts
    printf "...allowing distractions.\n"
fi

Update OSX 10.9 to use bash4

Source.

Script started on Sat Jun 21 12:25:07 2014
ESC[~> echo $BASH_VERSION
3.2.51(1)-release
gcr@orion:~> which bash
/bin/bash
gcr@orion:~> brew info bash
bash: stable 4.3.18, HEAD
http://www.gnu.org/software/bash/
Not installed
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/bash.rb
ESC[1;34m==>ESC[1;39m DependenciesESC[0m
Required: ESC[1;32mreadlineESC[0m
ESC[1;34m==>ESC[1;39m CaveatsESC[0m
In order to use this build of bash as your login shell,
it must be added to /etc/shells.
gcr@orion:~> brew install bash
[1;34m==>ESC[1;39m PatchingESC[0m
patching file arrayfunc.c
patching file bashline.c
patching file externs.h
patching file jobs.c
patching file lib/glob/glob.c
patching file lib/glob/gmisc.c
patching file lib/readline/display.c
patching file lib/readline/readline.c
patching file lib/sh/shquote.c
patching file parse.y
patching file patchlevel.h
patching file pcomplete.c
patching file subst.c
patching file test.c
patching file trap.c
patching file variables.c
patching file y.tab.c
ESC[1;34m==>ESC[1;39m ./configure --prefix=/usr/local/Cellar/bash/4.3.18 --with-installed-readlineESC[0m
ESC[1;34m==>ESC[1;39m make installESC[0m
ESC[1;34m==>ESC[1;39m CaveatsESC[0m
In order to use this build of bash as your login shell,
it must be added to /etc/shells.
ESC[1;34m==>ESC[1;39m SummaryESC[0m
/usr/local/Cellar/bash/4.3.18: 59 files, 7.4M, built in 41 seconds
gcr@orion:~> /usr/local/bin/bash --versinESCESC[Kon
GNU bash, version 4.3.18(1)-release (x86_64-apple-darwin13.2.0)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
gcr@orion:~> sudo echo "/usr/local/bin/bashbug" >> /etc/shells
bash: /etc/shells: Permission denied
gcr@orion:~> sudo vi /etc/shells
Password:
ESC[?1049hESC[?1hESC=ESC[1;25rESC[?12;25hESC[?12lESC[?25hESC[27mESC[mESC[HESC[2JESC[?25lESC[25;1H"/etc/shells" 10L, 179CESC[>cESC[1;1H# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
gcr@orion:~> chsh

Then login again

gcr@orion:~> which bash
/usr/local/bin/bash
gcr@orion:~> echo $BASH-VESCESC[KESCESC[K_VERSION
4.3.18(1)-release
gcr@orion:~> bash --version
GNU bash, version 4.3.18(1)-release (x86_64-apple-darwin13.2.0)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
gcr@orion:~> exit