-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
200 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function bak | ||
if [ (count $argv) -ne 1 ] | ||
echo "1 path must be supplied" | ||
return 1 | ||
end | ||
set file (basename $argv[1] '.bak') | ||
set other "$file.bak" | ||
if test -e $argv[1] | ||
if test -e $other | ||
mv $argv[1] $other.tmp | ||
mv $other $argv[1] | ||
mv $other.tmp $other | ||
else | ||
mv $argv[1] $other | ||
end | ||
else | ||
if test -e $other | ||
mv $other $argv[1] | ||
else | ||
echo "Neither $argv[1] nor $other exist" | ||
return 1 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function cd --description 'change directory and run onefetch if a git directory' | ||
set -l parent | ||
|
||
# navigate to root of git repo | ||
if [ $argv = ":/" ] | ||
set -l top (command git rev-parse --show-cdup) | ||
builtin cd $top | ||
# check if cd to file and route to parent | ||
else if [ -f $argv ] && [ -e $argv ] | ||
set parent (dirname $argv) | ||
if [ "$parent" != . ] && [ -d "$parent" ] | ||
builtin cd "$parent" | ||
end | ||
# if navigating to a directory, cd as usual | ||
else if [ -d $argv ] | ||
if test -n "$argv" && | ||
builtin cd "$argv" | ||
else | ||
builtin cd | ||
end | ||
end | ||
|
||
# check for git information | ||
git rev-parse 2>/dev/null | ||
|
||
if test $status -eq 0 | ||
if test -z "$LAST_REPO" -o "$LAST_REPO" != $(basename $(git rev-parse --show-toplevel)) | ||
onefetch | ||
set -g LAST_REPO $(basename $(git rev-parse --show-toplevel)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
function ex | ||
if test -f $argv[1] | ||
set filename (basename $argv[1]) | ||
set foldername (echo $filename | sed 's/\.[^.]*$//') | ||
mkdir -p $foldername | ||
switch $argv[1] | ||
case '*.tar.bz2' | ||
tar xjf $argv[1] -C $foldername | ||
case '*.tar.gz' | ||
tar xzf $argv[1] -C $foldername | ||
case '*.bz2' | ||
bunzip2 -k $argv[1] | ||
mv (basename $argv[1] .bz2) ./$foldername/ | ||
case '*.rar' | ||
unrar x $argv[1] ./$foldername/ | ||
case '*.gz' | ||
gunzip -k $argv[1] | ||
mv (basename $argv[1] .gz) ./$foldername/ | ||
case '*.tar' | ||
tar xf $argv[1] -C ./$foldername/ | ||
case '*.tbz2' | ||
tar xjf $argv[1] -C ./$foldername/ | ||
case '*.tgz' | ||
tar xzf $argv[1] -C ./$foldername/ | ||
case '*.zip' | ||
unzip -d ./$foldername/ "$filename" | ||
case '*.Z' | ||
uncompress "$filename" | ||
mv (basename "$filename" ".Z") "./$foldername/" | ||
case '*.7z' | ||
7z x "$filename" "-o./$foldername/" | ||
otherwise | ||
echo "'$filename' cannot be extracted via ex()" | ||
end | ||
else | ||
echo "'$filename' is not a valid file" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Add custom git extensions | ||
function git | ||
set -l code | ||
|
||
# Truncate long lines in git grep | ||
if test "$argv[1]" = grep | ||
|
||
if ! command -v perl &>/dev/null | ||
command git $argv | ||
return | ||
end | ||
|
||
command git -c color.ui=always $argv | perl -pe 'my $truncate = 500; (my $blank = $_) =~ s/\e\[[^m]*m//g; if (length $blank > $truncate) { | ||
s/^((?:(?:\e\[[^m]*m)+(?:.|$)|.(?:\e\[[^m]*m)*|$(*SKIP)(*FAIL)){$truncate})(?=(?:(?:\e\[[^m]*m)+(?:.|$)|.(?:\e\[[^m]*m)*|$(*SKIP)(*FAIL)){15}).*/$1\e\[m...(truncated)/ | ||
}' | ||
|
||
return | ||
end | ||
|
||
# Prevent accidental git commit -a | ||
if test "$argv[1]" = commit && contains -- "$argv[2]" -a | ||
if ! command git diff-index --cached --quiet HEAD -- && ! command git diff-files --quiet | ||
|
||
echo >&2 '\e[0;31mERROR!\e[0m Changes are already staged. Preventing git commit -a' | ||
echo >&2 '\e[0;31mERROR!\e[0m Run git commit without -a or run git reset HEAD first' | ||
|
||
return 1 | ||
end | ||
end | ||
|
||
# forward original git command | ||
if test -n "$argv" | ||
command git $argv | ||
else | ||
command git | ||
end | ||
|
||
# record command exit code | ||
set code $status | ||
|
||
# output commit length if successful | ||
if test "$argv[1]" = commit && ! code | ||
printf 'Commit subject length: ' | ||
command git log -1 --format="%s" | tr -d '\n' | wc -m | awk '{print $1}' | ||
end | ||
|
||
# return original exit code | ||
return $code | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function load_ssh | ||
if status is-login | ||
and status is-interactive | ||
# To add a key, set -Ua SSH_KEYS_TO_AUTOLOAD keypath | ||
# To remove a key, set -U --erase SSH_KEYS_TO_AUTOLOAD[index_of_key] | ||
set -Ua SSH_KEYS_TO_AUTOLOAD ~/.ssh/id_rsa | ||
keychain -q -Q --eval $SSH_KEYS_TO_AUTOLOAD | source | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function mkcd | ||
mkdir -p $argv | ||
cd $argv | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function mvcd -d "Moves files and directories and changes the current directory" | ||
if test (count $argv) -gt 1 | ||
mkdir -p $argv[2] | ||
mv $argv[1] $argv[2] | ||
cd $argv[2] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function nixify | ||
if not test -e ./.envrc | ||
echo "use nix" >.envrc | ||
direnv allow | ||
end | ||
if not test -e shell.nix -a ! -e default.nix | ||
set code 'with import <nixpkgs> {}; | ||
mkShell { | ||
nativeBuildInputs = [ | ||
bashInteractive | ||
]; | ||
}' | ||
echo $code | sed "s/'/'\\\\''/g" | xargs echo >default.nix | ||
eval (env $EDITOR "default.nix") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters