shell functions
This commit is contained in:
parent
9584c63aa2
commit
32506837ad
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
if [ "$#" -ne 1 ]; then
|
if [ "$#" -ne 1 ]; then
|
||||||
echo "usage: $0 <file>"
|
echo "usage: ${0##*/} <file>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ _load history
|
||||||
_load aliases
|
_load aliases
|
||||||
# set xdg env vars to keep home directory clean
|
# set xdg env vars to keep home directory clean
|
||||||
_load xdg
|
_load xdg
|
||||||
|
_load show
|
||||||
|
|
||||||
if _exists fzf; then
|
if _exists fzf; then
|
||||||
export FZF_DEFAULT_OPTS="--bind=ctrl-u:page-up,ctrl-d:page-down"
|
export FZF_DEFAULT_OPTS="--bind=ctrl-u:page-up,ctrl-d:page-down"
|
||||||
|
|
|
||||||
32
user/config/bash/show
Normal file
32
user/config/bash/show
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
function show() {
|
||||||
|
if [[ "$#" -ne 1 ]]; then
|
||||||
|
echo "usage: show <prog>" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
case "$(type -t "$1")" in
|
||||||
|
alias)
|
||||||
|
alias "$1" | bat -pl sh ;;
|
||||||
|
keyword|builtin)
|
||||||
|
help "$1" ;;
|
||||||
|
function)
|
||||||
|
declare -f "$1" | bat -l sh ;;
|
||||||
|
file)
|
||||||
|
local path="$(which "$1")"
|
||||||
|
local real="$(realpath "$path")"
|
||||||
|
[[ "$path" != "$real" ]] && echo "$path"
|
||||||
|
bat "$real" ;;
|
||||||
|
"")
|
||||||
|
echo "$1 doesn't exist" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
function goto() {
|
||||||
|
if [[ "$#" -ne 1 ]]; then
|
||||||
|
echo "usage: goto <prog>" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
local path="$(which "$1")"
|
||||||
|
[[ -z "$path" ]] && return 2
|
||||||
|
local real="$(realpath "$path")"
|
||||||
|
cd "${real%/*}"
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue