├── .gitignore ├── README.md ├── tasks ├── _config ├── ling-personal-tasks │ ├── bnb │ │ ├── universe-import-as-dir.sh │ │ └── universe-import-as-symlink.sh │ ├── explorer │ │ └── sync-explorer-script.sh │ ├── kamille │ │ ├── pack-modules.php │ │ ├── pack-modules.sh │ │ ├── pack-widgets.php │ │ ├── pack-widgets.sh │ │ ├── prepare-modules-for-export.sh │ │ ├── prepare-widgets-for-export.sh │ │ └── prepareForExport.php │ ├── nullos │ │ ├── crud-gen-list-and-forms.sh │ │ ├── icons.sh │ │ ├── import-nullos-planets-dirs.sh │ │ ├── import-nullos-planets-symlinks.sh │ │ ├── php-log.sh │ │ └── push-nullos.sh │ ├── oui │ │ ├── db-distant-update.sh │ │ ├── git-upload-with-nullos.sh │ │ └── git-upload.sh │ ├── universe │ │ ├── import-universe.sh │ │ └── push-universe.sh │ ├── zilu │ │ ├── planets-to-dirs.sh │ │ └── planets-to-symlinks.sh │ └── zuk │ │ ├── planets-to-dirs.sh │ │ └── planets-to-symlinks.sh ├── my-website │ ├── example-db-distant-update.sh │ ├── git-upload.sh │ └── php-log.sh └── universe │ └── push-universe.sh └── tm.sh /.gitignore: -------------------------------------------------------------------------------- 1 | private 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Task manager 2 | ===================== 3 | 2016-10-20 4 | 5 | 6 | 7 | 8 | A task manager for your daily tasks. 9 | 10 | 11 | 12 | 13 | Note: works better with bash 4 (I had problems with bash 3.2 which wouldn't display color codes correctly). 14 | 15 | 16 | 17 | 18 | 19 | What is it? 20 | ------------------------- 21 | 22 | Task manager helps you organize your tasks. 23 | 24 | - put all your tasks in the same directory 25 | - navigate your scripts structure via a simple gui interface 26 | - execute your scripts via the simple gui interface 27 | 28 | 29 | The simple benefits are: 30 | 31 | - it's easy to call a task 32 | - to reorganize the task structure, just reorganize the file structure 33 | 34 | 35 | 36 | 37 | How does it work? 38 | ---------------------- 39 | 40 | You create a tasks folder in your home and put all your scripts in it. 41 | 42 | You can create subdirectories, which represents categories of tasks. 43 | 44 | Then you launch taskmanager 45 | 46 | ```bash 47 | tm 48 | ``` 49 | 50 | It will list the items (directories or tasks) in the tasks directory (direct children) and associate them with one number for you to pick. 51 | 52 | 53 | - select a directory item to list the content of that directory. This is a recursive process 54 | - select a task item to execute the script 55 | 56 | 57 | 58 | 59 | 60 | Ideas for organizing your tasks 61 | ------------------------------------------ 62 | 63 | 64 | 65 | ### per task style 66 | 67 | - cd/ 68 | - nginx conf dir 69 | - php conf dir 70 | - php-fpm conf dir 71 | - mySite home 72 | - mySite2 home 73 | - edit/ 74 | - nginx conf 75 | - php conf 76 | - php-fpm conf 77 | - mySite index 78 | - mySite xxx script 79 | - tail/ 80 | - nginx error logs 81 | - nginx access logs 82 | - mySite nginx access logs 83 | - mySite nginx error logs 84 | - mySite/ 85 | - show last 50 entries of the database 86 | - validate last entries in the database 87 | - validator script 88 | - backups 89 | - backup mySite 90 | - backup mySite2 91 | - others 92 | - todo list 93 | - exit 94 | 95 | 96 | ### per site style 97 | 98 | - open/ 99 | - nginx conf dir 100 | - nginx conf 101 | - php conf dir 102 | - php conf 103 | - php-fpm conf dir 104 | - php-fpm conf 105 | - tail/ 106 | - nginx error logs 107 | - nginx access logs 108 | - mySite/ 109 | - show last 50 entries of the database 110 | - validate last entries in the database 111 | - validator script 112 | - open mySite index 113 | - open mySite xxx script 114 | - mySite nginx access logs 115 | - mySite nginx error logs 116 | - backup mySite 117 | - others 118 | - todo list 119 | - exit 120 | 121 | 122 | 123 | 124 | The different types of task items 125 | ---------------------------------------- 126 | 127 | There are four types of task items that you can create, differentiated by their file extension: 128 | 129 | - sh: the item is executed in a subshell 130 | - source: the item is sourced from the current shell 131 | - loc: the file contains a path for task manager to cd into 132 | - edit: the file contains a path for task manager to open (with the configured editor, vim by default) 133 | 134 | 135 | Once the task item is executed, task manager exits. 136 | 137 | Note: If a task is of type sh, and it's not executable yet, task manager will automatically ask you can make it you want to make it executable, thus saving you to type a chmod command. 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | Install 147 | -------------- 148 | 149 | The goal is that when you type tm in a terminal, it sources the task manager. 150 | 151 | Sourcing is required (just executing the task manager is not enough) to allow operations like changing the current directory of the current shell. 152 | 153 | 154 | 1. Download the tm.sh script. 155 | 156 | 2. Create the alias. 157 | Open your .bashrc (linux) or .bash_profile (mac) and add the following line: 158 | 159 | ```bash 160 | alias tm='source "/path/to/tm.sh"' 161 | ``` 162 | 163 | 164 | 165 | 166 | 167 | 168 | Configuration 169 | ------------------ 170 | 171 | You can change taskManager's behaviour by creating a _config file at the tasks directory's root. 172 | The _config file consists of a list of key=value pairs, one per line. 173 | 174 | The available key/value pairs are located at the beginning of the tm.sh script, in the "VARS FOR USER" section. 175 | 176 | You can override a lot of the visual aspect of task manager. 177 | 178 | So for instance, to override the default banner text (Welcome to Task Manager), 179 | add the following in your _config file. 180 | 181 | ```bash 182 | BANNER="Yo, I'm the TaskManager, what's up?" 183 | ``` 184 | 185 | An useful key is the TM_EDITOR key, which defines the editor to open the .edit files. 186 | 187 | The default value is vim, but you can set it to pico, emacs or any other editor. 188 | 189 | 190 | 191 | 192 | 193 | Nomenclature 194 | ------------------ 195 | 196 | A taskManager displays a **list** of **items**. 197 | 198 | An **item** can be either a **task** item or a **directory** item. 199 | 200 | 201 | 202 | 203 | Example tasks 204 | ---------------- 205 | 206 | Look inside the [tasks](https://github.com/lingtalfi/task-manager/tree/master/tasks) directory to find some example tasks, amongst which 207 | 208 | - example-db-distant-update.sh: exports a local database to a remote server (one liner) 209 | 210 | 211 | 212 | 213 | 214 | 215 | -------------------------------------------------------------------------------- /tasks/_config: -------------------------------------------------------------------------------- 1 | BANNER="Welcome to my Task Manager" -------------------------------------------------------------------------------- /tasks/ling-personal-tasks/bnb/universe-import-as-dir.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | 4 | 5 | 6 | php -f "/pathto/bnb-test/app/scripts/universe-import.php" -- -d -------------------------------------------------------------------------------- /tasks/ling-personal-tasks/bnb/universe-import-as-symlink.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | 4 | 5 | 6 | php -f "/pathto/bnb-test/app/scripts/universe-import.php" -------------------------------------------------------------------------------- /tasks/ling-personal-tasks/explorer/sync-explorer-script.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | 4 | 5 | fileA="/pathto/php/projects/universe/planets/Explorer/Explorer" 6 | fileB="/pathto/php/projects/universe/planets/Explorer/Importer" 7 | fileC="/pathto/php/projects/universe/planets/Explorer/Log" 8 | fileD="/pathto/php/projects/universe/planets/Explorer/Util" 9 | fileE="/pathto/php/projects/universe/planets/Explorer/explorer-script/explorer.php" 10 | 11 | 12 | 13 | cd "/pathto/php/projects/universe/planets/Explorer/explorer-script" 14 | 15 | cp "$fileE" . 16 | cd pack 17 | rm -r Explorer 18 | mkdir Explorer 19 | cd Explorer 20 | cp -r "$fileA" . 21 | cp -r "$fileB" . 22 | cp -r "$fileC" . 23 | cp -r "$fileD" . 24 | 25 | 26 | 27 | cd "/me/explorer-script" 28 | 29 | 30 | cp "$fileE" . 31 | cd pack 32 | rm -r Explorer 33 | mkdir Explorer 34 | cd Explorer 35 | cp -r "$fileA" . 36 | cp -r "$fileB" . 37 | cp -r "$fileC" . 38 | cp -r "$fileD" . 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /tasks/ling-personal-tasks/kamille/pack-modules.php: -------------------------------------------------------------------------------- 1 | set('appDir', $appDir)); 22 | 23 | 24 | 25 | $packer->pack("Authenticate"); 26 | $packer->pack("Core"); 27 | 28 | 29 | -------------------------------------------------------------------------------- /tasks/ling-personal-tasks/kamille/pack-modules.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | php -f "/mytasks/kamille/pack-modules.php" -------------------------------------------------------------------------------- /tasks/ling-personal-tasks/kamille/pack-widgets.php: -------------------------------------------------------------------------------- 1 | set('appDir', $appDir)); 18 | 19 | 20 | 21 | 22 | $packer->pack("Notification"); 23 | -------------------------------------------------------------------------------- /tasks/ling-personal-tasks/kamille/pack-widgets.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | php -f "/mytasks/kamille/pack-widgets.php" -------------------------------------------------------------------------------- /tasks/ling-personal-tasks/kamille/prepare-modules-for-export.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | php -f "/mytasks/kamille/prepareForExport.php" -- module -------------------------------------------------------------------------------- /tasks/ling-personal-tasks/kamille/prepare-widgets-for-export.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | php -f "/mytasks/kamille/prepareForExport.php" -- widget -------------------------------------------------------------------------------- /tasks/ling-personal-tasks/kamille/prepareForExport.php: -------------------------------------------------------------------------------- 1 | "; 30 | $itemsDir = 0; 31 | $appItemsDir = 0; 32 | switch ($itemType) { 33 | case 'widget': 34 | $itemsDir = "/myphp/kamille-widgets"; 35 | $appItemsDir = $appDir . "/class-widgets"; 36 | break; 37 | case 'module': 38 | $itemsDir = "/myphp/kamille-modules"; 39 | $appItemsDir = $appDir . "/class-modules"; 40 | break; 41 | default: 42 | throw new \Exception("Unknown item type: $itemType"); 43 | break; 44 | } 45 | 46 | 47 | function copyDirExceptGit($srcDir, $dstDir) 48 | { 49 | WithFilterCopyDirUtil::create() 50 | ->setFilter(function ($baseName) { 51 | if (0 === strpos($baseName, ".")) { 52 | return false; 53 | } 54 | return true; 55 | }) 56 | ->copyDir($srcDir, $dstDir); 57 | } 58 | 59 | 60 | $dirs = YorgDirScannerTool::getDirs($appItemsDir, false, true); 61 | foreach ($dirs as $dir) { 62 | echo "processing $itemType $dir" . $br; 63 | $appItemDir = $appItemsDir . "/" . $dir; 64 | $targetDir = $itemsDir . "/" . $dir; 65 | copyDirExceptGit($appItemDir, $targetDir); 66 | } 67 | } 68 | else{ 69 | throw new \Exception("This type of item is not allowed: $itemType"); 70 | } 71 | } 72 | else{ 73 | throw new \Exception("Please provide the type of item as the first argument: widget|module"); 74 | } 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /tasks/ling-personal-tasks/nullos/crud-gen-list-and-forms.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | php -f "/pathto/php/projects/nullos-admin/app-nullos/scripts/crudgen.php" 4 | 5 | 6 | -------------------------------------------------------------------------------- /tasks/ling-personal-tasks/nullos/icons.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | 4 | ## Below is the content of the geenrate-icons-factory.php script 5 | ## I use this in nullos to generate my IconsFactory from the icons.svg file, 6 | ## which is easier to manipulate than switch case statements. 7 | # 8 | # 9 | # 10 | # "; 90 | # } 91 | # echo $m; 92 | # } 93 | 94 | # function hr(){ 95 | # if('cli' === PHP_SAPI){ 96 | # echo "\n----------------------------"; 97 | # } 98 | # else{ 99 | # echo "
"; 100 | # } 101 | # } 102 | 103 | 104 | # /** 105 | # * Then clean that out 106 | # */ 107 | # $files2Remove = [ 108 | # '.DS_Store', 109 | # '.gitignore', 110 | # ]; 111 | # $dirs2Remove = [ 112 | # 'private', 113 | # '.git', 114 | # ]; 115 | # DirScanner::create()->scanDir($universeCopyDir, function ($path, $rPath) use ($files2Remove, $dirs2Remove) { 116 | # // echo $rPath; 117 | # $base = basename($rPath); 118 | # if (in_array($base, $files2Remove, true) && is_file($path)) { 119 | # line("removing $rPath"); 120 | # FileSystemTool::remove($path); 121 | # } 122 | # if (in_array($base, $dirs2Remove, true) && is_dir($path)) { 123 | # line("removing dir $rPath"); 124 | # FileSystemTool::remove($path); 125 | # } 126 | # //hr(); 127 | # }); 128 | 129 | -------------------------------------------------------------------------------- /tm.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | #------------------------------ 4 | # TASK MANAGER 5 | # lingtalfi - 2016-10-20 6 | #------------------------------ 7 | 8 | 9 | #------------------------------ 10 | # VARS FOR USER 11 | #------------------------------ 12 | # format codes: http://misc.flogisoft.com/bash/tip_colors_and_formatting 13 | # or here: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html 14 | BANNER="Welcome to Task Manager" 15 | BANNER_FORMAT_CODE="\e[34m"; # blue 16 | 17 | BANNER2="Task Manager -- (ctrl+c to exit)" 18 | BANNER2_FORMAT_CODE="\e[34m"; # blue 19 | 20 | SUB_BANNER="Ctrl+c to exit\n"; 21 | SUB_BANNER_FORMAT_CODE="\e[39m"; # regular 22 | 23 | GO_BACK_ITEM=".."; 24 | GO_BACK_ITEM_FORMAT_CODE="\e[35m"; # purple 25 | 26 | TASK_FILE_EXTENSIONS="sh source loc edit" # space separated list of extensions 27 | LABELIZE_TASK_FORMAT_CODE="\e[39m" # default foreground color 28 | 29 | 30 | 31 | LABELIZE_DIRECTORY_TRAILING_CHARS="/" # chars to append to a directory 32 | LABELIZE_DIRECTORY_FORMAT_CODE="\e[32m" # green 33 | 34 | SELECT_WRONG_CHOICE="Unknown choice, please try again" 35 | SELECT_WRONG_CHOICE_FORMAT_CODE="\e[31m" # red 36 | 37 | 38 | NOW_INSIDE_DIR_TEXT="Now inside " 39 | NOW_INSIDE_DIR_TEXT_FORMAT_CODE="\e[39m" # default foreground color 40 | NOW_INSIDE_DIR_BREADCRUMB_PREFIX="[TASKS]" 41 | 42 | PS3=$'\n'"What task should I execute, master? " 43 | 44 | 45 | ON_TASK_EXECUTED_AFTER_TEXT="Task Manager: The script has been executed" 46 | ON_TASK_EXECUTED_AFTER_TEXT_FORMAT_CODE="\e[34m" 47 | 48 | MAKE_IT_EXECUTABLE_TEXT="Do you want to make it executable? (y/n) " 49 | MAKE_IT_EXECUTABLE_TEXT_FORMAT_CODE="\e[34m" 50 | 51 | NOW_IT_IS_EXECUTABLE_TEXT="Now file '_s_' is executable" # _s_ is replaced with the (now executable) file 52 | NOW_IT_IS_EXECUTABLE_TEXT_FORMAT_CODE="\e[34m" 53 | 54 | PRESS_ANY_KEY_TO_CONTINUE="Press any key to continue..." 55 | PRESS_ANY_KEY_TO_CONTINUE_FORMAT_CODE="\e[35m" 56 | 57 | TM_EDITOR="vim" 58 | 59 | 60 | #------------------------------ 61 | # VARS FOR TASK MANAGER 62 | #------------------------------ 63 | # Note: it's better to keep the tasks directory in the user dir 64 | # because then the user can open multiple tmux windows (for instance), 65 | # and just type vm in each window to access her tasks 66 | TASKS_DIR_HOME="$HOME" # the directory that contains the tasks dir 67 | TASKS_DIR_NAME="tasks" # the name of the tasks dir 68 | PROGRAM_NAME="task manager" 69 | ORIGINAL_IFS="$IFS" 70 | FORMAT_END="\e[0m" 71 | CURRENT_DIR="" # will be updated as the user goes down/up the task structure 72 | NB_COLUMNS=1 # number of columns spanned by the select function 73 | 74 | 75 | 76 | 77 | 78 | #------------------------------ 79 | # PRE-PROCESS 80 | #------------------------------ 81 | # overriding TASKS_DIR_HOME? (mainly for testing purpose) 82 | ORIGINAL_DIR="$(pwd)" 83 | ORIGINAL_DIR_LEN="" # set later on 84 | if [ -n "$1" ]; then 85 | TASKS_DIR_HOME="$1" 86 | fi 87 | TASKS_DIR="$TASKS_DIR_HOME/$TASKS_DIR_NAME" 88 | CURRENT_DIR="$TASKS_DIR" 89 | _t=$(which sudo) 90 | HAS_SUDO='true' 91 | if [ "" = "$_t" ]; then 92 | HAS_SUDO='false' 93 | fi 94 | 95 | 96 | 97 | #------------------------------ 98 | # FUNCTIONS 99 | #------------------------------ 100 | function error { 101 | echo -e "\e[01;31m$PROGRAM_NAME: $1$FORMAT_END" 102 | } 103 | 104 | function parseConfig { 105 | file="$TASKS_DIR/_config" 106 | if [ -f "$file" ]; then 107 | source "$file" 108 | fi 109 | } 110 | 111 | function isConfigFile { 112 | if [ "$1" = "_config" ]; then 113 | echo "true" 114 | else 115 | echo "false" 116 | fi 117 | } 118 | 119 | 120 | function hasTaskExtension { 121 | fileExt="$(getFileExtension "$1")" 122 | hasExt="false" 123 | IFS=" " 124 | for ext in $TASK_FILE_EXTENSIONS 125 | do 126 | if [ "$fileExt" = "$ext" ]; then 127 | hasExt="true" 128 | fi 129 | done 130 | echo "$hasExt" 131 | } 132 | 133 | function getFileExtension { 134 | if grep -q '\.' <<<"$1"; then 135 | echo "${1##*.}" 136 | else 137 | echo "" 138 | fi 139 | } 140 | 141 | 142 | function endsWith { 143 | if grep -q "$2""$" <<<"$1"; then 144 | echo 'true' 145 | else 146 | echo 'false' 147 | fi 148 | } 149 | 150 | function substr { 151 | if [ -n "$3" ]; then 152 | echo ${1: $2: $3} 153 | else 154 | echo ${1: $2} 155 | fi 156 | } 157 | 158 | 159 | function isItem { 160 | if [ -d "$1" ]; then 161 | echo "true" 162 | else 163 | echo "false" 164 | fi 165 | } 166 | 167 | function labelizeTask { 168 | file="$1" 169 | echo "$LABELIZE_TASK_FORMAT_CODE$file$FORMAT_END" 170 | } 171 | 172 | function labelizeDirectory { 173 | file="$1" 174 | echo "$LABELIZE_DIRECTORY_FORMAT_CODE$file$LABELIZE_DIRECTORY_TRAILING_CHARS$FORMAT_END" 175 | } 176 | 177 | 178 | function strlen { 179 | echo ${#1} 180 | } 181 | 182 | function replace { 183 | echo "${3/$1/$2}" 184 | } 185 | 186 | 187 | function restoreIfs { 188 | IFS="$ORIGINAL_IFS" 189 | } 190 | 191 | #------------------------------ 192 | # HANDLING THE USER'S CHOICE 193 | #------------------------------ 194 | # define the actual lengths as seen by the select command below 195 | # (we use them to unformat the formatted/labelled task items and dir items) 196 | with_e_format_end_length=$(strlen $(echo -e $FORMAT_END)) 197 | with_e_labelize_directory_format_code_length=$(strlen $(echo -e $LABELIZE_DIRECTORY_FORMAT_CODE)) 198 | with_e_labelize_task_format_code_length=$(strlen $(echo -e $LABELIZE_TASK_FORMAT_CODE)) 199 | with_e_go_back=$(echo -e $GO_BACK_ITEM_FORMAT_CODE$GO_BACK_ITEM$FORMAT_END) 200 | trailingCharsLen=$(strlen $LABELIZE_DIRECTORY_TRAILING_CHARS) 201 | tasksDirLen=$(strlen $TASKS_DIR) 202 | ORIGINAL_DIR_LEN=$(strlen $ORIGINAL_DIR) 203 | 204 | 205 | # collection collectItems ( dir ) 206 | # collection: string, list of \n separated prefixed items 207 | # a file is prefixed with f 208 | # a dir is prefixed with d 209 | # prefixing allows us to format (add color to) the dir or the file 210 | function collectItems { 211 | items="" 212 | pos=$(( $(strlen $1) + 1 )) 213 | for file in "$1/"* 214 | do 215 | 216 | fileName=$(substr "$file" "$pos") 217 | if [ "false" = $(isConfigFile "$file") ]; then 218 | if [ -d "$file" -o "true" = $(hasTaskExtension "$fileName") ]; then 219 | 220 | # labelize the file name 221 | if [ -d "$file" ]; then 222 | fileName=$(labelizeDirectory "$fileName") 223 | else 224 | fileName=$(labelizeTask "$fileName") 225 | fi 226 | 227 | # append the file name to the list of items to display 228 | if [ -z "$items" ]; then 229 | items="$fileName" 230 | else 231 | items="$items\n$fileName" 232 | fi 233 | fi 234 | fi 235 | done 236 | echo "$items" 237 | } 238 | 239 | 240 | function handleItems { 241 | IFS=$'\n' 242 | theItems="$1" 243 | COLUMNS=$NB_COLUMNS 244 | select FILENAME in $(echo -e "$theItems"); 245 | do 246 | if [ -n "$FILENAME" ]; then 247 | 248 | # is it the go back reply? 249 | if [ "$with_e_go_back" = "$FILENAME" ]; then 250 | handleGoBack 251 | else 252 | # remove the suffix (FORMAT_END) part 253 | fileNameLength=$(strlen "$FILENAME") # with e because of the way it was passed to the select command 254 | endBeginOffset=$(( $fileNameLength - $with_e_format_end_length )) 255 | FILENAME=$(substr "$FILENAME" 0 "$endBeginOffset") 256 | 257 | # if it ends with the LABELIZE_DIRECTORY_TRAILING_CHARS, 258 | # I consider that the item is a dir 259 | # the obvious flaw of this technique is that if a regular file ends 260 | # with the LABELIZE_DIRECTORY_TRAILING_CHARS, it will be considered as a dir, 261 | # but for now, I'm okay with that, assuming that this will be a rare case, 262 | # and/or it could be stated in the doc so that users don't append 263 | # LABELIZE_DIRECTORY_TRAILING_CHARS to their filename. 264 | if [ 'true' = $(endsWith "$FILENAME" "$LABELIZE_DIRECTORY_TRAILING_CHARS") ]; then 265 | # if it's a dir 266 | 267 | # now remove prefix part to get the original string back 268 | FILENAME=$(substr "$FILENAME" "$with_e_labelize_directory_format_code_length") 269 | 270 | # don't forget to remove the trailing chars 271 | fileNameLen=$(strlen "$FILENAME") 272 | endPos=$(( $fileNameLen - $trailingCharsLen )) 273 | FILENAME=$(substr "$FILENAME" 0 $endPos) 274 | 275 | 276 | handleDirItem "$FILENAME" 277 | 278 | 279 | else 280 | # if it's a file 281 | 282 | # now remove prefix part to get the original string back 283 | FILENAME=$(substr "$FILENAME" "$with_e_labelize_task_format_code_length") 284 | handleFileItem "$FILENAME" 285 | 286 | fi 287 | fi 288 | else 289 | echo -e $SELECT_WRONG_CHOICE_FORMAT_CODE$SELECT_WRONG_CHOICE"\e[0m" 290 | pressAnyKeyToContinue 291 | openDir 292 | fi 293 | 294 | break 295 | done 296 | 297 | } 298 | 299 | function handleDirItem { 300 | dirSegment="$1" 301 | newDir="$CURRENT_DIR/$dirSegment" 302 | if [ -d "$newDir" ]; then 303 | CURRENT_DIR="$CURRENT_DIR/$dirSegment" 304 | openDir 305 | else 306 | error "Unable to navigate to directory '$newDir', directory not found" 307 | fi 308 | } 309 | 310 | function pressAnyKeyToContinue { 311 | echo -e "$PRESS_ANY_KEY_TO_CONTINUE_FORMAT_CODE$PRESS_ANY_KEY_TO_CONTINUE$FORMAT_END" 312 | read -s -n 1 key 313 | } 314 | 315 | function needExecutePermission { 316 | ret='false' 317 | if [ "sh" = "$1" ]; then 318 | ret="true" 319 | fi 320 | echo "$ret" 321 | } 322 | 323 | function handleFileItem { 324 | local taskWasCancelled='false' 325 | file="$CURRENT_DIR/$1" 326 | 327 | if [ -f "$file" ]; then 328 | 329 | fileExt=$(getFileExtension "$file") 330 | needExecute=$(needExecutePermission "$fileExt") 331 | 332 | 333 | if [ "true" = "$needExecute" ]; then 334 | if ! [ -x "$file" ]; then 335 | # not executable 336 | taskWasCancelled='true' 337 | 338 | error "file '$file' is not executable" 339 | 340 | if [ 'true' = "$HAS_SUDO" ]; then 341 | # do we make it executable? 342 | echo -e "$MAKE_IT_EXECUTABLE_TEXT_FORMAT_CODE$MAKE_IT_EXECUTABLE_TEXT$FORMAT_END" 343 | read -s -n 1 key 344 | if [ 'y' = "$key" ]; then 345 | sudo chmod u+x "$file" 346 | nowText="$(replace "_s_" "$file" "$NOW_IT_IS_EXECUTABLE_TEXT")" 347 | echo -e "$NOW_IT_IS_EXECUTABLE_TEXT_FORMAT_CODE$nowText$FORMAT_END" 348 | pressAnyKeyToContinue 349 | taskWasCancelled='false' 350 | fi 351 | fi 352 | 353 | if [ 'true' = "$taskWasCancelled" ]; then 354 | error "Couldn't execute script '$file'" 355 | pressAnyKeyToContinue 356 | 357 | openDir 358 | 359 | fi 360 | fi 361 | fi 362 | 363 | 364 | if [ 'false' = "$taskWasCancelled" ]; then 365 | case "$fileExt" in 366 | "sh" ) 367 | "$file" 368 | ;; 369 | "source" ) 370 | source "$file" 371 | ;; 372 | "loc" ) 373 | dest="$(cat "$file")" 374 | if [ -d "$dest" ]; then 375 | cd "$dest" 376 | echo "you are now in $dest" 377 | else 378 | error "'$dest' is not a valid directory; defined in '$file'" 379 | fi 380 | ;; 381 | "edit" ) 382 | target="$(cat "$file")" 383 | if [ -f "$target" ]; then 384 | "$TM_EDITOR" "$target" 385 | else 386 | error "'$target' is not a valid file, defined in '$file'" 387 | fi 388 | ;; 389 | *) 390 | error "Don't know how to handle a script with extension '$fileExt' yet, please teach me. Bye for now." 391 | taskWasCancelled='true' 392 | ;; 393 | esac 394 | if [ 'false' = "$taskWasCancelled" ]; then 395 | echo -e "$ON_TASK_EXECUTED_AFTER_TEXT_FORMAT_CODE$ON_TASK_EXECUTED_AFTER_TEXT$FORMAT_END" 396 | fi 397 | fi 398 | 399 | else 400 | error "file not found: '$file'" 401 | fi 402 | } 403 | 404 | 405 | function getCurrentRelativeDir { 406 | substr "$CURRENT_DIR" "$tasksDirLen" 407 | } 408 | 409 | function openDir { 410 | clear 411 | breadCrumb=$(getCurrentRelativeDir) 412 | echo -e "$BANNER2_FORMAT_CODE$BANNER2$FORMAT_END" 413 | echo "" 414 | echo -e "$NOW_INSIDE_DIR_TEXT_FORMAT_CODE$NOW_INSIDE_DIR_TEXT$LABELIZE_DIRECTORY_FORMAT_CODE$NOW_INSIDE_DIR_BREADCRUMB_PREFIX$breadCrumb$LABELIZE_DIRECTORY_TRAILING_CHARS$FORMAT_END" 415 | echo "" 416 | 417 | items="$(collectItems "$CURRENT_DIR")" 418 | 419 | # add the goback item if it's not the root directory 420 | if [ "$TASKS_DIR" != "$CURRENT_DIR" ]; then 421 | items="$GO_BACK_ITEM_FORMAT_CODE$GO_BACK_ITEM$FORMAT_END\n$items" 422 | fi 423 | handleItems "$items" 424 | } 425 | 426 | function handleGoBack { 427 | newDir="$(dirname "$CURRENT_DIR")" 428 | if [ -d "$newDir" ]; then 429 | CURRENT_DIR="$newDir" 430 | openDir 431 | else 432 | error "Unable to navigate to parent directory '$newDir', directory not found" 433 | fi 434 | } 435 | 436 | #------------------------------ 437 | # STARTING THE TM SCRIPT 438 | #------------------------------ 439 | clear 440 | if [ -d "$TASKS_DIR" ]; then 441 | 442 | 443 | #------------------------------ 444 | # PARSE THE CONFIG 445 | #------------------------------ 446 | parseConfig 447 | 448 | 449 | #------------------------------ 450 | # DISPLAYING THE LIST OF ITEMS 451 | #------------------------------ 452 | echo -e "$BANNER_FORMAT_CODE$BANNER$FORMAT_END" 453 | echo -e "$SUB_BANNER_FORMAT_CODE$SUB_BANNER$FORMAT_END" 454 | 455 | 456 | items="$(collectItems "$TASKS_DIR")" 457 | handleItems "$items" 458 | 459 | else 460 | error "'$TASKS_DIR_NAME' directory not found in '$TASKS_DIR_HOME'" 461 | fi 462 | 463 | 464 | 465 | 466 | 467 | --------------------------------------------------------------------------------