Update zsh directory structure
This commit is contained in:
parent
3cdbc7aa67
commit
2f99658289
20
zsh/plugins.d/cf.zsh
Normal file
20
zsh/plugins.d/cf.zsh
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Fuzzy cd from anywhere
|
||||||
|
# Dependencies
|
||||||
|
# - fzf
|
||||||
|
# - mlocate
|
||||||
|
cf() {
|
||||||
|
[[ -z "${*}" ]] && return 1
|
||||||
|
[[ ! -x /usr/bin/fzf ]] && return 1
|
||||||
|
|
||||||
|
dir="$(locate --all --ignore-case --null -- "${@}" | fzf --read0 --select-1 --exit-0)"
|
||||||
|
|
||||||
|
[[ -z "${dir}" ]] && return 1
|
||||||
|
|
||||||
|
if [[ -f "${dir}" ]]; then
|
||||||
|
cd "${dir%/*}"
|
||||||
|
else
|
||||||
|
cd "${dir}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
autoload -Uz cf
|
79
zsh/plugins.d/ef.zsh
Normal file
79
zsh/plugins.d/ef.zsh
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
# ef - fuzzy find a file and edit it
|
||||||
|
# Dependencies
|
||||||
|
# - fzf
|
||||||
|
# - mlocate
|
||||||
|
|
||||||
|
_ef_help() {
|
||||||
|
cat << done
|
||||||
|
Usage: ef [-h|--help] [-E|--editor editor] [patterns]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h print this help page
|
||||||
|
-E, --editor use a different editor (default: ${EDITOR:-none})
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
ef() {
|
||||||
|
# Pre-run correctness checks
|
||||||
|
editor=
|
||||||
|
file=
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
case "${1}" in
|
||||||
|
"-E"|"--editor")
|
||||||
|
case "${2}" in
|
||||||
|
""|-*)
|
||||||
|
printf '%s\n' "Not an editor or none entered" >&2
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
editor="${2}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift 2
|
||||||
|
continue
|
||||||
|
;;
|
||||||
|
--editor=*)
|
||||||
|
editor="${1#*=}"
|
||||||
|
[[ -z "${editor}" ]] && printf '%s\n' "Editor not entered" >&2 && return 1
|
||||||
|
shift
|
||||||
|
continue
|
||||||
|
;;
|
||||||
|
"-h"|"--help")
|
||||||
|
_ef_help
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
-?)
|
||||||
|
printf '%s\n' "Unknown option: ${1}" >&2
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -z "${editor:-${EDITOR}}" ]]; then
|
||||||
|
printf '%s\n' "No editor found" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
file="$(locate --all --ignore-case --null -- "${@}" | fzf --read0 --exit-0 --select-1 --no-mouse)"
|
||||||
|
|
||||||
|
if [[ -z "${file}" ]]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -w "${file}" ]]; then
|
||||||
|
"${editor:-${EDITOR}}" -- "${file}"
|
||||||
|
else
|
||||||
|
sudo --edit -- "${file}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#zle -N ef
|
||||||
|
#bindkey -M viins '^o' ef
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/bash
|
# call the fedit script
|
||||||
|
|
||||||
_etcedit() {
|
_etcedit() {
|
||||||
fedit -e
|
fedit -e
|
||||||
}
|
}
|
3
zsh/plugins.d/fless.zsh
Normal file
3
zsh/plugins.d/fless.zsh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# key bindings for fless script
|
||||||
|
zle -N fless
|
||||||
|
bindkey -M viins '^n' fless
|
8
zsh/plugins.d/mkcd.zsh
Normal file
8
zsh/plugins.d/mkcd.zsh
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Make a directory, then change into it
|
||||||
|
|
||||||
|
mkcd() {
|
||||||
|
[[ ! -d "${1}" ]] && mkdir --parents -- "${1}"
|
||||||
|
cd "${1}" || exit
|
||||||
|
}
|
||||||
|
|
||||||
|
autoload -Uz mkcd
|
Loading…
x
Reference in New Issue
Block a user