Skip to content

Commit 73d35b0

Browse files
committed
moving old dotfiles to bare tilde repo
0 parents  commit 73d35b0

File tree

9 files changed

+351
-0
lines changed

9 files changed

+351
-0
lines changed

.bash_profile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Load the shell dotfiles:
2+
for file in ~/.config/dotfiles/.{exports,functions,aliases,profile,path,prompt}; do
3+
[ -r "$file" ] && [ -f "$file" ] && source "$file";
4+
done;
5+
unset file;

.bashrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[ -n "$PS1" ] && source ~/.bash_profile;

.config/dotfiles/.aliases

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
#####################################################################################
4+
# SHORTCUTS
5+
#####################################################################################
6+
# paths
7+
alias ..='cd ..'
8+
alias ...='cd ../..'
9+
alias projectes='cd ~/Documents/projectes/'
10+
alias profile='s ~/.bash_profile'
11+
alias reload="source ~/.bash_profile"
12+
alias fuck='sudo $(history -p \!\!)' # add sudo to last command
13+
# make mv and rm a bit more safe
14+
alias mv='mv -i'
15+
alias rm='rm -i'
16+
# console
17+
alias ls="exa -l --git -h -g -a"
18+
alias lst="exa -l --git -h -g -a -T -L=2"
19+
alias host="sudo vi /etc/hosts"
20+
alias v="nvim"
21+
alias vi="nvim"
22+
alias s="code ."
23+
#weinre WEb INspector REmote
24+
alias weinreall="weinre -boundHost -all-"
25+
# Install npm plugins from package.json and save to devDependencies
26+
alias npmdev="npm install --save-dev"
27+
# Empty the Trash on all mounted volumes and the main HDD.
28+
# Also, clear Apple’s System Logs to improve shell startup speed.
29+
# Finally, clear download history from quarantine. https://mths.be/bum
30+
alias emptytrash="sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl; sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'"
31+
#####################################################################################
32+
# Git
33+
#####################################################################################
34+
alias tilde='/usr/bin/git --git-dir=/Users/zgtc/.config-tilde/ --work-tree=/Users/zgtc'
35+
alias gs="git status"
36+
alias gl="git log --pretty=format:'%Cgreen%h%Creset -%Creset %s%C(yellow)%d %Cblue(%aN, %cr)%Creset' --abbrev-commit --date=relative --first-parent"
37+
alias glg="git log --graph --pretty=format:'%Cgreen%h%Creset -%Creset %s%C(yellow)%d %Cblue(%aN, %cr)%Creset' --abbrev-commit --date=relative"
38+
alias gall="git add ."
39+
alias gback="git reset --soft HEAD~1 && git reset HEAD ."
40+
alias grall="git clean -df ." # removes all untracked files
41+
alias gp="git pull"
42+
alias gam="git commit -am"
43+
alias gpom="git push origin master"
44+
alias gpoh="git push origin HEAD"
45+
alias gc="git checkout"
46+
alias gcd="git checkout develop"
47+
alias gb="git branch --list -a"
48+
alias gg="git log --oneline --abbrev-commit --branches=* --graph --decorate --color"
49+
alias gatpc="git branch --merged | grep -Gv '*' | xargs git branch -d"

.config/dotfiles/.exports

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
#####################################################################################
4+
# EXPORTS
5+
#####################################################################################
6+
7+
export EDITOR="code -w"
8+
9+
# Increase Bash history size. Allow 32³ entries; the default is 500.
10+
export HISTSIZE='32768';
11+
export HISTFILESIZE="${HISTSIZE}";
12+
# Omit duplicates and commands that begin with a space from history.
13+
export HISTCONTROL='ignoreboth';

