aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/db215
-rwxr-xr-xbin/gen-self-signed26
-rwxr-xr-xbin/git-fork55
-rwxr-xr-xbin/git-nuke17
-rwxr-xr-xbin/license131
-rw-r--r--bin/sass78
-rwxr-xr-xbin/toggle-keyboard-layout.sh27
-rwxr-xr-xinstall.sh12
8 files changed, 19 insertions, 542 deletions
diff --git a/bin/db b/bin/db
deleted file mode 100644
index 9ea279a..0000000
--- a/bin/db
+++ /dev/null
@@ -1,215 +0,0 @@
-#!/usr/bin/perl -w
-# Copyright (C) 2014-2023 Miquel Sabaté Solà <mikisabate@gmail.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# This script allows us to connect with psql properly for the given environment.
-#
-# The environments that we can use have to be specified in a JSON file. This
-# JSON file has to be specified in the "$json" configurable value (by default
-# is "db/database.json"). This JSON file has to specify the environments
-# available and a set of values. Each environment has to specify the following
-# values:
-#
-# * dbname: the name of the database.
-# * host: the host to be used.
-# * user: the user that is accessing the database.
-# * password: the password for the user@host.
-#
-# More values can be specified, but they will be ignored by this script. You
-# can find an example of this in the examples/database.json file.
-#
-# You can call this script with the following optional arguments:
-#
-# -e name
-# This argument can be used to specify the environment that we want to
-# connect to. If this argument has not been passed, it will take the
-# value of the "$default" configurable value ("development" by default).
-# Note that this argument can be used in combination with other
-# arguments.
-#
-# -m, --migrate
-# This argument can be used to migrate a set of .sql files into the
-# database. The path to these files can be set with the "$migrate"
-# configurable value (by default it is "db/migrate"). Keep in mind that
-# migration files can have the comment "-- ignore." in the beginning of
-# the file (other previous comments or blank lines will be ignored). This
-# comment tells this script to ignore this migration file.
-#
-# -b, --backup
-# Spit to the STDOUT a backup of the database.
-#
-# Therefore, this command has the following usage:
-#
-# $ db [-e name] [[-m | --migrate] | [-b | --backup]]
-#
-
-use strict;
-use File::Basename;
-use Cwd 'abs_path', 'getcwd';
-
-
-##
-# Config values. Ideally you should only modify these values to adapt this
-# script to your project.
-#
-# NOTE: path values should *not* start and/or end with a slash.
-
-
-# The base path that this script will use. By default it picks the current
-# working directory.
-my $base = abs_path(getcwd);
-
-# The relative path to the json file (including the name of the json file
-# itself).
-my $json = 'db/database.json';
-
-# The default environment. This is the environment to be used when no
-# environment has been given through the '-e' option.
-my $default = 'development';
-
-# The relative path with migration files. Migration files are plain .sql files
-# that will be used with the '-m' option.
-my $migrate = 'db/migrate';
-
-
-##
-# And here starts the program itself.
-
-
-# Show the usage string and exit.
-sub usage {
- print "Usage: db [-e name] [[-m | --migrate] | [-b | --backup]]\n";
- print " -e Specify an environment.\n";
- print " -m Migrate all the files from the db/migrate directory.\n";
- print " -b Backup the proper DB.\n";
- exit(1);
-}
-
-# Check that a given value has been defined in the given hash.
-sub check {
- my ($ary, $value) = @_;
- if (!defined($ary->{$value})) {
- print "ERROR: you haven't defined the '$value' value.\n";
- exit(1);
- }
-}
-
-# Returns true if we should ignore the given migration.
-sub should_ignore {
- my ($path) = @_;
- my $res = 0;
-
- if (open(MIGRATION, $path)) {
- while (<MIGRATION>) {
- if ($_ =~ /^--\s*ignore\.?/) {
- # Ok boss, let's ignore it.
- $res = 1;
- last;
- } elsif ($_ =~ /^\s*$/) {
- # It's a blank line, next.
- next;
- } elsif ($_ =~ /^--/) {
- # It's an SQL comment, next.
- next;
- }
- last;
- }
- close(MIGRATION);
- }
- return $res;
-}
-
-# Apply all the migrations if needed.
-sub migrate {
- my ($cmd, $path) = @_;
-
- print "Starting migration\n";
- opendir(DIR, $path) or die $!;
- while (my $file = readdir(DIR)) {
- next if ($file =~ m/^\./);
- next if ($file !~ m/\.sql$/);
-
- if (should_ignore("$path/$file")) {
- print "Ignoring migration: $file\n";
- } else {
- print "Applying migration: $file\n";
- system("$cmd < $path/$file\n");
- }
- }
- closedir(DIR);
-}
-
-# Parsing options.
-my %opts = ('e', $default, 'm', 0, 'b', 0);
-for (my $it = 0; $it < @ARGV; $it++) {
- if ($ARGV[$it] eq '-e') {
- usage() if (!$ARGV[$it + 1]);
- $opts{e} = $ARGV[$it + 1];
- $it++;
- } elsif ($ARGV[$it] eq '-m' || $ARGV[$it] eq '--migrate') {
- $opts{m} = 1;
- } elsif ($ARGV[$it] eq '-b' || $ARGV[$it] eq '--backup') {
- $opts{b} = 1;
- } else {
- if ($ARGV[$it] ne '-h' && $ARGV[$it] ne '--help') {
- print "Unknown option `$ARGV[$it]'\n\n";
- }
- usage();
- }
-}
-
-# Let's fetch the configuration of the environment.
-my $config = "$base/$json";
-if (!-f $config) {
- print "ERROR: the $config file does not exist!\n";
- exit(1)
-}
-
-open(FILE, $config);
-my $file = '';
-while (<FILE>) {
- my $line = $_;
- chomp($line);
- $file .= " $line";
-}
-close(FILE);
-
-# Fetch the values.
-$file =~ m/"$opts{e}":\s?({(.*?)})/;
-my $contents = $1;
-if (!defined($contents)) {
- print "The `$opts{e}' environment does not exist.\n";
- exit(1);
-}
-
-# Setup the command.
-my %ary = ();
-$ary{$1} = $2 while ($contents =~ /"(\w+)":\s?"([\w\-]*)"/g);
-foreach (qw{dbname user host password}) {
- check(\%ary, $_);
-}
-
-my $opts = "-d $ary{'dbname'} -U $ary{'user'} -h $ary{'host'}";
-my $cmd = "PGPASSWORD=$ary{'password'} psql $opts";
-
-# Now execute the command properly.
-if ($opts{m}) {
- migrate($cmd, "$base/$migrate");
-} elsif ($opts{b}) {
- my $opts = "-d $ary{'dbname'} -U $ary{'user'}";
- system("PGPASSWORD=$ary{'password'} pg_dump $opts");
-} else {
- system("$cmd");
-}
diff --git a/bin/gen-self-signed b/bin/gen-self-signed
deleted file mode 100755
index ff98ca7..0000000
--- a/bin/gen-self-signed
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/bin/bash
-# Copyright (C) 2018-2023 Miquel Sabaté Solà <mikisabate@gmail.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-set -e
-
-if [ -z "$1" ]; then
- program=$(basename $0)
- echo "usage: $program <name>"
- exit 1
-fi
-name=$1
-
-openssl req -nodes -new -x509 -keyout $name.key -out $name.crt \ No newline at end of file
diff --git a/bin/git-fork b/bin/git-fork
deleted file mode 100755
index bfe4cb7..0000000
--- a/bin/git-fork
+++ /dev/null
@@ -1,55 +0,0 @@
-#!/bin/bash
-# Copyright (C) 2015-2023 Miquel Sabaté Solà <mikisabate@gmail.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-set -e
-
-# This script adds the `fork` subcommand to git. This subcommand helps to keep
-# a forked project updated with upstream. So, in a forked repository you would
-# do:
-#
-# $ git fork
-#
-# The previous command will fetch the upstream remote and merge the master
-# branch. You can change the remote and the branch to be picked like this:
-#
-# $ git fork branch
-# $ git fork remote branch
-#
-# Finally, if the given remote does not exist, the user will be prompted to
-# provide the URL to the remote, so it can be created.
-
-# Configurable values: the name of the branch to be picked and the name of the
-# upstream remote.
-branch='master'
-upstream='upstream'
-
-if [ ! -z "$1" ]; then
- upstream="$1"
-fi
-if [ ! -z "$2" ]; then
- branch="$2"
-fi
-
-# Check whether the given upstream remote really exists. If it doesn't it will
-# ask the user for a remote URL.
-if [[ $(git remote show | xargs -0 | grep -Fxq "$upstream") -eq 1 ]]; then
- echo "The given upstream '$upstream' remote does not exist"
- echo -n "Provide one: "
- read -ra url
- git remote add $upstream $url
-fi
-
-git fetch $upstream && git merge $upstream/$branch
diff --git a/bin/git-nuke b/bin/git-nuke
index f86cb57..037899d 100755
--- a/bin/git-nuke
+++ b/bin/git-nuke
@@ -24,13 +24,22 @@ if [ "$#" -ne 1 ]; then
exit 1
fi
-# The `master` branch should not be removed.
-if [ "$1" = "master" ]; then
- echo "You are not allowed to delete the 'master' branch."
+upstream="origin"
+if [ -n "$1" ]; then
+ upstream="$1"
+fi
+default=$(git rev-parse --abbrev-ref "$upstream"/HEAD | cut -c8-)
+
+# The `default` branch should not be removed.
+if [ "$1" = "$default" ]; then
+ echo "You are not allowed to delete the default branch."
exit 1
fi
-full_name="$(git symbolic-ref HEAD 2>/dev/null)" || (echo "Detached branch, bailing..."; exit 1)
+full_name="$(git symbolic-ref HEAD 2>/dev/null)" || (
+ echo "Detached branch, bailing..."
+ exit 1
+)
name="$(basename "$full_name")"
# If we are nuking the current branch, move to `master` first.
diff --git a/bin/license b/bin/license
deleted file mode 100755
index 449848e..0000000
--- a/bin/license
+++ /dev/null
@@ -1,131 +0,0 @@
-#!/usr/bin/perl -w
-# Copyright (C) 2014-2023 Miquel Sabaté Solà <mikisabate@gmail.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# Yay! A new year! Oops, wait, now I have to update the dates from all my stuff
-# right? Well, this script solves this very specific case. It basically updates
-# all the copyright notices so they match the new year. So, for example
-# (assuming that the current year is 2015):
-#
-# Copyright (c) John Smith -> Copyright (c) 2015 John Smith
-# Copyright (c) 2014 John Smith -> Copyright (c) 2014-2015 John Smith
-# Copyright (c) 2009-2014 John Smith -> Copyright (c) 2009-2015 John Smith
-#
-# The date to be picked is set in the `$current_year` configurable value. This
-# script will apply this to all the files as given as command line arguments.
-# So, for example:
-#
-# $ ls | xargs license
-#
-# The line above will update the license notice for all the files in the
-# current directory. By default, if you don't pass any arguments, it will do
-# the following:
-#
-# $ git grep -l 'Copyright' | xargs license
-#
-# This default behavior can be changed through the `$default_cmd` configurable
-# value.
-#
-# Some notes:
-#
-# - This script will respect the (c) symbol, accepting the following formats:
-# (c), (C) and &copy; . More on the configurable value `$re`.
-# - This script will leave intact anything that comes before the (c) symbol
-# and anything that comes after the range of years.
-# - This script needs an author, because we don't want to modify the ownership
-# from other people. More on the configurable value `$name`.
-# - Don't blindly trust this guy, since it might be quite destructive if
-# something goes wrong. So I would check the results (e.g. `git status` and
-# then `git diff`).
-
-use strict;
-
-##
-# Config values. You will have to update for sure the `$name` (unless you're
-# also called Miquel :P) and the `$current_year`.
-
-# The author name. We don't want to mess with copyright notices from other
-# people. Note that just setting the name might be a bit weak, so it might be
-# interesting to add last names, email, etc. (that is, anything that you
-# usually put after the range of years).
-my $name = 'Miquel';
-
-# The current year. I previously thought to be clever and set it to `date +%Y`,
-# but then I decided that I didn't want to be clever here to avoid problems and
-# be more flexible.
-my $current_year = '2023';
-
-# The command that feeds this command if no command line argument was given.
-my $default_cmd = "git grep -l 'Copyright' | xargs";
-
-# The regular expression that matches copyright notices. I wouldn't change it,
-# because if you do, you probably would have to change the `update_file`
-# subroutine.
-my $re = qr/
- ^(.*) # Save all the previous stuff.
- Copyright # Our regexp starts with the `Copyright` word.
- (\ \([Cc]\)|\ &copy;)? # An optional (c) or markdown symbol.
- (\ (\d{4})(-\d{4})?)? # An optional range of dates.
- \ $name # The author name. This word confirms the match.
- (.*)$ # Save the rest of the line.
-/x;
-
-sub update_file {
- my ($file) = @_;
-
- open my $in, '<', $file or die "Can't open file $file";
- my $perm = ( stat $in )[2] & 07777;
- open my $out, '>', "$file.new" or die "Can't open file $file.new";
-
- while (<$in>) {
- my $line = $_;
- if ( $line =~ $re ) {
-
- # Get the values from the regular expression safely.
- my $prev = ($1) ? $1 : '';
- my $year = ($3) ? $3 : $current_year;
- my $c = ($2) ? $2 : '(C)';
- my $next = ($6) ? $6 : '';
- $c =~ s/^\s//;
- $year =~ s/^\s//;
-
- # Get the range of years straight.
- my @years = split( '-', $year );
- if ( $years[0] ne $current_year ) {
- $year = "$years[0]-$current_year";
- }
-
- # Behold! Our majestic line!
- $line = "${prev}Copyright $c $year $name${next}\n";
- }
- print $out "$line";
- }
- close($in);
- close($out);
-
- # And move the file while preserving the old permission bits.
- `mv $file.new $file`;
- open $in, '<', $file or die "Can't open file $file";
- chmod( $perm | 0600, $in );
- close($in);
-}
-
-##
-# Main: get the files from the command line and update them.
-
-my @files = ( @ARGV > 0 ) ? @ARGV : split( ' ', `$default_cmd` );
-foreach my $f (@files) {
- update_file($f);
-}
diff --git a/bin/sass b/bin/sass
deleted file mode 100644
index 3066d83..0000000
--- a/bin/sass
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2014-2023 Miquel Sabaté Solà <mikisabate@gmail.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# Launch a background job that deals with SASS/SCSS.
-#
-# If no arguments were given, then it will try to kill a previous instance
-# of the background job and launch another one. You can prevent the
-# re-launching by passing the "stop" argument. This way, this script will
-# efectively kill the currently running process and quit. Any other argument
-# will be ignored.
-#
-# Therefore, the usage of this script is as follows:
-#
-# $ sass [stop]
-#
-
-
-##
-# Config values.
-#
-# NOTE: path values should *not* start and/or end with a slash.
-
-# The base directory.
-dir="$( cd "$( dirname "$0" )" && pwd )/.."
-
-# The absolute path to the directory where we can store temporary files. You
-# don't really want to use this default since it can easily clash with other
-# projects ;)
-tmp="/tmp"
-
-# The absolute path to the file that will store the PID of the currently
-# running background job.
-pidfile="$tmp/assets.pid"
-
-# The absolute path to the SASS log.
-csslog="$tmp/sass.log"
-
-# The absolute path of the directory containing the SASS files.
-cssdir="$dir/public/stylesheets"
-
-
-##
-# And here starts the script itself.
-
-
-# Get pidfile.
-mkdir -p $tmp
-touch $pidfile
-
-# Kill off old processes
-while read pid; do
- kill $pid > /dev/null 2>&1;
-done < $pidfile
-
-# Truncate the PID file
-> $pidfile
-
-# If the user just wanted to stop all old processes, then exit here.
-if [[ $1 == "stop" ]]; then
- exit 1
-fi
-
-# SASS
-sass --watch "$cssdir" > $csslog 2>&1 &
-echo $! >> $pidfile
diff --git a/bin/toggle-keyboard-layout.sh b/bin/toggle-keyboard-layout.sh
deleted file mode 100755
index bbda542..0000000
--- a/bin/toggle-keyboard-layout.sh
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/bash
-# Copyright (C) 2016-2023 Miquel Sabaté Solà <mikisabate@gmail.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# Idea taken from: https://github.com/ereslibre/dotfiles. All the credit goes
-# to him.
-
-layout=$(setxkbmap -query | awk '/layout/{print $2}')
-if [ "$layout" == 'mao' ]
-then
- setxkbmap es -option ctrl:nocap
-else
- setxkbmap mao -option ctrl:nocap
-fi
-killall -SIGUSR1 i3status
diff --git a/install.sh b/install.sh
index 1d54850..d9ff512 100755
--- a/install.sh
+++ b/install.sh
@@ -21,17 +21,17 @@ set -e
binaries=(git curl vim emacs)
for bin in "${binaries[@]}"; do
- if ! [ -x "$(command -v ${bin})" ]; then
- echo "Error: the binary '${bin}' is not installed." >&2
- exit 1
- fi
+ if ! [ -x "$(command -v ${bin})" ]; then
+ echo "Error: the binary '${bin}' is not installed." >&2
+ exit 1
+ fi
done
##
# Main procedure: link as many files as possible.
ary=(.git .gitignore .gitmodules LICENSE *.gitignore *.yml *.org install.sh
- update.sh .emacs.d .config .gnupg Images .i3 .i3status.conf)
+ update.sh .emacs.d .config .gnupg Images .i3 .i3status.conf README.md)
ignore="-name ${ary[0]}"
for i in "${ary[@]:1:${#ary[@]}}"; do
ignore+=" -or -name $i"
@@ -88,7 +88,7 @@ fi
# Get git completiom right.
if ! [ -f "${HOME:?}/.git-prompt.sh" ]; then
- curl -o "${HOME:?}/.git-prompt.sh" https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
+ curl -o "${HOME:?}/.git-prompt.sh" https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
fi
# Initialize Vim plugins.