Guest User

Untitled

a guest
Nov 13th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. ## A workspace manager
  2.  
  3. : ${WS_CONFIG_DIR:=~/.config/ws}
  4.  
  5. ws_l () {
  6. for ws_file in "${WS_CONFIG_DIR}"/*.ws; do
  7. local ws_name="$(basename "$ws_file")"
  8. ws_name="${ws_name%.ws}"
  9. printf "%-10s\t%s\n" "$ws_name" "$(cat "${ws_file}")"
  10. done
  11. }
  12.  
  13.  
  14. ws_path () {
  15. printf '%s\n' "${WS_CONFIG_DIR}/${1}".ws
  16. }
  17.  
  18.  
  19. ws_check () {
  20. if (( $# != 1 )); then
  21. echo "missing workspace name" >&2
  22. return 1
  23. fi
  24.  
  25. if ! [ -f "$(ws_path "$1")" ]; then
  26. echo "workspace does not exist" >&2
  27. return 1
  28. fi
  29. }
  30.  
  31.  
  32. ws_n () {
  33. if (( $# < 1 )) || (( $# > 2 )); then
  34. echo "usage: ws n NAME [PATH]" >&2
  35. return
  36. fi
  37.  
  38. local name="$1"
  39. local target_path="$2"
  40. if [ -z "$target_path" ]; then
  41. path="$(pwd)"
  42. fi
  43.  
  44. printf '%s\n' "$target_path" > "$(ws_path "$name")"
  45. }
  46.  
  47. ws_g () {
  48. local target_path="$(ws_path "$1")"
  49. if ! [ -f "$target_path" ]; then
  50. echo "no such workspace" >&2
  51. fi
  52.  
  53. cd "$(cat "$target_path")"
  54. }
  55.  
  56. ws () {
  57. mkdir -p -- "${WS_CONFIG_DIR}"
  58. local sub_name="$1"
  59. shift
  60. ws_"${sub_name}" "$@"
  61. }
  62.  
  63. pgo () {
  64. ws g "$@"
  65. }
Add Comment
Please, Sign In to add comment