.config/dotfiles/.functions

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
3+
#####################################################################################
4+
# FUNCTIONS
5+
#####################################################################################
6+
7+
# Create a new directory and enter it
8+
function mkd() {
9+
mkdir -p "$@" && cd "$_";
10+
}
11+
12+
# Determine size of a file or total size of a directory
13+
function fs() {
14+
if du -b /dev/null > /dev/null 2>&1; then
15+
local arg=-sbh;
16+
else
17+
local arg=-sh;
18+
fi
19+
if [[ -n "$@" ]]; then
20+
du $arg -- "$@";
21+
else
22+
du $arg .[^.]* ./*;
23+
fi;
24+
}
25+
26+
# Create a data URL from a file
27+
function dataurl() {
28+
local mimeType=$(file -b --mime-type "$1");
29+
if [[ $mimeType == text/* ]]; then
30+
mimeType="${mimeType};charset=utf-8";
31+
fi
32+
echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')";
33+
}
34+
35+
# start quick server from folder
36+
function zerve() {
37+
python -m SimpleHTTPServer 7777
38+
}
39+
40+
# `o` with no arguments opens the current directory, otherwise opens the given
41+
# location
42+
function o() {
43+
if [ $# -eq 0 ]; then
44+
open .;
45+
else
46+
open "$@";
47+
fi;
48+
}
49+
50+
# youtube downloader
51+
# use: ytd video-url
52+
function ytd() {
53+
youtube-dl -f 'bestvideo+bestaudio/best/best' --merge-output-format mkv $1
54+
}
55+
56+
# only audio
57+
function ytda() {
58+
youtube-dl -x --audio-format flac $1
59+
}
60+
61+
# ffmpeg quick edits (remove n secs from start or end of file)
62+
# use: trims 100 'input-file.extension' 'output-file.extension'
63+
function trims(){ ffmpeg -ss $1 -i "$2" -c copy "$3"; }
64+
function trime(){ ffmpeg -ss 0 -t $1 -i "$2" -c copy "$3"; }

.config/dotfiles/.path

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#####################################################################################
2+
# PATH
3+
#####################################################################################
4+
5+
export PATH="$HOME/bin:$PATH"
6+
export homebrew="/usr/local/bin:/usr/local/sbin"
7+
export PATH="$homebrew:$PATH"
8+
export PATH="/usr/local/heroku/bin:$PATH"
9+
export PATH="/opt/anaconda2/bin:$PATH"
10+
export NVM_DIR="/Users/zgtc/.nvm"
11+
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

.config/dotfiles/.profile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
# Bash completion
4+
bind 'set completion-ignore-case on'
5+
shopt -s cdspell autocd histappend
6+
complete -d cd
7+
8+
# Bash Git completion
9+
gitcompletionpath="/usr/local/Cellar/git/2.7.4/etc/bash_completion.d/git-completion.bash"
10+
[[ -s $gitcompletionpath ]] && source $gitcompletionpath

.config/dotfiles/.prompt

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#!/usr/bin/env bash
2+
3+
#####################################################################################
4+
# COLORS & ICONS
5+
#####################################################################################
6+
# you might need to install icon fonts and make them available to terminal
7+
# https://github.com/gabrielelana/awesome-terminal-fonts/wiki/OS-X
8+
: ${os_icon:=''}
9+
: ${node_icon:=''}
10+
: ${branch_icon:=''}
11+
: ${clean_icon:=''}
12+
: ${merge_icon:=''}
13+
: ${ahead_icon:=''}
14+
: ${behind_icon:=''}
15+
: ${staged_icon:=''}
16+
: ${untracked_icon:=''}
17+
: ${alert_icon:=''}
18+
19+
Red="$(tput setaf 1)"
20+
Green="$(tput setaf 2)"
21+
Yellow="$(tput setaf 3)"
22+
Blue="$(tput setaf 4)"
23+
RESET="$(tput sgr0)"
24+
25+
#####################################################################################
26+
# PROMPT
27+
#####################################################################################
28+
dev_jump() {
29+
echo "\n ${Yellow}└─"
30+
}
31+
32+
dev_start() {
33+
echo "${Yellow}("
34+
}
35+
36+
dev_end() {
37+
echo "${Yellow})"
38+
}
39+
40+
# https://stackoverflow.com/a/24067243
41+
function version_gt() {
42+
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
43+
}
44+
45+
node_v() {
46+
if hash node 2>/dev/null; then
47+
nv=$(node -v | tr -d '[v]')
48+
fi
49+
50+
# do we have a .nvmrc to compare against
51+
if [ -r ".nvmrc" ] && [ -f ".nvmrc" ]; then
52+
expected="$(cat .nvmrc | tr -d '[:space:]' | tr -d '[v]')"
53+
if version_gt $expected $nv; then
54+
[ "$nv" != "" ] && echo -ne "${Red}${node_icon} ${nv}${alert_icon} "
55+
else
56+
[ "$nv" != "" ] && echo -ne "${Green}${node_icon} ${nv}"
57+
fi
58+
else
59+
[ "$nv" != "" ] && echo -ne "${Green}${node_icon} ${nv}"
60+
fi
61+
}
62+
63+
git_dirty() {
64+
local repo_status=$(git status 2>&1 | tail -n1)
65+
[[ $repo_status != "nothing to commit, working directory clean" ]] && echo " ${Red}*"
66+
}
67+
68+
git_branch() {
69+
# show either the branch name or the detached HEAD
70+
_branch="$(git symbolic-ref --short HEAD)"
71+
if [[ $_branch != "" ]]; then
72+
echo -ne "${Yellow} ${branch_icon}$_branch"
73+
else
74+
hd="$(git rev-parse --short HEAD | head -n 1)"
75+
echo -ne "${Red} ${branch_icon} detached HEAD $hd"
76+
fi
77+
}
78+
79+
staged() {
80+
count="$(git diff --cached --name-only | wc -l)"
81+
count=`echo $count | xargs`
82+
if [[ $count != "0" ]]; then
83+
echo -ne "${Green} ${staged_icon}${count}"
84+
else
85+
echo ""
86+
fi
87+
}
88+
89+
unstaged() {
90+
count="$(git diff --name-status | wc -l)"
91+
count=`echo $count | xargs`
92+
if [[ $count != "0" ]]; then
93+
echo -ne "${Red} ?${count}"
94+
else
95+
echo ""
96+
fi
97+
}
98+
99+
untracked() {
100+
count="$(git ls-files --others --exclude-standard | wc -l)"`echo $count | sed 's/ *$//g'`
101+
count=`echo $count | xargs`
102+
if [[ $count != "0" ]]; then
103+
echo -ne "${Red} ${untracked_icon}${count}"
104+
else
105+
echo ""
106+
fi
107+
}
108+
109+
behindahead() {
110+
# current branch name
111+
br="$(git rev-parse --abbrev-ref HEAD)"
112+
if [[ $br != "HEAD" ]]; then
113+
# check if remote 'origin' exists
114+
# yes, for simplicity we assume our remote is 'origin'
115+
r="$(git remote get-url origin 2>&1 | tail -n1)"
116+
if [[ $r != "fatal: No such remote 'origin'" ]]; then
117+
# check if remote branch exists
118+
# master & squashed branches compare to their remotes
119+
# all other branches compare to origin/develop
120+
if [[ $br != "master" ]] && [[ $br != "squashed" ]] && [[ $br != "develop" ]]; then
121+
rbr="develop"
122+
else
123+
rbr="${br}"
124+
fi
125+
126+
ub="$(git ls-remote --heads ${r} ${rbr} 2>&1 | sed -n 2p)"
127+
if [[ $ub != 0 ]] && [[ $ub != "fatal: Could not read from remote repository." ]]; then
128+
#echo "we have upstream branch in remote origin"
129+
upstream="origin/${rbr}"
130+
bh=`git rev-list ${br}..${upstream} --count `;
131+
bh=`echo $bh | xargs`
132+
ah=`git rev-list ${upstream}..${br} --count `;
133+
ah=`echo $ah | xargs`
134+
135+
if [[ $bh != "0" ]] || [[ $ah != "0" ]]; then
136+
if [[ $bh != "0" ]]; then
137+
echo -ne "${Red} ${merge_icon}"
138+
else
139+
echo -ne "${Green} ${merge_icon}"
140+
fi
141+
fi
142+
if [[ $bh != "0" ]]; then
143+
echo -ne "${Red} ${behind_icon}${bh}"
144+
fi
145+
if [[ $ah != "0" ]]; then
146+
echo -ne "${Green} ${ahead_icon}${ah}"
147+
fi
148+
if [[ $bh == "0" ]] && [[ $ah == "0" ]]; then
149+
echo -ne "${Green} ${clean_icon}"
150+
fi
151+
fi
152+
fi
153+
fi
154+
}
155+
156+
real_time_prompt() {
157+
PS1="\[\033]0;\W\007\]";
158+
PS1+="\n\[${os_icon}\] \u \[${Blue}\]\w "
159+
160+
# modify prompt adding development info if we are in a git repo folder
161+
if `git status &> /dev/null`; then
162+
PS1+="\[$(dev_jump)\]\[${Yellow}\]\[$(dev_start)\]"
163+
PS1+="\[$(node_v)\]"
164+
PS1+="\[$(git_branch)\]\[$(git_dirty)\]\[$(staged)\]\[$(unstaged)\]\[$(untracked)\]"
165+
166+
# show behind/ahead info if branches count>0 (maybe we just init'ed git repo)
167+
bc="$(git branch --list | wc -l | xargs)"
168+
if [[ $bc != "0" ]]; then
169+
PS1+="\[$(behindahead)\]"
170+
fi
171+
172+
PS1+="\[$(dev_end)\]"
173+
fi
174+
175+
PS1+="\[${RESET}\]$ "
176+
177+
export PS1
178+
}
179+
PROMPT_COMMAND='real_time_prompt'

.config/dotfiles/readme.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# dotfiles
2+
3+
I finally ordered my dotfiles a bit, making each file a bit smaller, moving to a config folder, etc.
4+
5+
Here's the current approach. `.bashr` just sources the profile:
6+
7+
```.bashrc
8+
[ -n "$PS1" ] && source ~/.bash_profile;
9+
```
10+
11+
In turn, `.bash_profile` loops through the dotfiles placed in `~/.config/.dotfiles` and source each of them:
12+
13+
```.bash_profile
14+
# Load the shell dotfiles:
15+
for file in ~/.config/.dotfiles/.{exports,functions,aliases,profile,path,prompt}; do
16+
[ -r "$file" ] && [ -f "$file" ] && source "$file";
17+
done;
18+
unset file;
19+
```

0 commit comments

Comments
 (0)