mirror of
https://github.com/chenasraf/dotfiles.git
synced 2026-05-17 17:28:07 +00:00
feat: mac/linux detection
This commit is contained in:
1
.zshrc
1
.zshrc
@@ -4,6 +4,7 @@ export DOTBIN="$DOTFILES/bin"
|
||||
source $DOTFILES/exports.sh # must run before zsh_init
|
||||
source $DOTFILES/zsh_init.sh
|
||||
source $DOTFILES/aliases.sh
|
||||
source $DOTFILES/functions.sh
|
||||
source $DOTFILES/sources.sh
|
||||
source $DOTFILES/scripts/home/home.sh
|
||||
|
||||
|
||||
47
aliases.sh
47
aliases.sh
@@ -52,50 +52,3 @@ alias unq="sudo xattr -rd com.apple.quarantine"
|
||||
alias h="home"
|
||||
alias rh="rhome"
|
||||
alias spider="ssh root@spider.casraf.dev"
|
||||
|
||||
motd() {
|
||||
if [[ -f /etc/motd.head ]]; then lolcat -f /etc/motd.head; fi
|
||||
uname -a
|
||||
if [[ -f /etc/motd ]]; then cat /etc/motd; fi
|
||||
}
|
||||
|
||||
docker-bash() {
|
||||
docker exec -ti $1 /bin/bash
|
||||
}
|
||||
|
||||
# Functions
|
||||
|
||||
# show all man entries under a specific section
|
||||
# e.g. mansect 7
|
||||
mansect() { man -aWS ${1?man section not provided} \* | xargs basename | sed "s/\.[^.]*$//" | sort -u; }
|
||||
|
||||
# TODO not working with custom commands...
|
||||
tcd() {
|
||||
source $HOME/.zshrc
|
||||
cd $1
|
||||
shift
|
||||
exec $@ 2>&1 | tee --
|
||||
# command "$@" 2>&1
|
||||
cd $OLDPWD
|
||||
}
|
||||
|
||||
# mkdir -p then navigate to said directory
|
||||
mkcd() {
|
||||
mkdir -p -- "$1" && cd -P -- "$1"
|
||||
}
|
||||
|
||||
listening() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
lsof -iTCP -sTCP:LISTEN -n -P
|
||||
elif [[ $# -eq 1 ]]; then
|
||||
lsof -iTCP -sTCP:LISTEN -n -P | grep -i --color $1
|
||||
else
|
||||
echo "Usage: listening [pattern]"
|
||||
fi
|
||||
}
|
||||
|
||||
# example echo '1' | prepend 'result: '
|
||||
prepend() {
|
||||
echo -n "$@"
|
||||
cat -
|
||||
}
|
||||
|
||||
72
functions.sh
Normal file
72
functions.sh
Normal file
@@ -0,0 +1,72 @@
|
||||
source $HOME/.dotfiles/colors.sh
|
||||
|
||||
motd() {
|
||||
if [[ -f /etc/motd.head ]]; then lolcat -f /etc/motd.head; fi
|
||||
uname -a
|
||||
if [[ -f /etc/motd ]]; then cat /etc/motd; fi
|
||||
}
|
||||
|
||||
docker-bash() {
|
||||
docker exec -ti $1 /bin/bash
|
||||
}
|
||||
|
||||
# Functions
|
||||
|
||||
# show all man entries under a specific section
|
||||
# e.g. mansect 7
|
||||
mansect() { man -aWS ${1?man section not provided} \* | xargs basename | sed "s/\.[^.]*$//" | sort -u; }
|
||||
|
||||
# TODO not working with custom commands...
|
||||
tcd() {
|
||||
source $HOME/.zshrc
|
||||
cd $1
|
||||
shift
|
||||
exec $@ 2>&1 | tee --
|
||||
# command "$@" 2>&1
|
||||
cd $OLDPWD
|
||||
}
|
||||
|
||||
# mkdir -p then navigate to said directory
|
||||
mkcd() {
|
||||
mkdir -p -- "$1" && cd -P -- "$1"
|
||||
}
|
||||
|
||||
listening() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
lsof -iTCP -sTCP:LISTEN -n -P
|
||||
elif [[ $# -eq 1 ]]; then
|
||||
lsof -iTCP -sTCP:LISTEN -n -P | grep -i --color $1
|
||||
else
|
||||
echo "Usage: listening [pattern]"
|
||||
fi
|
||||
}
|
||||
|
||||
# example echo '1' | prepend 'result: '
|
||||
prepend() {
|
||||
echo -n "$@"
|
||||
cat -
|
||||
}
|
||||
|
||||
lcase() {
|
||||
echo "$@" | tr '[:upper:]' '[:lower:]'
|
||||
}
|
||||
|
||||
int_res() {
|
||||
# get all but last
|
||||
c=$(($# - 1))
|
||||
out="$(lcase $(bash -c "${@:1:$c}"))"
|
||||
check="$(lcase ${@: -1})"
|
||||
if [[ $out =~ $check ]]; then
|
||||
echo 0
|
||||
else
|
||||
echo 1
|
||||
fi
|
||||
}
|
||||
|
||||
is_mac() {
|
||||
int_res "uname -s" "darwin"
|
||||
}
|
||||
|
||||
is_linux() {
|
||||
int_res "uname -s" "linux"
|
||||
}
|
||||
@@ -16,36 +16,36 @@ before running the supplied command
|
||||
|
||||
home takes one command:
|
||||
|
||||
git, g Run arbitrary git commands from .dotfiles directory
|
||||
git, g Run arbitrary git commands from .dotfiles directory
|
||||
|
||||
worflows, w Manage custom workflows for Alfred, keeping them in sync between dotfiles and external repository
|
||||
(if applicable).
|
||||
- Sub commands available: push, pull
|
||||
worflows, w Manage custom workflows for Alfred, keeping them in sync between dotfiles and external repository
|
||||
(if applicable).
|
||||
- Sub commands available: push, pull
|
||||
|
||||
motd, m Manage syncd MOTD (Message of the Day)
|
||||
- Sub commands available: restore, backup, edit, show
|
||||
motd, m Manage syncd MOTD (Message of the Day)
|
||||
- Sub commands available: restore, backup, edit, show
|
||||
|
||||
brew, b Use brew bundle to load or dump currently installed packages.
|
||||
Will read/write from Brewfile in .dotfiles directory
|
||||
- Subcommands: dump, restore.
|
||||
brew, b Use brew bundle to load or dump currently installed packages.
|
||||
Will read/write from Brewfile in .dotfiles directory
|
||||
- Subcommands: dump, restore.
|
||||
|
||||
brew, b Manage data for Dropzone installation.
|
||||
- Subcommands: dump, restore.
|
||||
brew, b Manage data for Dropzone installation.
|
||||
- Subcommands: dump, restore.
|
||||
|
||||
status, s See git status for dotfiles directory
|
||||
status, s See git status for dotfiles directory
|
||||
|
||||
push, p Add all files, commit and push updates to git. Supply commit msg as first arg or it will ask
|
||||
interactively.
|
||||
push, p Add all files, commit and push updates to git. Supply commit msg as first arg or it will ask
|
||||
interactively.
|
||||
|
||||
pull, l Pull updates from git and reload home
|
||||
pull, l Pull updates from git and reload home
|
||||
|
||||
reload, rz Reload (source) the current ZSH shell. Incrementally slower as you use it in same terminal.
|
||||
reload-term, rt Reload (source) the current ZSH shell. Incrementally slower as you use it in same terminal.
|
||||
|
||||
refresh, rh Refresh (source) only the home script and tools. Faster than reload.
|
||||
reload-home, rh Reload (source) only the home script and tools. Faster than reload-term.
|
||||
|
||||
install, i Install all settings files to their appropriate locations (e.g. MAN page, plugins, themes, bins, etc)
|
||||
install, i Install all settings files to their appropriate locations (e.g. MAN page, plugins, themes, bins, etc)
|
||||
|
||||
help, -h Dislpay help file
|
||||
help, -h Dislpay help file
|
||||
|
||||
.SH CUSTOM ALIASES
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
# OSX defaults overrides
|
||||
|
||||
__write_default() {
|
||||
if [[ $(is_mac) == "1" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
cmd=$1
|
||||
shift
|
||||
args=($@)
|
||||
|
||||
@@ -37,11 +37,11 @@ home() {
|
||||
reload-zsh
|
||||
__home_revert_dir
|
||||
;;
|
||||
reload | rz)
|
||||
reload-term | rt)
|
||||
reload-zsh
|
||||
return 0
|
||||
;;
|
||||
refresh | rh)
|
||||
reload-home | rh)
|
||||
source $DOTFILES/scripts/home/home.sh
|
||||
return 0
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user