Browse Source

git gud

pull/6/head
DanielFGray 4 years ago
parent
commit
c5b9b6cdba
7 changed files with 83 additions and 83 deletions
  1. 37
    37
      fv
  2. 4
    4
      fzmp
  3. 15
    15
      fzmv
  4. 4
    4
      goog
  5. 6
    6
      ix
  6. 12
    12
      pkgsearch
  7. 5
    5
      sshget

+ 37
- 37
fv View File

@@ -14,14 +14,14 @@ die() {
}

has() {
local verbose=false
local verbose=0
if [[ $1 == '-v' ]]; then
verbose=true
verbose=1
shift
fi
for c in "$@"; do c="${c%% *}"
for c; do c="${c%% *}"
if ! command -v "$c" &> /dev/null; then
[[ "$verbose" == true ]] && err "$c not found"
(( verbose > 0 )) && err "$c not found"
return 1
fi
done
@@ -48,9 +48,9 @@ set_cmd() {

declare cmd='vim'
declare cmdopts=()
declare searchstr=''
declare searchcmd=''
declare searchopts=()
declare search_str=''
declare search_cmd=''
declare search_opts=()
declare allfiles=0

while getopts "hadlc:" opt; do
@@ -59,7 +59,7 @@ while getopts "hadlc:" opt; do
a) allfiles=1 ;;
c) set_cmd "$OPTARG" ;;
d) unset detach ;;
l) searchopts+=( '-l' ) ;;
l) search_opts+=( '-l' ) ;;
esac
done
shift "$((OPTIND-1))"
@@ -68,73 +68,73 @@ has -v 'fzf' || die

for c in 'ag' 'ack' 'grep'; do
if has "$c"; then
searchcmd="$c"
search_cmd="$c"
break
fi
done

if [[ $searchcmd == 'grep' ]]; then
if [[ "$search_cmd" == 'grep' ]]; then
err 'grep is slow, you should strongly consider installing ag or ack'
sleep .5
fi

if [[ -n "$1" ]]; then
if [[ -d "$1" ]]; then
searchopts+=( "$1" )
search_opts+=( "$1" )
else
searchstr="$1"
search_str="$1"
fi
shift
fi

case "$searchcmd" in
case "$search_cmd" in
'ag')
searchopts+=( '--color' )
search_opts+=( '--color' )
if [[ "$allfiles" == 1 ]]; then
searchopts+=( '-u' '--hidden' )
search_opts+=( '-u' '--hidden' )
fi
if [[ "$searchstr" == '' ]]; then
searchopts+=( '-l' )
if [[ "$search_str" == '' ]]; then
search_opts+=( '-l' )
fi
;;
'ack')
if [[ "$searchstr" == '' ]]; then
if [[ "$search_str" == '' ]]; then
if [[ "$allfiles" == 0 ]]; then
searchopts+=( '-g' '^[^\.]' )
search_opts+=( '-g' '^[^\.]' )
else
searchopts+=( '-f' )
search_opts+=( '-f' )
fi
else
searchopts+=( '-l' )
# searchopts+=( '--match' )
search_opts+=( '-l' )
# search_opts+=( '--match' )
fi
;;
'grep')
searchopts+=( '-r' '-I' )
search_opts+=( '-r' '-I' )
if [[ "$allfiles" == 0 ]]; then
searchopts+=( '--exclude-dir=bower_components' )
searchopts+=( '--exclude-dir=node_modules' )
searchopts+=( '--exclude-dir=jspm_packages' )
searchopts+=( '--exclude-dir=.cvs' )
searchopts+=( '--exclude-dir=.git' )
searchopts+=( '--exclude-dir=.hg' )
searchopts+=( '--exclude-dir=.svn' )
search_opts+=( '--exclude-dir=bower_components' )
search_opts+=( '--exclude-dir=node_modules' )
search_opts+=( '--exclude-dir=jspm_packages' )
search_opts+=( '--exclude-dir=.cvs' )
search_opts+=( '--exclude-dir=.git' )
search_opts+=( '--exclude-dir=.hg' )
search_opts+=( '--exclude-dir=.svn' )
fi
if [[ "$searchstr" == '' ]]; then
searchopts+=( '' )
if [[ "$search_str" == '' ]]; then
search_opts+=( '' )
fi
;;
esac

