mirror of https://github.com/nirenjan/dotfiles.git
Move scripts to submodule
parent
1afa6ba95b
commit
9f75a8b596
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "scripts"]
|
||||||
|
path = scripts
|
||||||
|
url = git@github.com:nirenjan/scripts
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 6e000ca76d644e455dba0ecb30b2053bbad8c1f1
|
|
@ -1,27 +0,0 @@
|
||||||
#!/usr/bin/env perl
|
|
||||||
# Script to apply git configuration to global gitconfig
|
|
||||||
|
|
||||||
my $section = 'unknown';
|
|
||||||
my $variable;
|
|
||||||
my $value;
|
|
||||||
my $command;
|
|
||||||
|
|
||||||
while(<>) {
|
|
||||||
chomp;
|
|
||||||
if (m/^\[(\w+)\]$/) {
|
|
||||||
$section = $1;
|
|
||||||
#print "Section: $section\n";
|
|
||||||
} elsif (m/^\[(\w+) +"(\w+)"\]/) {
|
|
||||||
$section = "$1.$2";
|
|
||||||
#print "Section: $section\n";
|
|
||||||
} elsif (m/(\w+) += +(.+)$/) {
|
|
||||||
$variable = $1;
|
|
||||||
$value = $2;
|
|
||||||
|
|
||||||
$value =~ s/"/\\"/g;
|
|
||||||
#print "\t$section.$variable = \"$value\"\n";
|
|
||||||
$command = "git config --global $section.$variable \"$value\"";
|
|
||||||
print "$command\n";
|
|
||||||
system($command);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
if [[ $# -gt 0 ]]
|
|
||||||
then
|
|
||||||
eval "$@"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -e "\007"
|
|
195
scripts/deploy
195
scripts/deploy
|
@ -1,195 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
# Script to copy files from a Git repository to a destination
|
|
||||||
# Reads deployment instructions from a file and acts accordingly
|
|
||||||
#
|
|
||||||
# File Format
|
|
||||||
# ===========
|
|
||||||
#
|
|
||||||
# Comments begin with a # character and terminate at the end of the line.
|
|
||||||
#
|
|
||||||
# The keyword 'repo' specifies the path to the repository. The repository must
|
|
||||||
# be accessible locally without having to resort to ssh, https or git protocols.
|
|
||||||
# Usage: repo <path to repo>
|
|
||||||
#
|
|
||||||
# The keyword 'target' specifies the location to which to deploy. If omitted, it
|
|
||||||
# defaults to the current folder. Folders can be specified relative to the
|
|
||||||
# current folder, relative to the home directory, or relative to the root, using
|
|
||||||
# ./ or ../, ~/ and / as prefixes respectively. The parameter must be a valid
|
|
||||||
# directory.
|
|
||||||
# Usage: target <path to install to>
|
|
||||||
#
|
|
||||||
# The keyword 'file' specifies the file location relative to the root of the
|
|
||||||
# Git repository, along with the version to install and an optional rename
|
|
||||||
# argument which allows you to rename the destination file. If the version is
|
|
||||||
# omitted, it defaults to HEAD. If the rename-to parameter is omitted, the
|
|
||||||
# filename is the same as the name within the repository.
|
|
||||||
# Usage: file <path to file within repo> [version [rename-to]]
|
|
||||||
|
|
||||||
# Default environment variables used
|
|
||||||
DEPLOY_GIT=''
|
|
||||||
DEPLOY_TGT=$(pwd)
|
|
||||||
DEPLOY_SRC=''
|
|
||||||
DEPLOY_LST=''
|
|
||||||
DEPLOY_DEBUG=false
|
|
||||||
|
|
||||||
# Usage function will display the usage
|
|
||||||
usage()
|
|
||||||
{
|
|
||||||
local deploy=$(basename $0)
|
|
||||||
echo "Usage: $deploy <deploy-file1> <deploy-file2> ..."
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
# Die function will print the error message to stderr and abort the script
|
|
||||||
die()
|
|
||||||
{
|
|
||||||
local exit_code=$1
|
|
||||||
local deploy=$(basename $0)
|
|
||||||
shift
|
|
||||||
|
|
||||||
for msg in "$@"
|
|
||||||
do
|
|
||||||
echo -e "$deploy: $msg" >&2
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ $exit_code != 128 && $exit_code != 0 ]]
|
|
||||||
then
|
|
||||||
echo -e "\tError in file $DEPLOY_SRC line ${BASH_LINENO[1]}" >&2
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit $exit_code
|
|
||||||
}
|
|
||||||
|
|
||||||
# Debug function will display all data, but only if debugs are enabled
|
|
||||||
debug()
|
|
||||||
{
|
|
||||||
$DEPLOY_DEBUG && echo "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Repo function checks if it is a valid Git repo and sets the DEPLOY_GIT
|
|
||||||
repo()
|
|
||||||
{
|
|
||||||
if [[ $# != 1 ]]
|
|
||||||
then
|
|
||||||
die 4 "Invalid usage of repo command" "Usage: repo <path to Git repo>"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -d "$1" ]]
|
|
||||||
then
|
|
||||||
cd "$1"
|
|
||||||
local gtl=$(git rev-parse --show-toplevel 2>/dev/null)
|
|
||||||
|
|
||||||
if [[ -z $gtl ]]
|
|
||||||
then
|
|
||||||
die 3 "Path $1 is not a valid Git repository!"
|
|
||||||
else
|
|
||||||
debug "Using repository $gtl"
|
|
||||||
DEPLOY_GIT="$gtl"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
die 1 "Path $1 does not exist!"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Target function checks if it is a valid directory and sets the DEPLOY_TGT
|
|
||||||
target()
|
|
||||||
{
|
|
||||||
if [[ $# != 1 ]]
|
|
||||||
then
|
|
||||||
die 4 "Invalid usage of target command" "Usage: target <path>"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -d "$1" ]]
|
|
||||||
then
|
|
||||||
debug "Target folder $1"
|
|
||||||
DEPLOY_TGT="$1"
|
|
||||||
else
|
|
||||||
die 1 "Path $1 does not exist!"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# File command selects a file to deploy
|
|
||||||
file()
|
|
||||||
{
|
|
||||||
if [[ $# == 0 || $# > 3 ]]
|
|
||||||
then
|
|
||||||
die 4 "Invalid usage of file command" \
|
|
||||||
"Usage: file <path from root of repo> [<version> [<rename-to>] ]"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -z $DEPLOY_GIT ]]
|
|
||||||
then
|
|
||||||
die 2 "Must specify repo before file!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -z $DEPLOY_TGT ]]
|
|
||||||
then
|
|
||||||
die 2 "Must specify target before file!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
local file=$1
|
|
||||||
local ver=$2
|
|
||||||
local rename=$3
|
|
||||||
|
|
||||||
debug "file $@"
|
|
||||||
|
|
||||||
# Sanity check on ver
|
|
||||||
[[ -z $ver ]] && ver=HEAD
|
|
||||||
|
|
||||||
# Sanity check on rename
|
|
||||||
[[ -z $rename ]] && rename=$(basename $file)
|
|
||||||
|
|
||||||
cd $DEPLOY_GIT
|
|
||||||
|
|
||||||
# Check to make sure that version is a sane version
|
|
||||||
git rev-parse $ver &>/dev/null
|
|
||||||
|
|
||||||
if [[ $? != 0 ]]
|
|
||||||
then
|
|
||||||
die 3 "Version $ver does not exist in the repository $DEPLOY_GIT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
local vercheck=$(git rev-parse $ver 2>/dev/null)
|
|
||||||
debug "Using version $vercheck"
|
|
||||||
|
|
||||||
# Check to make sure that the file is valid in the specified version
|
|
||||||
git show $vercheck:$file &>/dev/null
|
|
||||||
|
|
||||||
if [[ $? != 0 ]]
|
|
||||||
then
|
|
||||||
die 3 "File $file does not exist in version $ver of the repo $DEPLOY_GIT"
|
|
||||||
else
|
|
||||||
debug "Using file $file"
|
|
||||||
# Build the commands to extract the file and set the
|
|
||||||
# executable permissions bit in the deployed file.
|
|
||||||
local cmd="cd $DEPLOY_GIT"
|
|
||||||
cmd="$cmd; git show $vercheck:$file > $DEPLOY_TGT/$rename"
|
|
||||||
cmd="$cmd; chmod +x $DEPLOY_TGT/$rename;"
|
|
||||||
DEPLOY_LST="$DEPLOY_LST $cmd"
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ $# == 0 ]]
|
|
||||||
then
|
|
||||||
usage
|
|
||||||
else
|
|
||||||
for i in "$@"
|
|
||||||
do
|
|
||||||
if [[ -f $i && -r $i ]]
|
|
||||||
then
|
|
||||||
DEPLOY_SRC=$i
|
|
||||||
source $i
|
|
||||||
else
|
|
||||||
die 128 "Deploy file $i does not exist or is not readable!"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -z $DEPLOY_LST ]]
|
|
||||||
then
|
|
||||||
eval $DEPLOY_LST
|
|
||||||
else
|
|
||||||
die 0 "No files to deploy!"
|
|
||||||
fi
|
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
#!/usr/bin/perl
|
|
||||||
# A utility script to test out dircolors settings without reloading
|
|
||||||
# Usage: dircolortest <dircolors file>
|
|
||||||
|
|
||||||
if ($#ARGV < 0) {
|
|
||||||
die "Usage: $0 <dircolors file>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($#ARGV > 0) {
|
|
||||||
warn "Ignoring additional command line arguments\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
# Open the file and get the handle
|
|
||||||
open DCFILE, $ARGV[0] or
|
|
||||||
die "Cannot open dircolors file $ARGV[0]! $!\n";
|
|
||||||
|
|
||||||
$line_counter = 0;
|
|
||||||
|
|
||||||
while ($line = <DCFILE>) {
|
|
||||||
chomp $line;
|
|
||||||
|
|
||||||
# Strip off any comments
|
|
||||||
$line =~ s/#.*$//;
|
|
||||||
|
|
||||||
# Strip off leading and trailing whitespace
|
|
||||||
$line =~ s/^\s*//;
|
|
||||||
$line =~ s/\s*$//;
|
|
||||||
|
|
||||||
if ($line ne '') {
|
|
||||||
($type, $format) = split /\s+/, $line;
|
|
||||||
|
|
||||||
# Ignore the following lines, we don't care about them here
|
|
||||||
next if (($type eq 'TERM') || ($type eq 'COLOR') ||
|
|
||||||
($type eq 'OPTIONS') || ($type eq 'EIGHTBIT'));
|
|
||||||
|
|
||||||
# Just a little enhancement, if the type begins with a .
|
|
||||||
if ($type =~ m/^\./) {
|
|
||||||
$type = "*$type";
|
|
||||||
}
|
|
||||||
|
|
||||||
print "\033[${format}m$type\033[m";
|
|
||||||
|
|
||||||
$line_counter = $line_counter + 1;
|
|
||||||
|
|
||||||
if ($line_counter == 8) {
|
|
||||||
print "\n";
|
|
||||||
$line_counter = 0;
|
|
||||||
} else {
|
|
||||||
print "\t";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
print "\n" if ($line_counter != 0);
|
|
||||||
|
|
||||||
close DCFILE;
|
|
|
@ -1,28 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Support script to find the commit from which the given branch was spawned.
|
|
||||||
# Takes one or two arguments, the first argument is mandatory and specifies
|
|
||||||
# the child branch while the second argument is optional and specifies the
|
|
||||||
# parent branch. If omitted, the parent branch defaults to 'master'
|
|
||||||
|
|
||||||
CHILD=$1
|
|
||||||
PARENT=$2
|
|
||||||
|
|
||||||
USAGE="Usage: $0 <child branch> <parent branch>"
|
|
||||||
|
|
||||||
if [ "$CHILD" == "" ]
|
|
||||||
then
|
|
||||||
echo $USAGE
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$PARENT" == "" ]
|
|
||||||
then
|
|
||||||
PARENT="master"
|
|
||||||
fi
|
|
||||||
|
|
||||||
PCOMMIT=`diff -u <(git rev-list --first-parent $CHILD) \
|
|
||||||
<(git rev-list --first-parent $PARENT) | sed -ne 's/^ //p' | head -1`
|
|
||||||
|
|
||||||
git show --pretty="%H %an | %s" $PCOMMIT | head -1
|
|
||||||
|
|
52
scripts/mlog
52
scripts/mlog
|
@ -1,52 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
# Monthly logging script
|
|
||||||
# Call mlog and it will update a log file
|
|
||||||
|
|
||||||
# Set the default mlog folder
|
|
||||||
[[ -z $MLOG_FOLDER ]] && MLOG_FOLDER="$HOME/mlog"
|
|
||||||
|
|
||||||
# Make sure that the folder exists
|
|
||||||
[[ ! -d $MLOG_FOLDER ]] && mkdir -pv $MLOG_FOLDER
|
|
||||||
|
|
||||||
# Make sure that we have a valid TMPDIR
|
|
||||||
[[ -z $TMPDIR ]] && TMPDIR='/tmp'
|
|
||||||
|
|
||||||
# Make sure that we have a valid EDITOR
|
|
||||||
[[ -z $EDITOR ]] && EDITOR=vim
|
|
||||||
|
|
||||||
MLOG_HDR=''
|
|
||||||
MLOG_TS="[$(date)]"
|
|
||||||
MLOG_LOG="$MLOG_FOLDER/$(date +%Y-%m)"
|
|
||||||
MLOG_FILE="$TMPDIR/mlog-tmp-$$"
|
|
||||||
|
|
||||||
if [[ -x $HOME/bin/stardate ]]
|
|
||||||
then
|
|
||||||
[[ -z $MLOG_RANK ]] && MLOG_RANK='Chief Engineer'
|
|
||||||
|
|
||||||
MLOG_HDR=`echo "$MLOG_RANK's log, Stardate $($HOME/bin/stardate)" | sed 's/.$//'`
|
|
||||||
|
|
||||||
if [[ -e $MLOG_LOG ]]
|
|
||||||
then
|
|
||||||
MLOG_LAST=$(grep Stardate $MLOG_LOG | tail -1)
|
|
||||||
|
|
||||||
if [[ "$MLOG_LAST" == "$MLOG_HDR" ]]
|
|
||||||
then
|
|
||||||
MLOG_HDR="$MLOG_RANK's log, supplemental"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
$EDITOR $MLOG_FILE
|
|
||||||
|
|
||||||
[[ ! -s $MLOG_FILE ]] && rm -f $MLOG_FILE && exit 0
|
|
||||||
|
|
||||||
|
|
||||||
echo "$MLOG_HDR" >> $MLOG_LOG
|
|
||||||
echo "$MLOG_TS" >> $MLOG_LOG
|
|
||||||
echo >> $MLOG_LOG # Empty line
|
|
||||||
cat $MLOG_FILE >> $MLOG_LOG
|
|
||||||
echo -en "\n----------------------------------------" >> $MLOG_LOG
|
|
||||||
echo -e "----------------------------------------\n" >> $MLOG_LOG
|
|
||||||
|
|
||||||
rm -f $MLOG_FILE
|
|
||||||
|
|
330
scripts/note
330
scripts/note
|
@ -1,330 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
# Notes manager for the command line
|
|
||||||
|
|
||||||
NOTES_VER="0.1a"
|
|
||||||
NOTES_DIR="$HOME/.notes"
|
|
||||||
|
|
||||||
# Initialize with the default editor
|
|
||||||
[ -z "$EDITOR" ] && EDITOR="/usr/bin/vim"
|
|
||||||
|
|
||||||
dprint() {
|
|
||||||
if [ ! -z $NOTES_DEBUG ]; then
|
|
||||||
echo $*
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
notes_init() {
|
|
||||||
# Check if the notes folder exists, if not, create it
|
|
||||||
if [ ! -d $NOTES_DIR ]
|
|
||||||
then
|
|
||||||
echo -n "Creating notes folder..."
|
|
||||||
mkdir -p $NOTES_DIR
|
|
||||||
cd $NOTES_DIR
|
|
||||||
echo "done."
|
|
||||||
|
|
||||||
git init .
|
|
||||||
else
|
|
||||||
echo "Notes has already been initialized."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
make_title() {
|
|
||||||
echo "$*" | sed 's/[^A-Za-z0-9_]\+/-/g' | \
|
|
||||||
sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'
|
|
||||||
}
|
|
||||||
|
|
||||||
title_to_name() {
|
|
||||||
note_file=$NOTES_DIR/$(make_title $note_arg)
|
|
||||||
}
|
|
||||||
|
|
||||||
check_arg() {
|
|
||||||
if [ -z "$note_arg" ]
|
|
||||||
then
|
|
||||||
echo "Must specify a note title!"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
note_exists() {
|
|
||||||
[[ -f "$note_file" ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
check_md5() {
|
|
||||||
if [[ "$note_old_md5" == "$note_new_md5" ]]
|
|
||||||
then
|
|
||||||
echo "No changes to '$note_arg'"
|
|
||||||
|
|
||||||
if [[ ! -z "$1" ]]
|
|
||||||
then
|
|
||||||
rm -f $1
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
check_empty() {
|
|
||||||
if [[ ! -s "$note_file" ]]
|
|
||||||
then
|
|
||||||
if [[ "$1" == "restore" ]]
|
|
||||||
then
|
|
||||||
cd "$NOTES_DIR"
|
|
||||||
gitfile=$(basename "$note_file")
|
|
||||||
git checkout $gitfile
|
|
||||||
echo "Restored empty note '$note_arg'"
|
|
||||||
elif [[ "$1" == "delete" ]]
|
|
||||||
then
|
|
||||||
rm -f $note_file
|
|
||||||
echo "Deleted empty note '$note_arg'"
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
check_dir() {
|
|
||||||
if [[ ! -d "$NOTES_DIR" ]]
|
|
||||||
then
|
|
||||||
echo "Notes not initialized. Run init first!"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
md5_sum() {
|
|
||||||
openssl dgst -md5 $*
|
|
||||||
}
|
|
||||||
|
|
||||||
help_cmd() {
|
|
||||||
echo '
|
|
||||||
Notes Manager for the Command Line
|
|
||||||
==================================
|
|
||||||
|
|
||||||
This is a bash script that lets you take notes which are maintained in a
|
|
||||||
Git repository. You can run this script by typing the following command
|
|
||||||
at the command line:
|
|
||||||
|
|
||||||
Usage: note <command> <arguments>
|
|
||||||
|
|
||||||
Commands
|
|
||||||
--------
|
|
||||||
You can use the first letter of each command as a shortcut key.
|
|
||||||
|
|
||||||
Command Usage
|
|
||||||
------- -----
|
|
||||||
new Follow this with the note name to create a new note
|
|
||||||
edit Follow this with the note name to edit an existing note
|
|
||||||
show Follow this with the note name to display an existing note
|
|
||||||
delete Follow this with the note name to delete a note
|
|
||||||
find Prints the list of available notes
|
|
||||||
log Displays the note history
|
|
||||||
grep Finds all notes with the specified keyword in the text
|
|
||||||
init Run this the very first time to set up the folders
|
|
||||||
help Prints this help message
|
|
||||||
version Prints the version information
|
|
||||||
'
|
|
||||||
}
|
|
||||||
|
|
||||||
version_info() {
|
|
||||||
echo "Notes Manager version $NOTES_VER"
|
|
||||||
}
|
|
||||||
|
|
||||||
note_new() {
|
|
||||||
check_dir
|
|
||||||
check_arg
|
|
||||||
title_to_name
|
|
||||||
|
|
||||||
if note_exists
|
|
||||||
then
|
|
||||||
echo "Note '$note_arg' already exists! Use edit instead."
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$note_arg" > $note_file
|
|
||||||
note_old_md5=$(md5_sum $note_file)
|
|
||||||
|
|
||||||
$EDITOR $note_file
|
|
||||||
|
|
||||||
note_new_title=$(head -1 $note_file)
|
|
||||||
note_new_md5=$(md5_sum $note_file)
|
|
||||||
note_new_file=$NOTES_DIR/$(make_title $note_new_title)
|
|
||||||
check_md5 $note_file
|
|
||||||
check_empty delete
|
|
||||||
|
|
||||||
dprint "Original filename = " $note_file
|
|
||||||
dprint "New filename = " $note_new_file
|
|
||||||
|
|
||||||
# Check for a title rename
|
|
||||||
if [[ "$note_file" != "$note_new_file" ]]
|
|
||||||
then
|
|
||||||
mv -f $note_file $note_new_file
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd $NOTES_DIR
|
|
||||||
gitfile=$(basename $note_new_file)
|
|
||||||
|
|
||||||
git add $gitfile
|
|
||||||
git commit -m "Create note '$note_new_title'"
|
|
||||||
echo "Created note '$note_new_title'"
|
|
||||||
}
|
|
||||||
|
|
||||||
note_edit() {
|
|
||||||
check_dir
|
|
||||||
check_arg
|
|
||||||
title_to_name
|
|
||||||
if ! note_exists
|
|
||||||
then
|
|
||||||
echo "Cannot find note '$note_arg'!"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
note_old_title=$(head -1 $note_file)
|
|
||||||
note_old_md5=$(md5_sum $note_file)
|
|
||||||
|
|
||||||
$EDITOR $note_file
|
|
||||||
|
|
||||||
note_new_title=$(head -1 $note_file)
|
|
||||||
note_new_md5=$(md5_sum $note_file)
|
|
||||||
|
|
||||||
check_md5
|
|
||||||
check_empty restore
|
|
||||||
|
|
||||||
cd $NOTES_DIR
|
|
||||||
gitfile=$(basename $note_file)
|
|
||||||
commit_msg="Update note '$note_new_title'"
|
|
||||||
if [[ "$note_old_title" != "$note_new_title" ]]
|
|
||||||
then
|
|
||||||
note_new_file=$(make_title $note_new_title)
|
|
||||||
|
|
||||||
git mv $gitfile $note_new_file
|
|
||||||
git add $note_new_file
|
|
||||||
commit_msg="$commit_msg. Rename from '$note_old_title'"
|
|
||||||
else
|
|
||||||
git add $gitfile
|
|
||||||
fi
|
|
||||||
|
|
||||||
git commit -m "$commit_msg"
|
|
||||||
echo "Updated note '$note_new_title'"
|
|
||||||
}
|
|
||||||
|
|
||||||
note_show() {
|
|
||||||
check_dir
|
|
||||||
check_arg
|
|
||||||
title_to_name
|
|
||||||
if ! note_exists
|
|
||||||
then
|
|
||||||
echo "Cannot find note '$note_arg'!"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
less -R $note_file
|
|
||||||
}
|
|
||||||
|
|
||||||
note_delete() {
|
|
||||||
check_dir
|
|
||||||
check_arg
|
|
||||||
title_to_name
|
|
||||||
if ! note_exists
|
|
||||||
then
|
|
||||||
echo "Cannot find note '$note_arg'!"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd $NOTES_DIR
|
|
||||||
gitfile=$(basename $note_file)
|
|
||||||
git rm $gitfile
|
|
||||||
git commit -m "Delete note '$note_arg'"
|
|
||||||
echo "Deleted note '$note_arg'"
|
|
||||||
}
|
|
||||||
|
|
||||||
note_history() {
|
|
||||||
check_dir
|
|
||||||
cd $NOTES_DIR
|
|
||||||
git log --pretty=format:'%ai - %s' -- $note_arg
|
|
||||||
}
|
|
||||||
|
|
||||||
note_list() {
|
|
||||||
check_dir
|
|
||||||
cd $NOTES_DIR
|
|
||||||
if [[ -z "$1" ]]
|
|
||||||
then
|
|
||||||
ls -1
|
|
||||||
else
|
|
||||||
ls -1 | grep -i $1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
note_search() {
|
|
||||||
check_dir
|
|
||||||
|
|
||||||
if [[ -z "$1" ]]; then
|
|
||||||
echo "Must specify a pattern to search titles!"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd $NOTES_DIR
|
|
||||||
for file in *
|
|
||||||
do
|
|
||||||
grep --color=always -il "$1" $file
|
|
||||||
grep --color=always -inhT -m2 -C1 "$1" $file
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
parse_args() {
|
|
||||||
note_cmd=$1
|
|
||||||
shift
|
|
||||||
note_arg="$*"
|
|
||||||
|
|
||||||
case "$note_cmd" in
|
|
||||||
"h" | "help")
|
|
||||||
help_cmd
|
|
||||||
;;
|
|
||||||
|
|
||||||
"n" | "new")
|
|
||||||
note_new
|
|
||||||
;;
|
|
||||||
|
|
||||||
"e" | "edit")
|
|
||||||
note_edit
|
|
||||||
;;
|
|
||||||
|
|
||||||
"s" | "show")
|
|
||||||
note_show
|
|
||||||
;;
|
|
||||||
|
|
||||||
"d" | "delete")
|
|
||||||
note_delete
|
|
||||||
;;
|
|
||||||
|
|
||||||
"l" | "log")
|
|
||||||
note_history
|
|
||||||
;;
|
|
||||||
|
|
||||||
"i" | "init")
|
|
||||||
notes_init
|
|
||||||
;;
|
|
||||||
|
|
||||||
"f" | "find")
|
|
||||||
note_list $1
|
|
||||||
;;
|
|
||||||
|
|
||||||
"g" | "grep")
|
|
||||||
note_search $1
|
|
||||||
;;
|
|
||||||
|
|
||||||
"v" | "version")
|
|
||||||
version_info
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
echo "Unrecognized command '$note_cmd'. Use help."
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ $# -lt 1 ]]
|
|
||||||
then
|
|
||||||
echo "Usage: note <command> <arguments>"
|
|
||||||
echo "Type 'note help' for detailed help"
|
|
||||||
else
|
|
||||||
parse_args $*
|
|
||||||
fi
|
|
|
@ -1,10 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
# Set the Xterm/Tmux pane title
|
|
||||||
|
|
||||||
if [[ -z $TMUX ]]
|
|
||||||
then
|
|
||||||
echo -e "\033]0;$*\007"
|
|
||||||
else
|
|
||||||
echo -e "\033k$*\033\\"
|
|
||||||
fi
|
|
||||||
|
|
|
@ -1,69 +0,0 @@
|
||||||
#!/usr/bin/env ruby
|
|
||||||
# -*- ruby -*-
|
|
||||||
# Script to smartly chop off portions of the current working directory for
|
|
||||||
# use in the shell prompt
|
|
||||||
|
|
||||||
# Some of the methods don't work with Ruby versions older than 1.8.7
|
|
||||||
min_release = "1.8.7 (2008-08-11)"
|
|
||||||
ruby_release = "#{RUBY_VERSION} (#{RUBY_RELEASE_DATE})"
|
|
||||||
|
|
||||||
# Constants used to decide when to start chopping
|
|
||||||
DIRLIM = 5
|
|
||||||
DIR_L = 3
|
|
||||||
DIR_R = 2
|
|
||||||
PWDLEN = 14
|
|
||||||
|
|
||||||
def backslash_w
|
|
||||||
homedir = ENV['HOME']
|
|
||||||
pwd = ENV['PWD']
|
|
||||||
print pwd.gsub(homedir, '~')
|
|
||||||
end
|
|
||||||
|
|
||||||
def smartwd
|
|
||||||
username = ENV['USER']
|
|
||||||
homedir = ENV['HOME']
|
|
||||||
pwd = ENV['PWD']
|
|
||||||
|
|
||||||
path = pwd.split('/')
|
|
||||||
|
|
||||||
# Ignore the root path
|
|
||||||
if (path.length > 0)
|
|
||||||
index = path.index(username)
|
|
||||||
if index
|
|
||||||
prefix = path.shift(index + 1)
|
|
||||||
|
|
||||||
# We need to map additional paths in environments where the user
|
|
||||||
# may have more than one available folder in his/her name.
|
|
||||||
if prefix.join('/') == homedir
|
|
||||||
path.unshift('~')
|
|
||||||
else
|
|
||||||
# The first entry in the prefix array is the empty string
|
|
||||||
pre = prefix[1].split('').shift(4).join('') + '~'
|
|
||||||
path.unshift(pre)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
# Replace the first two entries in the array with /<entry1>
|
|
||||||
# (because the first entry is always empty string)
|
|
||||||
prefix = path.shift(2).join('/')
|
|
||||||
path.unshift(prefix)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Check to make sure that both the DIRLIM and PWDLEN constraints
|
|
||||||
# are met before splitting
|
|
||||||
pwd = path.join('/')
|
|
||||||
if path.length > DIRLIM and pwd.length > PWDLEN
|
|
||||||
pwd_l = path.shift(DIR_L).join('/')
|
|
||||||
pwd_r = path.pop(DIR_R).join('/')
|
|
||||||
pwd = pwd_l + '/.../' + pwd_r
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
print pwd
|
|
||||||
end
|
|
||||||
|
|
||||||
if (ruby_release < min_release)
|
|
||||||
backslash_w
|
|
||||||
else
|
|
||||||
smartwd
|
|
||||||
end
|
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
""" Calculate the Julian Date """
|
|
||||||
|
|
||||||
import time
|
|
||||||
import math
|
|
||||||
|
|
||||||
t = time.time()
|
|
||||||
|
|
||||||
""" Technically, we should be adding 2440587.5,
|
|
||||||
however, since we are trying to stick to the stardate
|
|
||||||
concept, we add only 40587.5"""
|
|
||||||
jd = (t / 86400.0 + 40587.5)
|
|
||||||
|
|
||||||
# Use the idea that 1 Julian day is equal to 1 stardate
|
|
||||||
print ("%05.9f" % jd)[:-7]
|
|
||||||
|
|
Loading…
Reference in New Issue