Skip to content
Karl N. Redman edited this page Jun 6, 2018 · 4 revisions

Welcome to the dirp wiki!

Primary Topics of interest

Using in tmux/screen/terminals

  • Same system terminals of all types should work out of the box.
  • The expected behavior is as follows:
    • Upon first use, (dirpl, and other commands) dirp will load the most recent project in all new terminals.
    • If a current project does not exist when a dirp command is first executed then a prompt to select a project will be provided.

Using the same project directory lists across machines

Basically this is up to the user to implement.

  • You need these three things:
    • Duplicate (or similar "enough") directory structures.
    • shared ssh keys between the systems
    • some method of copying the dirlists (by default) directory
    • optionally: a script to do the copy

My method for synchronizing dirp between systems:

I use git as a personal preference for synchronizing my dirlists directory from a centralized, bare, repository. This way all systems are performing 'pull' requests to synchronize rather than push -and I have a history for backups and such. You can easily substitute rsync or scp for git here.

  • Things to keep in mind about my various systems:
    • directory structures are very similar.
    • my ssh public keys are distributed between systems on a trusted network (obviously no password).
    • my backup system is plugged into my consistent directory structures.
    • my repository update scripts are plugged into my consistent directory structures.
    • I use the same update scripts and dot files (under Linked_files) on all/most systems.
    • My working repos very rarely have changes (other than dirlists content).

TL;DR:

  • On each machine I have a cron job that pulls, checks-in, and pushes my dirlists directory every hour from/to my bare repo (Linked_files.git).
  • Each machine has a working clone of my bare repos.
  • Each machine offsets the crontab time with slightly different times.
  • if I'm ssh-ing into a system and feel that I need to update my repos (i.e. dirlists) I merely run update_repos.sh on that system before working on it.
  • Sometimes I run the update_repos.sh script remotely via ssh (i.e ssh karl@othermachine ~/mbin/update_repos.sh)
  • I use encryption heavily on/between systems so there are details that I'm not telling you here.

Details:

  • My directory structure looks like this:
/home/karl
├── .bash_profile
├── .bashrc                                             # sources ~/.my_bashrc
├── .my_bashrc -> Repositories/Linked_Files/my_bashrc
├── .profile
├── .ssh
├── dirlists -> Repositories/Linked_Files/dirlists
├── Documents
│   ├── Persistent_Data                                 # my backup directory
│   │   └── Repositories.bare                           # my bare repos
│   │       ├── Linked_Files.git                        # where I keep my dot files
│   │       │   ├── dirlists
│   │       │   └── my_bashrc
│   │       │
│   │       └── mbin.git                                # where I keep my scripts
│   │           └── update_repos.sh                     # my automated repo update script
│   ├── Repositories                                    # my working reops
│   │   ├── Linked_Files
│   │   │   ├── dirlists
│   │   │   └── my_bashrc                               # sources $HOME/Projects/github/dirp/dirp.bash
│   │   └── mbin
│   │       └── update_repos.sh
├── mbin -> Repositories/mbin                           # linked for convenience and set in my $PATH
├── Projects                                            # working project directories
│   └── github
│       ├── dirp
│       │   ├── CONTRIBUTING.md
│       │   ├── dirp.bash
│       │   ├── docs
│       │   ├── LICENSE
│       │   └── README.md
│       └── dirp.wiki
│           ├── Feature_Examples.md
│           ├── Home.md
│           └── _Sidebar.md
└── Repositories -> Documents/Repositories              # linked for convenience
  • dirp is installed and running on both systems
  • my update_repos.sh script looks like this:
#!/bin/bash

# TODO: (????)
# options:
# -k: 'press any key' before script exit
# -r <name@server>: run command on remote system (must already exist)
# -p <path>: remote script path

# anything as a parameter triggers the 'press any key'
## for use with running from desktop temporary terminal
KeyExit=false
if [[ $# -gt 0 ]]; then
    # provides a 'press any key' at program end
    KeyExit=true
fi


# repository toplevel dir
REPO="$HOME/Documents/Repositories"

# get list of repos to traverse
DIRLIST=()

# list of dirs that error
ERRLIST=()

while IFS= read -r -d $'\0';
do
	DIRLIST+=("$REPLY")
done< <(find "$REPO" -follow -maxdepth 1 -type d -print0)

function command () {
	ret=$($@)

    local status=$?
    if [ $status -ne 0 ]; then
		if [[ $ret = *'nothing to commit'* ]] || [[ $ret = *'Changes not staged'* ]]
		then
			status=0
		else
			echo "Error with: $@"
		fi
    fi
    return $status
}

function runcommand () {
	command $1

	if [ $? -ne 0 ]; then
		ERRLIST+=("$2: $1")
	fi
}

# ---------------------- main -------------------
PROMPT_COMMAND='echo -ne "\033]0;Updating Repositories\007"'
ORIG=$PS1
TITLE="\e]2;\"Updating Repositories\"\a"
PS1=${ORIG}${TITLE}

for d in "${DIRLIST[@]}";
do
	if [ $d == "$REPO" ]; then
		continue;
	fi

	echo "Processing: $d"

	pushd $d >/dev/null 2<&1
	runcommand "git pull" $d
	runcommand "git add -A" $d
	runcommand 'git commit -m "update"' $d
	runcommand "git push" $d
	popd >/dev/null 2<&1
	echo
done

echo
echo "---------------------------"
if [ ${#ERRLIST[@]} -ne 0 ]; then
	echo "Errors Found:"
	for d in "${ERRLIST[@]}";
	do
		echo $d
	done
else
	echo "No Errors."
fi


# end program
if [[ $KeyExit = "true" ]]; then
    echo
    echo "done."
    read -n 1 -s -r -p "Press any key to continue..."
    echo
fi
  • my crontab has an entry that looks like this:
# once every hour at xx:00
0 * * * * $HOME/mbin/update_repos.sh