if [[ "$searchstr" != '' ]]; then
searchopts+=( "$searchstr" )
if [[ "$search_str" != '' ]]; then
search_opts+=( "$search_str" )
fi

choices=$($searchcmd "${searchopts[@]}" 2> /dev/null |
choices=$($search_cmd "${search_opts[@]}" 2> /dev/null |
fzf --ansi --cycle --multi) || exit 1

if [[ "$searchstr" != '' ]]; then
if [[ $searchcmd == 'ag' ]]; then
if [[ "$search_str" != '' ]]; then
if [[ $search_cmd == 'ag' ]]; then
choices=$(cut -d: -f1 <<< "$choices")
fi
fi

+ 4
- 4
fzmp View File

@@ -53,14 +53,14 @@ die() {
}

has() {
local verbose=false
local verbose=0
if [[ $1 == '-v' ]]; then
verbose=true
verbose=1
shift
fi
for c in "$@"; do c="${c%% *}"
for c; do c="${c%% *}"
if ! command -v "$c" &> /dev/null; then
[[ "$verbose" == true ]] && err "$c not found"
(( verbose > 0 )) && err "$c not found"
return 1
fi
done

+ 15
- 15
fzmv View File

@@ -16,14 +16,14 @@ die() {
}

has() {
local verbose=false
local verbose=0
if [[ $1 == '-v' ]]; then
verbose=true
verbose=1
shift
fi
for c in "$@"; do c="${c%% *}"
for c; do c="${c%% *}"
if ! command -v "$c" &> /dev/null; then
[[ "$verbose" == true ]] && err "$c not found"
(( verbose > 0 )) && err "$c not found"
return 1
fi
done
@@ -53,25 +53,25 @@ pick_files() {
}

pick_destination() {
local cwd browsedir browseinfo query dirs
local cwd browse_dir browse_info query dirs
cwd=$(pwd)
while [[ "$browsedir" != "$cwd" ]]; do
while [[ "$browse_dir" != "$cwd" ]]; do
dirs=$( (echo '..'; find -maxdepth 1 -type d 2> /dev/null ) |
sed 's|./||' |
sort -h)
mapfile -t browseinfo < <(
mapfile -t browse_info < <(
fzf --print-query \
--history="${HOME}/.cache/fzmv_history" \
--header="${errors:-move files here}" <<< "$dirs")
query=${browseinfo[0]}
browsedir=${browseinfo[1]}
[[ -d "$query" ]] && browsedir="$query"
[[ ! -d "$browsedir" ]] && return 1
if [[ "$browsedir" == '.' && $(realpath "$browsedir") != "$cwd" ]]; then
realpath "$browsedir"
query=${browse_info[0]}
browse_dir=${browse_info[1]}
[[ -d "$query" ]] && browse_dir="$query"
[[ ! -d "$browse_dir" ]] && return 1
if [[ "$browse_dir" == '.' && $(realpath "$browse_dir") != "$cwd" ]]; then
realpath "$browse_dir"
break
else
cd "$browsedir" || die
cd "$browse_dir" || die
continue
fi
done
@@ -80,7 +80,7 @@ pick_destination() {
while (( $# > 0 )); do
case $1 in
-t|--test) dryrun=true ;;
-v|--verbose) verbose=true ;;
-v|--verbose) verbose=1 ;;
esac
shift
done

+ 4
- 4
goog View File

@@ -14,14 +14,14 @@ die() {
}

has() {
local verbose=false
local verbose=0
if [[ $1 == '-v' ]]; then
verbose=true
verbose=1
shift
fi
for c in "$@"; do c="${c%% *}"
for c; do c="${c%% *}"
if ! command -v "$c" &> /dev/null; then
[[ "$verbose" == true ]] && err "$c not found"
(( verbose > 0 )) && err "$c not found"
return 1
fi
done

+ 6
- 6
ix View File

@@ -27,14 +27,14 @@ die() {
}

has() {
local verbose=false
local verbose=0
if [[ $1 == '-v' ]]; then
verbose=true
verbose=1
shift
fi
for c in "$@"; do c="${c%% *}"
for c; do c="${c%% *}"
if ! command -v "$c" &> /dev/null; then
[[ "$verbose" == true ]] && err "$c not found"
(( verbose > 0 )) && err "$c not found"
return 1
fi
done
@@ -42,7 +42,7 @@ has() {

select-from() {
local cmd='command -v'
for a in "$@"; do
for a; do
case "$a" in
-c)
cmd="$2"
@@ -50,7 +50,7 @@ select-from() {
;;
esac
done
for c in "$@"; do
for c; do
if $cmd "${c%% *}" &> /dev/null; then
echo "$c"
return 0

+ 12
- 12
pkgsearch View File

@@ -29,22 +29,22 @@ die() {
}

has() {
local verbose=false
local verbose=0
if [[ $1 == '-v' ]]; then
verbose=true
verbose=1
shift
fi
for c in "$@"; do c="${c%% *}"
for c; do c="${c%% *}"
if ! command -v "$c" &> /dev/null; then
[[ "$verbose" == true ]] && err "$c not found"
(( "$verbose" > 0 )) && err "$c not found"
return 1
fi
done
}

select-from() {
select_from() {
local cmd='command -v'
for a in "$@"; do
for a; do
case "$a" in
-c)
cmd="$2"
@@ -52,7 +52,7 @@ select-from() {
;;
esac
done
for c in "$@"; do
for c; do
if $cmd "${c%% *}" &> /dev/null; then
echo "$c"
return 0
@@ -86,13 +86,13 @@ debian() {
< <(apt-cache search '' | sort |
sed -u -r "s|^([^ ]+)|${c_green}\1${c_reset}|") |
cut -d' ' -f1 |
install "sudo $(select-from 'apt' 'aptitude' 'apt-get') install"
install "sudo $(select_from 'apt' 'aptitude' 'apt-get') install"
}

arch() {
local search packages
search='pacman'
[[ -n "$1" ]] && search=$(select-from 'pacaur' 'yaourt' 'packer' 'apacman' 'pacman')
[[ -n "$1" ]] && search=$(select_from 'pacaur' 'yaourt' 'packer' 'apacman' 'pacman')
packages=$(fzf --bind="Ctrl-X:execute[
p=\$(cut -d' ' -f2 <<< {});
less < <($search -Si \$p) > /dev/tty]" \
@@ -111,11 +111,11 @@ arch() {
}

void() {
local packagelist packagename='{ sub(/-[^\-]*$/, "", $2); print $2 }'
packagelist=$(xbps-query -Rs '' | sort)
local package_list packagename='{ sub(/-[^\-]*$/, "", $2); print $2 }'
package_list=$(xbps-query -Rs '' | sort)
fzf --bind="Ctrl-X:execute[
p=\$(awk \"$packagename\" <<< {});
less < <(xbps-query -Rx \$p) > /dev/tty]" <<< "$packagelist" |
less < <(xbps-query -Rx \$p) > /dev/tty]" <<< "$package_list" |
awk "$packagename" |
install 'xbps-install -S'
}

+ 5
- 5
sshget View File

@@ -24,14 +24,14 @@ HELP
}

has() {
local verbose=false
local verbose=0
if [[ $1 == '-v' ]]; then
verbose=true
verbose=1
shift
fi
for c in "$@"; do c="${c%% *}"
for c; do c="${c%% *}"
if ! command -v "$c" &> /dev/null; then
[[ "$verbose" == true ]] && err "$c not found"
(( verbose > 0 )) && err "$c not found"
return 1
fi
done
@@ -51,7 +51,7 @@ if (( $# < 1 )); then
die
fi

for a in "$@"; do
for a; do
host="${a%:*}"
path="${a##*:}"
domains+=( ["$a"]="$host" )

Loading…
Cancel
Save