[{"data":1,"prerenderedAt":1251},["ShallowReactive",2],{"articles-tmux-project-laucher":3},{"id":4,"title":5,"body":6,"date":1235,"description":1236,"extension":1237,"image":1238,"meta":1239,"navigation":98,"path":1241,"published":98,"seo":1242,"snippet":1243,"stem":1244,"tags":1245,"video":1249,"__hash__":1250},"articles\u002Farticles\u002Ftmux-project-laucher.md","Build a Tmux project laucher",{"type":7,"value":8,"toc":1230},"minimark",[9,14,26,41,44,47,63,67,75,106,109,112,115,296,299,302,305,331,334,365,368,457,464,504,507,573,578,581,1162,1169,1176,1202,1206,1209,1213,1226],[10,11,13],"h1",{"id":12},"rationale","Rationale",[15,16,17,18,25],"p",{},"I found myself growing increasingly frustrated with the need to rapidly switch between multiple coding projects. To tackle this, I resorted to managing various terminal sessions, utilizing ",[19,20,24],"a",{"href":21,"rel":22},"https:\u002F\u002Fgithub.com\u002Fianyh\u002FAmethyst",[23],"nofollow","Amethyst"," – a tiling window manager for macOS. The challenge arose when these sessions began to stack up, often reaching three or more terminals in full-screen mode, making it easy to lose track of which window corresponded to which project.",[15,27,28,29,34,35,40],{},"Although I had previously tried my hand at using ",[19,30,33],{"href":31,"rel":32},"https:\u002F\u002Fgithub.com\u002Ftmux\u002Ftmux\u002Fwiki",[23],"Tmux"," and even delved into experimenting with ",[19,36,39],{"href":37,"rel":38},"https:\u002F\u002Fgithub.com\u002Ftmuxinator\u002Ftmuxinator",[23],"Tmuxinator",", neither option truly resonated with me. The process of managing and navigating sessions was less intuitive than my initial expectations. Tasks like crafting sessions, renaming them, or typing out the complete tmuxinator command alongside the project name often felt cumbersome.",[15,42,43],{},"Recently, I was inspired by a video of ThePrimeagen, He implemented fzf a fuzzy search program for selecting his project folders, enabling seamless switching between projects, even when not yet within a tmux session.",[15,45,46],{},"This inspiration prompted me to develop a similar program with the following key objectives:",[48,49,50,54,57,60],"ul",{},[51,52,53],"li",{},"It should exclusively list project directories.",[51,55,56],{},"It should instantiate a new tmux session at the root of the selected project.",[51,58,59],{},"It should provide the capability to attach from outside of tmux to an existing session, if one is available.",[51,61,62],{},"It should switch to an existing session, provided that it is already attached to an other a tmux session.",[10,64,66],{"id":65},"lets-get-started","Lets get started",[15,68,69,70,74],{},"Let's begin by creating a file named project-launcher within the ~\u002F.local\u002Fbin\u002F directory and open ",[71,72,73],"code",{},"~\u002F.local\u002Fbin\u002Fproject-launcher"," in your text editor of choice.",[76,77,82],"pre",{"className":78,"code":79,"language":80,"meta":81,"style":81},"language-console shiki shiki-themes github-light github-dark","#!\u002Fusr\u002Fbin\u002Fenv bash\n\n...\n","console","",[71,83,84,93,100],{"__ignoreMap":81},[85,86,89],"span",{"class":87,"line":88},"line",1,[85,90,92],{"class":91},"sj4cs","#!\u002Fusr\u002Fbin\u002Fenv bash\n",[85,94,96],{"class":87,"line":95},2,[85,97,99],{"emptyLinePlaceholder":98},true,"\n",[85,101,103],{"class":87,"line":102},3,[85,104,105],{"class":91},"...\n",[15,107,108],{},"Let's begin by addressing our inputs, specifically the project folders that we intend to present as options. All of my project directories are situated within ~\u002Fprojects, categorized into either personal projects or various organization projects. The structure involves a distinct directory for personal projects and multiple directories housing organizational projects.",[15,110,111],{},"Consequently, our objective is to accommodate the passage of multiple paths, which will subsequently feature in our fuzzy search functionality. To achieve this, we'll designate these paths under the -d flag. Furthermore, we should account for handling the --help and -h flags, while ensuring that any other scenarios prompt an appropriate error message.",[15,113,114],{},"With the aid of optargs, our implementation might take the following form:",[76,116,118],{"className":78,"code":117,"language":80,"meta":81,"style":81},"...\n\noptstring=\":hd:-:\"\nwhile getopts ${optstring} arg; do\n  case ${arg} in\n    -)\n      case \"${OPTARG}\" in\n        help)\n            usage\n            ;;\n        *)\n            if [ \"$OPTERR\" = 1 ] && [ \"${optspec:0:1}\" != \":\" ]; then\n                echo \"Invalid option --${OPTARG}\" >&2\n            fi\n            ;;\n      esac;;\n    h)\n      usage\n      ;;\n    d)\n      multi+=(\"$OPTARG\")\n      ;;\n    ?)\n      echo \"Invalid option: -${OPTARG}.\"\n      exit 2\n      ;;\n  esac\ndone\nshift $(expr $OPTIND - 1 )\n\n...\n",[71,119,120,124,128,133,139,145,151,157,163,169,175,181,187,193,199,204,210,216,222,228,234,240,245,251,257,263,268,274,280,286,291],{"__ignoreMap":81},[85,121,122],{"class":87,"line":88},[85,123,105],{"class":91},[85,125,126],{"class":87,"line":95},[85,127,99],{"emptyLinePlaceholder":98},[85,129,130],{"class":87,"line":102},[85,131,132],{"class":91},"optstring=\":hd:-:\"\n",[85,134,136],{"class":87,"line":135},4,[85,137,138],{"class":91},"while getopts ${optstring} arg; do\n",[85,140,142],{"class":87,"line":141},5,[85,143,144],{"class":91},"  case ${arg} in\n",[85,146,148],{"class":87,"line":147},6,[85,149,150],{"class":91},"    -)\n",[85,152,154],{"class":87,"line":153},7,[85,155,156],{"class":91},"      case \"${OPTARG}\" in\n",[85,158,160],{"class":87,"line":159},8,[85,161,162],{"class":91},"        help)\n",[85,164,166],{"class":87,"line":165},9,[85,167,168],{"class":91},"            usage\n",[85,170,172],{"class":87,"line":171},10,[85,173,174],{"class":91},"            ;;\n",[85,176,178],{"class":87,"line":177},11,[85,179,180],{"class":91},"        *)\n",[85,182,184],{"class":87,"line":183},12,[85,185,186],{"class":91},"            if [ \"$OPTERR\" = 1 ] && [ \"${optspec:0:1}\" != \":\" ]; then\n",[85,188,190],{"class":87,"line":189},13,[85,191,192],{"class":91},"                echo \"Invalid option --${OPTARG}\" >&2\n",[85,194,196],{"class":87,"line":195},14,[85,197,198],{"class":91},"            fi\n",[85,200,202],{"class":87,"line":201},15,[85,203,174],{"class":91},[85,205,207],{"class":87,"line":206},16,[85,208,209],{"class":91},"      esac;;\n",[85,211,213],{"class":87,"line":212},17,[85,214,215],{"class":91},"    h)\n",[85,217,219],{"class":87,"line":218},18,[85,220,221],{"class":91},"      usage\n",[85,223,225],{"class":87,"line":224},19,[85,226,227],{"class":91},"      ;;\n",[85,229,231],{"class":87,"line":230},20,[85,232,233],{"class":91},"    d)\n",[85,235,237],{"class":87,"line":236},21,[85,238,239],{"class":91},"      multi+=(\"$OPTARG\")\n",[85,241,243],{"class":87,"line":242},22,[85,244,227],{"class":91},[85,246,248],{"class":87,"line":247},23,[85,249,250],{"class":91},"    ?)\n",[85,252,254],{"class":87,"line":253},24,[85,255,256],{"class":91},"      echo \"Invalid option: -${OPTARG}.\"\n",[85,258,260],{"class":87,"line":259},25,[85,261,262],{"class":91},"      exit 2\n",[85,264,266],{"class":87,"line":265},26,[85,267,227],{"class":91},[85,269,271],{"class":87,"line":270},27,[85,272,273],{"class":91},"  esac\n",[85,275,277],{"class":87,"line":276},28,[85,278,279],{"class":91},"done\n",[85,281,283],{"class":87,"line":282},29,[85,284,285],{"class":91},"shift $(expr $OPTIND - 1 )\n",[85,287,289],{"class":87,"line":288},30,[85,290,99],{"emptyLinePlaceholder":98},[85,292,294],{"class":87,"line":293},31,[85,295,105],{"class":91},[15,297,298],{},"Next, our focus is on utilizing the paths provided under the -d flag to generate two lists: one consisting of paths to all subdirectories containing projects, and the other containing project names to be displayed when we select a project.",[15,300,301],{},"To accomplish this, consider the following approach:",[15,303,304],{},"To begin, we pass the project paths to the find command, specifying an argument to limit the search to a single level deep.",[76,306,308],{"className":78,"code":307,"language":80,"meta":81,"style":81},"...\n\nprojectPaths=($(find ${multi[@]} -mindepth 1 -maxdepth 1 -type d))\n\n...\n",[71,309,310,314,318,323,327],{"__ignoreMap":81},[85,311,312],{"class":87,"line":88},[85,313,105],{"class":91},[85,315,316],{"class":87,"line":95},[85,317,99],{"emptyLinePlaceholder":98},[85,319,320],{"class":87,"line":102},[85,321,322],{"class":91},"projectPaths=($(find ${multi[@]} -mindepth 1 -maxdepth 1 -type d))\n",[85,324,325],{"class":87,"line":135},[85,326,99],{"emptyLinePlaceholder":98},[85,328,329],{"class":87,"line":141},[85,330,105],{"class":91},[15,332,333],{},"Additionally, we require the name of the session to which we are currently attached, along with a list of active sessions.",[76,335,337],{"className":78,"code":336,"language":80,"meta":81,"style":81},"...\n\nattachedSessionName=$(tmux display-message -p \\#S)\nsessions=$(tmux list-session -F \\#S)\n\n...\n",[71,338,339,343,347,352,357,361],{"__ignoreMap":81},[85,340,341],{"class":87,"line":88},[85,342,105],{"class":91},[85,344,345],{"class":87,"line":95},[85,346,99],{"emptyLinePlaceholder":98},[85,348,349],{"class":87,"line":102},[85,350,351],{"class":91},"attachedSessionName=$(tmux display-message -p \\#S)\n",[85,353,354],{"class":87,"line":135},[85,355,356],{"class":91},"sessions=$(tmux list-session -F \\#S)\n",[85,358,359],{"class":87,"line":141},[85,360,99],{"emptyLinePlaceholder":98},[85,362,363],{"class":87,"line":147},[85,364,105],{"class":91},[15,366,367],{},"We iterate through each project path to create a roster of project names, which will be display through fzf. Moreover, we assess the activity status of the session, accentuating the name in blue if it's active. Furthermore, if the project name corresponds to the existing tmux session name, we emphasize this particular project in yellow.",[76,369,371],{"className":78,"code":370,"language":80,"meta":81,"style":81},"...\n\nprojectDisplayNames=()\nprojectNames=()\n\nfor key in ${projectPaths[@]}; do\n  value=$(basename \"$(dirname \"${key}\")\")\"\u002F\"$(basename \"${key}\")\n    projectNames+=($value)\n  if [[ $value == $attachedSessionName ]]; then \n    projectDisplayNames+=(\"\u001b[33m$value\u001b[0m\")\n  elif $(contains ${value} ${sessions[@]}); then \n    projectDisplayNames+=(\"\u001b[34m$value\u001b[0m\")\n  else\n    projectDisplayNames+=($value)\n  fi\ndone\n\n...\n",[71,372,373,377,381,386,391,395,400,405,410,415,420,425,430,435,440,445,449,453],{"__ignoreMap":81},[85,374,375],{"class":87,"line":88},[85,376,105],{"class":91},[85,378,379],{"class":87,"line":95},[85,380,99],{"emptyLinePlaceholder":98},[85,382,383],{"class":87,"line":102},[85,384,385],{"class":91},"projectDisplayNames=()\n",[85,387,388],{"class":87,"line":135},[85,389,390],{"class":91},"projectNames=()\n",[85,392,393],{"class":87,"line":141},[85,394,99],{"emptyLinePlaceholder":98},[85,396,397],{"class":87,"line":147},[85,398,399],{"class":91},"for key in ${projectPaths[@]}; do\n",[85,401,402],{"class":87,"line":153},[85,403,404],{"class":91},"  value=$(basename \"$(dirname \"${key}\")\")\"\u002F\"$(basename \"${key}\")\n",[85,406,407],{"class":87,"line":159},[85,408,409],{"class":91},"    projectNames+=($value)\n",[85,411,412],{"class":87,"line":165},[85,413,414],{"class":91},"  if [[ $value == $attachedSessionName ]]; then \n",[85,416,417],{"class":87,"line":171},[85,418,419],{"class":91},"    projectDisplayNames+=(\"\u001b[33m$value\u001b[0m\")\n",[85,421,422],{"class":87,"line":177},[85,423,424],{"class":91},"  elif $(contains ${value} ${sessions[@]}); then \n",[85,426,427],{"class":87,"line":183},[85,428,429],{"class":91},"    projectDisplayNames+=(\"\u001b[34m$value\u001b[0m\")\n",[85,431,432],{"class":87,"line":189},[85,433,434],{"class":91},"  else\n",[85,436,437],{"class":87,"line":195},[85,438,439],{"class":91},"    projectDisplayNames+=($value)\n",[85,441,442],{"class":87,"line":201},[85,443,444],{"class":91},"  fi\n",[85,446,447],{"class":87,"line":206},[85,448,279],{"class":91},[85,450,451],{"class":87,"line":212},[85,452,99],{"emptyLinePlaceholder":98},[85,454,455],{"class":87,"line":218},[85,456,105],{"class":91},[15,458,459,460,463],{},"Now, utilizing ",[71,461,462],{},"projectDisplayNames"," and prompt the user to select an option using fzf. The chosen option will then be used to retrieve the corresponding project path.",[76,465,467],{"className":78,"code":466,"language":80,"meta":81,"style":81},"...\n\nselectedProjectName=$(printf \"%s\\n\" \"${projectDisplayNames[@]}\" | fzf --ansi)\n\nindex=$(indexOf ${selectedProjectName} ${projectNames[@]})\nselectedPath=\"${projectPaths[$index]}\"\n\n...\n",[71,468,469,473,477,482,486,491,496,500],{"__ignoreMap":81},[85,470,471],{"class":87,"line":88},[85,472,105],{"class":91},[85,474,475],{"class":87,"line":95},[85,476,99],{"emptyLinePlaceholder":98},[85,478,479],{"class":87,"line":102},[85,480,481],{"class":91},"selectedProjectName=$(printf \"%s\\n\" \"${projectDisplayNames[@]}\" | fzf --ansi)\n",[85,483,484],{"class":87,"line":135},[85,485,99],{"emptyLinePlaceholder":98},[85,487,488],{"class":87,"line":141},[85,489,490],{"class":91},"index=$(indexOf ${selectedProjectName} ${projectNames[@]})\n",[85,492,493],{"class":87,"line":147},[85,494,495],{"class":91},"selectedPath=\"${projectPaths[$index]}\"\n",[85,497,498],{"class":87,"line":153},[85,499,99],{"emptyLinePlaceholder":98},[85,501,502],{"class":87,"line":159},[85,503,105],{"class":91},[15,505,506],{},"The final step is to utilize the output from fzf, and us this to attach, switch to, or create a new tmux session. In case the user opts not to make a selection, we gracefully exit the process.",[76,508,510],{"className":78,"code":509,"language":80,"meta":81,"style":81},"if [[ -z $selectedProjectName ]]; then\n    exit 0\nfi\n\nif ! $(contains ${selectedProjectName} ${sessions[@]} ); then\n  tmux new-session -ds $selectedProjectName -c $selectedPath\nfi\n\nif ! [[ -z $TMUX ]]; then\n  tmux switch-client -t $selectedProjectName\nelse\n  tmux attach-session -t=$selectedProjectName\nfi\n\n",[71,511,512,517,522,527,531,536,541,545,549,554,559,564,569],{"__ignoreMap":81},[85,513,514],{"class":87,"line":88},[85,515,516],{"class":91},"if [[ -z $selectedProjectName ]]; then\n",[85,518,519],{"class":87,"line":95},[85,520,521],{"class":91},"    exit 0\n",[85,523,524],{"class":87,"line":102},[85,525,526],{"class":91},"fi\n",[85,528,529],{"class":87,"line":135},[85,530,99],{"emptyLinePlaceholder":98},[85,532,533],{"class":87,"line":141},[85,534,535],{"class":91},"if ! $(contains ${selectedProjectName} ${sessions[@]} ); then\n",[85,537,538],{"class":87,"line":147},[85,539,540],{"class":91},"  tmux new-session -ds $selectedProjectName -c $selectedPath\n",[85,542,543],{"class":87,"line":153},[85,544,526],{"class":91},[85,546,547],{"class":87,"line":159},[85,548,99],{"emptyLinePlaceholder":98},[85,550,551],{"class":87,"line":165},[85,552,553],{"class":91},"if ! [[ -z $TMUX ]]; then\n",[85,555,556],{"class":87,"line":171},[85,557,558],{"class":91},"  tmux switch-client -t $selectedProjectName\n",[85,560,561],{"class":87,"line":177},[85,562,563],{"class":91},"else\n",[85,565,566],{"class":87,"line":183},[85,567,568],{"class":91},"  tmux attach-session -t=$selectedProjectName\n",[85,570,571],{"class":87,"line":189},[85,572,526],{"class":91},[574,575,577],"h2",{"id":576},"the-final-product","The final product",[15,579,580],{},"The end result should resemble something like this.",[76,582,584],{"className":78,"code":583,"filename":73,"language":80,"meta":81,"style":81},"#!\u002Fusr\u002Fbin\u002Fenv bash\n\nfunction usage {\n  echo \"Project Launcher\"\n  echo \"\"\n  echo \"Launch tmux session at your project directory or attach\u002Fswitch to an existing session\"\n  echo \"Supports fuzzy search power by fzf in multiple project directories\"\n  echo \"\"\n  echo \"Usage: $(basename $0) [-d \u003Carg>...] [--] [DIRECTORY...]\" 2>&1\n  echo \"\"\n  echo \"projectPaths:\"\n  echo \"   -d           add directory for fuzzy search\"\n  echo \"   -h|--help    show usage\"\n  exit 1\n}\n\noptstring=\":hd:-:\"\nwhile getopts ${optstring} arg; do\n  case ${arg} in\n    -)\n      case \"${OPTARG}\" in\n        help)\n            usage\n            ;;\n        *)\n            if [ \"$OPTERR\" = 1 ] && [ \"${optspec:0:1}\" != \":\" ]; then\n                echo \"Invalid option --${OPTARG}\" >&2\n            fi\n            ;;\n      esac;;\n    h)\n      usage\n      ;;\n    d)\n      multi+=(\"$OPTARG\")\n      ;;\n    ?)\n      echo \"Invalid option: -${OPTARG}.\"\n      exit 2\n      ;;\n  esac\ndone\nshift $(expr $OPTIND - 1 )\n\nfunction contains () {\n  local value=$1\n  shift\n  local elements=(\"$@\")\n\n  for el in ${elements[@]}; do\n    if [[ \"${el}\" = \"${value}\" ]]; then\n      return 0\n    fi\n  done\n\n  return 1\n}\n\nfunction indexOf () {\n  local value=$1\n  shift\n  local elements=(\"$@\")\n\n  for i in \"${!elements[@]}\"; do\n    if [[ \"${elements[$i]}\" = \"${value}\" ]]; then\n      echo \"${i}\";\n      break;\n    fi\n  done\n}\n\nif [[ $# -eq 1 ]]; then\n    selectedProjectName=$1\nelse\n  projectPaths=($(find ${multi[@]} -mindepth 1 -maxdepth 1 -type d))\n\n    attachedSessionName=$(tmux display-message -p \\#S)\n    sessions=$(tmux list-session -F \\#S)\n    projectDisplayNames=()\n    projectNames=()\n\n    for key in ${projectPaths[@]}; do\n      value=$(basename \"$(dirname \"${key}\")\")\"\u002F\"$(basename \"${key}\")\n        projectNames+=($value)\n      if [[ $value == $attachedSessionName ]]; then \n        projectDisplayNames+=(\"\u001b[33m$value\u001b[0m\")\n      elif $(contains ${value} ${sessions[@]}); then \n        projectDisplayNames+=(\"\u001b[34m$value\u001b[0m\")\n      else\n        projectDisplayNames+=($value)\n      fi\n    done\n\n    selectedProjectName=$(printf \"%s\\n\" \"${projectDisplayNames[@]}\" | fzf --ansi)\n\n    index=$(indexOf ${selectedProjectName} ${projectNames[@]})\n    selectedPath=\"${projectPaths[$index]}\"\nfi\n\nif [[ -z $selectedProjectName ]]; then\n    exit 0\nfi\n\nif ! $(contains ${selectedProjectName} ${sessions[@]} ); then\n  tmux new-session -ds $selectedProjectName -c $selectedPath\nfi\n\nif ! [[ -z $TMUX ]]; then\n  tmux switch-client -t $selectedProjectName\nelse\n  tmux attach-session -t=$selectedProjectName\nfi\n",[71,585,586,590,594,599,604,609,614,619,623,628,632,637,642,647,652,657,661,665,669,673,677,681,685,689,693,697,701,705,709,713,717,721,726,731,736,741,746,751,756,761,766,771,776,781,786,792,798,804,810,815,821,827,833,839,845,850,856,861,866,872,877,882,887,892,898,904,910,916,921,926,931,936,942,948,953,959,964,970,976,982,988,993,999,1005,1011,1017,1023,1029,1035,1041,1047,1053,1059,1064,1070,1075,1081,1087,1092,1097,1102,1107,1112,1117,1122,1127,1132,1137,1142,1147,1152,1157],{"__ignoreMap":81},[85,587,588],{"class":87,"line":88},[85,589,92],{"class":91},[85,591,592],{"class":87,"line":95},[85,593,99],{"emptyLinePlaceholder":98},[85,595,596],{"class":87,"line":102},[85,597,598],{"class":91},"function usage {\n",[85,600,601],{"class":87,"line":135},[85,602,603],{"class":91},"  echo \"Project Launcher\"\n",[85,605,606],{"class":87,"line":141},[85,607,608],{"class":91},"  echo \"\"\n",[85,610,611],{"class":87,"line":147},[85,612,613],{"class":91},"  echo \"Launch tmux session at your project directory or attach\u002Fswitch to an existing session\"\n",[85,615,616],{"class":87,"line":153},[85,617,618],{"class":91},"  echo \"Supports fuzzy search power by fzf in multiple project directories\"\n",[85,620,621],{"class":87,"line":159},[85,622,608],{"class":91},[85,624,625],{"class":87,"line":165},[85,626,627],{"class":91},"  echo \"Usage: $(basename $0) [-d \u003Carg>...] [--] [DIRECTORY...]\" 2>&1\n",[85,629,630],{"class":87,"line":171},[85,631,608],{"class":91},[85,633,634],{"class":87,"line":177},[85,635,636],{"class":91},"  echo \"projectPaths:\"\n",[85,638,639],{"class":87,"line":183},[85,640,641],{"class":91},"  echo \"   -d           add directory for fuzzy search\"\n",[85,643,644],{"class":87,"line":189},[85,645,646],{"class":91},"  echo \"   -h|--help    show usage\"\n",[85,648,649],{"class":87,"line":195},[85,650,651],{"class":91},"  exit 1\n",[85,653,654],{"class":87,"line":201},[85,655,656],{"class":91},"}\n",[85,658,659],{"class":87,"line":206},[85,660,99],{"emptyLinePlaceholder":98},[85,662,663],{"class":87,"line":212},[85,664,132],{"class":91},[85,666,667],{"class":87,"line":218},[85,668,138],{"class":91},[85,670,671],{"class":87,"line":224},[85,672,144],{"class":91},[85,674,675],{"class":87,"line":230},[85,676,150],{"class":91},[85,678,679],{"class":87,"line":236},[85,680,156],{"class":91},[85,682,683],{"class":87,"line":242},[85,684,162],{"class":91},[85,686,687],{"class":87,"line":247},[85,688,168],{"class":91},[85,690,691],{"class":87,"line":253},[85,692,174],{"class":91},[85,694,695],{"class":87,"line":259},[85,696,180],{"class":91},[85,698,699],{"class":87,"line":265},[85,700,186],{"class":91},[85,702,703],{"class":87,"line":270},[85,704,192],{"class":91},[85,706,707],{"class":87,"line":276},[85,708,198],{"class":91},[85,710,711],{"class":87,"line":282},[85,712,174],{"class":91},[85,714,715],{"class":87,"line":288},[85,716,209],{"class":91},[85,718,719],{"class":87,"line":293},[85,720,215],{"class":91},[85,722,724],{"class":87,"line":723},32,[85,725,221],{"class":91},[85,727,729],{"class":87,"line":728},33,[85,730,227],{"class":91},[85,732,734],{"class":87,"line":733},34,[85,735,233],{"class":91},[85,737,739],{"class":87,"line":738},35,[85,740,239],{"class":91},[85,742,744],{"class":87,"line":743},36,[85,745,227],{"class":91},[85,747,749],{"class":87,"line":748},37,[85,750,250],{"class":91},[85,752,754],{"class":87,"line":753},38,[85,755,256],{"class":91},[85,757,759],{"class":87,"line":758},39,[85,760,262],{"class":91},[85,762,764],{"class":87,"line":763},40,[85,765,227],{"class":91},[85,767,769],{"class":87,"line":768},41,[85,770,273],{"class":91},[85,772,774],{"class":87,"line":773},42,[85,775,279],{"class":91},[85,777,779],{"class":87,"line":778},43,[85,780,285],{"class":91},[85,782,784],{"class":87,"line":783},44,[85,785,99],{"emptyLinePlaceholder":98},[85,787,789],{"class":87,"line":788},45,[85,790,791],{"class":91},"function contains () {\n",[85,793,795],{"class":87,"line":794},46,[85,796,797],{"class":91},"  local value=$1\n",[85,799,801],{"class":87,"line":800},47,[85,802,803],{"class":91},"  shift\n",[85,805,807],{"class":87,"line":806},48,[85,808,809],{"class":91},"  local elements=(\"$@\")\n",[85,811,813],{"class":87,"line":812},49,[85,814,99],{"emptyLinePlaceholder":98},[85,816,818],{"class":87,"line":817},50,[85,819,820],{"class":91},"  for el in ${elements[@]}; do\n",[85,822,824],{"class":87,"line":823},51,[85,825,826],{"class":91},"    if [[ \"${el}\" = \"${value}\" ]]; then\n",[85,828,830],{"class":87,"line":829},52,[85,831,832],{"class":91},"      return 0\n",[85,834,836],{"class":87,"line":835},53,[85,837,838],{"class":91},"    fi\n",[85,840,842],{"class":87,"line":841},54,[85,843,844],{"class":91},"  done\n",[85,846,848],{"class":87,"line":847},55,[85,849,99],{"emptyLinePlaceholder":98},[85,851,853],{"class":87,"line":852},56,[85,854,855],{"class":91},"  return 1\n",[85,857,859],{"class":87,"line":858},57,[85,860,656],{"class":91},[85,862,864],{"class":87,"line":863},58,[85,865,99],{"emptyLinePlaceholder":98},[85,867,869],{"class":87,"line":868},59,[85,870,871],{"class":91},"function indexOf () {\n",[85,873,875],{"class":87,"line":874},60,[85,876,797],{"class":91},[85,878,880],{"class":87,"line":879},61,[85,881,803],{"class":91},[85,883,885],{"class":87,"line":884},62,[85,886,809],{"class":91},[85,888,890],{"class":87,"line":889},63,[85,891,99],{"emptyLinePlaceholder":98},[85,893,895],{"class":87,"line":894},64,[85,896,897],{"class":91},"  for i in \"${!elements[@]}\"; do\n",[85,899,901],{"class":87,"line":900},65,[85,902,903],{"class":91},"    if [[ \"${elements[$i]}\" = \"${value}\" ]]; then\n",[85,905,907],{"class":87,"line":906},66,[85,908,909],{"class":91},"      echo \"${i}\";\n",[85,911,913],{"class":87,"line":912},67,[85,914,915],{"class":91},"      break;\n",[85,917,919],{"class":87,"line":918},68,[85,920,838],{"class":91},[85,922,924],{"class":87,"line":923},69,[85,925,844],{"class":91},[85,927,929],{"class":87,"line":928},70,[85,930,656],{"class":91},[85,932,934],{"class":87,"line":933},71,[85,935,99],{"emptyLinePlaceholder":98},[85,937,939],{"class":87,"line":938},72,[85,940,941],{"class":91},"if [[ $# -eq 1 ]]; then\n",[85,943,945],{"class":87,"line":944},73,[85,946,947],{"class":91},"    selectedProjectName=$1\n",[85,949,951],{"class":87,"line":950},74,[85,952,563],{"class":91},[85,954,956],{"class":87,"line":955},75,[85,957,958],{"class":91},"  projectPaths=($(find ${multi[@]} -mindepth 1 -maxdepth 1 -type d))\n",[85,960,962],{"class":87,"line":961},76,[85,963,99],{"emptyLinePlaceholder":98},[85,965,967],{"class":87,"line":966},77,[85,968,969],{"class":91},"    attachedSessionName=$(tmux display-message -p \\#S)\n",[85,971,973],{"class":87,"line":972},78,[85,974,975],{"class":91},"    sessions=$(tmux list-session -F \\#S)\n",[85,977,979],{"class":87,"line":978},79,[85,980,981],{"class":91},"    projectDisplayNames=()\n",[85,983,985],{"class":87,"line":984},80,[85,986,987],{"class":91},"    projectNames=()\n",[85,989,991],{"class":87,"line":990},81,[85,992,99],{"emptyLinePlaceholder":98},[85,994,996],{"class":87,"line":995},82,[85,997,998],{"class":91},"    for key in ${projectPaths[@]}; do\n",[85,1000,1002],{"class":87,"line":1001},83,[85,1003,1004],{"class":91},"      value=$(basename \"$(dirname \"${key}\")\")\"\u002F\"$(basename \"${key}\")\n",[85,1006,1008],{"class":87,"line":1007},84,[85,1009,1010],{"class":91},"        projectNames+=($value)\n",[85,1012,1014],{"class":87,"line":1013},85,[85,1015,1016],{"class":91},"      if [[ $value == $attachedSessionName ]]; then \n",[85,1018,1020],{"class":87,"line":1019},86,[85,1021,1022],{"class":91},"        projectDisplayNames+=(\"\u001b[33m$value\u001b[0m\")\n",[85,1024,1026],{"class":87,"line":1025},87,[85,1027,1028],{"class":91},"      elif $(contains ${value} ${sessions[@]}); then \n",[85,1030,1032],{"class":87,"line":1031},88,[85,1033,1034],{"class":91},"        projectDisplayNames+=(\"\u001b[34m$value\u001b[0m\")\n",[85,1036,1038],{"class":87,"line":1037},89,[85,1039,1040],{"class":91},"      else\n",[85,1042,1044],{"class":87,"line":1043},90,[85,1045,1046],{"class":91},"        projectDisplayNames+=($value)\n",[85,1048,1050],{"class":87,"line":1049},91,[85,1051,1052],{"class":91},"      fi\n",[85,1054,1056],{"class":87,"line":1055},92,[85,1057,1058],{"class":91},"    done\n",[85,1060,1062],{"class":87,"line":1061},93,[85,1063,99],{"emptyLinePlaceholder":98},[85,1065,1067],{"class":87,"line":1066},94,[85,1068,1069],{"class":91},"    selectedProjectName=$(printf \"%s\\n\" \"${projectDisplayNames[@]}\" | fzf --ansi)\n",[85,1071,1073],{"class":87,"line":1072},95,[85,1074,99],{"emptyLinePlaceholder":98},[85,1076,1078],{"class":87,"line":1077},96,[85,1079,1080],{"class":91},"    index=$(indexOf ${selectedProjectName} ${projectNames[@]})\n",[85,1082,1084],{"class":87,"line":1083},97,[85,1085,1086],{"class":91},"    selectedPath=\"${projectPaths[$index]}\"\n",[85,1088,1090],{"class":87,"line":1089},98,[85,1091,526],{"class":91},[85,1093,1095],{"class":87,"line":1094},99,[85,1096,99],{"emptyLinePlaceholder":98},[85,1098,1100],{"class":87,"line":1099},100,[85,1101,516],{"class":91},[85,1103,1105],{"class":87,"line":1104},101,[85,1106,521],{"class":91},[85,1108,1110],{"class":87,"line":1109},102,[85,1111,526],{"class":91},[85,1113,1115],{"class":87,"line":1114},103,[85,1116,99],{"emptyLinePlaceholder":98},[85,1118,1120],{"class":87,"line":1119},104,[85,1121,535],{"class":91},[85,1123,1125],{"class":87,"line":1124},105,[85,1126,540],{"class":91},[85,1128,1130],{"class":87,"line":1129},106,[85,1131,526],{"class":91},[85,1133,1135],{"class":87,"line":1134},107,[85,1136,99],{"emptyLinePlaceholder":98},[85,1138,1140],{"class":87,"line":1139},108,[85,1141,553],{"class":91},[85,1143,1145],{"class":87,"line":1144},109,[85,1146,558],{"class":91},[85,1148,1150],{"class":87,"line":1149},110,[85,1151,563],{"class":91},[85,1153,1155],{"class":87,"line":1154},111,[85,1156,568],{"class":91},[85,1158,1160],{"class":87,"line":1159},112,[85,1161,526],{"class":91},[15,1163,1164,1165,1168],{},"to use the program we have writen you can run ",[71,1166,1167],{},"project-launcher -d ~\u002Fprojects\u002Fpersonal\u002F -d ~\u002Fprojects\u002Fwork",".",[15,1170,1171,1172,1175],{},"I prever to put this command behind an alias in my ",[71,1173,1174],{},"~\u002F.zshrc"," like so",[76,1177,1179],{"className":78,"code":1178,"language":80,"meta":81,"style":81},"...\n\nalias p=\"project-launcher -d ~\u002Fprojects\u002Fpersonal\u002F -d ~\u002Fprojects\u002Fwork\"\n\n...\n",[71,1180,1181,1185,1189,1194,1198],{"__ignoreMap":81},[85,1182,1183],{"class":87,"line":88},[85,1184,105],{"class":91},[85,1186,1187],{"class":87,"line":95},[85,1188,99],{"emptyLinePlaceholder":98},[85,1190,1191],{"class":87,"line":102},[85,1192,1193],{"class":91},"alias p=\"project-launcher -d ~\u002Fprojects\u002Fpersonal\u002F -d ~\u002Fprojects\u002Fwork\"\n",[85,1195,1196],{"class":87,"line":135},[85,1197,99],{"emptyLinePlaceholder":98},[85,1199,1200],{"class":87,"line":141},[85,1201,105],{"class":91},[574,1203,1205],{"id":1204},"wrapping-up","Wrapping Up",[15,1207,1208],{},"I've been using this little script for a few weeks, and I must say, I'm committed to continuing using tmux this time. I hope that this serves as motivation for you to also develop your personal tools, ultimately enhancing both your productivity and workflow.",[574,1210,1212],{"id":1211},"sources","Sources",[48,1214,1215],{},[51,1216,1217,1220,1221],{},[85,1218,1219],{},"1"," ",[19,1222,1225],{"href":1223,"rel":1224},"https:\u002F\u002Fgithub.com\u002FThePrimeagen\u002F.dotfiles\u002Fblob\u002Fdbfcb9f56e74e035212dcfdeb1675583d13210c6\u002Fbin\u002F.local\u002Fbin\u002Ftmux-sessionizer",[23],"https:\u002F\u002Fgithub.com\u002FThePrimeagen\u002F.dotfiles",[1227,1228,1229],"style",{},"html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":81,"searchDepth":95,"depth":95,"links":1231},[1232,1233,1234],{"id":576,"depth":95,"text":577},{"id":1204,"depth":95,"text":1205},{"id":1211,"depth":95,"text":1212},"2022-07-27","I found myself growing increasingly frustrated with the need to rapidly switch between multiple coding projects. To tackle this, I resorted to managing various terminal sessions, utilizing Amethyst – a tiling window manager for macOS. The challenge arose when these sessions began to stack up, often reaching three or more terminals in full-screen mode, making it easy to lose track of which window corresponded to which project.","md","\u002Fimages\u002Fbuild-a-tmux-project-launcher.png",{"slug":1240},"build-a-tmux-project-launcher","\u002Farticles\u002Ftmux-project-laucher",{"title":5,"description":1236},"Build a Tmux project laucher in shell script in a few minutes.","articles\u002Ftmux-project-laucher",[1246,33,1247,1248],"Terminal","Zsh","Bash",null,"vKLt6oJTDl6uLO-TmTxnX7IRceTWTBpgelhicfsSrxE",1793104389256]