├── README.md └── install.sh /README.md: -------------------------------------------------------------------------------- 1 | # Portalize 2 | 3 | A simple shell alias to make portals 🧙 4 | 5 | ![Runescape tablet teleport animation](https://oldschool.runescape.wiki/images/1/1a/Teleport_Tablet.gif) 6 | 7 | ## How it works? 8 | 9 | It's a very simple alias that allows you to create alias for your current directory. 10 | 11 | Several times we need to go from a different directory path to another as well as when you change the project that you are working, or needs to go working on a very deep directory path. 12 | 13 | We make it easy to you with `portalize`. 14 | 15 | ## Install 16 | 17 | Execute on your shell: 18 | 19 | ```sh 20 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/dapx/portalize/master/install.sh)" 21 | . ~/.portals # Load portals after install, or you can simply start a new shell session. 22 | ``` 23 | 24 | ## How to create portals? 25 | 26 | Create a portal is easy peasy: 27 | 28 | ```sh 29 | cd project/directory 30 | portalize aliasname 31 | ``` 32 | 33 | After that you can call the alias from any place: 34 | 35 | ```sh 36 | aliasname 37 | ``` 38 | 39 | And you will be teleported to there. 40 | 41 | ## How to list portals 42 | 43 | Call the `portals` alias and it will list all portals ordered by creation: 44 | 45 | ```sh 46 | portals 47 | ``` 48 | 49 | You can also compose with `sort` to list all portals ordered by name: 50 | 51 | ```sh 52 | portals | sort 53 | ``` 54 | 55 | ## How to remove portals 56 | 57 | Call the `unportalize` alias from any place passing the alias name that you want to remove: 58 | 59 | ```sh 60 | unportalize aliasname 61 | ``` 62 | 63 | ## How to uninstall 64 | 65 | Remove the portal alias file load command from your rc file: 66 | 67 | ```sh 68 | printf "%s\n" "g/^\. ~\/\.portals$/d" w | ed -s ~/.$(basename $SHELL)rc 69 | ``` 70 | 71 | And if don't want to maintain your portals saved, you can simply remove the `~/.portals` file: 72 | 73 | ```sh 74 | rm ~/.portals 75 | ``` 76 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | rc_filename=".$(basename $SHELL)rc" 3 | portals_filename=".portals" 4 | 5 | portals_alias="alias portals='sed \"/^alias portals/d; /^alias portalize/d; /^alias unportalize/d; s/alias //g; s/=/ /g\" ~/$portals_filename'" 6 | portalize_function_alias="alias portalize='make_portal() { echo alias \$1=\$PWD >> ~/$portals_filename; unset -f make_portal; . ~/$portals_filename }; make_portal'" 7 | unportalize_function_alias="alias unportalize='destroy_portal() { printf \"%s\\\\n\" \"g/alias \$1=/d\" w | ed -s ~/$portals_filename; unalias \$1; unset -f destroy_portal; . ~/$portals_filename }; destroy_portal'" 8 | 9 | add_text_to_file_if_not_exists() { 10 | text=$1 11 | file=$2 12 | grep -qxF "$text" $file || echo $text >> $file 13 | unset text file 14 | } 15 | 16 | remove_alias() { 17 | # Uses printf with ed 18 | # 'cause the default 'sed -i' is different between Linux and BSD like. 19 | printf "%s\n" "g/alias $1=/d" w | ed -s ~/$portals_filename &>/dev/null 20 | } 21 | 22 | add_text_to_file_if_not_exists ". ~/$portals_filename" ~/$rc_filename 23 | 24 | remove_alias portals 25 | remove_alias portalize 26 | remove_alias unportalize 27 | 28 | echo $portals_alias >> ~/$portals_filename 29 | echo $portalize_function_alias >> ~/$portals_filename 30 | echo $unportalize_function_alias >> ~/$portals_filename 31 | 32 | unset portals_alias portalize_function_alias unportalize_function_alias rc_filename portals_filename 33 | --------------------------------------------------------------------------------