Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## A workspace manager
- : ${WS_CONFIG_DIR:=~/.config/ws}
- ws_l () {
- for ws_file in "${WS_CONFIG_DIR}"/*.ws; do
- local ws_name="$(basename "$ws_file")"
- ws_name="${ws_name%.ws}"
- printf "%-10s\t%s\n" "$ws_name" "$(cat "${ws_file}")"
- done
- }
- ws_path () {
- printf '%s\n' "${WS_CONFIG_DIR}/${1}".ws
- }
- ws_check () {
- if (( $# != 1 )); then
- echo "missing workspace name" >&2
- return 1
- fi
- if ! [ -f "$(ws_path "$1")" ]; then
- echo "workspace does not exist" >&2
- return 1
- fi
- }
- ws_n () {
- if (( $# < 1 )) || (( $# > 2 )); then
- echo "usage: ws n NAME [PATH]" >&2
- return
- fi
- local name="$1"
- local target_path="$2"
- if [ -z "$target_path" ]; then
- path="$(pwd)"
- fi
- printf '%s\n' "$target_path" > "$(ws_path "$name")"
- }
- ws_g () {
- local target_path="$(ws_path "$1")"
- if ! [ -f "$target_path" ]; then
- echo "no such workspace" >&2
- fi
- cd "$(cat "$target_path")"
- }
- ws () {
- mkdir -p -- "${WS_CONFIG_DIR}"
- local sub_name="$1"
- shift
- ws_"${sub_name}" "$@"
- }
- pgo () {
- ws g "$@"
- }
Add Comment
Please, Sign In to add comment