Initial commit of very basic dotfiles
This commit is contained in:
@@ -0,0 +1 @@
|
||||
alias lsa='ls -hal --color=tty'
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# returns the active git branch - this is used in rewrite_prompt()
|
||||
git_branch()
|
||||
{
|
||||
git branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(branch: \1)/'
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
#!/bin/bash
|
||||
|
||||
##################################################
|
||||
# Fancy PWD display function
|
||||
##################################################
|
||||
# The home directory (HOME) is replaced with a ~
|
||||
# The last pwdmaxlen characters of the PWD are displayed
|
||||
# Leading partial directory names are striped off
|
||||
# /home/me/stuff -> ~/stuff if username=me
|
||||
# /usr/share/big_dir_name -> ../share/big_dir_name if pwdmaxlen=20
|
||||
##################################################
|
||||
rewrite_pwd()
|
||||
{
|
||||
# how many characters of the $PWD should be kept
|
||||
local pwdmaxlen=25
|
||||
|
||||
# indicate that there has been dir truncation
|
||||
local trunc_symbol=".."
|
||||
local dir=${PWD##*/}
|
||||
|
||||
pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
|
||||
|
||||
NEW_PWD=${PWD/$HOME/~}
|
||||
|
||||
local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))
|
||||
|
||||
if [ ${pwdoffset} -gt "0" ]
|
||||
then
|
||||
NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}
|
||||
NEW_PWD=${trunc_symbol}/${NEW_PWD#*/}
|
||||
fi
|
||||
}
|
||||
|
||||
# rewrites the PS1 bash prompt var
|
||||
rewrite_prompt()
|
||||
{
|
||||
local NONE='\[\033[0m\]' # unsets color to term's fg color
|
||||
|
||||
# regular colors
|
||||
local K='\[\033[0;30m\]' # black
|
||||
local R='\[\033[0;31m\]' # red
|
||||
local G='\[\033[0;32m\]' # green
|
||||
local Y='\[\033[0;33m\]' # yellow
|
||||
local B='\[\033[0;34m\]' # blue
|
||||
local M='\[\033[0;35m\]' # magenta
|
||||
local C='\[\033[0;36m\]' # cyan
|
||||
local W='\[\033[0;37m\]' # white
|
||||
|
||||
# empahsized (bolded) colors
|
||||
local EMK='\[\033[1;30m\]'
|
||||
local EMR='\[\033[1;31m\]'
|
||||
local EMG='\[\033[1;32m\]'
|
||||
local EMY='\[\033[1;33m\]'
|
||||
local EMB='\[\033[1;34m\]'
|
||||
local EMM='\[\033[1;35m\]'
|
||||
local EMC='\[\033[1;36m\]'
|
||||
local EMW='\[\033[1;37m\]'
|
||||
|
||||
# background colors
|
||||
local BGK='\[\033[40m\]'
|
||||
local BGR='\[\033[41m\]'
|
||||
local BGG='\[\033[42m\]'
|
||||
local BGY='\[\033[43m\]'
|
||||
local BGB='\[\033[44m\]'
|
||||
local BGM='\[\033[45m\]'
|
||||
local BGC='\[\033[46m\]'
|
||||
local BGW='\[\033[47m\]'
|
||||
|
||||
local UC=$C # username's color
|
||||
[ $UID -eq "0" ] && UC=$R # root's color
|
||||
|
||||
# rewrite prompt
|
||||
PS1="${G}\u@\h> \${NEW_PWD} ${C}\$(git_branch)\${NONE}${NONE}\n$ "
|
||||
}
|
||||
|
||||
# adds ~/.ssh/config to the ssh autocomplete
|
||||
ssh_load_autocomplete()
|
||||
{
|
||||
complete -W "$(awk '/^\s*Host\s*/ { sub(/^\s*Host /, ""); print; }' ~/.ssh/config)" ssh
|
||||
}
|
||||
|
||||
# adds Git autocompletion
|
||||
if [ -f ~/.bin/git-completion.bash ]; then
|
||||
. ~/.bin/git-completion.bash
|
||||
fi
|
||||
|
||||
PROMPT_COMMAND=rewrite_pwd
|
||||
rewrite_prompt
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# General settings
|
||||
export EDITOR=vim
|
||||
export CLICOLOR=1
|
||||
|
||||
# Prefer the Queen's English and use UTF-8.
|
||||
export LC_ALL='en_GB.UTF-8';
|
||||
export LANG='en_GB';
|
||||
|
||||
# don't put duplicate lines in the history
|
||||
export HISTCONTROL=ignoredups
|
||||
|
||||
# let the history ignore the following commands
|
||||
export HISTIGNORE="ls:ll:la:pwd:clear:h:j"
|
||||
|
||||
# append to the history file rather than overwriting
|
||||
shopt -s histappend
|
||||
shopt -s nocaseglob;
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Source the files in the bash folder
|
||||
for file in ~/.bash/{shell,commands,prompt,aliases}; do
|
||||
[ -r "$file" ] && source "$file";
|
||||
done;
|
||||
unset file;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# This might seem backwards when you look at the "Bash startup files" reference
|
||||
# <http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files> or
|
||||
# the "INVOCATION" section in the man page. However, my workflow typically is:
|
||||
#
|
||||
# * Open a terminal with four shells in tabs
|
||||
# * Edit code in Vim, and shell out using ":sh"
|
||||
#
|
||||
# The initial four shells are login shells, so they source ~/.bash_profile.
|
||||
# The shells spawned by Vim are not login shells, but they /are/ interactive.
|
||||
# They look for .bashrc, but not .bash_profile. Because they are interactive,
|
||||
# PS1 is set, so I know it is OK to run all the shell initialisation code.
|
||||
#
|
||||
# If I were to put the contents of ~/.bash_profile in ~/.bashrc and make the
|
||||
# former source the latter, I would have to wrap the entire contents of the
|
||||
# latter in a huge "if [ -n "$PS1" ]; then ... fi" block. That does not really
|
||||
# help readability, does it?
|
||||
#
|
||||
# The difference between a login shell and an interactive non-login shell is
|
||||
# moot for me, so I consider all interactive shells to be equal and wanting
|
||||
# the same treatment.
|
||||
#
|
||||
# If you're wondering what a non-interactive shell might be, i.e. when PS1
|
||||
# might not be set, try this:
|
||||
#
|
||||
# ssh localhost 'echo "PS1: >$PS1<"'
|
||||
#
|
||||
|
||||
[ -n "$PS1" ] && source ~/.bash_profile;
|
||||
File diff suppressed because it is too large
Load Diff
+76
@@ -0,0 +1,76 @@
|
||||
[pretty]
|
||||
concise = %C(yellow)%h%C(reset) %s %C(bold black)(%an, %ar)%C(reset)%C(bold blue)%d%C(reset)
|
||||
|
||||
[alias]
|
||||
# When doing "git git log" or some such, do not complain about "git" not
|
||||
# being a valid Git command. This happens when copy-pasting examples, for
|
||||
# instance.
|
||||
git = !git
|
||||
|
||||
# Show a concise status of the working directory, along with the branch
|
||||
# and the number of commits behind and/or ahead.
|
||||
st = status --short --branch
|
||||
|
||||
# Quickly push to the most common destination.
|
||||
pom = push origin master
|
||||
|
||||
# Quickly push to the origin
|
||||
po = push origin
|
||||
|
||||
# Quickly pull from the origin
|
||||
pu = pull origin
|
||||
|
||||
# I know "pum" could just as well stand for "PUsh" instead of "PUll", but
|
||||
# I am so used to "git pom" that "git pum" feels like a natural
|
||||
# counterpart. I always try to rebase to prevent unnecessary merge
|
||||
# commits.
|
||||
pum = pull --rebase origin master
|
||||
|
||||
# Show the staged changes.
|
||||
dc = diff --cached
|
||||
|
||||
# Commit
|
||||
ci = commit
|
||||
|
||||
# Like "git show myfile", but uses the last commit that changed "myfile".
|
||||
sl = log -n 1 -p
|
||||
|
||||
# Switch branches, creating them if necessary. I want to unlearn using
|
||||
# "git checkout" for switching between branches because of the possible
|
||||
# dataloss when not paying attention. (You could see the PEBKAC, but I
|
||||
# could reply with another four letter acronym, slightly resembling TOFU.)
|
||||
#
|
||||
# Suppose I have modified a file named "password" and have two branches,
|
||||
# "password-expiry-mechanism" and "password-reset-mail". If I want to
|
||||
# switch to either branch, I would type "git checkout pass<Tab><Enter>",
|
||||
# but the autocomplete would stop at "git checkout password" because of
|
||||
# the ambiguity. Because I press <Enter> without really thinking, I have
|
||||
# now reset my "password" file. With "git go pass<Tab><Enter>", I would
|
||||
# simply have created a new branch called "password". (I would be forced
|
||||
# to use "--" to separate paths from banch names, which is a Good Thing™.)
|
||||
cob = checkout -B
|
||||
co = checkout
|
||||
|
||||
# Make life easier, we only need git aa to add/remove git files
|
||||
aa = add --all
|
||||
|
||||
# Show pretty log
|
||||
ll = !git pgl --all
|
||||
|
||||
# Show only 20 git log items
|
||||
l = !git pgl -20
|
||||
|
||||
# Show a git log with detailed log information.
|
||||
pgl = "!source ~/.githelpers && pretty_git_log"
|
||||
|
||||
|
||||
[core]
|
||||
excludesfile = ~/.gitignore
|
||||
autocrlf = input
|
||||
safecrlf = true
|
||||
|
||||
[color]
|
||||
ui = true
|
||||
|
||||
[merge]
|
||||
tool = vimdiff
|
||||
@@ -0,0 +1,147 @@
|
||||
# History
|
||||
# -----------------------------------------------------------------------------
|
||||
# Use more intelligent Up/Down behaviour: use the text that has already been
|
||||
# typed as the prefix for searching through commands, like in Vim.
|
||||
"\e[B": history-search-forward
|
||||
"\e[A": history-search-backward
|
||||
|
||||
# Remember the cursor position for each history line. Note that this only works
|
||||
# for previous-history and next-history, and apparently not (or not so well)
|
||||
# with my Up/Down key bindings history-search-{back,for}ward.
|
||||
set history-preserve-point on
|
||||
|
||||
# Autocompletion
|
||||
# -----------------------------------------------------------------------------
|
||||
# Make Tab autocompletion case-insensitive (cd ~/dow<Tab> => cd ~/Downloads/).
|
||||
set completion-ignore-case On
|
||||
|
||||
# When autocompleting symlinks to directories, immediately add a trailing "/".
|
||||
set mark-symlinked-directories on
|
||||
|
||||
# Flip through autocompletion matches with Shift-Tab.
|
||||
"\e[Z": menu-complete
|
||||
|
||||
# Do not autocomplete hidden files ("dot files") unless the pattern explicitly
|
||||
# begins with a dot.
|
||||
set match-hidden-files off
|
||||
|
||||
# Show all autocomplete results at once.
|
||||
set page-completions off
|
||||
|
||||
# If there are more than 200 possible completions for a word, ask to show them
|
||||
# all.
|
||||
set completion-query-items 200
|
||||
|
||||
# Immediately show all possible completions.
|
||||
set show-all-if-ambiguous on
|
||||
|
||||
# Show extra file information when completing, like ls -F does.
|
||||
set visible-stats on
|
||||
|
||||
# Be more intelligent when autocompleting by also looking at the text after
|
||||
# the cursor. For example, when the current line is "cd ~/src/mozil", and
|
||||
# the cursor is on the "z", pressing Tab will not autocomplete it to "cd
|
||||
# ~/src/mozillail", but to "cd ~/src/mozilla". (This is supported by the
|
||||
# Readline used by Bash 4.)
|
||||
set skip-completed-text on
|
||||
|
||||
# Line editing
|
||||
# -----------------------------------------------------------------------------
|
||||
# Allow UTF-8 input and output, instead of showing them like $'\0123\0456'.
|
||||
set input-meta on
|
||||
set output-meta on
|
||||
set convert-meta off
|
||||
|
||||
# Use Alt/Meta+Delete to delete the preceding word.
|
||||
"\e[3;3~": kill-word
|
||||
|
||||
# Delete for wonky terminals.
|
||||
"\e[3~": delete-char
|
||||
|
||||
# Use Ctrl+â and Ctrl+â (or Alt/Meta, or Esc) to move between words.
|
||||
"\e[1;5D": backward-word
|
||||
"\e[1;3D": backward-word
|
||||
"\e[5D": backward-word
|
||||
"\e\e[D": backward-word
|
||||
"\e[1;5C": forward-word
|
||||
"\e[1;3C": forward-word
|
||||
"\e[5C": forward-word
|
||||
"\e\e[C": forward-word
|
||||
|
||||
# Miscellaneous
|
||||
# -----------------------------------------------------------------------------
|
||||
# Neither sound a beep nor flash the screen when trying to ring the bell.
|
||||
set bell-style none
|
||||
# History
|
||||
# -----------------------------------------------------------------------------
|
||||
# Use more intelligent Up/Down behaviour: use the text that has already been
|
||||
# typed as the prefix for searching through commands, like in Vim.
|
||||
"\e[B": history-search-forward
|
||||
"\e[A": history-search-backward
|
||||
|
||||
# Remember the cursor position for each history line. Note that this only works
|
||||
# for previous-history and next-history, and apparently not (or not so well)
|
||||
# with my Up/Down key bindings history-search-{back,for}ward.
|
||||
set history-preserve-point on
|
||||
|
||||
# Autocompletion
|
||||
# -----------------------------------------------------------------------------
|
||||
# Make Tab autocompletion case-insensitive (cd ~/dow<Tab> => cd ~/Downloads/).
|
||||
set completion-ignore-case On
|
||||
|
||||
# When autocompleting symlinks to directories, immediately add a trailing "/".
|
||||
set mark-symlinked-directories on
|
||||
|
||||
# Flip through autocompletion matches with Shift-Tab.
|
||||
"\e[Z": menu-complete
|
||||
|
||||
# Do not autocomplete hidden files ("dot files") unless the pattern explicitly
|
||||
# begins with a dot.
|
||||
set match-hidden-files off
|
||||
|
||||
# Show all autocomplete results at once.
|
||||
set page-completions off
|
||||
|
||||
# If there are more than 200 possible completions for a word, ask to show them
|
||||
# all.
|
||||
set completion-query-items 200
|
||||
|
||||
# Immediately show all possible completions.
|
||||
set show-all-if-ambiguous on
|
||||
|
||||
# Show extra file information when completing, like ls -F does.
|
||||
set visible-stats on
|
||||
|
||||
# Be more intelligent when autocompleting by also looking at the text after
|
||||
# the cursor. For example, when the current line is "cd ~/src/mozil", and
|
||||
# the cursor is on the "z", pressing Tab will not autocomplete it to "cd
|
||||
# ~/src/mozillail", but to "cd ~/src/mozilla". (This is supported by the
|
||||
# Readline used by Bash 4.)
|
||||
set skip-completed-text on
|
||||
|
||||
# Line editing
|
||||
# -----------------------------------------------------------------------------
|
||||
# Allow UTF-8 input and output, instead of showing them like $'\0123\0456'.
|
||||
set input-meta on
|
||||
set output-meta on
|
||||
set convert-meta off
|
||||
|
||||
# Use Alt/Meta+Delete to delete the preceding word.
|
||||
"\e[3;3~": kill-word
|
||||
|
||||
# Delete for wonky terminals.
|
||||
"\e[3~": delete-char
|
||||
|
||||
# Use Alt+← and Alt+→ to move between words.
|
||||
"\e[1;9D": backward-word
|
||||
"\e[1;9C": forward-word
|
||||
|
||||
# Use Control+← and Control+→
|
||||
"\e[1;5D": backward-word
|
||||
"\e[1;5C": forward-word
|
||||
|
||||
# Miscellaneous
|
||||
# -----------------------------------------------------------------------------
|
||||
# Neither sound a beep nor flash the screen when trying to ring the bell.
|
||||
set bell-style none
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
set encoding=utf-8
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" When editing a file, always jump to the last known cursor position.
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g`\"" | endif
|
||||
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" Delete trailing whitespaces on saving a file
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
autocmd BufWritePre * :%s/\s\+$//e
|
||||
@@ -12,3 +12,5 @@ These files will replace any personal dotfiles to prevent unexpected behavior.
|
||||
- Must show if we are on staging, test or production
|
||||
- Must show the current branch we are on, in case of a git repo
|
||||
- Aliases to show list of recursive folder -and dirsizes
|
||||
- Git information with handy aliases and pretty= formats
|
||||
- install/uninstall
|
||||
|
||||
Executable
+94
@@ -0,0 +1,94 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Go trough all the files available in this folder.
|
||||
commonFiles=();
|
||||
for sourceFile in .*; do
|
||||
|
||||
# Exclude some files.
|
||||
if [[ "$sourceFile" == "dotfiles-002.png" || "$sourceFile" == "dotfiles-001.png" || "$sourceFile" == "install.sh" ]] || [[ "$sourceFile" == "README.md" ]] || [[ "$sourceFile" == "." ]] || [[ "$sourceFile" == ".." ]] || [[ "$sourceFile" == ".git" ]]; then
|
||||
continue;
|
||||
fi;
|
||||
|
||||
# Set the target path for the source file.
|
||||
# We'll port them to the ~/ (home) directory.
|
||||
targetFile="$HOME/$sourceFile";
|
||||
|
||||
# The file already exists.
|
||||
if [ -e "$targetFile" ]; then
|
||||
|
||||
# The source and target point to the same file, continue.
|
||||
[ "$sourceFile" -ef "$targetFile" ] && continue;
|
||||
|
||||
# The content of the file is the same, continue.
|
||||
diff -rq "$sourceFile" "$targetFile" > /dev/null 2>&1 && continue;
|
||||
|
||||
# The source file is another file than our dotfile.
|
||||
# Store it in the commonFiles array so we can back it up.
|
||||
commonFiles+=("$sourceFile");
|
||||
|
||||
fi;
|
||||
done;
|
||||
|
||||
# Show the files that will be overwritten.
|
||||
conflictCount=${#commonFiles[@]};
|
||||
if [ $conflictCount -gt 0 ]; then
|
||||
|
||||
# Create a suffix with a timestamp so the user can see which
|
||||
# files and when they've been backupped.
|
||||
backupSuffix=".jsVimconfig-$(date +'%Y%m%d-%H%M%S')";
|
||||
|
||||
# Print some information about the replacement.
|
||||
tput setaf 3;
|
||||
printf "Warning: there are some files that will be overwritten.";
|
||||
tput sgr0;
|
||||
echo " Your files will be given the suffix $backupSuffix and will be" \
|
||||
"replaced by symlinks to the Dotfiles:";
|
||||
|
||||
# Print the conflict files.
|
||||
for sourceFile in "${commonFiles[@]}"; do
|
||||
targetFile="$HOME/$sourceFile";
|
||||
echo "Yours: $targetFile";
|
||||
echo "Dotfiles: $sourceFile";
|
||||
done;
|
||||
|
||||
# Make sure the user knows that we'll be replacing the old files.
|
||||
read -p "Would you like to overwrite the current files? (yes|no): ";
|
||||
case "$(tr '[:upper:]' '[:lower:]' <<< "$REPLY")" in
|
||||
'yes'|'y')
|
||||
# The user is sure, continue.
|
||||
;;
|
||||
'no'|'n')
|
||||
# The user isn't sure, abort.
|
||||
echo 'Aborting.';
|
||||
exit 1;
|
||||
;;
|
||||
*)
|
||||
# The user didn't type yes/no.
|
||||
echo 'Invalid answer. Assumed "no". Installation aborted.';
|
||||
exit 1;
|
||||
esac;
|
||||
fi;
|
||||
|
||||
# Rename the conflicting files as backup.
|
||||
for sourceFile in "${commonFiles[@]}"; do
|
||||
targetFile="$HOME/$sourceFile";
|
||||
mv -v "$targetFile" "$targetFile$backupSuffix";
|
||||
done;
|
||||
|
||||
# Symlink the files in the home dir by those in the dotfiles repo.
|
||||
for sourceFile in .*; do
|
||||
|
||||
# Exclude some files.
|
||||
if [[ "$sourceFile" == "dotfiles-002.png" || "$sourceFile" == "dotfiles-001.png" || "$sourceFile" == "install.sh" ]] || [[ "$sourceFile" == "README.md" ]] || [[ "$sourceFile" == "." ]] || [[ "$sourceFile" == ".." ]] || [[ "$sourceFile" == ".git" ]]; then
|
||||
continue;
|
||||
fi;
|
||||
|
||||
targetFile="$HOME/$sourceFile";
|
||||
|
||||
# Delete the old file and replace it by the symlink.
|
||||
rm -rf "$targetFile" &&
|
||||
ln -vs "$PWD/$sourceFile" "$targetFile";
|
||||
done;
|
||||
|
||||
echo "Done.";
|
||||
|
||||
Reference in New Issue
Block a user