p10k.zsh 334 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410
  1. if [[ $__p9k_sourced != 13 ]]; then
  2. >&2 print -P ""
  3. >&2 print -P "[%F{1}ERROR%f]: Corrupted powerlevel10k installation."
  4. >&2 print -P ""
  5. if (( ${+functions[antigen]} )); then
  6. >&2 print -P "If using %Bantigen%b, run the following command to fix:"
  7. >&2 print -P ""
  8. >&2 print -P " %F{2}antigen%f reset"
  9. if [[ -d ~/.antigen ]]; then
  10. >&2 print -P ""
  11. >&2 print -P "If it doesn't help, try this:"
  12. >&2 print -P ""
  13. >&2 print -P " %F{2}rm%f -rf %U~/.antigen%u"
  14. fi
  15. else
  16. >&2 print -P "Try resetting cache in your plugin manager or"
  17. >&2 print -P "reinstalling powerlevel10k from scratch."
  18. fi
  19. >&2 print -P ""
  20. return 1
  21. fi
  22. if [[ $ZSH_VERSION != (5.<1->*|<6->.*) ]]; then
  23. () {
  24. >&2 echo -E "You are using ZSH version $ZSH_VERSION. The minimum required version for Powerlevel10k is 5.1."
  25. >&2 echo -E "Type 'echo \$ZSH_VERSION' to see your current zsh version."
  26. local def=${SHELL:c:A}
  27. local cur=${${ZSH_ARGZERO#-}:c:A}
  28. local cur_v="$($cur -c 'echo -E $ZSH_VERSION' 2>/dev/null)"
  29. if [[ $cur_v == $ZSH_VERSION && $cur != $def ]]; then
  30. >&2 echo -E "The shell you are currently running is likely $cur."
  31. fi
  32. local other=${${:-zsh}:c}
  33. if [[ -n $other ]] && $other -fc '[[ $ZSH_VERSION == (5.<1->*|<6->.*) ]]' &>/dev/null; then
  34. local other_v="$($other -fc 'echo -E $ZSH_VERSION' 2>/dev/null)"
  35. if [[ -n $other_v && $other_v != $ZSH_VERSION ]]; then
  36. >&2 echo -E "You have $other with version $other_v but this is not what you are using."
  37. if [[ -n $def && $def != ${other:A} ]]; then
  38. >&2 echo -E "To change your user shell, type the following command:"
  39. >&2 echo -E ""
  40. if [[ "$(grep -F $other /etc/shells 2>/dev/null)" != $other ]]; then
  41. >&2 echo -E " echo ${(q-)other} | sudo tee -a /etc/shells"
  42. fi
  43. >&2 echo -E " chsh -s ${(q-)other}"
  44. fi
  45. fi
  46. fi
  47. }
  48. return 1
  49. fi
  50. builtin source "${__p9k_root_dir}/internal/configure.zsh"
  51. builtin source "${__p9k_root_dir}/internal/worker.zsh"
  52. builtin source "${__p9k_root_dir}/internal/parser.zsh"
  53. builtin source "${__p9k_root_dir}/internal/icons.zsh"
  54. # For compatibility with Powerlevel9k. It's not recommended to use mnemonic color
  55. # names in the configuration except for colors 0-7 as these are standard.
  56. typeset -grA __p9k_colors=(
  57. black 000 red 001 green 002 yellow 003
  58. blue 004 magenta 005 cyan 006 white 007
  59. grey 008 maroon 009 lime 010 olive 011
  60. navy 012 fuchsia 013 aqua 014 teal 014
  61. silver 015 grey0 016 navyblue 017 darkblue 018
  62. blue3 020 blue1 021 darkgreen 022 deepskyblue4 025
  63. dodgerblue3 026 dodgerblue2 027 green4 028 springgreen4 029
  64. turquoise4 030 deepskyblue3 032 dodgerblue1 033 darkcyan 036
  65. lightseagreen 037 deepskyblue2 038 deepskyblue1 039 green3 040
  66. springgreen3 041 cyan3 043 darkturquoise 044 turquoise2 045
  67. green1 046 springgreen2 047 springgreen1 048 mediumspringgreen 049
  68. cyan2 050 cyan1 051 purple4 055 purple3 056
  69. blueviolet 057 grey37 059 mediumpurple4 060 slateblue3 062
  70. royalblue1 063 chartreuse4 064 paleturquoise4 066 steelblue 067
  71. steelblue3 068 cornflowerblue 069 darkseagreen4 071 cadetblue 073
  72. skyblue3 074 chartreuse3 076 seagreen3 078 aquamarine3 079
  73. mediumturquoise 080 steelblue1 081 seagreen2 083 seagreen1 085
  74. darkslategray2 087 darkred 088 darkmagenta 091 orange4 094
  75. lightpink4 095 plum4 096 mediumpurple3 098 slateblue1 099
  76. wheat4 101 grey53 102 lightslategrey 103 mediumpurple 104
  77. lightslateblue 105 yellow4 106 darkseagreen 108 lightskyblue3 110
  78. skyblue2 111 chartreuse2 112 palegreen3 114 darkslategray3 116
  79. skyblue1 117 chartreuse1 118 lightgreen 120 aquamarine1 122
  80. darkslategray1 123 deeppink4 125 mediumvioletred 126 darkviolet 128
  81. purple 129 mediumorchid3 133 mediumorchid 134 darkgoldenrod 136
  82. rosybrown 138 grey63 139 mediumpurple2 140 mediumpurple1 141
  83. darkkhaki 143 navajowhite3 144 grey69 145 lightsteelblue3 146
  84. lightsteelblue 147 darkolivegreen3 149 darkseagreen3 150 lightcyan3 152
  85. lightskyblue1 153 greenyellow 154 darkolivegreen2 155 palegreen1 156
  86. darkseagreen2 157 paleturquoise1 159 red3 160 deeppink3 162
  87. magenta3 164 darkorange3 166 indianred 167 hotpink3 168
  88. hotpink2 169 orchid 170 orange3 172 lightsalmon3 173
  89. lightpink3 174 pink3 175 plum3 176 violet 177
  90. gold3 178 lightgoldenrod3 179 tan 180 mistyrose3 181
  91. thistle3 182 plum2 183 yellow3 184 khaki3 185
  92. lightyellow3 187 grey84 188 lightsteelblue1 189 yellow2 190
  93. darkolivegreen1 192 darkseagreen1 193 honeydew2 194 lightcyan1 195
  94. red1 196 deeppink2 197 deeppink1 199 magenta2 200
  95. magenta1 201 orangered1 202 indianred1 204 hotpink 206
  96. mediumorchid1 207 darkorange 208 salmon1 209 lightcoral 210
  97. palevioletred1 211 orchid2 212 orchid1 213 orange1 214
  98. sandybrown 215 lightsalmon1 216 lightpink1 217 pink1 218
  99. plum1 219 gold1 220 lightgoldenrod2 222 navajowhite1 223
  100. mistyrose1 224 thistle1 225 yellow1 226 lightgoldenrod1 227
  101. khaki1 228 wheat1 229 cornsilk1 230 grey100 231
  102. grey3 232 grey7 233 grey11 234 grey15 235
  103. grey19 236 grey23 237 grey27 238 grey30 239
  104. grey35 240 grey39 241 grey42 242 grey46 243
  105. grey50 244 grey54 245 grey58 246 grey62 247
  106. grey66 248 grey70 249 grey74 250 grey78 251
  107. grey82 252 grey85 253 grey89 254 grey93 255)
  108. # For compatibility with Powerlevel9k.
  109. #
  110. # Type `getColorCode background` or `getColorCode foreground` to see the list of predefined colors.
  111. function getColorCode() {
  112. eval "$__p9k_intro"
  113. if (( ARGC == 1 )); then
  114. case $1 in
  115. foreground)
  116. local k
  117. for k in "${(k@)__p9k_colors}"; do
  118. local v=${__p9k_colors[$k]}
  119. print -rP -- "%F{$v}$v - $k%f"
  120. done
  121. return 0
  122. ;;
  123. background)
  124. local k
  125. for k in "${(k@)__p9k_colors}"; do
  126. local v=${__p9k_colors[$k]}
  127. print -rP -- "%K{$v}$v - $k%k"
  128. done
  129. return 0
  130. ;;
  131. esac
  132. fi
  133. echo "Usage: getColorCode background|foreground" >&2
  134. return 1
  135. }
  136. # _p9k_declare <type> <uppercase-name> [default]...
  137. function _p9k_declare() {
  138. local -i set=$+parameters[$2]
  139. (( ARGC > 2 || set )) || return 0
  140. case $1 in
  141. -b)
  142. if (( set )); then
  143. [[ ${(P)2} == true ]] && typeset -gi _$2=1 || typeset -gi _$2=0
  144. else
  145. typeset -gi _$2=$3
  146. fi
  147. ;;
  148. -a)
  149. local -a v=("${(@P)2}")
  150. if (( set )); then
  151. eval "typeset -ga _${(q)2}=(${(@qq)v})";
  152. else
  153. if [[ $3 != '--' ]]; then
  154. echo "internal error in _p9k_declare " "${(qqq)@}" >&2
  155. fi
  156. eval "typeset -ga _${(q)2}=(${(@qq)*[4,-1]})"
  157. fi
  158. ;;
  159. -i)
  160. (( set )) && typeset -gi _$2=$2 || typeset -gi _$2=$3
  161. ;;
  162. -F)
  163. (( set )) && typeset -gF _$2=$2 || typeset -gF _$2=$3
  164. ;;
  165. -s)
  166. (( set )) && typeset -g _$2=${(P)2} || typeset -g _$2=$3
  167. ;;
  168. -e)
  169. if (( set )); then
  170. local v=${(P)2}
  171. typeset -g _$2=${(g::)v}
  172. else
  173. typeset -g _$2=${(g::)3}
  174. fi
  175. ;;
  176. *)
  177. echo "internal error in _p9k_declare " "${(qqq)@}" >&2
  178. esac
  179. }
  180. function _p9k_read_word() {
  181. local -a stat
  182. zstat -A stat +mtime -- $1 2>/dev/null || stat=(-1)
  183. local cached=$_p9k__read_word_cache[$1]
  184. if [[ $cached == $stat[1]:* ]]; then
  185. _p9k__ret=${cached#*:}
  186. else
  187. local rest
  188. _p9k__ret=
  189. { read _p9k__ret rest <$1 } 2>/dev/null
  190. _p9k__ret=${_p9k__ret%$'\r'}
  191. _p9k__read_word_cache[$1]=$stat[1]:$_p9k__ret
  192. fi
  193. [[ -n $_p9k__ret ]]
  194. }
  195. function _p9k_fetch_cwd() {
  196. if [[ $PWD == /* && $PWD -ef . ]]; then
  197. _p9k__cwd=$PWD
  198. else
  199. _p9k__cwd=${${${:-.}:a}:-.}
  200. fi
  201. _p9k__cwd_a=${${_p9k__cwd:A}:-.}
  202. case $_p9k__cwd in
  203. /|.)
  204. _p9k__parent_dirs=()
  205. _p9k__parent_mtimes=()
  206. _p9k__parent_mtimes_i=()
  207. _p9k__parent_mtimes_s=
  208. return
  209. ;;
  210. ~|~/*)
  211. local parent=${${${:-~/..}:a}%/}/
  212. local parts=(${(s./.)_p9k__cwd#$parent})
  213. ;;
  214. *)
  215. local parent=/
  216. local parts=(${(s./.)_p9k__cwd})
  217. ;;
  218. esac
  219. local MATCH
  220. _p9k__parent_dirs=(${(@)${:-{$#parts..1}}/(#m)*/$parent${(pj./.)parts[1,MATCH]}})
  221. if ! zstat -A _p9k__parent_mtimes +mtime -- $_p9k__parent_dirs 2>/dev/null; then
  222. _p9k__parent_mtimes=(${(@)parts/*/-1})
  223. fi
  224. _p9k__parent_mtimes_i=(${(@)${:-{1..$#parts}}/(#m)*/$MATCH:$_p9k__parent_mtimes[MATCH]})
  225. _p9k__parent_mtimes_s="$_p9k__parent_mtimes_i"
  226. }
  227. # Usage: _p9k_glob parent_dir_index pattern [glob_qual]
  228. #
  229. # parent_dir_index indexes _p9k__parent_dirs.
  230. #
  231. # Returns the number of matches.
  232. #
  233. # Pattern cannot have slashes.
  234. #
  235. # Example: _p9k_glob 3 '*.csproj'
  236. function _p9k_glob() {
  237. local dir=$_p9k__parent_dirs[$1]
  238. local cached=$_p9k__glob_cache[$dir/$2]
  239. if [[ $cached == $_p9k__parent_mtimes[$1]:* ]]; then
  240. return ${cached##*:}
  241. fi
  242. local -a stat
  243. zstat -A stat +mtime -- $dir 2>/dev/null || stat=(-1)
  244. eval 'local files=($dir/$~2('$3'N:t))'
  245. _p9k__glob_cache[$dir/$2]="$stat[1]:$#files"
  246. return $#files
  247. }
  248. # Usage: _p9k_upglob pattern [glob_qual]
  249. #
  250. # Returns index within _p9k__parent_dirs or 0 if there is no match.
  251. #
  252. # Search stops before reaching ~/../ or / and never matches in those directories.
  253. #
  254. # Example: _p9k_upglob '*.csproj'
  255. function _p9k_upglob() {
  256. local cached=$_p9k__upsearch_cache[$_p9k__cwd/$1]
  257. if [[ -n $cached ]]; then
  258. if [[ $_p9k__parent_mtimes_s == ${cached% *}(| *) ]]; then
  259. return ${cached##* }
  260. fi
  261. cached=(${(s: :)cached})
  262. local last_idx=$cached[-1]
  263. cached[-1]=()
  264. local -i i
  265. for i in ${(@)${cached:|_p9k__parent_mtimes_i}%:*}; do
  266. _p9k_glob $i "$@" && continue
  267. _p9k__upsearch_cache[$_p9k__cwd/$1]="${_p9k__parent_mtimes_i[1,i]} $i"
  268. return i
  269. done
  270. if (( i != last_idx )); then
  271. _p9k__upsearch_cache[$_p9k__cwd/$1]="${_p9k__parent_mtimes_i[1,$#cached]} $last_idx"
  272. return last_idx
  273. fi
  274. i=$(($#cached + 1))
  275. else
  276. local -i i=1
  277. fi
  278. for ((; i <= $#_p9k__parent_mtimes; ++i)); do
  279. _p9k_glob $i "$@" && continue
  280. _p9k__upsearch_cache[$_p9k__cwd/$1]="${_p9k__parent_mtimes_i[1,i]} $i"
  281. return i
  282. done
  283. _p9k__upsearch_cache[$_p9k__cwd/$1]="$_p9k__parent_mtimes_s 0"
  284. return 0
  285. }
  286. # If we execute `print -P $1`, how many characters will be printed on the last line?
  287. # Assumes that `%{%}` and `%G` don't lie.
  288. #
  289. # _p9k_prompt_length '' => 0
  290. # _p9k_prompt_length 'abc' => 3
  291. # _p9k_prompt_length $'abc\nxy' => 2
  292. # _p9k_prompt_length $'\t' => 8
  293. # _p9k_prompt_length '%F{red}abc' => 3
  294. # _p9k_prompt_length $'%{a\b%Gb%}' => 1
  295. function _p9k_prompt_length() {
  296. local -i COLUMNS=1024
  297. local -i x y=${#1} m
  298. if (( y )); then
  299. while (( ${${(%):-$1%$y(l.1.0)}[-1]} )); do
  300. x=y
  301. (( y *= 2 ))
  302. done
  303. while (( y > x + 1 )); do
  304. (( m = x + (y - x) / 2 ))
  305. (( ${${(%):-$1%$m(l.x.y)}[-1]} = m ))
  306. done
  307. fi
  308. typeset -g _p9k__ret=$x
  309. }
  310. typeset -gr __p9k_byte_suffix=('B' 'K' 'M' 'G' 'T' 'P' 'E' 'Z' 'Y')
  311. # 512 => 512B
  312. # 1800 => 1.76K
  313. # 18000 => 17.6K
  314. function _p9k_human_readable_bytes() {
  315. typeset -F n=$1
  316. local suf
  317. for suf in $__p9k_byte_suffix; do
  318. (( n < 1024 )) && break
  319. (( n /= 1024 ))
  320. done
  321. if (( n >= 100 )); then
  322. printf -v _p9k__ret '%.0f.' $n
  323. elif (( n >= 10 )); then
  324. printf -v _p9k__ret '%.1f' $n
  325. else
  326. printf -v _p9k__ret '%.2f' $n
  327. fi
  328. _p9k__ret=${${_p9k__ret%%0#}%.}$suf
  329. }
  330. if [[ $ZSH_VERSION == (5.<4->*|<6->.*) ]]; then
  331. function _p9k_print_params() { typeset -p -- "$@" }
  332. else
  333. # Cannot use `typeset -p` unconditionally because of bugs in zsh.
  334. function _p9k_print_params() {
  335. local name
  336. for name; do
  337. case $parameters[$name] in
  338. array*)
  339. print -r -- "$name=(" "${(@q)${(@P)name}}" ")"
  340. ;;
  341. association*)
  342. # Cannot use "${(@q)${(@kvP)name}}" because of bugs in zsh.
  343. local kv=("${(@kvP)name}")
  344. print -r -- "$name=(" "${(@q)kv}" ")"
  345. ;;
  346. *)
  347. print -r -- "$name=${(q)${(P)name}}"
  348. ;;
  349. esac
  350. done
  351. }
  352. fi
  353. # Determine if the passed segment is used in the prompt
  354. #
  355. # Pass the name of the segment to this function to test for its presence in
  356. # either the LEFT or RIGHT prompt arrays.
  357. # * $1: The segment to be tested.
  358. _p9k_segment_in_use() {
  359. (( $_POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[(I)$1(|_joined)] ||
  360. $_POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[(I)$1(|_joined)] ))
  361. }
  362. # Caching allows storing array-to-array associations. It should be used like this:
  363. #
  364. # if ! _p9k_cache_get "$key1" "$key2"; then
  365. # # Compute val1 and val2 and then store them in the cache.
  366. # _p9k_cache_set "$val1" "$val2"
  367. # fi
  368. # # Here ${_p9k__cache_val[1]} and ${_p9k__cache_val[2]} are $val1 and $val2 respectively.
  369. #
  370. # Limitations:
  371. #
  372. # * Calling _p9k_cache_set without arguments clears the cache entry. Subsequent calls to
  373. # _p9k_cache_get for the same key will return an error.
  374. # * There must be no intervening _p9k_cache_get calls between the associated _p9k_cache_get
  375. # and _p9k_cache_set.
  376. _p9k_cache_set() {
  377. # Uncomment to see cache misses.
  378. # echo "caching: ${(@0q)_p9k__cache_key} => (${(q)@})" >&2
  379. _p9k_cache[$_p9k__cache_key]="${(pj:\0:)*}0"
  380. _p9k__cache_val=("$@")
  381. _p9k__state_dump_scheduled=1
  382. }
  383. _p9k_cache_get() {
  384. _p9k__cache_key="${(pj:\0:)*}"
  385. local v=$_p9k_cache[$_p9k__cache_key]
  386. [[ -n $v ]] && _p9k__cache_val=("${(@0)${v[1,-2]}}")
  387. }
  388. _p9k_cache_ephemeral_set() {
  389. # Uncomment to see cache misses.
  390. # echo "caching: ${(@0q)_p9k__cache_key} => (${(q)@})" >&2
  391. _p9k__cache_ephemeral[$_p9k__cache_key]="${(pj:\0:)*}0"
  392. _p9k__cache_val=("$@")
  393. }
  394. _p9k_cache_ephemeral_get() {
  395. _p9k__cache_key="${(pj:\0:)*}"
  396. local v=$_p9k__cache_ephemeral[$_p9k__cache_key]
  397. [[ -n $v ]] && _p9k__cache_val=("${(@0)${v[1,-2]}}")
  398. }
  399. _p9k_cache_stat_get() {
  400. local -H stat
  401. local label=$1 f
  402. shift
  403. _p9k__cache_stat_meta=
  404. _p9k__cache_stat_fprint=
  405. for f; do
  406. if zstat -H stat -- $f 2>/dev/null; then
  407. _p9k__cache_stat_meta+="${(q)f} $stat[inode] $stat[mtime] $stat[size] $stat[mode]; "
  408. fi
  409. done
  410. if _p9k_cache_get $0 $label meta "$@"; then
  411. if [[ $_p9k__cache_val[1] == $_p9k__cache_stat_meta ]]; then
  412. _p9k__cache_stat_fprint=$_p9k__cache_val[2]
  413. local -a key=($0 $label fprint "$@" "$_p9k__cache_stat_fprint")
  414. _p9k__cache_fprint_key="${(pj:\0:)key}"
  415. shift 2 _p9k__cache_val
  416. return 0
  417. else
  418. local -a key=($0 $label fprint "$@" "$_p9k__cache_val[2]")
  419. _p9k__cache_ephemeral[${(pj:\0:)key}]="${(pj:\0:)_p9k__cache_val[3,-1]}0"
  420. fi
  421. fi
  422. if (( $+commands[md5] )); then
  423. _p9k__cache_stat_fprint="$(md5 -- $* 2>&1)"
  424. elif (( $+commands[md5sum] )); then
  425. _p9k__cache_stat_fprint="$(md5sum -b -- $* 2>&1)"
  426. else
  427. return 1
  428. fi
  429. local meta_key=$_p9k__cache_key
  430. if _p9k_cache_ephemeral_get $0 $label fprint "$@" "$_p9k__cache_stat_fprint"; then
  431. _p9k__cache_fprint_key=$_p9k__cache_key
  432. _p9k__cache_key=$meta_key
  433. _p9k_cache_set "$_p9k__cache_stat_meta" "$_p9k__cache_stat_fprint" "$_p9k__cache_val[@]"
  434. shift 2 _p9k__cache_val
  435. return 0
  436. fi
  437. _p9k__cache_fprint_key=$_p9k__cache_key
  438. _p9k__cache_key=$meta_key
  439. return 1
  440. }
  441. _p9k_cache_stat_set() {
  442. _p9k_cache_set "$_p9k__cache_stat_meta" "$_p9k__cache_stat_fprint" "$@"
  443. _p9k__cache_key=$_p9k__cache_fprint_key
  444. _p9k_cache_ephemeral_set "$@"
  445. }
  446. # _p9k_param prompt_foo_BAR BACKGROUND red
  447. _p9k_param() {
  448. local key="_p9k_param ${(pj:\0:)*}"
  449. _p9k__ret=$_p9k_cache[$key]
  450. if [[ -n $_p9k__ret ]]; then
  451. _p9k__ret[-1,-1]=''
  452. else
  453. if [[ ${1//-/_} == (#b)prompt_([a-z0-9_]#)(*) ]]; then
  454. local var=_POWERLEVEL9K_${${(U)match[1]}//İ/I}$match[2]_$2
  455. if (( $+parameters[$var] )); then
  456. _p9k__ret=${(P)var}
  457. else
  458. var=_POWERLEVEL9K_${${(U)match[1]%_}//İ/I}_$2
  459. if (( $+parameters[$var] )); then
  460. _p9k__ret=${(P)var}
  461. else
  462. var=_POWERLEVEL9K_$2
  463. if (( $+parameters[$var] )); then
  464. _p9k__ret=${(P)var}
  465. else
  466. _p9k__ret=$3
  467. fi
  468. fi
  469. fi
  470. else
  471. local var=_POWERLEVEL9K_$2
  472. if (( $+parameters[$var] )); then
  473. _p9k__ret=${(P)var}
  474. else
  475. _p9k__ret=$3
  476. fi
  477. fi
  478. _p9k_cache[$key]=${_p9k__ret}.
  479. fi
  480. }
  481. # _p9k_get_icon prompt_foo_BAR BAZ_ICON quix
  482. _p9k_get_icon() {
  483. local key="_p9k_get_icon ${(pj:\0:)*}"
  484. _p9k__ret=$_p9k_cache[$key]
  485. if [[ -n $_p9k__ret ]]; then
  486. _p9k__ret[-1,-1]=''
  487. else
  488. if [[ $2 == $'\1'* ]]; then
  489. _p9k__ret=${2[2,-1]}
  490. else
  491. _p9k_param "$1" "$2" ${icons[$2]-$'\1'$3}
  492. if [[ $_p9k__ret == $'\1'* ]]; then
  493. _p9k__ret=${_p9k__ret[2,-1]}
  494. else
  495. _p9k__ret=${(g::)_p9k__ret}
  496. [[ $_p9k__ret != $'\b'? ]] || _p9k__ret="%{$_p9k__ret%}" # penance for past sins
  497. fi
  498. fi
  499. _p9k_cache[$key]=${_p9k__ret}.
  500. fi
  501. }
  502. _p9k_translate_color() {
  503. if [[ $1 == <-> ]]; then # decimal color code: 255
  504. _p9k__ret=${(l.3..0.)1}
  505. elif [[ $1 == '#'[[:xdigit:]]## ]]; then # hexadecimal color code: #ffffff
  506. _p9k__ret=${${(L)1}//ı/i}
  507. else # named color: red
  508. # Strip prifixes if there are any.
  509. _p9k__ret=$__p9k_colors[${${${1#bg-}#fg-}#br}]
  510. fi
  511. }
  512. # _p9k_color prompt_foo_BAR BACKGROUND red
  513. _p9k_color() {
  514. local key="_p9k_color ${(pj:\0:)*}"
  515. _p9k__ret=$_p9k_cache[$key]
  516. if [[ -n $_p9k__ret ]]; then
  517. _p9k__ret[-1,-1]=''
  518. else
  519. _p9k_param "$@"
  520. _p9k_translate_color $_p9k__ret
  521. _p9k_cache[$key]=${_p9k__ret}.
  522. fi
  523. }
  524. # _p9k_vcs_style CLEAN REMOTE_BRANCH
  525. _p9k_vcs_style() {
  526. local key="$0 ${(pj:\0:)*}"
  527. _p9k__ret=$_p9k_cache[$key]
  528. if [[ -n $_p9k__ret ]]; then
  529. _p9k__ret[-1,-1]=''
  530. else
  531. local style=%b # TODO: support bold
  532. _p9k_color prompt_vcs_$1 BACKGROUND "${__p9k_vcs_states[$1]}"
  533. _p9k_background $_p9k__ret
  534. style+=$_p9k__ret
  535. local var=_POWERLEVEL9K_VCS_${1}_${2}FORMAT_FOREGROUND
  536. if (( $+parameters[$var] )); then
  537. _p9k_translate_color "${(P)var}"
  538. else
  539. var=_POWERLEVEL9K_VCS_${2}FORMAT_FOREGROUND
  540. if (( $+parameters[$var] )); then
  541. _p9k_translate_color "${(P)var}"
  542. else
  543. _p9k_color prompt_vcs_$1 FOREGROUND "$_p9k_color1"
  544. fi
  545. fi
  546. _p9k_foreground $_p9k__ret
  547. _p9k__ret=$style$_p9k__ret
  548. _p9k_cache[$key]=${_p9k__ret}.
  549. fi
  550. }
  551. _p9k_background() {
  552. [[ -n $1 ]] && _p9k__ret="%K{$1}" || _p9k__ret="%k"
  553. }
  554. _p9k_foreground() {
  555. # Note: This code used to produce `%1F` instead of `%F{1}` because it's more efficient.
  556. # Unfortunately, this triggers a bug in zsh. Namely, `%1F{2}` gets percent-expanded as if
  557. # it was `%F{2}`.
  558. [[ -n $1 ]] && _p9k__ret="%F{$1}" || _p9k__ret="%f"
  559. }
  560. _p9k_escape_style() {
  561. [[ $1 == *'}'* ]] && _p9k__ret='${:-"'$1'"}' || _p9k__ret=$1
  562. }
  563. _p9k_escape() {
  564. [[ $1 == *["~!#\`\$^&*()\\\"'<>?{}[]"]* ]] && _p9k__ret="\${(Q)\${:-${(qqq)${(q)1}}}}" || _p9k__ret=$1
  565. }
  566. # * $1: Name of the function that was originally invoked.
  567. # Necessary, to make the dynamic color-overwrite mechanism work.
  568. # * $2: Background color.
  569. # * $3: Foreground color.
  570. # * $4: An identifying icon.
  571. # * $5: 1 to to perform parameter expansion and process substitution.
  572. # * $6: If not empty but becomes empty after parameter expansion and process substitution,
  573. # the segment isn't rendered.
  574. # * $7: Content.
  575. _p9k_left_prompt_segment() {
  576. if ! _p9k_cache_get "$0" "$1" "$2" "$3" "$4" "$_p9k__segment_index"; then
  577. _p9k_color $1 BACKGROUND $2
  578. local bg_color=$_p9k__ret
  579. _p9k_background $bg_color
  580. local bg=$_p9k__ret
  581. _p9k_color $1 FOREGROUND $3
  582. local fg_color=$_p9k__ret
  583. _p9k_foreground $fg_color
  584. local fg=$_p9k__ret
  585. local style=%b$bg$fg
  586. local style_=${style//\}/\\\}}
  587. _p9k_get_icon $1 LEFT_SEGMENT_SEPARATOR
  588. local sep=$_p9k__ret
  589. _p9k_escape $_p9k__ret
  590. local sep_=$_p9k__ret
  591. _p9k_get_icon $1 LEFT_SUBSEGMENT_SEPARATOR
  592. _p9k_escape $_p9k__ret
  593. local subsep_=$_p9k__ret
  594. local icon_
  595. if [[ -n $4 ]]; then
  596. _p9k_get_icon $1 $4
  597. _p9k_escape $_p9k__ret
  598. icon_=$_p9k__ret
  599. fi
  600. _p9k_get_icon $1 LEFT_PROMPT_FIRST_SEGMENT_START_SYMBOL
  601. local start_sep=$_p9k__ret
  602. [[ -n $start_sep ]] && start_sep="%b%k%F{$bg_color}$start_sep"
  603. _p9k_get_icon $1 LEFT_PROMPT_LAST_SEGMENT_END_SYMBOL $sep
  604. _p9k_escape $_p9k__ret
  605. local end_sep_=$_p9k__ret
  606. _p9k_get_icon $1 WHITESPACE_BETWEEN_LEFT_SEGMENTS ' '
  607. local space=$_p9k__ret
  608. _p9k_get_icon $1 LEFT_LEFT_WHITESPACE $space
  609. local left_space=$_p9k__ret
  610. [[ $left_space == *%* ]] && left_space+=$style
  611. _p9k_get_icon $1 LEFT_RIGHT_WHITESPACE $space
  612. _p9k_escape $_p9k__ret
  613. local right_space_=$_p9k__ret
  614. [[ $right_space_ == *%* ]] && right_space_+=$style_
  615. local s='<_p9k__s>' ss='<_p9k__ss>'
  616. local -i non_hermetic=0
  617. # Segment separator logic:
  618. #
  619. # if [[ $_p9k__bg == NONE ]]; then
  620. # 1
  621. # elif (( joined )); then
  622. # 2
  623. # elif [[ $bg_color == (${_p9k__bg}|${_p9k__bg:-0}) ]]; then
  624. # 3
  625. # else
  626. # 4
  627. # fi
  628. local t=$(($#_p9k_t - __p9k_ksh_arrays))
  629. _p9k_t+=$start_sep$style$left_space # 1
  630. _p9k_t+=$style # 2
  631. if [[ -n $fg_color && $fg_color == $bg_color ]]; then
  632. if [[ $fg_color == $_p9k_color1 ]]; then
  633. _p9k_foreground $_p9k_color2
  634. else
  635. _p9k_foreground $_p9k_color1
  636. fi
  637. _p9k_t+=%b$bg$_p9k__ret$ss$style$left_space # 3
  638. else
  639. _p9k_t+=%b$bg$ss$style$left_space # 3
  640. fi
  641. _p9k_t+=%b$bg$s$style$left_space # 4
  642. local join="_p9k__i>=$_p9k_left_join[$_p9k__segment_index]"
  643. _p9k_param $1 SELF_JOINED false
  644. if [[ $_p9k__ret == false ]]; then
  645. if (( _p9k__segment_index > $_p9k_left_join[$_p9k__segment_index] )); then
  646. join+="&&_p9k__i<$_p9k__segment_index"
  647. else
  648. join=
  649. fi
  650. fi
  651. local p=
  652. p+="\${_p9k__n::=}"
  653. p+="\${\${\${_p9k__bg:-0}:#NONE}:-\${_p9k__n::=$((t+1))}}" # 1
  654. if [[ -n $join ]]; then
  655. p+="\${_p9k__n:=\${\${\$(($join)):#0}:+$((t+2))}}" # 2
  656. fi
  657. if (( __p9k_sh_glob )); then
  658. p+="\${_p9k__n:=\${\${(M)\${:-x$bg_color}:#x\$_p9k__bg}:+$((t+3))}}" # 3
  659. p+="\${_p9k__n:=\${\${(M)\${:-x$bg_color}:#x\$${_p9k__bg:-0}}:+$((t+3))}}" # 3
  660. else
  661. p+="\${_p9k__n:=\${\${(M)\${:-x$bg_color}:#x(\$_p9k__bg|\${_p9k__bg:-0})}:+$((t+3))}}" # 3
  662. fi
  663. p+="\${_p9k__n:=$((t+4))}" # 4
  664. _p9k_param $1 VISUAL_IDENTIFIER_EXPANSION '${P9K_VISUAL_IDENTIFIER}'
  665. [[ $_p9k__ret == (|*[^\\])'$('* ]] && non_hermetic=1
  666. local icon_exp_=${_p9k__ret:+\"$_p9k__ret\"}
  667. _p9k_param $1 CONTENT_EXPANSION '${P9K_CONTENT}'
  668. [[ $_p9k__ret == (|*[^\\])'$('* ]] && non_hermetic=1
  669. local content_exp_=${_p9k__ret:+\"$_p9k__ret\"}
  670. if [[ ( $icon_exp_ != '"${P9K_VISUAL_IDENTIFIER}"' && $icon_exp_ == *'$'* ) ||
  671. ( $content_exp_ != '"${P9K_CONTENT}"' && $content_exp_ == *'$'* ) ]]; then
  672. p+="\${P9K_VISUAL_IDENTIFIER::=$icon_}"
  673. fi
  674. local -i has_icon=-1 # maybe
  675. if [[ $icon_exp_ != '"${P9K_VISUAL_IDENTIFIER}"' && $icon_exp_ == *'$'* ]]; then
  676. p+='${_p9k__v::='$icon_exp_$style_'}'
  677. else
  678. [[ $icon_exp_ == '"${P9K_VISUAL_IDENTIFIER}"' ]] && _p9k__ret=$icon_ || _p9k__ret=$icon_exp_
  679. if [[ -n $_p9k__ret ]]; then
  680. p+="\${_p9k__v::=$_p9k__ret"
  681. [[ $_p9k__ret == *%* ]] && p+=$style_
  682. p+="}"
  683. has_icon=1 # definitely yes
  684. else
  685. has_icon=0 # definitely no
  686. fi
  687. fi
  688. p+='${_p9k__c::='$content_exp_'}${_p9k__c::=${_p9k__c//'$'\r''}}'
  689. p+='${_p9k__e::=${${_p9k__'${_p9k__line_index}l${${1#prompt_}%%[A-Z0-9_]#}'+00}:-'
  690. if (( has_icon == -1 )); then
  691. p+='${${(%):-$_p9k__c%1(l.1.0)}[-1]}${${(%):-$_p9k__v%1(l.1.0)}[-1]}}'
  692. else
  693. p+='${${(%):-$_p9k__c%1(l.1.0)}[-1]}'$has_icon'}'
  694. fi
  695. p+='}}+}'
  696. p+='${${_p9k__e:#00}:+${${_p9k_t[$_p9k__n]/'$ss'/$_p9k__ss}/'$s'/$_p9k__s}'
  697. _p9k_param $1 ICON_BEFORE_CONTENT ''
  698. if [[ $_p9k__ret != false ]]; then
  699. _p9k_param $1 PREFIX ''
  700. _p9k__ret=${(g::)_p9k__ret}
  701. _p9k_escape $_p9k__ret
  702. p+=$_p9k__ret
  703. [[ $_p9k__ret == *%* ]] && local -i need_style=1 || local -i need_style=0
  704. if (( has_icon != 0 )); then
  705. _p9k_color $1 VISUAL_IDENTIFIER_COLOR $fg_color
  706. _p9k_foreground $_p9k__ret
  707. _p9k__ret=%b$bg$_p9k__ret
  708. _p9k__ret=${_p9k__ret//\}/\\\}}
  709. if [[ $_p9k__ret != $style_ ]]; then
  710. p+=$_p9k__ret'${_p9k__v}'$style_
  711. else
  712. (( need_style )) && p+=$style_
  713. p+='${_p9k__v}'
  714. fi
  715. _p9k_get_icon $1 LEFT_MIDDLE_WHITESPACE ' '
  716. if [[ -n $_p9k__ret ]]; then
  717. _p9k_escape $_p9k__ret
  718. [[ _p9k__ret == *%* ]] && _p9k__ret+=$style_
  719. p+='${${(M)_p9k__e:#11}:+'$_p9k__ret'}'
  720. fi
  721. elif (( need_style )); then
  722. p+=$style_
  723. fi
  724. p+='${_p9k__c}'$style_
  725. else
  726. _p9k_param $1 PREFIX ''
  727. _p9k__ret=${(g::)_p9k__ret}
  728. _p9k_escape $_p9k__ret
  729. p+=$_p9k__ret
  730. [[ $_p9k__ret == *%* ]] && p+=$style_
  731. p+='${_p9k__c}'$style_
  732. if (( has_icon != 0 )); then
  733. local -i need_style=0
  734. _p9k_get_icon $1 LEFT_MIDDLE_WHITESPACE ' '
  735. if [[ -n $_p9k__ret ]]; then
  736. _p9k_escape $_p9k__ret
  737. [[ $_p9k__ret == *%* ]] && need_style=1
  738. p+='${${(M)_p9k__e:#11}:+'$_p9k__ret'}'
  739. fi
  740. _p9k_color $1 VISUAL_IDENTIFIER_COLOR $fg_color
  741. _p9k_foreground $_p9k__ret
  742. _p9k__ret=%b$bg$_p9k__ret
  743. _p9k__ret=${_p9k__ret//\}/\\\}}
  744. [[ $_p9k__ret != $style_ || $need_style == 1 ]] && p+=$_p9k__ret
  745. p+='$_p9k__v'
  746. fi
  747. fi
  748. _p9k_param $1 SUFFIX ''
  749. _p9k__ret=${(g::)_p9k__ret}
  750. _p9k_escape $_p9k__ret
  751. p+=$_p9k__ret
  752. [[ $_p9k__ret == *%* && -n $right_space_ ]] && p+=$style_
  753. p+=$right_space_
  754. p+='${${:-'
  755. p+="\${_p9k__s::=%F{$bg_color\}$sep_}\${_p9k__ss::=$subsep_}\${_p9k__sss::=%F{$bg_color\}$end_sep_}"
  756. p+="\${_p9k__i::=$_p9k__segment_index}\${_p9k__bg::=$bg_color}"
  757. p+='}+}'
  758. p+='}'
  759. _p9k_param $1 SHOW_ON_UPGLOB ''
  760. _p9k_cache_set "$p" $non_hermetic $_p9k__ret
  761. fi
  762. if [[ -n $_p9k__cache_val[3] ]]; then
  763. _p9k__has_upglob=1
  764. _p9k_upglob $_p9k__cache_val[3] && return
  765. fi
  766. _p9k__non_hermetic_expansion=$_p9k__cache_val[2]
  767. (( $5 )) && _p9k__ret=\"$7\" || _p9k_escape $7
  768. if [[ -z $6 ]]; then
  769. _p9k__prompt+="\${\${:-\${P9K_CONTENT::=$_p9k__ret}$_p9k__cache_val[1]"
  770. else
  771. _p9k__prompt+="\${\${:-\"$6\"}:+\${\${:-\${P9K_CONTENT::=$_p9k__ret}$_p9k__cache_val[1]}"
  772. fi
  773. }
  774. # The same as _p9k_left_prompt_segment above but for the right prompt.
  775. _p9k_right_prompt_segment() {
  776. if ! _p9k_cache_get "$0" "$1" "$2" "$3" "$4" "$_p9k__segment_index"; then
  777. _p9k_color $1 BACKGROUND $2
  778. local bg_color=$_p9k__ret
  779. _p9k_background $bg_color
  780. local bg=$_p9k__ret
  781. local bg_=${_p9k__ret//\}/\\\}}
  782. _p9k_color $1 FOREGROUND $3
  783. local fg_color=$_p9k__ret
  784. _p9k_foreground $fg_color
  785. local fg=$_p9k__ret
  786. local style=%b$bg$fg
  787. local style_=${style//\}/\\\}}
  788. _p9k_get_icon $1 RIGHT_SEGMENT_SEPARATOR
  789. local sep=$_p9k__ret
  790. _p9k_escape $_p9k__ret
  791. local sep_=$_p9k__ret
  792. _p9k_get_icon $1 RIGHT_SUBSEGMENT_SEPARATOR
  793. local subsep=$_p9k__ret
  794. [[ $subsep == *%* ]] && subsep+=$style
  795. local icon_
  796. if [[ -n $4 ]]; then
  797. _p9k_get_icon $1 $4
  798. _p9k_escape $_p9k__ret
  799. icon_=$_p9k__ret
  800. fi
  801. _p9k_get_icon $1 RIGHT_PROMPT_FIRST_SEGMENT_START_SYMBOL $sep
  802. local start_sep=$_p9k__ret
  803. [[ -n $start_sep ]] && start_sep="%b%k%F{$bg_color}$start_sep"
  804. _p9k_get_icon $1 RIGHT_PROMPT_LAST_SEGMENT_END_SYMBOL
  805. _p9k_escape $_p9k__ret
  806. local end_sep_=$_p9k__ret
  807. _p9k_get_icon $1 WHITESPACE_BETWEEN_RIGHT_SEGMENTS ' '
  808. local space=$_p9k__ret
  809. _p9k_get_icon $1 RIGHT_LEFT_WHITESPACE $space
  810. local left_space=$_p9k__ret
  811. [[ $left_space == *%* ]] && left_space+=$style
  812. _p9k_get_icon $1 RIGHT_RIGHT_WHITESPACE $space
  813. _p9k_escape $_p9k__ret
  814. local right_space_=$_p9k__ret
  815. [[ $right_space_ == *%* ]] && right_space_+=$style_
  816. local w='<_p9k__w>' s='<_p9k__s>'
  817. local -i non_hermetic=0
  818. # Segment separator logic:
  819. #
  820. # if [[ $_p9k__bg == NONE ]]; then
  821. # 1
  822. # elif (( joined )); then
  823. # 2
  824. # elif [[ $_p9k__bg == (${bg_color}|${bg_color:-0}) ]]; then
  825. # 3
  826. # else
  827. # 4
  828. # fi
  829. local t=$(($#_p9k_t - __p9k_ksh_arrays))
  830. _p9k_t+=$start_sep$style$left_space # 1
  831. _p9k_t+=$w$style # 2
  832. _p9k_t+=$w$style$subsep$left_space # 3
  833. _p9k_t+=$w%F{$bg_color}$sep$style$left_space # 4
  834. local join="_p9k__i>=$_p9k_right_join[$_p9k__segment_index]"
  835. _p9k_param $1 SELF_JOINED false
  836. if [[ $_p9k__ret == false ]]; then
  837. if (( _p9k__segment_index > $_p9k_right_join[$_p9k__segment_index] )); then
  838. join+="&&_p9k__i<$_p9k__segment_index"
  839. else
  840. join=
  841. fi
  842. fi
  843. local p=
  844. p+="\${_p9k__n::=}"
  845. p+="\${\${\${_p9k__bg:-0}:#NONE}:-\${_p9k__n::=$((t+1))}}" # 1
  846. if [[ -n $join ]]; then
  847. p+="\${_p9k__n:=\${\${\$(($join)):#0}:+$((t+2))}}" # 2
  848. fi
  849. if (( __p9k_sh_glob )); then
  850. p+="\${_p9k__n:=\${\${(M)\${:-x\$_p9k__bg}:#x${(b)bg_color}}:+$((t+3))}}" # 3
  851. p+="\${_p9k__n:=\${\${(M)\${:-x\$_p9k__bg}:#x${(b)bg_color:-0}}:+$((t+3))}}" # 3
  852. else
  853. p+="\${_p9k__n:=\${\${(M)\${:-x\$_p9k__bg}:#x(${(b)bg_color}|${(b)bg_color:-0})}:+$((t+3))}}" # 3
  854. fi
  855. p+="\${_p9k__n:=$((t+4))}" # 4
  856. _p9k_param $1 VISUAL_IDENTIFIER_EXPANSION '${P9K_VISUAL_IDENTIFIER}'
  857. [[ $_p9k__ret == (|*[^\\])'$('* ]] && non_hermetic=1
  858. local icon_exp_=${_p9k__ret:+\"$_p9k__ret\"}
  859. _p9k_param $1 CONTENT_EXPANSION '${P9K_CONTENT}'
  860. [[ $_p9k__ret == (|*[^\\])'$('* ]] && non_hermetic=1
  861. local content_exp_=${_p9k__ret:+\"$_p9k__ret\"}
  862. if [[ ( $icon_exp_ != '"${P9K_VISUAL_IDENTIFIER}"' && $icon_exp_ == *'$'* ) ||
  863. ( $content_exp_ != '"${P9K_CONTENT}"' && $content_exp_ == *'$'* ) ]]; then
  864. p+="\${P9K_VISUAL_IDENTIFIER::=$icon_}"
  865. fi
  866. local -i has_icon=-1 # maybe
  867. if [[ $icon_exp_ != '"${P9K_VISUAL_IDENTIFIER}"' && $icon_exp_ == *'$'* ]]; then
  868. p+="\${_p9k__v::=$icon_exp_$style_}"
  869. else
  870. [[ $icon_exp_ == '"${P9K_VISUAL_IDENTIFIER}"' ]] && _p9k__ret=$icon_ || _p9k__ret=$icon_exp_
  871. if [[ -n $_p9k__ret ]]; then
  872. p+="\${_p9k__v::=$_p9k__ret"
  873. [[ $_p9k__ret == *%* ]] && p+=$style_
  874. p+="}"
  875. has_icon=1 # definitely yes
  876. else
  877. has_icon=0 # definitely no
  878. fi
  879. fi
  880. p+='${_p9k__c::='$content_exp_'}${_p9k__c::=${_p9k__c//'$'\r''}}'
  881. p+='${_p9k__e::=${${_p9k__'${_p9k__line_index}r${${1#prompt_}%%[A-Z0-9_]#}'+00}:-'
  882. if (( has_icon == -1 )); then
  883. p+='${${(%):-$_p9k__c%1(l.1.0)}[-1]}${${(%):-$_p9k__v%1(l.1.0)}[-1]}}'
  884. else
  885. p+='${${(%):-$_p9k__c%1(l.1.0)}[-1]}'$has_icon'}'
  886. fi
  887. p+='}}+}'
  888. p+='${${_p9k__e:#00}:+${_p9k_t[$_p9k__n]/'$w'/$_p9k__w}'
  889. _p9k_param $1 ICON_BEFORE_CONTENT ''
  890. if [[ $_p9k__ret != true ]]; then
  891. _p9k_param $1 PREFIX ''
  892. _p9k__ret=${(g::)_p9k__ret}
  893. _p9k_escape $_p9k__ret
  894. p+=$_p9k__ret
  895. [[ $_p9k__ret == *%* ]] && p+=$style_
  896. p+='${_p9k__c}'$style_
  897. if (( has_icon != 0 )); then
  898. local -i need_style=0
  899. _p9k_get_icon $1 RIGHT_MIDDLE_WHITESPACE ' '
  900. if [[ -n $_p9k__ret ]]; then
  901. _p9k_escape $_p9k__ret
  902. [[ $_p9k__ret == *%* ]] && need_style=1
  903. p+='${${(M)_p9k__e:#11}:+'$_p9k__ret'}'
  904. fi
  905. _p9k_color $1 VISUAL_IDENTIFIER_COLOR $fg_color
  906. _p9k_foreground $_p9k__ret
  907. _p9k__ret=%b$bg$_p9k__ret
  908. _p9k__ret=${_p9k__ret//\}/\\\}}
  909. [[ $_p9k__ret != $style_ || $need_style == 1 ]] && p+=$_p9k__ret
  910. p+='$_p9k__v'
  911. fi
  912. else
  913. _p9k_param $1 PREFIX ''
  914. _p9k__ret=${(g::)_p9k__ret}
  915. _p9k_escape $_p9k__ret
  916. p+=$_p9k__ret
  917. [[ $_p9k__ret == *%* ]] && local -i need_style=1 || local -i need_style=0
  918. if (( has_icon != 0 )); then
  919. _p9k_color $1 VISUAL_IDENTIFIER_COLOR $fg_color
  920. _p9k_foreground $_p9k__ret
  921. _p9k__ret=%b$bg$_p9k__ret
  922. _p9k__ret=${_p9k__ret//\}/\\\}}
  923. if [[ $_p9k__ret != $style_ ]]; then
  924. p+=$_p9k__ret'${_p9k__v}'$style_
  925. else
  926. (( need_style )) && p+=$style_
  927. p+='${_p9k__v}'
  928. fi
  929. _p9k_get_icon $1 RIGHT_MIDDLE_WHITESPACE ' '
  930. if [[ -n $_p9k__ret ]]; then
  931. _p9k_escape $_p9k__ret
  932. [[ _p9k__ret == *%* ]] && _p9k__ret+=$style_
  933. p+='${${(M)_p9k__e:#11}:+'$_p9k__ret'}'
  934. fi
  935. elif (( need_style )); then
  936. p+=$style_
  937. fi
  938. p+='${_p9k__c}'$style_
  939. fi
  940. _p9k_param $1 SUFFIX ''
  941. _p9k__ret=${(g::)_p9k__ret}
  942. _p9k_escape $_p9k__ret
  943. p+=$_p9k__ret
  944. p+='${${:-'
  945. if [[ -n $fg_color && $fg_color == $bg_color ]]; then
  946. if [[ $fg_color == $_p9k_color1 ]]; then
  947. _p9k_foreground $_p9k_color2
  948. else
  949. _p9k_foreground $_p9k_color1
  950. fi
  951. else
  952. _p9k__ret=$fg
  953. fi
  954. _p9k__ret=${_p9k__ret//\}/\\\}}
  955. p+="\${_p9k__w::=${right_space_:+$style_}$right_space_%b$bg_$_p9k__ret}"
  956. p+='${_p9k__sss::='
  957. p+=$style_$right_space_
  958. [[ $right_space_ == *%* ]] && p+=$style_
  959. if [[ -n $end_sep_ ]]; then
  960. p+="%k%F{$bg_color\}$end_sep_$style_"
  961. fi
  962. p+='}'
  963. p+="\${_p9k__i::=$_p9k__segment_index}\${_p9k__bg::=$bg_color}"
  964. p+='}+}'
  965. p+='}'
  966. _p9k_param $1 SHOW_ON_UPGLOB ''
  967. _p9k_cache_set "$p" $non_hermetic $_p9k__ret
  968. fi
  969. if [[ -n $_p9k__cache_val[3] ]]; then
  970. _p9k__has_upglob=1
  971. _p9k_upglob $_p9k__cache_val[3] && return
  972. fi
  973. _p9k__non_hermetic_expansion=$_p9k__cache_val[2]
  974. (( $5 )) && _p9k__ret=\"$7\" || _p9k_escape $7
  975. if [[ -z $6 ]]; then
  976. _p9k__prompt+="\${\${:-\${P9K_CONTENT::=$_p9k__ret}$_p9k__cache_val[1]"
  977. else
  978. _p9k__prompt+="\${\${:-\"$6\"}:+\${\${:-\${P9K_CONTENT::=$_p9k__ret}$_p9k__cache_val[1]}"
  979. fi
  980. }
  981. function _p9k_prompt_segment() { "_p9k_${_p9k__prompt_side}_prompt_segment" "$@" }
  982. function p9k_prompt_segment() { p10k segment "$@" }
  983. function _p9k_python_version() {
  984. case $commands[python] in
  985. "")
  986. return 1
  987. ;;
  988. ${PYENV_ROOT:-~/.pyenv}/shims/python)
  989. local P9K_PYENV_PYTHON_VERSION _p9k__pyenv_version
  990. local -i _POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW=1 _POWERLEVEL9K_PYENV_SHOW_SYSTEM=1
  991. local _POWERLEVEL9K_PYENV_SOURCES=(shell local global)
  992. if _p9k_pyenv_compute && [[ $P9K_PYENV_PYTHON_VERSION == ([[:digit:].]##)* ]]; then
  993. _p9k__ret=$P9K_PYENV_PYTHON_VERSION
  994. return 0
  995. fi
  996. ;& # fall through
  997. *)
  998. _p9k_cached_cmd 1 '' python --version || return
  999. [[ $_p9k__ret == (#b)Python\ ([[:digit:].]##)* ]] && _p9k__ret=$match[1]
  1000. ;;
  1001. esac
  1002. }
  1003. ################################################################
  1004. # Prompt Segment Definitions
  1005. ################################################################
  1006. ################################################################
  1007. # Anaconda Environment
  1008. prompt_anaconda() {
  1009. local msg
  1010. if _p9k_python_version; then
  1011. P9K_ANACONDA_PYTHON_VERSION=$_p9k__ret
  1012. if (( _POWERLEVEL9K_ANACONDA_SHOW_PYTHON_VERSION )); then
  1013. msg="${P9K_ANACONDA_PYTHON_VERSION//\%/%%} "
  1014. fi
  1015. else
  1016. unset P9K_ANACONDA_PYTHON_VERSION
  1017. fi
  1018. local p=${CONDA_PREFIX:-$CONDA_ENV_PATH}
  1019. msg+="$_POWERLEVEL9K_ANACONDA_LEFT_DELIMITER${${p:t}//\%/%%}$_POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER"
  1020. _p9k_prompt_segment "$0" "blue" "$_p9k_color1" 'PYTHON_ICON' 0 '' "$msg"
  1021. }
  1022. _p9k_prompt_anaconda_init() {
  1023. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${CONDA_PREFIX:-$CONDA_ENV_PATH}'
  1024. }
  1025. # Populates array `reply` with "$#profile:$profile:$region" where $profile and $region
  1026. # come from the AWS config (~/.aws/config).
  1027. function _p9k_parse_aws_config() {
  1028. local cfg=$1
  1029. typeset -ga reply=()
  1030. [[ -f $cfg && -r $cfg ]] || return
  1031. local -a lines
  1032. lines=(${(f)"$(<$cfg)"}) || return
  1033. local line profile
  1034. local -a match mbegin mend
  1035. for line in $lines; do
  1036. if [[ $line == [[:space:]]#'[default]'[[:space:]]#(|'#'*) ]]; then
  1037. # example: [default]
  1038. profile=default
  1039. elif [[ $line == (#b)'[profile'[[:space:]]##([^[:space:]]|[^[:space:]]*[^[:space:]])[[:space:]]#']'[[:space:]]#(|'#'*) ]]; then
  1040. # example: [profile prod]
  1041. profile=${(Q)match[1]}
  1042. elif [[ $line == (#b)[[:space:]]#region[[:space:]]#=[[:space:]]#([^[:space:]]|[^[:space:]]*[^[:space:]])[[:space:]]# ]]; then
  1043. # example: region = eu-west-1
  1044. if [[ -n $profile ]]; then
  1045. reply+=$#profile:$profile:$match[1]
  1046. profile=
  1047. fi
  1048. fi
  1049. done
  1050. }
  1051. ################################################################
  1052. # AWS Profile
  1053. prompt_aws() {
  1054. typeset -g P9K_AWS_PROFILE="${AWS_VAULT:-${AWSUME_PROFILE:-${AWS_PROFILE:-$AWS_DEFAULT_PROFILE}}}"
  1055. local pat class state
  1056. for pat class in "${_POWERLEVEL9K_AWS_CLASSES[@]}"; do
  1057. if [[ $P9K_AWS_PROFILE == ${~pat} ]]; then
  1058. [[ -n $class ]] && state=_${${(U)class}//İ/I}
  1059. break
  1060. fi
  1061. done
  1062. if [[ -n ${AWS_REGION:-$AWS_DEFAULT_REGION} ]]; then
  1063. typeset -g P9K_AWS_REGION=${AWS_REGION:-$AWS_DEFAULT_REGION}
  1064. else
  1065. local cfg=${AWS_CONFIG_FILE:-~/.aws/config}
  1066. if ! _p9k_cache_stat_get $0 $cfg; then
  1067. local -a reply
  1068. _p9k_parse_aws_config $cfg
  1069. _p9k_cache_stat_set $reply
  1070. fi
  1071. local prefix=$#P9K_AWS_PROFILE:$P9K_AWS_PROFILE:
  1072. local kv=$_p9k__cache_val[(r)${(b)prefix}*]
  1073. typeset -g P9K_AWS_REGION=${kv#$prefix}
  1074. fi
  1075. _p9k_prompt_segment "$0$state" red white 'AWS_ICON' 0 '' "${P9K_AWS_PROFILE//\%/%%}"
  1076. }
  1077. _p9k_prompt_aws_init() {
  1078. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${AWS_VAULT:-${AWSUME_PROFILE:-${AWS_PROFILE:-$AWS_DEFAULT_PROFILE}}}'
  1079. }
  1080. ################################################################
  1081. # Current Elastic Beanstalk environment
  1082. prompt_aws_eb_env() {
  1083. _p9k_upglob .elasticbeanstalk -/ && return
  1084. local dir=$_p9k__parent_dirs[$?]
  1085. if ! _p9k_cache_stat_get $0 $dir/.elasticbeanstalk/config.yml; then
  1086. local env
  1087. env="$(command eb list 2>/dev/null)" || env=
  1088. env="${${(@M)${(@f)env}:#\* *}#\* }"
  1089. _p9k_cache_stat_set "$env"
  1090. fi
  1091. [[ -n $_p9k__cache_val[1] ]] || return
  1092. _p9k_prompt_segment "$0" black green 'AWS_EB_ICON' 0 '' "${_p9k__cache_val[1]//\%/%%}"
  1093. }
  1094. _p9k_prompt_aws_eb_env_init() {
  1095. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[eb]'
  1096. }
  1097. ################################################################
  1098. # Segment to indicate background jobs with an icon.
  1099. prompt_background_jobs() {
  1100. local -i len=$#_p9k__prompt _p9k__has_upglob
  1101. local msg
  1102. if (( _POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE )); then
  1103. if (( _POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE_ALWAYS )); then
  1104. msg='${(%):-%j}'
  1105. else
  1106. msg='${${(%):-%j}:#1}'
  1107. fi
  1108. fi
  1109. _p9k_prompt_segment $0 "$_p9k_color1" cyan BACKGROUND_JOBS_ICON 1 '${${(%):-%j}:#0}' "$msg"
  1110. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  1111. }
  1112. ################################################################
  1113. # Segment that indicates usage level of current partition.
  1114. prompt_disk_usage() {
  1115. local -i len=$#_p9k__prompt _p9k__has_upglob
  1116. _p9k_prompt_segment $0_CRITICAL red white DISK_ICON 1 '$_p9k__disk_usage_critical' '$_p9k__disk_usage_pct%%'
  1117. _p9k_prompt_segment $0_WARNING yellow $_p9k_color1 DISK_ICON 1 '$_p9k__disk_usage_warning' '$_p9k__disk_usage_pct%%'
  1118. if (( ! _POWERLEVEL9K_DISK_USAGE_ONLY_WARNING )); then
  1119. _p9k_prompt_segment $0_NORMAL $_p9k_color1 yellow DISK_ICON 1 '$_p9k__disk_usage_normal' '$_p9k__disk_usage_pct%%'
  1120. fi
  1121. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  1122. }
  1123. _p9k_prompt_disk_usage_init() {
  1124. typeset -g _p9k__disk_usage_pct=
  1125. typeset -g _p9k__disk_usage_normal=
  1126. typeset -g _p9k__disk_usage_warning=
  1127. typeset -g _p9k__disk_usage_critical=
  1128. _p9k__async_segments_compute+='_p9k_worker_invoke disk_usage "_p9k_prompt_disk_usage_compute ${(q)_p9k__cwd_a}"'
  1129. }
  1130. _p9k_prompt_disk_usage_compute() {
  1131. (( $+commands[df] )) || return
  1132. _p9k_worker_async "_p9k_prompt_disk_usage_async ${(q)1}" _p9k_prompt_disk_usage_sync
  1133. }
  1134. _p9k_prompt_disk_usage_async() {
  1135. local pct=${${=${(f)"$(df -P $1 2>/dev/null)"}[2]}[5]%%%}
  1136. [[ $pct == <0-100> && $pct != $_p9k__disk_usage_pct ]] || return
  1137. _p9k__disk_usage_pct=$pct
  1138. _p9k__disk_usage_normal=
  1139. _p9k__disk_usage_warning=
  1140. _p9k__disk_usage_critical=
  1141. if (( _p9k__disk_usage_pct >= _POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL )); then
  1142. _p9k__disk_usage_critical=1
  1143. elif (( _p9k__disk_usage_pct >= _POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL )); then
  1144. _p9k__disk_usage_warning=1
  1145. elif (( ! _POWERLEVEL9K_DISK_USAGE_ONLY_WARNING )); then
  1146. _p9k__disk_usage_normal=1
  1147. fi
  1148. _p9k_print_params \
  1149. _p9k__disk_usage_pct \
  1150. _p9k__disk_usage_normal \
  1151. _p9k__disk_usage_warning \
  1152. _p9k__disk_usage_critical
  1153. echo -E - 'reset=1'
  1154. }
  1155. _p9k_prompt_disk_usage_sync() {
  1156. eval $REPLY
  1157. _p9k_worker_reply $REPLY
  1158. }
  1159. function _p9k_read_file() {
  1160. _p9k__ret=''
  1161. [[ -n $1 ]] && IFS='' read -r _p9k__ret <$1
  1162. [[ -n $_p9k__ret ]]
  1163. }
  1164. function _p9k_fvm_old() {
  1165. _p9k_upglob fvm @ && return 1
  1166. local fvm=$_p9k__parent_dirs[$?]/fvm
  1167. if [[ ${fvm:A} == (#b)*/versions/([^/]##)/bin/flutter ]]; then
  1168. _p9k_prompt_segment prompt_fvm blue $_p9k_color1 FLUTTER_ICON 0 '' ${match[1]//\%/%%}
  1169. return 0
  1170. fi
  1171. return 1
  1172. }
  1173. function _p9k_fvm_new() {
  1174. _p9k_upglob .fvm @ && return 1
  1175. local sdk=$_p9k__parent_dirs[$?]/.fvm/flutter_sdk
  1176. if [[ ${sdk:A} == (#b)*/versions/([^/]##) ]]; then
  1177. _p9k_prompt_segment prompt_fvm blue $_p9k_color1 FLUTTER_ICON 0 '' ${match[1]//\%/%%}
  1178. return 0
  1179. fi
  1180. return 1
  1181. }
  1182. prompt_fvm() {
  1183. _p9k_fvm_new || _p9k_fvm_old
  1184. }
  1185. _p9k_prompt_fvm_init() {
  1186. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[fvm]'
  1187. }
  1188. ################################################################
  1189. # Segment that displays the battery status in levels and colors
  1190. prompt_battery() {
  1191. [[ $_p9k_os == (Linux|Android) ]] && _p9k_prompt_battery_set_args
  1192. (( $#_p9k__battery_args )) && _p9k_prompt_segment "${_p9k__battery_args[@]}"
  1193. }
  1194. _p9k_prompt_battery_init() {
  1195. typeset -ga _p9k__battery_args=()
  1196. if [[ $_p9k_os == OSX && $+commands[pmset] == 1 ]]; then
  1197. _p9k__async_segments_compute+='_p9k_worker_invoke battery _p9k_prompt_battery_compute'
  1198. return
  1199. fi
  1200. if [[ $_p9k_os != (Linux|Android) ||
  1201. -z /sys/class/power_supply/(CMB*|BAT*|*battery)/(energy_full|charge_full|charge_counter)(#qN) ]]; then
  1202. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${:-}'
  1203. fi
  1204. }
  1205. _p9k_prompt_battery_compute() {
  1206. _p9k_worker_async _p9k_prompt_battery_async _p9k_prompt_battery_sync
  1207. }
  1208. _p9k_prompt_battery_async() {
  1209. local prev="${(pj:\0:)_p9k__battery_args}"
  1210. _p9k_prompt_battery_set_args
  1211. [[ "${(pj:\0:)_p9k__battery_args}" == $prev ]] && return 1
  1212. _p9k_print_params _p9k__battery_args
  1213. echo -E - 'reset=2'
  1214. }
  1215. _p9k_prompt_battery_sync() {
  1216. eval $REPLY
  1217. _p9k_worker_reply $REPLY
  1218. }
  1219. _p9k_prompt_battery_set_args() {
  1220. _p9k__battery_args=()
  1221. local state remain
  1222. local -i bat_percent
  1223. case $_p9k_os in
  1224. OSX)
  1225. (( $+commands[pmset] )) || return
  1226. local raw_data=${${(Af)"$(pmset -g batt 2>/dev/null)"}[2]}
  1227. [[ $raw_data == *InternalBattery* ]] || return
  1228. remain=${${(s: :)${${(s:; :)raw_data}[3]}}[1]}
  1229. [[ $remain == *no* ]] && remain="..."
  1230. [[ $raw_data =~ '([0-9]+)%' ]] && bat_percent=$match[1]
  1231. case "${${(s:; :)raw_data}[2]}" in
  1232. 'charging'|'finishing charge'|'AC attached')
  1233. if (( bat_percent == 100 )); then
  1234. state=CHARGED
  1235. remain=''
  1236. else
  1237. state=CHARGING
  1238. fi
  1239. ;;
  1240. 'discharging')
  1241. (( bat_percent < _POWERLEVEL9K_BATTERY_LOW_THRESHOLD )) && state=LOW || state=DISCONNECTED
  1242. ;;
  1243. *)
  1244. state=CHARGED
  1245. remain=''
  1246. ;;
  1247. esac
  1248. ;;
  1249. Linux|Android)
  1250. # See https://sourceforge.net/projects/acpiclient.
  1251. local -a bats=( /sys/class/power_supply/(CMB*|BAT*|*battery)/(FN) )
  1252. (( $#bats )) || return
  1253. local -i energy_now energy_full power_now
  1254. local -i is_full=1 is_calculating is_charching
  1255. local dir
  1256. for dir in $bats; do
  1257. local -i pow=0 full=0
  1258. if _p9k_read_file $dir/(energy_full|charge_full|charge_counter)(N); then
  1259. (( energy_full += ${full::=_p9k__ret} ))
  1260. fi
  1261. if _p9k_read_file $dir/(power|current)_now(N) && (( $#_p9k__ret < 9 )); then
  1262. (( power_now += ${pow::=$_p9k__ret} ))
  1263. fi
  1264. if _p9k_read_file $dir/capacity(N); then
  1265. (( energy_now += _p9k__ret * full / 100. + 0.5 ))
  1266. elif _p9k_read_file $dir/(energy|charge)_now(N); then
  1267. (( energy_now += _p9k__ret ))
  1268. fi
  1269. _p9k_read_file $dir/status(N) && local bat_status=$_p9k__ret || continue
  1270. [[ $bat_status != Full ]] && is_full=0
  1271. [[ $bat_status == Charging ]] && is_charching=1
  1272. [[ $bat_status == (Charging|Discharging) && $pow == 0 ]] && is_calculating=1
  1273. done
  1274. (( energy_full )) || return
  1275. bat_percent=$(( 100. * energy_now / energy_full + 0.5 ))
  1276. (( bat_percent > 100 )) && bat_percent=100
  1277. if (( is_full || (bat_percent == 100 && is_charching) )); then
  1278. state=CHARGED
  1279. else
  1280. if (( is_charching )); then
  1281. state=CHARGING
  1282. elif (( bat_percent < _POWERLEVEL9K_BATTERY_LOW_THRESHOLD )); then
  1283. state=LOW
  1284. else
  1285. state=DISCONNECTED
  1286. fi
  1287. if (( power_now > 0 )); then
  1288. (( is_charching )) && local -i e=$((energy_full - energy_now)) || local -i e=energy_now
  1289. local -i minutes=$(( 60 * e / power_now ))
  1290. (( minutes > 0 )) && remain=$((minutes/60)):${(l#2##0#)$((minutes%60))}
  1291. elif (( is_calculating )); then
  1292. remain="..."
  1293. fi
  1294. fi
  1295. ;;
  1296. *)
  1297. return 0
  1298. ;;
  1299. esac
  1300. (( bat_percent >= _POWERLEVEL9K_BATTERY_${state}_HIDE_ABOVE_THRESHOLD )) && return
  1301. local msg="$bat_percent%%"
  1302. [[ $_POWERLEVEL9K_BATTERY_VERBOSE == 1 && -n $remain ]] && msg+=" ($remain)"
  1303. local icon=BATTERY_ICON
  1304. local var=_POWERLEVEL9K_BATTERY_${state}_STAGES
  1305. local -i idx="${#${(@P)var}}"
  1306. if (( idx )); then
  1307. (( bat_percent < 100 )) && idx=$((bat_percent * idx / 100 + 1))
  1308. icon=$'\1'"${${(@P)var}[idx]}"
  1309. fi
  1310. local bg=$_p9k_color1
  1311. local var=_POWERLEVEL9K_BATTERY_${state}_LEVEL_BACKGROUND
  1312. local -i idx="${#${(@P)var}}"
  1313. if (( idx )); then
  1314. (( bat_percent < 100 )) && idx=$((bat_percent * idx / 100 + 1))
  1315. bg="${${(@P)var}[idx]}"
  1316. fi
  1317. local fg=$_p9k_battery_states[$state]
  1318. local var=_POWERLEVEL9K_BATTERY_${state}_LEVEL_FOREGROUND
  1319. local -i idx="${#${(@P)var}}"
  1320. if (( idx )); then
  1321. (( bat_percent < 100 )) && idx=$((bat_percent * idx / 100 + 1))
  1322. fg="${${(@P)var}[idx]}"
  1323. fi
  1324. _p9k__battery_args=(prompt_battery_$state "$bg" "$fg" $icon 0 '' $msg)
  1325. }
  1326. ################################################################
  1327. # Public IP segment
  1328. prompt_public_ip() {
  1329. local -i len=$#_p9k__prompt _p9k__has_upglob
  1330. local ip='${_p9k__public_ip:-$_POWERLEVEL9K_PUBLIC_IP_NONE}'
  1331. if [[ -n $_POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ]]; then
  1332. _p9k_prompt_segment "$0" "$_p9k_color1" "$_p9k_color2" PUBLIC_IP_ICON 1 '${_p9k__public_ip_not_vpn:+'$ip'}' $ip
  1333. _p9k_prompt_segment "$0" "$_p9k_color1" "$_p9k_color2" VPN_ICON 1 '${_p9k__public_ip_vpn:+'$ip'}' $ip
  1334. else
  1335. _p9k_prompt_segment "$0" "$_p9k_color1" "$_p9k_color2" PUBLIC_IP_ICON 1 $ip $ip
  1336. fi
  1337. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  1338. }
  1339. _p9k_prompt_public_ip_init() {
  1340. typeset -g _p9k__public_ip=
  1341. typeset -gF _p9k__public_ip_next_time=0
  1342. _p9k__async_segments_compute+='_p9k_worker_invoke public_ip _p9k_prompt_public_ip_compute'
  1343. }
  1344. _p9k_prompt_public_ip_compute() {
  1345. (( EPOCHREALTIME >= _p9k__public_ip_next_time )) || return
  1346. _p9k_worker_async _p9k_prompt_public_ip_async _p9k_prompt_public_ip_sync
  1347. }
  1348. _p9k_prompt_public_ip_async() {
  1349. local ip method
  1350. local -F start=EPOCHREALTIME
  1351. local -F next='start + 5'
  1352. for method in $_POWERLEVEL9K_PUBLIC_IP_METHODS $_POWERLEVEL9K_PUBLIC_IP_METHODS; do
  1353. case $method in
  1354. dig)
  1355. if (( $+commands[dig] )); then
  1356. ip="$(dig +tries=1 +short -4 A myip.opendns.com @resolver1.opendns.com 2>/dev/null)"
  1357. [[ $ip == ';'* ]] && ip=
  1358. if [[ -z $ip ]]; then
  1359. ip="$(dig +tries=1 +short -6 AAAA myip.opendns.com @resolver1.opendns.com 2>/dev/null)"
  1360. [[ $ip == ';'* ]] && ip=
  1361. fi
  1362. fi
  1363. ;;
  1364. curl)
  1365. if (( $+commands[curl] )); then
  1366. ip="$(curl --max-time 5 -w '\n' "$_POWERLEVEL9K_PUBLIC_IP_HOST" 2>/dev/null)"
  1367. fi
  1368. ;;
  1369. wget)
  1370. if (( $+commands[wget] )); then
  1371. ip="$(wget -T 5 -qO- "$_POWERLEVEL9K_PUBLIC_IP_HOST" 2>/dev/null)"
  1372. fi
  1373. ;;
  1374. esac
  1375. [[ $ip =~ '^[0-9a-f.:]+$' ]] || ip=''
  1376. if [[ -n $ip ]]; then
  1377. next=$((start + _POWERLEVEL9K_PUBLIC_IP_TIMEOUT))
  1378. break
  1379. fi
  1380. done
  1381. _p9k__public_ip_next_time=$next
  1382. _p9k_print_params _p9k__public_ip_next_time
  1383. [[ $_p9k__public_ip == $ip ]] && return
  1384. _p9k__public_ip=$ip
  1385. _p9k_print_params _p9k__public_ip
  1386. echo -E - 'reset=1'
  1387. }
  1388. _p9k_prompt_public_ip_sync() {
  1389. eval $REPLY
  1390. _p9k_worker_reply $REPLY
  1391. }
  1392. ################################################################
  1393. # Context: user@hostname (who am I and where am I)
  1394. prompt_context() {
  1395. local -i len=$#_p9k__prompt _p9k__has_upglob
  1396. local content
  1397. if [[ $_POWERLEVEL9K_ALWAYS_SHOW_CONTEXT == 0 && -n $DEFAULT_USER && $P9K_SSH == 0 ]]; then
  1398. local user="${(%):-%n}"
  1399. if [[ $user == $DEFAULT_USER ]]; then
  1400. content="${user//\%/%%}"
  1401. fi
  1402. fi
  1403. local state
  1404. if (( P9K_SSH )); then
  1405. if [[ -n "$SUDO_COMMAND" ]]; then
  1406. state="REMOTE_SUDO"
  1407. else
  1408. state="REMOTE"
  1409. fi
  1410. elif [[ -n "$SUDO_COMMAND" ]]; then
  1411. state="SUDO"
  1412. else
  1413. state="DEFAULT"
  1414. fi
  1415. local cond
  1416. for state cond in $state '${${(%):-%#}:#\#}' ROOT '${${(%):-%#}:#\%}'; do
  1417. local text=$content
  1418. if [[ -z $text ]]; then
  1419. local var=_POWERLEVEL9K_CONTEXT_${state}_TEMPLATE
  1420. if (( $+parameters[$var] )); then
  1421. text=${(P)var}
  1422. text=${(g::)text}
  1423. else
  1424. text=$_POWERLEVEL9K_CONTEXT_TEMPLATE
  1425. fi
  1426. fi
  1427. _p9k_prompt_segment "$0_$state" "$_p9k_color1" yellow '' 0 "$cond" "$text"
  1428. done
  1429. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  1430. }
  1431. instant_prompt_context() {
  1432. if [[ $_POWERLEVEL9K_ALWAYS_SHOW_CONTEXT == 0 && -n $DEFAULT_USER && $P9K_SSH == 0 ]]; then
  1433. if [[ ${(%):-%n} == $DEFAULT_USER ]]; then
  1434. if (( ! _POWERLEVEL9K_ALWAYS_SHOW_USER )); then
  1435. return
  1436. fi
  1437. fi
  1438. fi
  1439. prompt_context
  1440. }
  1441. _p9k_prompt_context_init() {
  1442. if [[ $_POWERLEVEL9K_ALWAYS_SHOW_CONTEXT == 0 && -n $DEFAULT_USER && $P9K_SSH == 0 ]]; then
  1443. if [[ ${(%):-%n} == $DEFAULT_USER ]]; then
  1444. if (( ! _POWERLEVEL9K_ALWAYS_SHOW_USER )); then
  1445. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${:-}'
  1446. fi
  1447. fi
  1448. fi
  1449. }
  1450. ################################################################
  1451. # User: user (who am I)
  1452. prompt_user() {
  1453. local -i len=$#_p9k__prompt _p9k__has_upglob
  1454. _p9k_prompt_segment "${0}_ROOT" "${_p9k_color1}" yellow ROOT_ICON 0 '${${(%):-%#}:#\%}' "$_POWERLEVEL9K_USER_TEMPLATE"
  1455. if [[ -n "$SUDO_COMMAND" ]]; then
  1456. _p9k_prompt_segment "${0}_SUDO" "${_p9k_color1}" yellow SUDO_ICON 0 '${${(%):-%#}:#\#}' "$_POWERLEVEL9K_USER_TEMPLATE"
  1457. else
  1458. _p9k_prompt_segment "${0}_DEFAULT" "${_p9k_color1}" yellow USER_ICON 0 '${${(%):-%#}:#\#}' "%n"
  1459. fi
  1460. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  1461. }
  1462. instant_prompt_user() {
  1463. if [[ $_POWERLEVEL9K_ALWAYS_SHOW_USER == 0 && "${(%):-%n}" == $DEFAULT_USER ]]; then
  1464. return
  1465. fi
  1466. prompt_user
  1467. }
  1468. _p9k_prompt_user_init() {
  1469. if [[ $_POWERLEVEL9K_ALWAYS_SHOW_USER == 0 && "${(%):-%n}" == $DEFAULT_USER ]]; then
  1470. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${:-}'
  1471. fi
  1472. }
  1473. ################################################################
  1474. # Host: machine (where am I)
  1475. prompt_host() {
  1476. local -i len=$#_p9k__prompt _p9k__has_upglob
  1477. if (( P9K_SSH )); then
  1478. _p9k_prompt_segment "$0_REMOTE" "${_p9k_color1}" yellow SSH_ICON 0 '' "$_POWERLEVEL9K_HOST_TEMPLATE"
  1479. else
  1480. _p9k_prompt_segment "$0_LOCAL" "${_p9k_color1}" yellow HOST_ICON 0 '' "$_POWERLEVEL9K_HOST_TEMPLATE"
  1481. fi
  1482. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  1483. }
  1484. instant_prompt_host() { prompt_host; }
  1485. ################################################################
  1486. # Toolbox: https://github.com/containers/toolbox
  1487. function prompt_toolbox() {
  1488. _p9k_prompt_segment $0 $_p9k_color1 yellow TOOLBOX_ICON 0 '' $P9K_TOOLBOX_NAME
  1489. }
  1490. _p9k_prompt_toolbox_init() {
  1491. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$P9K_TOOLBOX_NAME'
  1492. }
  1493. function instant_prompt_toolbox() {
  1494. _p9k_prompt_segment prompt_toolbox $_p9k_color1 yellow TOOLBOX_ICON 1 '$P9K_TOOLBOX_NAME' '$P9K_TOOLBOX_NAME'
  1495. }
  1496. ################################################################
  1497. # The 'custom` prompt provides a way for users to invoke commands and display
  1498. # the output in a segment.
  1499. _p9k_custom_prompt() {
  1500. local segment_name=${1:u}
  1501. local command=_POWERLEVEL9K_CUSTOM_${segment_name}
  1502. command=${(P)command}
  1503. local parts=("${(@z)command}")
  1504. local cmd="${(Q)parts[1]}"
  1505. (( $+functions[$cmd] || $+commands[$cmd] )) || return
  1506. local content="$(eval $command)"
  1507. [[ -n $content ]] || return
  1508. _p9k_prompt_segment "prompt_custom_$1" $_p9k_color2 $_p9k_color1 "CUSTOM_${segment_name}_ICON" 0 '' "$content"
  1509. }
  1510. ################################################################
  1511. # Display the duration the command needed to run.
  1512. prompt_command_execution_time() {
  1513. (( $+P9K_COMMAND_DURATION_SECONDS )) || return
  1514. (( P9K_COMMAND_DURATION_SECONDS >= _POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD )) || return
  1515. if (( P9K_COMMAND_DURATION_SECONDS < 60 )); then
  1516. if (( !_POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION )); then
  1517. local -i sec=$((P9K_COMMAND_DURATION_SECONDS + 0.5))
  1518. else
  1519. local -F $_POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION sec=P9K_COMMAND_DURATION_SECONDS
  1520. fi
  1521. local text=${sec}s
  1522. else
  1523. local -i d=$((P9K_COMMAND_DURATION_SECONDS + 0.5))
  1524. if [[ $_POWERLEVEL9K_COMMAND_EXECUTION_TIME_FORMAT == "H:M:S" ]]; then
  1525. local text=${(l.2..0.)$((d % 60))}
  1526. if (( d >= 60 )); then
  1527. text=${(l.2..0.)$((d / 60 % 60))}:$text
  1528. if (( d >= 36000 )); then
  1529. text=$((d / 3600)):$text
  1530. elif (( d >= 3600 )); then
  1531. text=0$((d / 3600)):$text
  1532. fi
  1533. fi
  1534. else
  1535. local text="$((d % 60))s"
  1536. if (( d >= 60 )); then
  1537. text="$((d / 60 % 60))m $text"
  1538. if (( d >= 3600 )); then
  1539. text="$((d / 3600 % 24))h $text"
  1540. if (( d >= 86400 )); then
  1541. text="$((d / 86400))d $text"
  1542. fi
  1543. fi
  1544. fi
  1545. fi
  1546. fi
  1547. _p9k_prompt_segment "$0" "red" "yellow1" 'EXECUTION_TIME_ICON' 0 '' $text
  1548. }
  1549. function _p9k_shorten_delim_len() {
  1550. local def=$1
  1551. _p9k__ret=${_POWERLEVEL9K_SHORTEN_DELIMITER_LENGTH:--1}
  1552. (( _p9k__ret >= 0 )) || _p9k_prompt_length $1
  1553. }
  1554. # Percents are duplicated because this function is currently used only
  1555. # where the result is going to be percent-expanded.
  1556. function _p9k_url_escape() {
  1557. emulate -L zsh -o no_multi_byte -o extended_glob
  1558. local MATCH MBEGIN MEND
  1559. _p9k__ret=${1//(#m)[^a-zA-Z0-9"\/:_.-!'()~"]/%%${(l:2::0:)$(([##16]#MATCH))}}
  1560. }
  1561. ################################################################
  1562. # Dir: current working directory
  1563. prompt_dir() {
  1564. if (( _POWERLEVEL9K_DIR_PATH_ABSOLUTE )); then
  1565. local p=${(V)_p9k__cwd}
  1566. local -a parts=("${(s:/:)p}")
  1567. elif [[ -o auto_name_dirs ]]; then
  1568. local p=${(V)${_p9k__cwd/#(#b)$HOME(|\/*)/'~'$match[1]}}
  1569. local -a parts=("${(s:/:)p}")
  1570. else
  1571. local p=${(%):-%~}
  1572. if [[ $p == '~['* ]]; then
  1573. # If "${(%):-%~}" expands to "~[a]/]/b", is the first component "~[a]" or "~[a]/]"?
  1574. # One would expect "${(%):-%-1~}" to give the right answer but alas it always simply
  1575. # gives the segment before the first slash, which would be "~[a]" in this case. Worse,
  1576. # for "~[a/b]" it'll give the nonsensical "~[a". To solve this problem we have to
  1577. # repeat what "${(%):-%~}" does and hope that it produces the same result.
  1578. local func=''
  1579. local -a parts=()
  1580. for func in zsh_directory_name $zsh_directory_name_functions; do
  1581. local reply=()
  1582. if (( $+functions[$func] )) && $func d $_p9k__cwd && [[ $p == '~['${(V)reply[1]}']'* ]]; then
  1583. parts+='~['${(V)reply[1]}']'
  1584. break
  1585. fi
  1586. done
  1587. if (( $#parts )); then
  1588. parts+=(${(s:/:)${p#$parts[1]}})
  1589. else
  1590. p=${(V)_p9k__cwd}
  1591. parts=("${(s:/:)p}")
  1592. fi
  1593. else
  1594. local -a parts=("${(s:/:)p}")
  1595. fi
  1596. fi
  1597. local -i fake_first=0 expand=0 shortenlen=${_POWERLEVEL9K_SHORTEN_DIR_LENGTH:--1}
  1598. if (( $+_POWERLEVEL9K_SHORTEN_DELIMITER )); then
  1599. local delim=$_POWERLEVEL9K_SHORTEN_DELIMITER
  1600. else
  1601. if [[ $langinfo[CODESET] == (utf|UTF)(-|)8 ]]; then
  1602. local delim=$'\u2026'
  1603. else
  1604. local delim='..'
  1605. fi
  1606. fi
  1607. case $_POWERLEVEL9K_SHORTEN_STRATEGY in
  1608. truncate_absolute|truncate_absolute_chars)
  1609. if (( shortenlen > 0 && $#p > shortenlen )); then
  1610. _p9k_shorten_delim_len $delim
  1611. if (( $#p > shortenlen + $_p9k__ret )); then
  1612. local -i n=shortenlen
  1613. local -i i=$#parts
  1614. while true; do
  1615. local dir=$parts[i]
  1616. local -i len=$(( $#dir + (i > 1) ))
  1617. if (( len <= n )); then
  1618. (( n -= len ))
  1619. (( --i ))
  1620. else
  1621. parts[i]=$'\1'$dir[-n,-1]
  1622. parts[1,i-1]=()
  1623. break
  1624. fi
  1625. done
  1626. fi
  1627. fi
  1628. ;;
  1629. truncate_with_package_name|truncate_middle|truncate_from_right)
  1630. () {
  1631. [[ $_POWERLEVEL9K_SHORTEN_STRATEGY == truncate_with_package_name &&
  1632. $+commands[jq] == 1 && $#_POWERLEVEL9K_DIR_PACKAGE_FILES > 0 ]] || return
  1633. local pats="(${(j:|:)_POWERLEVEL9K_DIR_PACKAGE_FILES})"
  1634. local -i i=$#parts
  1635. local dir=$_p9k__cwd
  1636. for (( ; i > 0; --i )); do
  1637. local markers=($dir/${~pats}(N))
  1638. if (( $#markers )); then
  1639. local pat= pkg_file=
  1640. for pat in $_POWERLEVEL9K_DIR_PACKAGE_FILES; do
  1641. for pkg_file in $markers; do
  1642. [[ $pkg_file == $dir/${~pat} ]] || continue
  1643. if ! _p9k_cache_stat_get $0_pkg $pkg_file; then
  1644. local pkg_name=''
  1645. pkg_name="$(jq -j '.name | select(. != null)' <$pkg_file 2>/dev/null)" || pkg_name=''
  1646. _p9k_cache_stat_set "$pkg_name"
  1647. fi
  1648. [[ -n $_p9k__cache_val[1] ]] || continue
  1649. parts[1,i]=($_p9k__cache_val[1])
  1650. fake_first=1
  1651. return 0
  1652. done
  1653. done
  1654. fi
  1655. dir=${dir:h}
  1656. done
  1657. }
  1658. if (( shortenlen > 0 )); then
  1659. _p9k_shorten_delim_len $delim
  1660. local -i d=_p9k__ret pref=shortenlen suf=0 i=2
  1661. [[ $_POWERLEVEL9K_SHORTEN_STRATEGY == truncate_middle ]] && suf=pref
  1662. for (( ; i < $#parts; ++i )); do
  1663. local dir=$parts[i]
  1664. if (( $#dir > pref + suf + d )); then
  1665. dir[pref+1,-suf-1]=$'\1'
  1666. parts[i]=$dir
  1667. fi
  1668. done
  1669. fi
  1670. ;;
  1671. truncate_to_last)
  1672. shortenlen=${_POWERLEVEL9K_SHORTEN_DIR_LENGTH:-1}
  1673. (( shortenlen > 0 )) || shortenlen=1
  1674. local -i i='shortenlen+1'
  1675. if [[ $#parts -gt i || $p[1] != / && $#parts -gt shortenlen ]]; then
  1676. fake_first=1
  1677. parts[1,-i]=()
  1678. fi
  1679. ;;
  1680. truncate_to_first_and_last)
  1681. if (( shortenlen > 0 )); then
  1682. local -i i=$(( shortenlen + 1 ))
  1683. [[ $p == /* ]] && (( ++i ))
  1684. for (( ; i <= $#parts - shortenlen; ++i )); do
  1685. parts[i]=$'\1'
  1686. done
  1687. fi
  1688. ;;
  1689. truncate_to_unique)
  1690. expand=1
  1691. delim=${_POWERLEVEL9K_SHORTEN_DELIMITER-'*'}
  1692. shortenlen=${_POWERLEVEL9K_SHORTEN_DIR_LENGTH:-1}
  1693. (( shortenlen >= 0 )) || shortenlen=1
  1694. local rp=${(g:oce:)p}
  1695. local rparts=("${(@s:/:)rp}")
  1696. local -i i=2 e=$(($#parts - shortenlen))
  1697. if [[ -n $_POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER ]]; then
  1698. (( e += shortenlen ))
  1699. local orig=("$parts[2]" "${(@)parts[$((shortenlen > $#parts ? -$#parts : -shortenlen)),-1]}")
  1700. elif [[ $p[1] == / ]]; then
  1701. (( ++i ))
  1702. fi
  1703. if (( i <= e )); then
  1704. local mtimes=(${(Oa)_p9k__parent_mtimes:$(($#parts-e)):$((e-i+1))})
  1705. local key="${(pj.:.)mtimes}"
  1706. else
  1707. local key=
  1708. fi
  1709. if ! _p9k_cache_ephemeral_get $0 $e $i $_p9k__cwd $p || [[ $key != $_p9k__cache_val[1] ]]; then
  1710. local rtail=${(j./.)rparts[i,-1]}
  1711. local parent=$_p9k__cwd[1,-2-$#rtail]
  1712. _p9k_prompt_length $delim
  1713. local -i real_delim_len=_p9k__ret
  1714. [[ -n $parts[i-1] ]] && parts[i-1]="\${(Q)\${:-${(qqq)${(q)parts[i-1]}}}}"$'\2'
  1715. local -i d=${_POWERLEVEL9K_SHORTEN_DELIMITER_LENGTH:--1}
  1716. (( d >= 0 )) || d=real_delim_len
  1717. local -i m=1
  1718. for (( ; i <= e; ++i, ++m )); do
  1719. local sub=$parts[i]
  1720. local rsub=$rparts[i]
  1721. local dir=$parent/$rsub mtime=$mtimes[m]
  1722. local pair=$_p9k__dir_stat_cache[$dir]
  1723. if [[ $pair == ${mtime:-x}:* ]]; then
  1724. parts[i]=${pair#*:}
  1725. else
  1726. [[ $sub != *["~!#\`\$^&*()\\\"'<>?{}[]"]* ]]
  1727. local -i q=$?
  1728. if [[ -n $_POWERLEVEL9K_SHORTEN_FOLDER_MARKER &&
  1729. -n $dir/${~_POWERLEVEL9K_SHORTEN_FOLDER_MARKER}(#qN) ]]; then
  1730. (( q )) && parts[i]="\${(Q)\${:-${(qqq)${(q)sub}}}}"
  1731. parts[i]+=$'\2'
  1732. else
  1733. local -i j=$rsub[(i)[^.]]
  1734. for (( ; j + d < $#rsub; ++j )); do
  1735. local -a matching=($parent/$rsub[1,j]*/(N))
  1736. (( $#matching == 1 )) && break
  1737. done
  1738. local -i saved=$((${(m)#${(V)${rsub:$j}}} - d))
  1739. if (( saved > 0 )); then
  1740. if (( q )); then
  1741. parts[i]='${${${_p9k__d:#-*}:+${(Q)${:-'${(qqq)${(q)sub}}'}}}:-${(Q)${:-'
  1742. parts[i]+=$'\3'${(qqq)${(q)${(V)${rsub[1,j]}}}}$'}}\1\3''${$((_p9k__d+='$saved'))+}}'
  1743. else
  1744. parts[i]='${${${_p9k__d:#-*}:+'$sub$'}:-\3'${(V)${rsub[1,j]}}$'\1\3''${$((_p9k__d+='$saved'))+}}'
  1745. fi
  1746. else
  1747. (( q )) && parts[i]="\${(Q)\${:-${(qqq)${(q)sub}}}}"
  1748. fi
  1749. fi
  1750. [[ -n $mtime ]] && _p9k__dir_stat_cache[$dir]="$mtime:$parts[i]"
  1751. fi
  1752. parent+=/$rsub
  1753. done
  1754. if [[ -n $_POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER ]]; then
  1755. local _2=$'\2'
  1756. if [[ $_POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER == last* ]]; then
  1757. (( e = ${parts[(I)*$_2]} + ${_POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER#*:} ))
  1758. else
  1759. (( e = ${parts[(ib:2:)*$_2]} + ${_POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER#*:} ))
  1760. fi
  1761. if (( e > 1 && e <= $#parts )); then
  1762. parts[1,e-1]=()
  1763. fake_first=1
  1764. elif [[ $p == /?* ]]; then
  1765. parts[2]="\${(Q)\${:-${(qqq)${(q)orig[1]}}}}"$'\2'
  1766. fi
  1767. for ((i = $#parts < shortenlen ? $#parts : shortenlen; i > 0; --i)); do
  1768. [[ $#parts[-i] == *$'\2' ]] && continue
  1769. if [[ $orig[-i] == *["~!#\`\$^&*()\\\"'<>?{}[]"]* ]]; then
  1770. parts[-i]='${(Q)${:-'${(qqq)${(q)orig[-i]}}'}}'$'\2'
  1771. else
  1772. parts[-i]=${orig[-i]}$'\2'
  1773. fi
  1774. done
  1775. else
  1776. for ((; i <= $#parts; ++i)); do
  1777. [[ $parts[i] == *["~!#\`\$^&*()\\\"'<>?{}[]"]* ]] && parts[i]='${(Q)${:-'${(qqq)${(q)parts[i]}}'}}'
  1778. parts[i]+=$'\2'
  1779. done
  1780. fi
  1781. _p9k_cache_ephemeral_set "$key" "${parts[@]}"
  1782. fi
  1783. parts=("${(@)_p9k__cache_val[2,-1]}")
  1784. ;;
  1785. truncate_with_folder_marker)
  1786. if [[ -n $_POWERLEVEL9K_SHORTEN_FOLDER_MARKER ]]; then
  1787. local dir=$_p9k__cwd
  1788. local -a m=()
  1789. local -i i=$(($#parts - 1))
  1790. for (( ; i > 1; --i )); do
  1791. dir=${dir:h}
  1792. [[ -n $dir/${~_POWERLEVEL9K_SHORTEN_FOLDER_MARKER}(#qN) ]] && m+=$i
  1793. done
  1794. m+=1
  1795. for (( i=1; i < $#m; ++i )); do
  1796. (( m[i] - m[i+1] > 2 )) && parts[m[i+1]+1,m[i]-1]=($'\1')
  1797. done
  1798. fi
  1799. ;;
  1800. *)
  1801. if (( shortenlen > 0 )); then
  1802. local -i len=$#parts
  1803. [[ -z $parts[1] ]] && (( --len ))
  1804. if (( len > shortenlen )); then
  1805. parts[1,-shortenlen-1]=($'\1')
  1806. fi
  1807. fi
  1808. ;;
  1809. esac
  1810. # w=0: writable
  1811. # w=1: not writable
  1812. # w=2: does not exist
  1813. (( !_POWERLEVEL9K_DIR_SHOW_WRITABLE )) || [[ -w $_p9k__cwd ]]
  1814. local -i w=$?
  1815. (( w && _POWERLEVEL9K_DIR_SHOW_WRITABLE > 2 )) && [[ ! -e $_p9k__cwd ]] && w=2
  1816. if ! _p9k_cache_ephemeral_get $0 $_p9k__cwd $p $w $fake_first "${parts[@]}"; then
  1817. local state=$0
  1818. local icon=''
  1819. local a='' b='' c=''
  1820. for a b c in "${_POWERLEVEL9K_DIR_CLASSES[@]}"; do
  1821. if [[ $_p9k__cwd == ${~a} ]]; then
  1822. [[ -n $b ]] && state+=_${${(U)b}//İ/I}
  1823. icon=$'\1'$c
  1824. break
  1825. fi
  1826. done
  1827. if (( w )); then
  1828. if (( _POWERLEVEL9K_DIR_SHOW_WRITABLE == 1 )); then
  1829. state=${0}_NOT_WRITABLE
  1830. elif (( w == 2 )); then
  1831. state+=_NON_EXISTENT
  1832. else
  1833. state+=_NOT_WRITABLE
  1834. fi
  1835. icon=LOCK_ICON
  1836. fi
  1837. local state_u=${${(U)state}//İ/I}
  1838. local style=%b
  1839. _p9k_color $state BACKGROUND blue
  1840. _p9k_background $_p9k__ret
  1841. style+=$_p9k__ret
  1842. _p9k_color $state FOREGROUND "$_p9k_color1"
  1843. _p9k_foreground $_p9k__ret
  1844. style+=$_p9k__ret
  1845. if (( expand )); then
  1846. _p9k_escape_style $style
  1847. style=$_p9k__ret
  1848. fi
  1849. parts=("${(@)parts//\%/%%}")
  1850. if [[ $_POWERLEVEL9K_HOME_FOLDER_ABBREVIATION != '~' && $fake_first == 0 && $p == ('~'|'~/'*) ]]; then
  1851. (( expand )) && _p9k_escape $_POWERLEVEL9K_HOME_FOLDER_ABBREVIATION || _p9k__ret=$_POWERLEVEL9K_HOME_FOLDER_ABBREVIATION
  1852. parts[1]=$_p9k__ret
  1853. [[ $_p9k__ret == *%* ]] && parts[1]+=$style
  1854. elif [[ $_POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER == 1 && $fake_first == 0 && $#parts > 1 && -z $parts[1] && -n $parts[2] ]]; then
  1855. parts[1]=()
  1856. fi
  1857. local last_style=
  1858. _p9k_param $state PATH_HIGHLIGHT_BOLD ''
  1859. [[ $_p9k__ret == true ]] && last_style+=%B
  1860. if (( $+parameters[_POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND] ||
  1861. $+parameters[_POWERLEVEL9K_${state_u}_PATH_HIGHLIGHT_FOREGROUND] )); then
  1862. _p9k_color $state PATH_HIGHLIGHT_FOREGROUND ''
  1863. _p9k_foreground $_p9k__ret
  1864. last_style+=$_p9k__ret
  1865. fi
  1866. if [[ -n $last_style ]]; then
  1867. (( expand )) && _p9k_escape_style $last_style || _p9k__ret=$last_style
  1868. parts[-1]=$_p9k__ret${parts[-1]//$'\1'/$'\1'$_p9k__ret}$style
  1869. fi
  1870. local anchor_style=
  1871. _p9k_param $state ANCHOR_BOLD ''
  1872. [[ $_p9k__ret == true ]] && anchor_style+=%B
  1873. if (( $+parameters[_POWERLEVEL9K_DIR_ANCHOR_FOREGROUND] ||
  1874. $+parameters[_POWERLEVEL9K_${state_u}_ANCHOR_FOREGROUND] )); then
  1875. _p9k_color $state ANCHOR_FOREGROUND ''
  1876. _p9k_foreground $_p9k__ret
  1877. anchor_style+=$_p9k__ret
  1878. fi
  1879. if [[ -n $anchor_style ]]; then
  1880. (( expand )) && _p9k_escape_style $anchor_style || _p9k__ret=$anchor_style
  1881. if [[ -z $last_style ]]; then
  1882. parts=("${(@)parts/%(#b)(*)$'\2'/$_p9k__ret$match[1]$style}")
  1883. else
  1884. (( $#parts > 1 )) && parts[1,-2]=("${(@)parts[1,-2]/%(#b)(*)$'\2'/$_p9k__ret$match[1]$style}")
  1885. parts[-1]=${parts[-1]/$'\2'}
  1886. fi
  1887. else
  1888. parts=("${(@)parts/$'\2'}")
  1889. fi
  1890. if (( $+parameters[_POWERLEVEL9K_DIR_SHORTENED_FOREGROUND] ||
  1891. $+parameters[_POWERLEVEL9K_${state_u}_SHORTENED_FOREGROUND] )); then
  1892. _p9k_color $state SHORTENED_FOREGROUND ''
  1893. _p9k_foreground $_p9k__ret
  1894. (( expand )) && _p9k_escape_style $_p9k__ret
  1895. local shortened_fg=$_p9k__ret
  1896. (( expand )) && _p9k_escape $delim || _p9k__ret=$delim
  1897. [[ $_p9k__ret == *%* ]] && _p9k__ret+=$style$shortened_fg
  1898. parts=("${(@)parts/(#b)$'\3'(*)$'\1'(*)$'\3'/$shortened_fg$match[1]$_p9k__ret$match[2]$style}")
  1899. parts=("${(@)parts/(#b)(*)$'\1'(*)/$shortened_fg$match[1]$_p9k__ret$match[2]$style}")
  1900. else
  1901. (( expand )) && _p9k_escape $delim || _p9k__ret=$delim
  1902. [[ $_p9k__ret == *%* ]] && _p9k__ret+=$style
  1903. parts=("${(@)parts/$'\1'/$_p9k__ret}")
  1904. parts=("${(@)parts//$'\3'}")
  1905. fi
  1906. if [[ $_p9k__cwd == / && $_POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER == 1 ]]; then
  1907. local sep='/'
  1908. else
  1909. local sep=''
  1910. if (( $+parameters[_POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND] ||
  1911. $+parameters[_POWERLEVEL9K_${state_u}_PATH_SEPARATOR_FOREGROUND] )); then
  1912. _p9k_color $state PATH_SEPARATOR_FOREGROUND ''
  1913. _p9k_foreground $_p9k__ret
  1914. (( expand )) && _p9k_escape_style $_p9k__ret
  1915. sep=$_p9k__ret
  1916. fi
  1917. _p9k_param $state PATH_SEPARATOR /
  1918. _p9k__ret=${(g::)_p9k__ret}
  1919. (( expand )) && _p9k_escape $_p9k__ret
  1920. sep+=$_p9k__ret
  1921. [[ $sep == *%* ]] && sep+=$style
  1922. fi
  1923. local content="${(pj.$sep.)parts}"
  1924. if (( _POWERLEVEL9K_DIR_HYPERLINK && _p9k_term_has_href )) && [[ $_p9k__cwd == /* ]]; then
  1925. _p9k_url_escape $_p9k__cwd
  1926. local header=$'%{\e]8;;file://'$_p9k__ret$'\a%}'
  1927. local footer=$'%{\e]8;;\a%}'
  1928. if (( expand )); then
  1929. _p9k_escape $header
  1930. header=$_p9k__ret
  1931. _p9k_escape $footer
  1932. footer=$_p9k__ret
  1933. fi
  1934. content=$header$content$footer
  1935. fi
  1936. (( expand )) && _p9k_prompt_length "${(e):-"\${\${_p9k__d::=0}+}$content"}" || _p9k__ret=
  1937. _p9k_cache_ephemeral_set "$state" "$icon" "$expand" "$content" $_p9k__ret
  1938. fi
  1939. if (( _p9k__cache_val[3] )); then
  1940. if (( $+_p9k__dir )); then
  1941. _p9k__cache_val[4]='${${_p9k__d::=-1024}+}'$_p9k__cache_val[4]
  1942. else
  1943. _p9k__dir=$_p9k__cache_val[4]
  1944. _p9k__dir_len=$_p9k__cache_val[5]
  1945. _p9k__cache_val[4]='%{d%}'$_p9k__cache_val[4]'%{d%}'
  1946. fi
  1947. fi
  1948. _p9k_prompt_segment "$_p9k__cache_val[1]" "blue" "$_p9k_color1" "$_p9k__cache_val[2]" "$_p9k__cache_val[3]" "" "$_p9k__cache_val[4]"
  1949. }
  1950. instant_prompt_dir() { prompt_dir; }
  1951. ################################################################
  1952. # Docker machine
  1953. prompt_docker_machine() {
  1954. _p9k_prompt_segment "$0" "magenta" "$_p9k_color1" 'SERVER_ICON' 0 '' "${DOCKER_MACHINE_NAME//\%/%%}"
  1955. }
  1956. _p9k_prompt_docker_machine_init() {
  1957. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$DOCKER_MACHINE_NAME'
  1958. }
  1959. ################################################################
  1960. # GO prompt
  1961. prompt_go_version() {
  1962. _p9k_cached_cmd 0 '' go version || return
  1963. [[ $_p9k__ret == (#b)*go([[:digit:].]##)* ]] || return
  1964. local v=$match[1]
  1965. if (( _POWERLEVEL9K_GO_VERSION_PROJECT_ONLY )); then
  1966. local p=$GOPATH
  1967. if [[ -z $p ]]; then
  1968. if [[ -d $HOME/go ]]; then
  1969. p=$HOME/go
  1970. else
  1971. p="$(go env GOPATH 2>/dev/null)" && [[ -n $p ]] || return
  1972. fi
  1973. fi
  1974. if [[ $_p9k__cwd/ != $p/* && $_p9k__cwd_a/ != $p/* ]]; then
  1975. _p9k_upglob go.mod -. && return
  1976. fi
  1977. fi
  1978. _p9k_prompt_segment "$0" "green" "grey93" "GO_ICON" 0 '' "${v//\%/%%}"
  1979. }
  1980. _p9k_prompt_go_version_init() {
  1981. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[go]'
  1982. }
  1983. ################################################################
  1984. # Command number (in local history)
  1985. prompt_history() {
  1986. local -i len=$#_p9k__prompt _p9k__has_upglob
  1987. _p9k_prompt_segment "$0" "grey50" "$_p9k_color1" '' 0 '' '%h'
  1988. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  1989. }
  1990. prompt_package() {
  1991. unset P9K_PACKAGE_NAME P9K_PACKAGE_VERSION
  1992. _p9k_upglob package.json -. && return
  1993. local file=$_p9k__parent_dirs[$?]/package.json
  1994. if ! _p9k_cache_stat_get $0 $file; then
  1995. () {
  1996. local data field
  1997. local -A found
  1998. # Redneck json parsing. Yields correct results for any well-formed json document.
  1999. # Produces random garbage for invalid json.
  2000. { data="$(<$file)" || return } 2>/dev/null
  2001. data=${${data//$'\r'}##[[:space:]]#}
  2002. [[ $data == '{'* ]] || return
  2003. data[1]=
  2004. local -i depth=1
  2005. while true; do
  2006. data=${data##[[:space:]]#}
  2007. [[ -n $data ]] || return
  2008. case $data[1] in
  2009. '{'|'[') data[1]=; (( ++depth ));;
  2010. '}'|']') data[1]=; (( --depth > 0 )) || return;;
  2011. ':') data[1]=;;
  2012. ',') data[1]=; field=;;
  2013. [[:alnum:].]) data=${data##[[:alnum:].]#};;
  2014. '"')
  2015. local tail=${data##\"([^\"\\]|\\?)#}
  2016. [[ $tail == '"'* ]] || return
  2017. local s=${data:1:-$#tail}
  2018. data=${tail:1}
  2019. (( depth == 1 )) || continue
  2020. if [[ -z $field ]]; then
  2021. field=${s:-x}
  2022. elif [[ $field == (name|version) ]]; then
  2023. (( ! $+found[$field] )) || return
  2024. [[ -n $s ]] || return
  2025. [[ $s != *($'\n'|'\')* ]] || return
  2026. found[$field]=$s
  2027. (( $#found == 2 )) && break
  2028. fi
  2029. ;;
  2030. *) return 1;;
  2031. esac
  2032. done
  2033. _p9k_cache_stat_set 1 $found[name] $found[version]
  2034. return 0
  2035. } || _p9k_cache_stat_set 0
  2036. fi
  2037. (( _p9k__cache_val[1] )) || return
  2038. P9K_PACKAGE_NAME=$_p9k__cache_val[2]
  2039. P9K_PACKAGE_VERSION=$_p9k__cache_val[3]
  2040. _p9k_prompt_segment "$0" "cyan" "$_p9k_color1" PACKAGE_ICON 0 '' ${P9K_PACKAGE_VERSION//\%/%%}
  2041. }
  2042. ################################################################
  2043. # Detection for virtualization (systemd based systems only)
  2044. prompt_detect_virt() {
  2045. local virt="$(systemd-detect-virt 2>/dev/null)"
  2046. if [[ "$virt" == "none" ]]; then
  2047. local -a inode
  2048. if zstat -A inode +inode / 2>/dev/null && [[ $inode[1] != 2 ]]; then
  2049. virt="chroot"
  2050. fi
  2051. fi
  2052. if [[ -n "${virt}" ]]; then
  2053. _p9k_prompt_segment "$0" "$_p9k_color1" "yellow" '' 0 '' "${virt//\%/%%}"
  2054. fi
  2055. }
  2056. _p9k_prompt_detect_virt_init() {
  2057. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[systemd-detect-virt]'
  2058. }
  2059. ################################################################
  2060. # Segment to display the current IP address
  2061. prompt_ip() {
  2062. local -i len=$#_p9k__prompt _p9k__has_upglob
  2063. _p9k_prompt_segment "$0" "cyan" "$_p9k_color1" 'NETWORK_ICON' 1 '$P9K_IP_IP' '$P9K_IP_IP'
  2064. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  2065. }
  2066. ################################################################
  2067. # Segment to display if VPN is active
  2068. prompt_vpn_ip() {
  2069. typeset -ga _p9k__vpn_ip_segments
  2070. _p9k__vpn_ip_segments+=($_p9k__prompt_side $_p9k__line_index $_p9k__segment_index)
  2071. local p='${(e)_p9k__vpn_ip_'$_p9k__prompt_side$_p9k__segment_index'}'
  2072. _p9k__prompt+=$p
  2073. typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$p
  2074. }
  2075. _p9k_vpn_ip_render() {
  2076. local _p9k__segment_name=vpn_ip _p9k__prompt_side ip
  2077. local -i _p9k__has_upglob _p9k__segment_index
  2078. for _p9k__prompt_side _p9k__line_index _p9k__segment_index in $_p9k__vpn_ip_segments; do
  2079. local _p9k__prompt=
  2080. for ip in $_p9k__vpn_ip_ips; do
  2081. _p9k_prompt_segment prompt_vpn_ip "cyan" "$_p9k_color1" 'VPN_ICON' 0 '' $ip
  2082. done
  2083. typeset -g _p9k__vpn_ip_$_p9k__prompt_side$_p9k__segment_index=$_p9k__prompt
  2084. done
  2085. }
  2086. ################################################################
  2087. # Segment to display laravel version
  2088. prompt_laravel_version() {
  2089. # TODO: add a '-/' or '-.' here depending on whether artisan is a directory or a file.
  2090. _p9k_upglob artisan && return
  2091. local dir=$_p9k__parent_dirs[$?]
  2092. local app=$dir/vendor/laravel/framework/src/Illuminate/Foundation/Application.php
  2093. [[ -r $app ]] || return
  2094. if ! _p9k_cache_stat_get $0 $dir/artisan $app; then
  2095. local v="$(php $dir/artisan --version 2> /dev/null)"
  2096. _p9k_cache_stat_set "${${(M)v:#Laravel Framework *}#Laravel Framework }"
  2097. fi
  2098. [[ -n $_p9k__cache_val[1] ]] || return
  2099. _p9k_prompt_segment "$0" "maroon" "white" 'LARAVEL_ICON' 0 '' "${_p9k__cache_val[1]//\%/%%}"
  2100. }
  2101. _p9k_prompt_laravel_version_init() {
  2102. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[php]'
  2103. }
  2104. ################################################################
  2105. # Segment to display load
  2106. prompt_load() {
  2107. if [[ $_p9k_os == (OSX|BSD) ]]; then
  2108. local -i len=$#_p9k__prompt _p9k__has_upglob
  2109. _p9k_prompt_segment $0_CRITICAL red "$_p9k_color1" LOAD_ICON 1 '$_p9k__load_critical' '$_p9k__load_value'
  2110. _p9k_prompt_segment $0_WARNING yellow "$_p9k_color1" LOAD_ICON 1 '$_p9k__load_warning' '$_p9k__load_value'
  2111. _p9k_prompt_segment $0_NORMAL green "$_p9k_color1" LOAD_ICON 1 '$_p9k__load_normal' '$_p9k__load_value'
  2112. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  2113. return
  2114. fi
  2115. [[ -r /proc/loadavg ]] || return
  2116. _p9k_read_file /proc/loadavg || return
  2117. local load=${${(A)=_p9k__ret}[_POWERLEVEL9K_LOAD_WHICH]//,/.}
  2118. local -F pct='100. * load / _p9k_num_cpus'
  2119. if (( pct > _POWERLEVEL9K_LOAD_CRITICAL_PCT )); then
  2120. _p9k_prompt_segment $0_CRITICAL red "$_p9k_color1" LOAD_ICON 0 '' $load
  2121. elif (( pct > _POWERLEVEL9K_LOAD_WARNING_PCT )); then
  2122. _p9k_prompt_segment $0_WARNING yellow "$_p9k_color1" LOAD_ICON 0 '' $load
  2123. else
  2124. _p9k_prompt_segment $0_NORMAL green "$_p9k_color1" LOAD_ICON 0 '' $load
  2125. fi
  2126. }
  2127. _p9k_prompt_load_init() {
  2128. if [[ $_p9k_os == (OSX|BSD) ]]; then
  2129. typeset -g _p9k__load_value=
  2130. typeset -g _p9k__load_normal=
  2131. typeset -g _p9k__load_warning=
  2132. typeset -g _p9k__load_critical=
  2133. _p9k__async_segments_compute+='_p9k_worker_invoke load _p9k_prompt_load_compute'
  2134. elif [[ ! -r /proc/loadavg ]]; then
  2135. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${:-}'
  2136. fi
  2137. }
  2138. _p9k_prompt_load_compute() {
  2139. (( $+commands[sysctl] )) || return
  2140. _p9k_worker_async _p9k_prompt_load_async _p9k_prompt_load_sync
  2141. }
  2142. _p9k_prompt_load_async() {
  2143. local load="$(sysctl -n vm.loadavg 2>/dev/null)" || return
  2144. load=${${(A)=load}[_POWERLEVEL9K_LOAD_WHICH+1]//,/.}
  2145. [[ $load == <->(|.<->) && $load != $_p9k__load_value ]] || return
  2146. _p9k__load_value=$load
  2147. _p9k__load_normal=
  2148. _p9k__load_warning=
  2149. _p9k__load_critical=
  2150. local -F pct='100. * _p9k__load_value / _p9k_num_cpus'
  2151. if (( pct > _POWERLEVEL9K_LOAD_CRITICAL_PCT )); then
  2152. _p9k__load_critical=1
  2153. elif (( pct > _POWERLEVEL9K_LOAD_WARNING_PCT )); then
  2154. _p9k__load_warning=1
  2155. else
  2156. _p9k__load_normal=1
  2157. fi
  2158. _p9k_print_params \
  2159. _p9k__load_value \
  2160. _p9k__load_normal \
  2161. _p9k__load_warning \
  2162. _p9k__load_critical
  2163. echo -E - 'reset=1'
  2164. }
  2165. _p9k_prompt_load_sync() {
  2166. eval $REPLY
  2167. _p9k_worker_reply $REPLY
  2168. }
  2169. # Usage: _p9k_cached_cmd <0|1> <dep> <cmd> [args...]
  2170. #
  2171. # The first argument says whether to capture stderr (1) or ignore it (0).
  2172. # The second argument can be empty or a file. If it's a file, the
  2173. # output of the command is presumed to potentially depend on it.
  2174. function _p9k_cached_cmd() {
  2175. local cmd=$commands[$3]
  2176. [[ -n $cmd ]] || return
  2177. if ! _p9k_cache_stat_get $0" ${(q)*}" $2 $cmd; then
  2178. local out
  2179. if (( $1 )); then
  2180. out="$($cmd "${@:4}" 2>&1)"
  2181. else
  2182. out="$($cmd "${@:4}" 2>/dev/null)"
  2183. fi
  2184. _p9k_cache_stat_set $(( ! $? )) "$out"
  2185. fi
  2186. (( $_p9k__cache_val[1] )) || return
  2187. _p9k__ret=$_p9k__cache_val[2]
  2188. }
  2189. ################################################################
  2190. # Segment to display Node version
  2191. prompt_node_version() {
  2192. _p9k_upglob package.json -.
  2193. local -i idx=$?
  2194. (( idx || ! _POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY )) || return
  2195. local node=$commands[node]
  2196. local -a file_deps env_deps
  2197. if [[ $node == ${NODENV_ROOT:-$HOME/.nodenv}/shims/node ]]; then
  2198. env_deps+=("$NODENV_VERSION")
  2199. file_deps+=(${NODENV_ROOT:-$HOME/.nodenv}/version)
  2200. if [[ $NODENV_DIR != (|.) ]]; then
  2201. [[ $NODENV_DIR == /* ]] && local dir=$NODENV_DIR || local dir="$_p9k__cwd_a/$NODENV_DIR"
  2202. dir=${dir:A}
  2203. if [[ $dir != $_p9k__cwd_a ]]; then
  2204. while true; do
  2205. if [[ -e $dir/.node-version ]]; then
  2206. file_deps+=($dir/.node-version)
  2207. break
  2208. fi
  2209. [[ $dir == (/|.) ]] && break
  2210. dir=${dir:h}
  2211. done
  2212. fi
  2213. fi
  2214. _p9k_upglob .node-version -. || file_deps+=($_p9k__parent_dirs[idx]/.node-version)
  2215. elif (( idx )); then
  2216. file_deps+=($_p9k__parent_dirs[idx]/package.json)
  2217. fi
  2218. if ! _p9k_cache_stat_get "$0 $#env_deps ${(j: :)${(@q)env_deps}} ${(j: :)${(@q)file_deps}}" $file_deps $node; then
  2219. local out
  2220. out=$($node --version 2>/dev/null)
  2221. _p9k_cache_stat_set $(( ! $? )) "$out"
  2222. fi
  2223. (( $_p9k__cache_val[1] )) || return
  2224. local v=$_p9k__cache_val[2]
  2225. [[ $v == v?* ]] || return
  2226. _p9k_prompt_segment "$0" "green" "white" 'NODE_ICON' 0 '' "${${v#v}//\%/%%}"
  2227. }
  2228. _p9k_prompt_node_version_init() {
  2229. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[node]'
  2230. }
  2231. # Almost the same as `nvm_version default` but faster. The differences shouldn't affect
  2232. # the observable behavior of Powerlevel10k.
  2233. function _p9k_nvm_ls_default() {
  2234. local v=default
  2235. local -a seen=($v)
  2236. while [[ -r $NVM_DIR/alias/$v ]]; do
  2237. local target=
  2238. IFS='' read -r target <$NVM_DIR/alias/$v
  2239. target=${target%$'\r'}
  2240. [[ -z $target ]] && break
  2241. (( $seen[(I)$target] )) && return
  2242. seen+=$target
  2243. v=$target
  2244. done
  2245. case $v in
  2246. default|N/A)
  2247. return 1
  2248. ;;
  2249. system|v)
  2250. _p9k__ret=system
  2251. return 0
  2252. ;;
  2253. iojs-[0-9]*)
  2254. v=iojs-v${v#iojs-}
  2255. ;;
  2256. [0-9]*)
  2257. v=v$v
  2258. ;;
  2259. esac
  2260. if [[ $v == v*.*.* ]]; then
  2261. if [[ -x $NVM_DIR/versions/node/$v/bin/node || -x $NVM_DIR/$v/bin/node ]]; then
  2262. _p9k__ret=$v
  2263. return 0
  2264. elif [[ -x $NVM_DIR/versions/io.js/$v/bin/node ]]; then
  2265. _p9k__ret=iojs-$v
  2266. return 0
  2267. else
  2268. return 1
  2269. fi
  2270. fi
  2271. local -a dirs=()
  2272. case $v in
  2273. node|node-|stable)
  2274. dirs=($NVM_DIR/versions/node $NVM_DIR)
  2275. v='(v[1-9]*|v0.*[02468].*)'
  2276. ;;
  2277. unstable)
  2278. dirs=($NVM_DIR/versions/node $NVM_DIR)
  2279. v='v0.*[13579].*'
  2280. ;;
  2281. iojs*)
  2282. dirs=($NVM_DIR/versions/io.js)
  2283. v=v${${${v#iojs}#-}#v}'*'
  2284. ;;
  2285. *)
  2286. dirs=($NVM_DIR/versions/node $NVM_DIR $NVM_DIR/versions/io.js)
  2287. v=v${v#v}'*'
  2288. ;;
  2289. esac
  2290. local -a matches=(${^dirs}/${~v}(/N))
  2291. (( $#matches )) || return
  2292. local max path
  2293. for path in ${(Oa)matches}; do
  2294. [[ ${path:t} == (#b)v(*).(*).(*) ]] || continue
  2295. v=${(j::)${(@l:6::0:)match}}
  2296. [[ $v > $max ]] || continue
  2297. max=$v
  2298. _p9k__ret=${path:t}
  2299. [[ ${path:h:t} != io.js ]] || _p9k__ret=iojs-$_p9k__ret
  2300. done
  2301. [[ -n $max ]]
  2302. }
  2303. # The same as `nvm_version current` but faster.
  2304. _p9k_nvm_ls_current() {
  2305. local node_path=${commands[node]:A}
  2306. [[ -n $node_path ]] || return
  2307. local nvm_dir=${NVM_DIR:A}
  2308. if [[ -n $nvm_dir && $node_path == $nvm_dir/versions/io.js/* ]]; then
  2309. _p9k_cached_cmd 0 '' iojs --version || return
  2310. _p9k__ret=iojs-v${_p9k__ret#v}
  2311. elif [[ -n $nvm_dir && $node_path == $nvm_dir/* ]]; then
  2312. _p9k_cached_cmd 0 '' node --version || return
  2313. _p9k__ret=v${_p9k__ret#v}
  2314. else
  2315. _p9k__ret=system
  2316. fi
  2317. }
  2318. ################################################################
  2319. # Segment to display Node version from NVM
  2320. # Only prints the segment if different than the default value
  2321. prompt_nvm() {
  2322. [[ -n $NVM_DIR ]] && _p9k_nvm_ls_current || return
  2323. local current=$_p9k__ret
  2324. (( _POWERLEVEL9K_NVM_SHOW_SYSTEM )) ||
  2325. [[ $current != system ]] ||
  2326. return
  2327. (( _POWERLEVEL9K_NVM_PROMPT_ALWAYS_SHOW )) ||
  2328. ! _p9k_nvm_ls_default ||
  2329. [[ $_p9k__ret != $current ]] ||
  2330. return
  2331. _p9k_prompt_segment "$0" "magenta" "black" 'NODE_ICON' 0 '' "${${current#v}//\%/%%}"
  2332. }
  2333. _p9k_prompt_nvm_init() {
  2334. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[nvm]:-${${+functions[nvm]}:#0}}'
  2335. }
  2336. ################################################################
  2337. # Segment to display NodeEnv
  2338. prompt_nodeenv() {
  2339. local msg
  2340. if (( _POWERLEVEL9K_NODEENV_SHOW_NODE_VERSION )) && _p9k_cached_cmd 0 '' node --version; then
  2341. msg="${_p9k__ret//\%/%%} "
  2342. fi
  2343. msg+="$_POWERLEVEL9K_NODEENV_LEFT_DELIMITER${${NODE_VIRTUAL_ENV:t}//\%/%%}$_POWERLEVEL9K_NODEENV_RIGHT_DELIMITER"
  2344. _p9k_prompt_segment "$0" "black" "green" 'NODE_ICON' 0 '' "$msg"
  2345. }
  2346. _p9k_prompt_nodeenv_init() {
  2347. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$NODE_VIRTUAL_ENV'
  2348. }
  2349. function _p9k_nodeenv_version_transform() {
  2350. local dir=${NODENV_ROOT:-$HOME/.nodenv}/versions
  2351. [[ -z $1 || $1 == system ]] && _p9k__ret=$1 && return
  2352. [[ -d $dir/$1 ]] && _p9k__ret=$1 && return
  2353. [[ -d $dir/${1/v} ]] && _p9k__ret=${1/v} && return
  2354. [[ -d $dir/${1#node-} ]] && _p9k__ret=${1#node-} && return
  2355. [[ -d $dir/${1#node-v} ]] && _p9k__ret=${1#node-v} && return
  2356. return 1
  2357. }
  2358. function _p9k_nodenv_global_version() {
  2359. _p9k_read_word ${NODENV_ROOT:-$HOME/.nodenv}/version || _p9k__ret=system
  2360. }
  2361. ################################################################
  2362. # Segment to display nodenv information
  2363. # https://github.com/nodenv/nodenv
  2364. prompt_nodenv() {
  2365. if [[ -n $NODENV_VERSION ]]; then
  2366. (( ${_POWERLEVEL9K_NODENV_SOURCES[(I)shell]} )) || return
  2367. local v=$NODENV_VERSION
  2368. else
  2369. (( ${_POWERLEVEL9K_NODENV_SOURCES[(I)local|global]} )) || return
  2370. _p9k__ret=
  2371. if [[ $NODENV_DIR != (|.) ]]; then
  2372. [[ $NODENV_DIR == /* ]] && local dir=$NODENV_DIR || local dir="$_p9k__cwd_a/$NODENV_DIR"
  2373. dir=${dir:A}
  2374. if [[ $dir != $_p9k__cwd_a ]]; then
  2375. while true; do
  2376. if _p9k_read_word $dir/.node-version; then
  2377. (( ${_POWERLEVEL9K_NODENV_SOURCES[(I)local]} )) || return
  2378. break
  2379. fi
  2380. [[ $dir == (/|.) ]] && break
  2381. dir=${dir:h}
  2382. done
  2383. fi
  2384. fi
  2385. if [[ -z $_p9k__ret ]]; then
  2386. _p9k_upglob .node-version -.
  2387. local -i idx=$?
  2388. if (( idx )) && _p9k_read_word $_p9k__parent_dirs[idx]/.node-version; then
  2389. (( ${_POWERLEVEL9K_NODENV_SOURCES[(I)local]} )) || return
  2390. else
  2391. _p9k__ret=
  2392. fi
  2393. fi
  2394. if [[ -z $_p9k__ret ]]; then
  2395. (( _POWERLEVEL9K_NODENV_PROMPT_ALWAYS_SHOW )) || return
  2396. (( ${_POWERLEVEL9K_NODENV_SOURCES[(I)global]} )) || return
  2397. _p9k_nodenv_global_version
  2398. fi
  2399. _p9k_nodeenv_version_transform $_p9k__ret || return
  2400. local v=$_p9k__ret
  2401. fi
  2402. if (( !_POWERLEVEL9K_NODENV_PROMPT_ALWAYS_SHOW )); then
  2403. _p9k_nodenv_global_version
  2404. _p9k_nodeenv_version_transform $_p9k__ret && [[ $v == $_p9k__ret ]] && return
  2405. fi
  2406. if (( !_POWERLEVEL9K_NODENV_SHOW_SYSTEM )); then
  2407. [[ $v == system ]] && return
  2408. fi
  2409. _p9k_prompt_segment "$0" "black" "green" 'NODE_ICON' 0 '' "${v//\%/%%}"
  2410. }
  2411. _p9k_prompt_nodenv_init() {
  2412. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[nodenv]:-${${+functions[nodenv]}:#0}}'
  2413. }
  2414. prompt_dotnet_version() {
  2415. if (( _POWERLEVEL9K_DOTNET_VERSION_PROJECT_ONLY )); then
  2416. _p9k_upglob 'project.json|global.json|packet.dependencies|*.csproj|*.fsproj|*.xproj|*.sln' -. && return
  2417. fi
  2418. local cfg
  2419. _p9k_upglob global.json -. || cfg=$_p9k__parent_dirs[$?]/global.json
  2420. _p9k_cached_cmd 0 "$cfg" dotnet --version || return
  2421. _p9k_prompt_segment "$0" "magenta" "white" 'DOTNET_ICON' 0 '' "$_p9k__ret"
  2422. }
  2423. _p9k_prompt_dotnet_init() {
  2424. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[dotnet]'
  2425. }
  2426. ################################################################
  2427. # Segment to print a little OS icon
  2428. prompt_os_icon() {
  2429. local -i len=$#_p9k__prompt _p9k__has_upglob
  2430. _p9k_prompt_segment "$0" "black" "white" '' 0 '' "$_p9k_os_icon"
  2431. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  2432. }
  2433. instant_prompt_os_icon() { prompt_os_icon; }
  2434. ################################################################
  2435. # Segment to display PHP version number
  2436. prompt_php_version() {
  2437. if (( _POWERLEVEL9K_PHP_VERSION_PROJECT_ONLY )); then
  2438. _p9k_upglob 'composer.json|*.php' -. && return
  2439. fi
  2440. _p9k_cached_cmd 0 '' php --version || return
  2441. [[ $_p9k__ret == (#b)(*$'\n')#'PHP '([[:digit:].]##)* ]] || return
  2442. local v=$match[2]
  2443. _p9k_prompt_segment "$0" "fuchsia" "grey93" 'PHP_ICON' 0 '' "${v//\%/%%}"
  2444. }
  2445. _p9k_prompt_php_version_init() {
  2446. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[php]'
  2447. }
  2448. ################################################################
  2449. # Segment to display free RAM and used Swap
  2450. prompt_ram() {
  2451. local -i len=$#_p9k__prompt _p9k__has_upglob
  2452. _p9k_prompt_segment $0 yellow "$_p9k_color1" RAM_ICON 1 '$_p9k__ram_free' '$_p9k__ram_free'
  2453. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  2454. }
  2455. function _p9k_prompt_ram_init() {
  2456. if [[ $_p9k_os == OSX && $+commands[vm_stat] == 0 ||
  2457. $_p9k_os == BSD && ! -r /var/run/dmesg.boot ||
  2458. $_p9k_os != (OSX|BSD) && ! -r /proc/meminfo ]]; then
  2459. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${:-}'
  2460. return
  2461. fi
  2462. typeset -g _p9k__ram_free=
  2463. _p9k__async_segments_compute+='_p9k_worker_invoke ram _p9k_prompt_ram_compute'
  2464. }
  2465. _p9k_prompt_ram_compute() {
  2466. _p9k_worker_async _p9k_prompt_ram_async _p9k_prompt_ram_sync
  2467. }
  2468. _p9k_prompt_ram_async() {
  2469. local -F free_bytes
  2470. case $_p9k_os in
  2471. OSX)
  2472. (( $+commands[vm_stat] )) || return
  2473. local stat && stat="$(vm_stat 2>/dev/null)" || return
  2474. [[ $stat =~ 'Pages free:[[:space:]]+([0-9]+)' ]] || return
  2475. (( free_bytes += match[1] ))
  2476. [[ $stat =~ 'Pages inactive:[[:space:]]+([0-9]+)' ]] || return
  2477. (( free_bytes += match[1] ))
  2478. if (( ! $+_p9k__ram_pagesize )); then
  2479. local p
  2480. (( $+commands[pagesize] )) && p=$(pagesize 2>/dev/null) && [[ $p == <1-> ]] || p=4096
  2481. typeset -gi _p9k__ram_pagesize=p
  2482. _p9k_print_params _p9k__ram_pagesize
  2483. fi
  2484. (( free_bytes *= _p9k__ram_pagesize ))
  2485. ;;
  2486. BSD)
  2487. local stat && stat="$(grep -F 'avail memory' /var/run/dmesg.boot 2>/dev/null)" || return
  2488. free_bytes=${${(A)=stat}[4]}
  2489. ;;
  2490. *)
  2491. [[ -r /proc/meminfo ]] || return
  2492. local stat && stat="$(</proc/meminfo)" || return
  2493. [[ $stat == (#b)*(MemAvailable:|MemFree:)[[:space:]]#(<->)* ]] || return
  2494. free_bytes=$(( $match[2] * 1024 ))
  2495. ;;
  2496. esac
  2497. _p9k_human_readable_bytes $free_bytes
  2498. [[ $_p9k__ret != $_p9k__ram_free ]] || return
  2499. _p9k__ram_free=$_p9k__ret
  2500. _p9k_print_params _p9k__ram_free
  2501. echo -E - 'reset=1'
  2502. }
  2503. _p9k_prompt_ram_sync() {
  2504. eval $REPLY
  2505. _p9k_worker_reply $REPLY
  2506. }
  2507. function _p9k_rbenv_global_version() {
  2508. _p9k_read_word ${RBENV_ROOT:-$HOME/.rbenv}/version || _p9k__ret=system
  2509. }
  2510. ################################################################
  2511. # Segment to display rbenv information
  2512. # https://github.com/rbenv/rbenv#choosing-the-ruby-version
  2513. prompt_rbenv() {
  2514. if [[ -n $RBENV_VERSION ]]; then
  2515. (( ${_POWERLEVEL9K_RBENV_SOURCES[(I)shell]} )) || return
  2516. local v=$RBENV_VERSION
  2517. else
  2518. (( ${_POWERLEVEL9K_RBENV_SOURCES[(I)local|global]} )) || return
  2519. _p9k__ret=
  2520. if [[ $RBENV_DIR != (|.) ]]; then
  2521. [[ $RBENV_DIR == /* ]] && local dir=$RBENV_DIR || local dir="$_p9k__cwd_a/$RBENV_DIR"
  2522. dir=${dir:A}
  2523. if [[ $dir != $_p9k__cwd_a ]]; then
  2524. while true; do
  2525. if _p9k_read_word $dir/.ruby-version; then
  2526. (( ${_POWERLEVEL9K_RBENV_SOURCES[(I)local]} )) || return
  2527. break
  2528. fi
  2529. [[ $dir == (/|.) ]] && break
  2530. dir=${dir:h}
  2531. done
  2532. fi
  2533. fi
  2534. if [[ -z $_p9k__ret ]]; then
  2535. _p9k_upglob .ruby-version -.
  2536. local -i idx=$?
  2537. if (( idx )) && _p9k_read_word $_p9k__parent_dirs[idx]/.ruby-version; then
  2538. (( ${_POWERLEVEL9K_RBENV_SOURCES[(I)local]} )) || return
  2539. else
  2540. _p9k__ret=
  2541. fi
  2542. fi
  2543. if [[ -z $_p9k__ret ]]; then
  2544. (( _POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW )) || return
  2545. (( ${_POWERLEVEL9K_RBENV_SOURCES[(I)global]} )) || return
  2546. _p9k_rbenv_global_version
  2547. fi
  2548. local v=$_p9k__ret
  2549. fi
  2550. if (( !_POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW )); then
  2551. _p9k_rbenv_global_version
  2552. [[ $v == $_p9k__ret ]] && return
  2553. fi
  2554. if (( !_POWERLEVEL9K_RBENV_SHOW_SYSTEM )); then
  2555. [[ $v == system ]] && return
  2556. fi
  2557. _p9k_prompt_segment "$0" "red" "$_p9k_color1" 'RUBY_ICON' 0 '' "${v//\%/%%}"
  2558. }
  2559. _p9k_prompt_rbenv_init() {
  2560. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[rbenv]:-${${+functions[rbenv]}:#0}}'
  2561. }
  2562. function _p9k_phpenv_global_version() {
  2563. _p9k_read_word ${PHPENV_ROOT:-$HOME/.phpenv}/version || _p9k__ret=system
  2564. }
  2565. function _p9k_scalaenv_global_version() {
  2566. _p9k_read_word ${SCALAENV_ROOT:-$HOME/.scalaenv}/version || _p9k__ret=system
  2567. }
  2568. # https://github.com/scalaenv/scalaenv
  2569. prompt_scalaenv() {
  2570. if [[ -n $SCALAENV_VERSION ]]; then
  2571. (( ${_POWERLEVEL9K_SCALAENV_SOURCES[(I)shell]} )) || return
  2572. local v=$SCALAENV_VERSION
  2573. else
  2574. (( ${_POWERLEVEL9K_SCALAENV_SOURCES[(I)local|global]} )) || return
  2575. _p9k__ret=
  2576. if [[ $SCALAENV_DIR != (|.) ]]; then
  2577. [[ $SCALAENV_DIR == /* ]] && local dir=$SCALAENV_DIR || local dir="$_p9k__cwd_a/$SCALAENV_DIR"
  2578. dir=${dir:A}
  2579. if [[ $dir != $_p9k__cwd_a ]]; then
  2580. while true; do
  2581. if _p9k_read_word $dir/.scala-version; then
  2582. (( ${_POWERLEVEL9K_SCALAENV_SOURCES[(I)local]} )) || return
  2583. break
  2584. fi
  2585. [[ $dir == (/|.) ]] && break
  2586. dir=${dir:h}
  2587. done
  2588. fi
  2589. fi
  2590. if [[ -z $_p9k__ret ]]; then
  2591. _p9k_upglob .scala-version -.
  2592. local -i idx=$?
  2593. if (( idx )) && _p9k_read_word $_p9k__parent_dirs[idx]/.scala-version; then
  2594. (( ${_POWERLEVEL9K_SCALAENV_SOURCES[(I)local]} )) || return
  2595. else
  2596. _p9k__ret=
  2597. fi
  2598. fi
  2599. if [[ -z $_p9k__ret ]]; then
  2600. (( _POWERLEVEL9K_SCALAENV_PROMPT_ALWAYS_SHOW )) || return
  2601. (( ${_POWERLEVEL9K_SCALAENV_SOURCES[(I)global]} )) || return
  2602. _p9k_scalaenv_global_version
  2603. fi
  2604. local v=$_p9k__ret
  2605. fi
  2606. if (( !_POWERLEVEL9K_SCALAENV_PROMPT_ALWAYS_SHOW )); then
  2607. _p9k_scalaenv_global_version
  2608. [[ $v == $_p9k__ret ]] && return
  2609. fi
  2610. if (( !_POWERLEVEL9K_SCALAENV_SHOW_SYSTEM )); then
  2611. [[ $v == system ]] && return
  2612. fi
  2613. _p9k_prompt_segment "$0" "red" "$_p9k_color1" 'SCALA_ICON' 0 '' "${v//\%/%%}"
  2614. }
  2615. _p9k_prompt_scalaenv_init() {
  2616. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[scalaenv]:-${${+functions[scalaenv]}:#0}}'
  2617. }
  2618. function _p9k_phpenv_global_version() {
  2619. _p9k_read_word ${PHPENV_ROOT:-$HOME/.phpenv}/version || _p9k__ret=system
  2620. }
  2621. prompt_phpenv() {
  2622. if [[ -n $PHPENV_VERSION ]]; then
  2623. (( ${_POWERLEVEL9K_PHPENV_SOURCES[(I)shell]} )) || return
  2624. local v=$PHPENV_VERSION
  2625. else
  2626. (( ${_POWERLEVEL9K_PHPENV_SOURCES[(I)local|global]} )) || return
  2627. _p9k__ret=
  2628. if [[ $PHPENV_DIR != (|.) ]]; then
  2629. [[ $PHPENV_DIR == /* ]] && local dir=$PHPENV_DIR || local dir="$_p9k__cwd_a/$PHPENV_DIR"
  2630. dir=${dir:A}
  2631. if [[ $dir != $_p9k__cwd_a ]]; then
  2632. while true; do
  2633. if _p9k_read_word $dir/.php-version; then
  2634. (( ${_POWERLEVEL9K_PHPENV_SOURCES[(I)local]} )) || return
  2635. break
  2636. fi
  2637. [[ $dir == (/|.) ]] && break
  2638. dir=${dir:h}
  2639. done
  2640. fi
  2641. fi
  2642. if [[ -z $_p9k__ret ]]; then
  2643. _p9k_upglob .php-version -.
  2644. local -i idx=$?
  2645. if (( idx )) && _p9k_read_word $_p9k__parent_dirs[idx]/.php-version; then
  2646. (( ${_POWERLEVEL9K_PHPENV_SOURCES[(I)local]} )) || return
  2647. else
  2648. _p9k__ret=
  2649. fi
  2650. fi
  2651. if [[ -z $_p9k__ret ]]; then
  2652. (( _POWERLEVEL9K_PHPENV_PROMPT_ALWAYS_SHOW )) || return
  2653. (( ${_POWERLEVEL9K_PHPENV_SOURCES[(I)global]} )) || return
  2654. _p9k_phpenv_global_version
  2655. fi
  2656. local v=$_p9k__ret
  2657. fi
  2658. if (( !_POWERLEVEL9K_PHPENV_PROMPT_ALWAYS_SHOW )); then
  2659. _p9k_phpenv_global_version
  2660. [[ $v == $_p9k__ret ]] && return
  2661. fi
  2662. if (( !_POWERLEVEL9K_PHPENV_SHOW_SYSTEM )); then
  2663. [[ $v == system ]] && return
  2664. fi
  2665. _p9k_prompt_segment "$0" "magenta" "$_p9k_color1" 'PHP_ICON' 0 '' "${v//\%/%%}"
  2666. }
  2667. _p9k_prompt_phpenv_init() {
  2668. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[phpenv]:-${${+functions[phpenv]}:#0}}'
  2669. }
  2670. function _p9k_luaenv_global_version() {
  2671. _p9k_read_word ${LUAENV_ROOT:-$HOME/.luaenv}/version || _p9k__ret=system
  2672. }
  2673. ################################################################
  2674. # Segment to display luaenv information
  2675. # https://github.com/cehoffman/luaenv
  2676. prompt_luaenv() {
  2677. if [[ -n $LUAENV_VERSION ]]; then
  2678. (( ${_POWERLEVEL9K_LUAENV_SOURCES[(I)shell]} )) || return
  2679. local v=$LUAENV_VERSION
  2680. else
  2681. (( ${_POWERLEVEL9K_LUAENV_SOURCES[(I)local|global]} )) || return
  2682. _p9k__ret=
  2683. if [[ $LUAENV_DIR != (|.) ]]; then
  2684. [[ $LUAENV_DIR == /* ]] && local dir=$LUAENV_DIR || local dir="$_p9k__cwd_a/$LUAENV_DIR"
  2685. dir=${dir:A}
  2686. if [[ $dir != $_p9k__cwd_a ]]; then
  2687. while true; do
  2688. if _p9k_read_word $dir/.lua-version; then
  2689. (( ${_POWERLEVEL9K_LUAENV_SOURCES[(I)local]} )) || return
  2690. break
  2691. fi
  2692. [[ $dir == (/|.) ]] && break
  2693. dir=${dir:h}
  2694. done
  2695. fi
  2696. fi
  2697. if [[ -z $_p9k__ret ]]; then
  2698. _p9k_upglob .lua-version -.
  2699. local -i idx=$?
  2700. if (( idx )) && _p9k_read_word $_p9k__parent_dirs[idx]/.lua-version; then
  2701. (( ${_POWERLEVEL9K_LUAENV_SOURCES[(I)local]} )) || return
  2702. else
  2703. _p9k__ret=
  2704. fi
  2705. fi
  2706. if [[ -z $_p9k__ret ]]; then
  2707. (( _POWERLEVEL9K_LUAENV_PROMPT_ALWAYS_SHOW )) || return
  2708. (( ${_POWERLEVEL9K_LUAENV_SOURCES[(I)global]} )) || return
  2709. _p9k_luaenv_global_version
  2710. fi
  2711. local v=$_p9k__ret
  2712. fi
  2713. if (( !_POWERLEVEL9K_LUAENV_PROMPT_ALWAYS_SHOW )); then
  2714. _p9k_luaenv_global_version
  2715. [[ $v == $_p9k__ret ]] && return
  2716. fi
  2717. if (( !_POWERLEVEL9K_LUAENV_SHOW_SYSTEM )); then
  2718. [[ $v == system ]] && return
  2719. fi
  2720. _p9k_prompt_segment "$0" blue "$_p9k_color1" 'LUA_ICON' 0 '' "${v//\%/%%}"
  2721. }
  2722. _p9k_prompt_luaenv_init() {
  2723. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[luaenv]:-${${+functions[luaenv]}:#0}}'
  2724. }
  2725. function _p9k_jenv_global_version() {
  2726. _p9k_read_word ${JENV_ROOT:-$HOME/.jenv}/version || _p9k__ret=system
  2727. }
  2728. ################################################################
  2729. # Segment to display jenv information
  2730. # https://github.com/jenv/jenv
  2731. prompt_jenv() {
  2732. if [[ -n $JENV_VERSION ]]; then
  2733. (( ${_POWERLEVEL9K_JENV_SOURCES[(I)shell]} )) || return
  2734. local v=$JENV_VERSION
  2735. else
  2736. (( ${_POWERLEVEL9K_JENV_SOURCES[(I)local|global]} )) || return
  2737. _p9k__ret=
  2738. if [[ $JENV_DIR != (|.) ]]; then
  2739. [[ $JENV_DIR == /* ]] && local dir=$JENV_DIR || local dir="$_p9k__cwd_a/$JENV_DIR"
  2740. dir=${dir:A}
  2741. if [[ $dir != $_p9k__cwd_a ]]; then
  2742. while true; do
  2743. if _p9k_read_word $dir/.java-version; then
  2744. (( ${_POWERLEVEL9K_JENV_SOURCES[(I)local]} )) || return
  2745. break
  2746. fi
  2747. [[ $dir == (/|.) ]] && break
  2748. dir=${dir:h}
  2749. done
  2750. fi
  2751. fi
  2752. if [[ -z $_p9k__ret ]]; then
  2753. _p9k_upglob .java-version -.
  2754. local -i idx=$?
  2755. if (( idx )) && _p9k_read_word $_p9k__parent_dirs[idx]/.java-version; then
  2756. (( ${_POWERLEVEL9K_JENV_SOURCES[(I)local]} )) || return
  2757. else
  2758. _p9k__ret=
  2759. fi
  2760. fi
  2761. if [[ -z $_p9k__ret ]]; then
  2762. (( _POWERLEVEL9K_JENV_PROMPT_ALWAYS_SHOW )) || return
  2763. (( ${_POWERLEVEL9K_JENV_SOURCES[(I)global]} )) || return
  2764. _p9k_jenv_global_version
  2765. fi
  2766. local v=$_p9k__ret
  2767. fi
  2768. if (( !_POWERLEVEL9K_JENV_PROMPT_ALWAYS_SHOW )); then
  2769. _p9k_jenv_global_version
  2770. [[ $v == $_p9k__ret ]] && return
  2771. fi
  2772. if (( !_POWERLEVEL9K_JENV_SHOW_SYSTEM )); then
  2773. [[ $v == system ]] && return
  2774. fi
  2775. _p9k_prompt_segment "$0" white red 'JAVA_ICON' 0 '' "${v//\%/%%}"
  2776. }
  2777. _p9k_prompt_jenv_init() {
  2778. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[jenv]:-${${+functions[jenv]}:#0}}'
  2779. }
  2780. function _p9k_plenv_global_version() {
  2781. _p9k_read_word ${PLENV_ROOT:-$HOME/.plenv}/version || _p9k__ret=system
  2782. }
  2783. ################################################################
  2784. # Segment to display plenv information
  2785. # https://github.com/plenv/plenv#choosing-the-perl-version
  2786. prompt_plenv() {
  2787. if [[ -n $PLENV_VERSION ]]; then
  2788. (( ${_POWERLEVEL9K_PLENV_SOURCES[(I)shell]} )) || return
  2789. local v=$PLENV_VERSION
  2790. else
  2791. (( ${_POWERLEVEL9K_PLENV_SOURCES[(I)local|global]} )) || return
  2792. _p9k__ret=
  2793. if [[ $PLENV_DIR != (|.) ]]; then
  2794. [[ $PLENV_DIR == /* ]] && local dir=$PLENV_DIR || local dir="$_p9k__cwd_a/$PLENV_DIR"
  2795. dir=${dir:A}
  2796. if [[ $dir != $_p9k__cwd_a ]]; then
  2797. while true; do
  2798. if _p9k_read_word $dir/.perl-version; then
  2799. (( ${_POWERLEVEL9K_PLENV_SOURCES[(I)local]} )) || return
  2800. break
  2801. fi
  2802. [[ $dir == (/|.) ]] && break
  2803. dir=${dir:h}
  2804. done
  2805. fi
  2806. fi
  2807. if [[ -z $_p9k__ret ]]; then
  2808. _p9k_upglob .perl-version -.
  2809. local -i idx=$?
  2810. if (( idx )) && _p9k_read_word $_p9k__parent_dirs[idx]/.perl-version; then
  2811. (( ${_POWERLEVEL9K_PLENV_SOURCES[(I)local]} )) || return
  2812. else
  2813. _p9k__ret=
  2814. fi
  2815. fi
  2816. if [[ -z $_p9k__ret ]]; then
  2817. (( _POWERLEVEL9K_PLENV_PROMPT_ALWAYS_SHOW )) || return
  2818. (( ${_POWERLEVEL9K_PLENV_SOURCES[(I)global]} )) || return
  2819. _p9k_plenv_global_version
  2820. fi
  2821. local v=$_p9k__ret
  2822. fi
  2823. if (( !_POWERLEVEL9K_PLENV_PROMPT_ALWAYS_SHOW )); then
  2824. _p9k_plenv_global_version
  2825. [[ $v == $_p9k__ret ]] && return
  2826. fi
  2827. if (( !_POWERLEVEL9K_PLENV_SHOW_SYSTEM )); then
  2828. [[ $v == system ]] && return
  2829. fi
  2830. _p9k_prompt_segment "$0" "blue" "$_p9k_color1" 'PERL_ICON' 0 '' "${v//\%/%%}"
  2831. }
  2832. _p9k_prompt_plenv_init() {
  2833. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[plenv]:-${${+functions[plenv]}:#0}}'
  2834. }
  2835. ################################################################
  2836. # Segment to display perlbrew information
  2837. # https://github.com/gugod/App-perlbrew
  2838. prompt_perlbrew() {
  2839. if (( _POWERLEVEL9K_PERLBREW_PROJECT_ONLY )); then
  2840. _p9k_upglob 'cpanfile|.perltidyrc|(|MY)META.(yml|json)|(Makefile|Build).PL|*.(pl|pm|t|pod)' -. && return
  2841. fi
  2842. local v=$PERLBREW_PERL
  2843. (( _POWERLEVEL9K_PERLBREW_SHOW_PREFIX )) || v=${v#*-}
  2844. [[ -n $v ]] || return
  2845. _p9k_prompt_segment "$0" "blue" "$_p9k_color1" 'PERL_ICON' 0 '' "${v//\%/%%}"
  2846. }
  2847. _p9k_prompt_perlbrew_init() {
  2848. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$PERLBREW_PERL'
  2849. }
  2850. ################################################################
  2851. # Segment to display chruby information
  2852. # see https://github.com/postmodern/chruby/issues/245 for chruby_auto issue with ZSH
  2853. prompt_chruby() {
  2854. local v=${(M)RUBY_ENGINE:#$~_POWERLEVEL9K_CHRUBY_SHOW_ENGINE_PATTERN}
  2855. [[ $_POWERLEVEL9K_CHRUBY_SHOW_VERSION == 1 && -n $RUBY_VERSION ]] && v+=${v:+ }$RUBY_VERSION
  2856. _p9k_prompt_segment "$0" "red" "$_p9k_color1" 'RUBY_ICON' 0 '' "${v//\%/%%}"
  2857. }
  2858. _p9k_prompt_chruby_init() {
  2859. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$RUBY_ENGINE'
  2860. }
  2861. ################################################################
  2862. # Segment to print an icon if user is root.
  2863. prompt_root_indicator() {
  2864. local -i len=$#_p9k__prompt _p9k__has_upglob
  2865. _p9k_prompt_segment "$0" "$_p9k_color1" "yellow" 'ROOT_ICON' 0 '${${(%):-%#}:#\%}' ''
  2866. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  2867. }
  2868. instant_prompt_root_indicator() { prompt_root_indicator; }
  2869. ################################################################
  2870. # Segment to display Rust version number
  2871. prompt_rust_version() {
  2872. unset P9K_RUST_VERSION
  2873. if (( _POWERLEVEL9K_RUST_VERSION_PROJECT_ONLY )); then
  2874. _p9k_upglob Cargo.toml -. && return
  2875. fi
  2876. local rustc=$commands[rustc] toolchain deps=()
  2877. if (( $+commands[ldd] )); then
  2878. if ! _p9k_cache_stat_get $0_so $rustc; then
  2879. local line so
  2880. for line in "${(@f)$(ldd $rustc 2>/dev/null)}"; do
  2881. [[ $line == (#b)[[:space:]]#librustc_driver[^[:space:]]#.so' => '(*)' (0x'[[:xdigit:]]#')' ]] || continue
  2882. so=$match[1]
  2883. break
  2884. done
  2885. _p9k_cache_stat_set "$so"
  2886. fi
  2887. deps+=$_p9k__cache_val[1]
  2888. fi
  2889. if (( $+commands[rustup] )); then
  2890. local rustup=$commands[rustup]
  2891. local rustup_home=${RUSTUP_HOME:-~/.rustup}
  2892. local cfg=($rustup_home/settings.toml(.N))
  2893. deps+=($cfg $rustup_home/update-hashes/*(.N))
  2894. if [[ -z ${toolchain::=$RUSTUP_TOOLCHAIN} ]]; then
  2895. if ! _p9k_cache_stat_get $0_overrides $rustup $cfg; then
  2896. local lines=(${(f)"$(rustup override list 2>/dev/null)"})
  2897. if [[ $lines[1] == "no overrides" ]]; then
  2898. _p9k_cache_stat_set
  2899. else
  2900. local MATCH
  2901. local keys=(${(@)${lines%%[[:space:]]#[^[:space:]]#}/(#m)*/${(b)MATCH}/})
  2902. local vals=(${(@)lines/(#m)*/$MATCH[(I)/] ${MATCH##*[[:space:]]}})
  2903. _p9k_cache_stat_set ${keys:^vals}
  2904. fi
  2905. fi
  2906. local -A overrides=($_p9k__cache_val)
  2907. _p9k_upglob rust-toolchain -.
  2908. local dir=$_p9k__parent_dirs[$?]
  2909. local -i n m=${dir[(I)/]}
  2910. local pair
  2911. for pair in ${overrides[(K)$_p9k__cwd/]}; do
  2912. n=${pair%% *}
  2913. (( n <= m )) && continue
  2914. m=n
  2915. toolchain=${pair#* }
  2916. done
  2917. if [[ -z $toolchain && -n $dir ]]; then
  2918. _p9k_read_word $dir/rust-toolchain
  2919. toolchain=$_p9k__ret
  2920. fi
  2921. fi
  2922. fi
  2923. if ! _p9k_cache_stat_get $0_v$toolchain $rustc $deps; then
  2924. _p9k_cache_stat_set "$($rustc --version 2>/dev/null)"
  2925. fi
  2926. local v=${${_p9k__cache_val[1]#rustc }%% *}
  2927. [[ -n $v ]] || return
  2928. typeset -g P9K_RUST_VERSION=$_p9k__cache_val[1]
  2929. _p9k_prompt_segment "$0" "darkorange" "$_p9k_color1" 'RUST_ICON' 0 '' "${v//\%/%%}"
  2930. }
  2931. _p9k_prompt_rust_version_init() {
  2932. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[rustc]'
  2933. }
  2934. # RSpec test ratio
  2935. prompt_rspec_stats() {
  2936. if [[ -d app && -d spec ]]; then
  2937. local -a code=(app/**/*.rb(N))
  2938. (( $#code )) || return
  2939. local tests=(spec/**/*.rb(N))
  2940. _p9k_build_test_stats "$0" "$#code" "$#tests" "RSpec" 'TEST_ICON'
  2941. fi
  2942. }
  2943. ################################################################
  2944. # Segment to display Ruby Version Manager information
  2945. prompt_rvm() {
  2946. [[ $GEM_HOME == *rvm* && $ruby_string != $rvm_path/bin/ruby ]] || return
  2947. local v=${GEM_HOME:t}
  2948. (( _POWERLEVEL9K_RVM_SHOW_GEMSET )) || v=${v%%${rvm_gemset_separator:-@}*}
  2949. (( _POWERLEVEL9K_RVM_SHOW_PREFIX )) || v=${v#*-}
  2950. [[ -n $v ]] || return
  2951. _p9k_prompt_segment "$0" "240" "$_p9k_color1" 'RUBY_ICON' 0 '' "${v//\%/%%}"
  2952. }
  2953. _p9k_prompt_rvm_init() {
  2954. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[rvm-prompt]:-${${+functions[rvm-prompt]}:#0}}'
  2955. }
  2956. ################################################################
  2957. # Segment to display SSH icon when connected
  2958. prompt_ssh() {
  2959. local -i len=$#_p9k__prompt _p9k__has_upglob
  2960. _p9k_prompt_segment "$0" "$_p9k_color1" "yellow" 'SSH_ICON' 0 '' ''
  2961. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  2962. }
  2963. _p9k_prompt_ssh_init() {
  2964. if (( ! P9K_SSH )); then
  2965. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${:-}'
  2966. fi
  2967. }
  2968. instant_prompt_ssh() {
  2969. if (( ! P9K_SSH )); then
  2970. return
  2971. fi
  2972. prompt_ssh
  2973. }
  2974. ################################################################
  2975. # Status: When an error occur, return the error code, or a cross icon if option is set
  2976. # Display an ok icon when no error occur, or hide the segment if option is set to false
  2977. prompt_status() {
  2978. if ! _p9k_cache_get $0 $_p9k__status $_p9k__pipestatus; then
  2979. (( _p9k__status )) && local state=ERROR || local state=OK
  2980. if (( _POWERLEVEL9K_STATUS_EXTENDED_STATES )); then
  2981. if (( _p9k__status )); then
  2982. if (( $#_p9k__pipestatus > 1 )); then
  2983. state+=_PIPE
  2984. elif (( _p9k__status > 128 )); then
  2985. state+=_SIGNAL
  2986. fi
  2987. elif [[ "$_p9k__pipestatus" == *[1-9]* ]]; then
  2988. state+=_PIPE
  2989. fi
  2990. fi
  2991. _p9k__cache_val=(:)
  2992. if (( _POWERLEVEL9K_STATUS_$state )); then
  2993. if (( _POWERLEVEL9K_STATUS_SHOW_PIPESTATUS )); then
  2994. local text=${(j:|:)${(@)_p9k__pipestatus:/(#b)(*)/$_p9k_exitcode2str[$match[1]+1]}}
  2995. else
  2996. local text=$_p9k_exitcode2str[_p9k__status+1]
  2997. fi
  2998. if (( _p9k__status )); then
  2999. if (( !_POWERLEVEL9K_STATUS_CROSS && _POWERLEVEL9K_STATUS_VERBOSE )); then
  3000. _p9k__cache_val=($0_$state red yellow1 CARRIAGE_RETURN_ICON 0 '' "$text")
  3001. else
  3002. _p9k__cache_val=($0_$state $_p9k_color1 red FAIL_ICON 0 '' '')
  3003. fi
  3004. elif (( _POWERLEVEL9K_STATUS_VERBOSE || _POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE )); then
  3005. [[ $state == OK ]] && text=''
  3006. _p9k__cache_val=($0_$state "$_p9k_color1" green OK_ICON 0 '' "$text")
  3007. fi
  3008. fi
  3009. if (( $#_p9k__pipestatus < 3 )); then
  3010. _p9k_cache_set "${(@)_p9k__cache_val}"
  3011. fi
  3012. fi
  3013. _p9k_prompt_segment "${(@)_p9k__cache_val}"
  3014. }
  3015. instant_prompt_status() {
  3016. if (( _POWERLEVEL9K_STATUS_OK )); then
  3017. _p9k_prompt_segment prompt_status_OK "$_p9k_color1" green OK_ICON 0 '' ''
  3018. fi
  3019. }
  3020. prompt_prompt_char() {
  3021. local saved=$_p9k__prompt_char_saved[$_p9k__prompt_side$_p9k__segment_index$((!_p9k__status))]
  3022. if [[ -n $saved ]]; then
  3023. _p9k__prompt+=$saved
  3024. return
  3025. fi
  3026. local -i len=$#_p9k__prompt _p9k__has_upglob
  3027. if (( __p9k_sh_glob )); then
  3028. if (( _p9k__status )); then
  3029. if (( _POWERLEVEL9K_PROMPT_CHAR_OVERWRITE_STATE )); then
  3030. _p9k_prompt_segment $0_ERROR_VIINS "$_p9k_color1" 196 '' 0 '${${${${${${:-$_p9k__keymap.$_p9k__zle_state}:#vicmd.*}:#vivis.*}:#vivli.*}:#*.*overwrite*}}' '❯'
  3031. _p9k_prompt_segment $0_ERROR_VIOWR "$_p9k_color1" 196 '' 0 '${${${${${${:-$_p9k__keymap.$_p9k__zle_state}:#vicmd.*}:#vivis.*}:#vivli.*}:#*.*insert*}}' '▶'
  3032. else
  3033. _p9k_prompt_segment $0_ERROR_VIINS "$_p9k_color1" 196 '' 0 '${${${${_p9k__keymap:#vicmd}:#vivis}:#vivli}}' '❯'
  3034. fi
  3035. _p9k_prompt_segment $0_ERROR_VICMD "$_p9k_color1" 196 '' 0 '${(M)${:-$_p9k__keymap$_p9k__region_active}:#vicmd0}' '❮'
  3036. _p9k_prompt_segment $0_ERROR_VIVIS "$_p9k_color1" 196 '' 0 '${$((! ${#${${${${:-$_p9k__keymap$_p9k__region_active}:#vicmd1}:#vivis?}:#vivli?}})):#0}' 'Ⅴ'
  3037. else
  3038. if (( _POWERLEVEL9K_PROMPT_CHAR_OVERWRITE_STATE )); then
  3039. _p9k_prompt_segment $0_OK_VIINS "$_p9k_color1" 76 '' 0 '${${${${${${:-$_p9k__keymap.$_p9k__zle_state}:#vicmd.*}:#vivis.*}:#vivli.*}:#*.*overwrite*}}' '❯'
  3040. _p9k_prompt_segment $0_OK_VIOWR "$_p9k_color1" 76 '' 0 '${${${${${${:-$_p9k__keymap.$_p9k__zle_state}:#vicmd.*}:#vivis.*}:#vivli.*}:#*.*insert*}}' '▶'
  3041. else
  3042. _p9k_prompt_segment $0_OK_VIINS "$_p9k_color1" 76 '' 0 '${${${${_p9k__keymap:#vicmd}:#vivis}:#vivli}}' '❯'
  3043. fi
  3044. _p9k_prompt_segment $0_OK_VICMD "$_p9k_color1" 76 '' 0 '${(M)${:-$_p9k__keymap$_p9k__region_active}:#vicmd0}' '❮'
  3045. _p9k_prompt_segment $0_OK_VIVIS "$_p9k_color1" 76 '' 0 '${$((! ${#${${${${:-$_p9k__keymap$_p9k__region_active}:#vicmd1}:#vivis?}:#vivli?}})):#0}' 'Ⅴ'
  3046. fi
  3047. else
  3048. if (( _p9k__status )); then
  3049. if (( _POWERLEVEL9K_PROMPT_CHAR_OVERWRITE_STATE )); then
  3050. _p9k_prompt_segment $0_ERROR_VIINS "$_p9k_color1" 196 '' 0 '${${:-$_p9k__keymap.$_p9k__zle_state}:#(vicmd.*|vivis.*|vivli.*|*.*overwrite*)}' '❯'
  3051. _p9k_prompt_segment $0_ERROR_VIOWR "$_p9k_color1" 196 '' 0 '${${:-$_p9k__keymap.$_p9k__zle_state}:#(vicmd.*|vivis.*|vivli.*|*.*insert*)}' '▶'
  3052. else
  3053. _p9k_prompt_segment $0_ERROR_VIINS "$_p9k_color1" 196 '' 0 '${_p9k__keymap:#(vicmd|vivis|vivli)}' '❯'
  3054. fi
  3055. _p9k_prompt_segment $0_ERROR_VICMD "$_p9k_color1" 196 '' 0 '${(M)${:-$_p9k__keymap$_p9k__region_active}:#vicmd0}' '❮'
  3056. _p9k_prompt_segment $0_ERROR_VIVIS "$_p9k_color1" 196 '' 0 '${(M)${:-$_p9k__keymap$_p9k__region_active}:#(vicmd1|vivis?|vivli?)}' 'Ⅴ'
  3057. else
  3058. if (( _POWERLEVEL9K_PROMPT_CHAR_OVERWRITE_STATE )); then
  3059. _p9k_prompt_segment $0_OK_VIINS "$_p9k_color1" 76 '' 0 '${${:-$_p9k__keymap.$_p9k__zle_state}:#(vicmd.*|vivis.*|vivli.*|*.*overwrite*)}' '❯'
  3060. _p9k_prompt_segment $0_OK_VIOWR "$_p9k_color1" 76 '' 0 '${${:-$_p9k__keymap.$_p9k__zle_state}:#(vicmd.*|vivis.*|vivli.*|*.*insert*)}' '▶'
  3061. else
  3062. _p9k_prompt_segment $0_OK_VIINS "$_p9k_color1" 76 '' 0 '${_p9k__keymap:#(vicmd|vivis|vivli)}' '❯'
  3063. fi
  3064. _p9k_prompt_segment $0_OK_VICMD "$_p9k_color1" 76 '' 0 '${(M)${:-$_p9k__keymap$_p9k__region_active}:#vicmd0}' '❮'
  3065. _p9k_prompt_segment $0_OK_VIVIS "$_p9k_color1" 76 '' 0 '${(M)${:-$_p9k__keymap$_p9k__region_active}:#(vicmd1|vivis?|vivli?)}' 'Ⅴ'
  3066. fi
  3067. fi
  3068. (( _p9k__has_upglob )) || _p9k__prompt_char_saved[$_p9k__prompt_side$_p9k__segment_index$((!_p9k__status))]=$_p9k__prompt[len+1,-1]
  3069. }
  3070. instant_prompt_prompt_char() {
  3071. _p9k_prompt_segment prompt_prompt_char_OK_VIINS "$_p9k_color1" 76 '' 0 '' '❯'
  3072. }
  3073. ################################################################
  3074. # Segment to display Swap information
  3075. prompt_swap() {
  3076. local -i len=$#_p9k__prompt _p9k__has_upglob
  3077. _p9k_prompt_segment $0 yellow "$_p9k_color1" SWAP_ICON 1 '$_p9k__swap_used' '$_p9k__swap_used'
  3078. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  3079. }
  3080. function _p9k_prompt_swap_init() {
  3081. if [[ $_p9k_os == OSX && $+commands[sysctl] == 0 || $_p9k_os != OSX && ! -r /proc/meminfo ]]; then
  3082. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${:-}'
  3083. return
  3084. fi
  3085. typeset -g _p9k__swap_used=
  3086. _p9k__async_segments_compute+='_p9k_worker_invoke swap _p9k_prompt_swap_compute'
  3087. }
  3088. _p9k_prompt_swap_compute() {
  3089. _p9k_worker_async _p9k_prompt_swap_async _p9k_prompt_swap_sync
  3090. }
  3091. _p9k_prompt_swap_async() {
  3092. local -F used_bytes
  3093. if [[ "$_p9k_os" == "OSX" ]]; then
  3094. (( $+commands[sysctl] )) || return
  3095. [[ "$(sysctl vm.swapusage 2>/dev/null)" =~ "used = ([0-9,.]+)([A-Z]+)" ]] || return
  3096. used_bytes=${match[1]//,/.}
  3097. case ${match[2]} in
  3098. 'K') (( used_bytes *= 1024 ));;
  3099. 'M') (( used_bytes *= 1048576 ));;
  3100. 'G') (( used_bytes *= 1073741824 ));;
  3101. 'T') (( used_bytes *= 1099511627776 ));;
  3102. *) return 0;;
  3103. esac
  3104. else
  3105. local meminfo && meminfo="$(grep -F 'Swap' /proc/meminfo 2>/dev/null)" || return
  3106. [[ $meminfo =~ 'SwapTotal:[[:space:]]+([0-9]+)' ]] || return
  3107. (( used_bytes+=match[1] ))
  3108. [[ $meminfo =~ 'SwapFree:[[:space:]]+([0-9]+)' ]] || return
  3109. (( used_bytes-=match[1] ))
  3110. (( used_bytes *= 1024 ))
  3111. fi
  3112. (( used_bytes >= 0 || (used_bytes = 0) ))
  3113. _p9k_human_readable_bytes $used_bytes
  3114. [[ $_p9k__ret != $_p9k__swap_used ]] || return
  3115. _p9k__swap_used=$_p9k__ret
  3116. _p9k_print_params _p9k__swap_used
  3117. echo -E - 'reset=1'
  3118. }
  3119. _p9k_prompt_swap_sync() {
  3120. eval $REPLY
  3121. _p9k_worker_reply $REPLY
  3122. }
  3123. ################################################################
  3124. # Symfony2-PHPUnit test ratio
  3125. prompt_symfony2_tests() {
  3126. if [[ -d src && -d app && -f app/AppKernel.php ]]; then
  3127. local -a all=(src/**/*.php(N))
  3128. local -a code=(${(@)all##*Tests*})
  3129. (( $#code )) || return
  3130. _p9k_build_test_stats "$0" "$#code" "$(($#all - $#code))" "SF2" 'TEST_ICON'
  3131. fi
  3132. }
  3133. ################################################################
  3134. # Segment to display Symfony2-Version
  3135. prompt_symfony2_version() {
  3136. if [[ -r app/bootstrap.php.cache ]]; then
  3137. local v="${$(grep -F " VERSION " app/bootstrap.php.cache 2>/dev/null)//[![:digit:].]}"
  3138. _p9k_prompt_segment "$0" "grey35" "$_p9k_color1" 'SYMFONY_ICON' 0 '' "${v//\%/%%}"
  3139. fi
  3140. }
  3141. ################################################################
  3142. # Show a ratio of tests vs code
  3143. _p9k_build_test_stats() {
  3144. local code_amount="$2"
  3145. local tests_amount="$3"
  3146. local headline="$4"
  3147. (( code_amount > 0 )) || return
  3148. local -F 2 ratio=$(( 100. * tests_amount / code_amount ))
  3149. (( ratio >= 75 )) && _p9k_prompt_segment "${1}_GOOD" "cyan" "$_p9k_color1" "$5" 0 '' "$headline: $ratio%%"
  3150. (( ratio >= 50 && ratio < 75 )) && _p9k_prompt_segment "$1_AVG" "yellow" "$_p9k_color1" "$5" 0 '' "$headline: $ratio%%"
  3151. (( ratio < 50 )) && _p9k_prompt_segment "$1_BAD" "red" "$_p9k_color1" "$5" 0 '' "$headline: $ratio%%"
  3152. }
  3153. ################################################################
  3154. # System time
  3155. prompt_time() {
  3156. if (( _POWERLEVEL9K_EXPERIMENTAL_TIME_REALTIME )); then
  3157. _p9k_prompt_segment "$0" "$_p9k_color2" "$_p9k_color1" "TIME_ICON" 0 '' "$_POWERLEVEL9K_TIME_FORMAT"
  3158. else
  3159. if [[ $_p9k__refresh_reason == precmd ]]; then
  3160. if [[ $+__p9k_instant_prompt_active == 1 && $__p9k_instant_prompt_time_format == $_POWERLEVEL9K_TIME_FORMAT ]]; then
  3161. _p9k__time=${__p9k_instant_prompt_time//\%/%%}
  3162. else
  3163. _p9k__time=${${(%)_POWERLEVEL9K_TIME_FORMAT}//\%/%%}
  3164. fi
  3165. fi
  3166. if (( _POWERLEVEL9K_TIME_UPDATE_ON_COMMAND )); then
  3167. _p9k_escape $_p9k__time
  3168. local t=$_p9k__ret
  3169. _p9k_escape $_POWERLEVEL9K_TIME_FORMAT
  3170. _p9k_prompt_segment "$0" "$_p9k_color2" "$_p9k_color1" "TIME_ICON" 1 '' \
  3171. "\${_p9k__line_finished-$t}\${_p9k__line_finished+$_p9k__ret}"
  3172. else
  3173. _p9k_prompt_segment "$0" "$_p9k_color2" "$_p9k_color1" "TIME_ICON" 0 '' $_p9k__time
  3174. fi
  3175. fi
  3176. }
  3177. instant_prompt_time() {
  3178. _p9k_escape $_POWERLEVEL9K_TIME_FORMAT
  3179. local stash='${${__p9k_instant_prompt_time::=${(%)${__p9k_instant_prompt_time_format::='$_p9k__ret'}}}+}'
  3180. _p9k_escape $_POWERLEVEL9K_TIME_FORMAT
  3181. _p9k_prompt_segment prompt_time "$_p9k_color2" "$_p9k_color1" "TIME_ICON" 1 '' $stash$_p9k__ret
  3182. }
  3183. _p9k_prompt_time_init() {
  3184. (( _POWERLEVEL9K_EXPERIMENTAL_TIME_REALTIME )) || return
  3185. _p9k__async_segments_compute+='_p9k_worker_invoke time _p9k_prompt_time_compute'
  3186. }
  3187. _p9k_prompt_time_compute() {
  3188. _p9k_worker_async _p9k_prompt_time_async _p9k_prompt_time_sync
  3189. }
  3190. _p9k_prompt_time_async() {
  3191. sleep 1 || true
  3192. }
  3193. _p9k_prompt_time_sync() {
  3194. _p9k_worker_reply '_p9k_worker_invoke _p9k_prompt_time_compute _p9k_prompt_time_compute; reset=1'
  3195. }
  3196. ################################################################
  3197. # System date
  3198. prompt_date() {
  3199. if [[ $_p9k__refresh_reason == precmd ]]; then
  3200. if [[ $+__p9k_instant_prompt_active == 1 && $__p9k_instant_prompt_date_format == $_POWERLEVEL9K_DATE_FORMAT ]]; then
  3201. _p9k__date=${__p9k_instant_prompt_date//\%/%%}
  3202. else
  3203. _p9k__date=${${(%)_POWERLEVEL9K_DATE_FORMAT}//\%/%%}
  3204. fi
  3205. fi
  3206. _p9k_prompt_segment "$0" "$_p9k_color2" "$_p9k_color1" "DATE_ICON" 0 '' "$_p9k__date"
  3207. }
  3208. instant_prompt_date() {
  3209. _p9k_escape $_POWERLEVEL9K_DATE_FORMAT
  3210. local stash='${${__p9k_instant_prompt_date::=${(%)${__p9k_instant_prompt_date_format::='$_p9k__ret'}}}+}'
  3211. _p9k_escape $_POWERLEVEL9K_DATE_FORMAT
  3212. _p9k_prompt_segment prompt_date "$_p9k_color2" "$_p9k_color1" "DATE_ICON" 1 '' $stash$_p9k__ret
  3213. }
  3214. ################################################################
  3215. # todo.sh: shows the number of tasks in your todo.sh file
  3216. prompt_todo() {
  3217. unset P9K_TODO_TOTAL_TASK_COUNT P9K_TODO_FILTERED_TASK_COUNT
  3218. [[ -r $_p9k__todo_file && -x $_p9k__todo_command ]] || return
  3219. if ! _p9k_cache_stat_get $0 $_p9k__todo_file; then
  3220. local count="$($_p9k__todo_command -p ls | command tail -1)"
  3221. if [[ $count == (#b)'TODO: '([[:digit:]]##)' of '([[:digit:]]##)' '* ]]; then
  3222. _p9k_cache_stat_set 1 $match[1] $match[2]
  3223. else
  3224. _p9k_cache_stat_set 0
  3225. fi
  3226. fi
  3227. (( $_p9k__cache_val[1] )) || return
  3228. typeset -gi P9K_TODO_FILTERED_TASK_COUNT=$_p9k__cache_val[2]
  3229. typeset -gi P9K_TODO_TOTAL_TASK_COUNT=$_p9k__cache_val[3]
  3230. if (( (P9K_TODO_TOTAL_TASK_COUNT || !_POWERLEVEL9K_TODO_HIDE_ZERO_TOTAL) &&
  3231. (P9K_TODO_FILTERED_TASK_COUNT || !_POWERLEVEL9K_TODO_HIDE_ZERO_FILTERED) )); then
  3232. if (( P9K_TODO_TOTAL_TASK_COUNT == P9K_TODO_FILTERED_TASK_COUNT )); then
  3233. local text=$P9K_TODO_TOTAL_TASK_COUNT
  3234. else
  3235. local text="$P9K_TODO_FILTERED_TASK_COUNT/$P9K_TODO_TOTAL_TASK_COUNT"
  3236. fi
  3237. _p9k_prompt_segment "$0" "grey50" "$_p9k_color1" 'TODO_ICON' 0 '' "$text"
  3238. fi
  3239. }
  3240. _p9k_prompt_todo_init() {
  3241. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$_p9k__todo_file'
  3242. }
  3243. ################################################################
  3244. # VCS segment: shows the state of your repository, if you are in a folder under
  3245. # version control
  3246. # The vcs segment can have 4 different states - defaults to 'CLEAN'.
  3247. typeset -gA __p9k_vcs_states=(
  3248. 'CLEAN' '2'
  3249. 'MODIFIED' '3'
  3250. 'UNTRACKED' '2'
  3251. 'LOADING' '8'
  3252. 'CONFLICTED' '3'
  3253. )
  3254. function +vi-git-untracked() {
  3255. [[ -z "${vcs_comm[gitdir]}" || "${vcs_comm[gitdir]}" == "." ]] && return
  3256. # get the root for the current repo or submodule
  3257. local repoTopLevel="$(git rev-parse --show-toplevel 2> /dev/null)"
  3258. # dump out if we're outside a git repository (which includes being in the .git folder)
  3259. [[ $? != 0 || -z $repoTopLevel ]] && return
  3260. local untrackedFiles="$(git ls-files --others --exclude-standard "${repoTopLevel}" 2> /dev/null)"
  3261. if [[ -z $untrackedFiles && $_POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY == 1 ]]; then
  3262. untrackedFiles+="$(git submodule foreach --quiet --recursive 'git ls-files --others --exclude-standard' 2> /dev/null)"
  3263. fi
  3264. [[ -z $untrackedFiles ]] && return
  3265. hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
  3266. VCS_WORKDIR_HALF_DIRTY=true
  3267. }
  3268. function +vi-git-aheadbehind() {
  3269. local ahead behind
  3270. local -a gitstatus
  3271. # for git prior to 1.7
  3272. # ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
  3273. ahead="$(git rev-list --count "${hook_com[branch]}"@{upstream}..HEAD 2>/dev/null)"
  3274. (( ahead )) && gitstatus+=( " $(print_icon 'VCS_OUTGOING_CHANGES_ICON')${ahead// /}" )
  3275. # for git prior to 1.7
  3276. # behind=$(git rev-list HEAD..origin/${hook_com[branch]} | wc -l)
  3277. behind="$(git rev-list --count HEAD.."${hook_com[branch]}"@{upstream} 2>/dev/null)"
  3278. (( behind )) && gitstatus+=( " $(print_icon 'VCS_INCOMING_CHANGES_ICON')${behind// /}" )
  3279. hook_com[misc]+=${(j::)gitstatus}
  3280. }
  3281. function +vi-git-remotebranch() {
  3282. local remote
  3283. local branch_name="${hook_com[branch]}"
  3284. # Are we on a remote-tracking branch?
  3285. remote="$(git rev-parse --verify HEAD@{upstream} --symbolic-full-name 2>/dev/null)"
  3286. remote=${remote/refs\/(remotes|heads)\/}
  3287. if (( $+_POWERLEVEL9K_VCS_SHORTEN_LENGTH && $+_POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH )); then
  3288. if (( ${#hook_com[branch]} > _POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH && ${#hook_com[branch]} > _POWERLEVEL9K_VCS_SHORTEN_LENGTH )); then
  3289. case $_POWERLEVEL9K_VCS_SHORTEN_STRATEGY in
  3290. truncate_middle)
  3291. hook_com[branch]="${branch_name:0:$_POWERLEVEL9K_VCS_SHORTEN_LENGTH}${_POWERLEVEL9K_VCS_SHORTEN_DELIMITER}${branch_name: -$_POWERLEVEL9K_VCS_SHORTEN_LENGTH}"
  3292. ;;
  3293. truncate_from_right)
  3294. hook_com[branch]="${branch_name:0:$_POWERLEVEL9K_VCS_SHORTEN_LENGTH}${_POWERLEVEL9K_VCS_SHORTEN_DELIMITER}"
  3295. ;;
  3296. esac
  3297. fi
  3298. fi
  3299. if (( _POWERLEVEL9K_HIDE_BRANCH_ICON )); then
  3300. hook_com[branch]="${hook_com[branch]}"
  3301. else
  3302. hook_com[branch]="$(print_icon 'VCS_BRANCH_ICON')${hook_com[branch]}"
  3303. fi
  3304. # Always show the remote
  3305. #if [[ -n ${remote} ]] ; then
  3306. # Only show the remote if it differs from the local
  3307. if [[ -n ${remote} ]] && [[ "${remote#*/}" != "${branch_name}" ]] ; then
  3308. hook_com[branch]+="$(print_icon 'VCS_REMOTE_BRANCH_ICON')${remote// /}"
  3309. fi
  3310. }
  3311. function +vi-git-tagname() {
  3312. if (( !_POWERLEVEL9K_VCS_HIDE_TAGS )); then
  3313. # If we are on a tag, append the tagname to the current branch string.
  3314. local tag
  3315. tag="$(git describe --tags --exact-match HEAD 2>/dev/null)"
  3316. if [[ -n "${tag}" ]] ; then
  3317. # There is a tag that points to our current commit. Need to determine if we
  3318. # are also on a branch, or are in a DETACHED_HEAD state.
  3319. if [[ -z "$(git symbolic-ref HEAD 2>/dev/null)" ]]; then
  3320. # DETACHED_HEAD state. We want to append the tag name to the commit hash
  3321. # and print it. Unfortunately, `vcs_info` blows away the hash when a tag
  3322. # exists, so we have to manually retrieve it and clobber the branch
  3323. # string.
  3324. local revision
  3325. revision="$(git rev-list -n 1 --abbrev-commit --abbrev=${_POWERLEVEL9K_CHANGESET_HASH_LENGTH} HEAD)"
  3326. if (( _POWERLEVEL9K_HIDE_BRANCH_ICON )); then
  3327. hook_com[branch]="${revision} $(print_icon 'VCS_TAG_ICON')${tag}"
  3328. else
  3329. hook_com[branch]="$(print_icon 'VCS_BRANCH_ICON')${revision} $(print_icon 'VCS_TAG_ICON')${tag}"
  3330. fi
  3331. else
  3332. # We are on both a tag and a branch; print both by appending the tag name.
  3333. hook_com[branch]+=" $(print_icon 'VCS_TAG_ICON')${tag}"
  3334. fi
  3335. fi
  3336. fi
  3337. }
  3338. # Show count of stashed changes
  3339. # Port from https://github.com/whiteinge/dotfiles/blob/5dfd08d30f7f2749cfc60bc55564c6ea239624d9/.zsh_shouse_prompt#L268
  3340. function +vi-git-stash() {
  3341. if [[ -s "${vcs_comm[gitdir]}/logs/refs/stash" ]] ; then
  3342. local -a stashes=( "${(@f)"$(<${vcs_comm[gitdir]}/logs/refs/stash)"}" )
  3343. hook_com[misc]+=" $(print_icon 'VCS_STASH_ICON')${#stashes}"
  3344. fi
  3345. }
  3346. function +vi-hg-bookmarks() {
  3347. if [[ -n "${hgbmarks[@]}" ]]; then
  3348. hook_com[hg-bookmark-string]=" $(print_icon 'VCS_BOOKMARK_ICON')${hgbmarks[@]}"
  3349. # To signal that we want to use the string we just generated, set the special
  3350. # variable `ret' to something other than the default zero:
  3351. ret=1
  3352. return 0
  3353. fi
  3354. }
  3355. function +vi-vcs-detect-changes() {
  3356. if [[ "${hook_com[vcs]}" == "git" ]]; then
  3357. local remote="$(git ls-remote --get-url 2> /dev/null)"
  3358. if [[ "$remote" =~ "github" ]] then
  3359. vcs_visual_identifier='VCS_GIT_GITHUB_ICON'
  3360. elif [[ "$remote" =~ "bitbucket" ]] then
  3361. vcs_visual_identifier='VCS_GIT_BITBUCKET_ICON'
  3362. elif [[ "$remote" =~ "stash" ]] then
  3363. vcs_visual_identifier='VCS_GIT_BITBUCKET_ICON'
  3364. elif [[ "$remote" =~ "gitlab" ]] then
  3365. vcs_visual_identifier='VCS_GIT_GITLAB_ICON'
  3366. else
  3367. vcs_visual_identifier='VCS_GIT_ICON'
  3368. fi
  3369. elif [[ "${hook_com[vcs]}" == "hg" ]]; then
  3370. vcs_visual_identifier='VCS_HG_ICON'
  3371. elif [[ "${hook_com[vcs]}" == "svn" ]]; then
  3372. vcs_visual_identifier='VCS_SVN_ICON'
  3373. fi
  3374. if [[ -n "${hook_com[staged]}" ]] || [[ -n "${hook_com[unstaged]}" ]]; then
  3375. VCS_WORKDIR_DIRTY=true
  3376. else
  3377. VCS_WORKDIR_DIRTY=false
  3378. fi
  3379. }
  3380. function +vi-svn-detect-changes() {
  3381. local svn_status="$(svn status)"
  3382. if [[ -n "$(echo "$svn_status" | \grep \^\?)" ]]; then
  3383. hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
  3384. VCS_WORKDIR_HALF_DIRTY=true
  3385. fi
  3386. if [[ -n "$(echo "$svn_status" | \grep \^\M)" ]]; then
  3387. hook_com[unstaged]+=" $(print_icon 'VCS_UNSTAGED_ICON')"
  3388. VCS_WORKDIR_DIRTY=true
  3389. fi
  3390. if [[ -n "$(echo "$svn_status" | \grep \^\A)" ]]; then
  3391. hook_com[staged]+=" $(print_icon 'VCS_STAGED_ICON')"
  3392. VCS_WORKDIR_DIRTY=true
  3393. fi
  3394. }
  3395. _p9k_vcs_info_init() {
  3396. autoload -Uz vcs_info
  3397. local prefix=''
  3398. if (( _POWERLEVEL9K_SHOW_CHANGESET )); then
  3399. _p9k_get_icon '' VCS_COMMIT_ICON
  3400. prefix="$_p9k__ret%0.${_POWERLEVEL9K_CHANGESET_HASH_LENGTH}i "
  3401. fi
  3402. zstyle ':vcs_info:*' check-for-changes true
  3403. zstyle ':vcs_info:*' formats "$prefix%b%c%u%m"
  3404. zstyle ':vcs_info:*' actionformats "%b %F{$_POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND}| %a%f"
  3405. _p9k_get_icon '' VCS_STAGED_ICON
  3406. zstyle ':vcs_info:*' stagedstr " $_p9k__ret"
  3407. _p9k_get_icon '' VCS_UNSTAGED_ICON
  3408. zstyle ':vcs_info:*' unstagedstr " $_p9k__ret"
  3409. zstyle ':vcs_info:git*+set-message:*' hooks $_POWERLEVEL9K_VCS_GIT_HOOKS
  3410. zstyle ':vcs_info:hg*+set-message:*' hooks $_POWERLEVEL9K_VCS_HG_HOOKS
  3411. zstyle ':vcs_info:svn*+set-message:*' hooks $_POWERLEVEL9K_VCS_SVN_HOOKS
  3412. # For Hg, only show the branch name
  3413. if (( _POWERLEVEL9K_HIDE_BRANCH_ICON )); then
  3414. zstyle ':vcs_info:hg*:*' branchformat "%b"
  3415. else
  3416. _p9k_get_icon '' VCS_BRANCH_ICON
  3417. zstyle ':vcs_info:hg*:*' branchformat "$_p9k__ret%b"
  3418. fi
  3419. # The `get-revision` function must be turned on for dirty-check to work for Hg
  3420. zstyle ':vcs_info:hg*:*' get-revision true
  3421. zstyle ':vcs_info:hg*:*' get-bookmarks true
  3422. zstyle ':vcs_info:hg*+gen-hg-bookmark-string:*' hooks hg-bookmarks
  3423. # TODO: fix the %b (branch) format for svn. Using %b breaks color-encoding of the foreground
  3424. # for the rest of the powerline.
  3425. zstyle ':vcs_info:svn*:*' formats "$prefix%c%u"
  3426. zstyle ':vcs_info:svn*:*' actionformats "$prefix%c%u %F{$_POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND}| %a%f"
  3427. if (( _POWERLEVEL9K_SHOW_CHANGESET )); then
  3428. zstyle ':vcs_info:*' get-revision true
  3429. else
  3430. zstyle ':vcs_info:*' get-revision false
  3431. fi
  3432. }
  3433. function _p9k_vcs_status_save() {
  3434. local z=$'\0'
  3435. _p9k__gitstatus_last[${${_p9k__git_dir:+GIT_DIR:$_p9k__git_dir}:-$VCS_STATUS_WORKDIR}]=\
  3436. $VCS_STATUS_COMMIT$z$VCS_STATUS_LOCAL_BRANCH$z$VCS_STATUS_REMOTE_BRANCH$z$VCS_STATUS_REMOTE_NAME$z\
  3437. $VCS_STATUS_REMOTE_URL$z$VCS_STATUS_ACTION$z$VCS_STATUS_INDEX_SIZE$z$VCS_STATUS_NUM_STAGED$z\
  3438. $VCS_STATUS_NUM_UNSTAGED$z$VCS_STATUS_NUM_CONFLICTED$z$VCS_STATUS_NUM_UNTRACKED$z\
  3439. $VCS_STATUS_HAS_STAGED$z$VCS_STATUS_HAS_UNSTAGED$z$VCS_STATUS_HAS_CONFLICTED$z\
  3440. $VCS_STATUS_HAS_UNTRACKED$z$VCS_STATUS_COMMITS_AHEAD$z$VCS_STATUS_COMMITS_BEHIND$z\
  3441. $VCS_STATUS_STASHES$z$VCS_STATUS_TAG$z$VCS_STATUS_NUM_UNSTAGED_DELETED$z\
  3442. $VCS_STATUS_NUM_STAGED_NEW$z$VCS_STATUS_NUM_STAGED_DELETED$z$VCS_STATUS_PUSH_REMOTE_NAME$z\
  3443. $VCS_STATUS_PUSH_REMOTE_URL$z$VCS_STATUS_PUSH_COMMITS_AHEAD$z$VCS_STATUS_PUSH_COMMITS_BEHIND$z\
  3444. $VCS_STATUS_NUM_SKIP_WORKTREE$z$VCS_STATUS_NUM_ASSUME_UNCHANGED
  3445. }
  3446. function _p9k_vcs_status_restore() {
  3447. for VCS_STATUS_COMMIT VCS_STATUS_LOCAL_BRANCH VCS_STATUS_REMOTE_BRANCH VCS_STATUS_REMOTE_NAME \
  3448. VCS_STATUS_REMOTE_URL VCS_STATUS_ACTION VCS_STATUS_INDEX_SIZE VCS_STATUS_NUM_STAGED \
  3449. VCS_STATUS_NUM_UNSTAGED VCS_STATUS_NUM_CONFLICTED VCS_STATUS_NUM_UNTRACKED \
  3450. VCS_STATUS_HAS_STAGED VCS_STATUS_HAS_UNSTAGED VCS_STATUS_HAS_CONFLICTED \
  3451. VCS_STATUS_HAS_UNTRACKED VCS_STATUS_COMMITS_AHEAD VCS_STATUS_COMMITS_BEHIND \
  3452. VCS_STATUS_STASHES VCS_STATUS_TAG VCS_STATUS_NUM_UNSTAGED_DELETED VCS_STATUS_NUM_STAGED_NEW \
  3453. VCS_STATUS_NUM_STAGED_DELETED VCS_STATUS_PUSH_REMOTE_NAME VCS_STATUS_PUSH_REMOTE_URL \
  3454. VCS_STATUS_PUSH_COMMITS_AHEAD VCS_STATUS_PUSH_COMMITS_BEHIND VCS_STATUS_NUM_SKIP_WORKTREE \
  3455. VCS_STATUS_NUM_ASSUME_UNCHANGED
  3456. in "${(@0)1}"; do done
  3457. }
  3458. function _p9k_vcs_status_for_dir() {
  3459. if [[ -n $GIT_DIR ]]; then
  3460. _p9k__ret=$_p9k__gitstatus_last[GIT_DIR:$GIT_DIR]
  3461. [[ -n $_p9k__ret ]]
  3462. else
  3463. local dir=$_p9k__cwd_a
  3464. while true; do
  3465. _p9k__ret=$_p9k__gitstatus_last[$dir]
  3466. [[ -n $_p9k__ret ]] && return 0
  3467. [[ $dir == (/|.) ]] && return 1
  3468. dir=${dir:h}
  3469. done
  3470. fi
  3471. }
  3472. function _p9k_vcs_status_purge() {
  3473. if [[ -n $_p9k__git_dir ]]; then
  3474. _p9k__gitstatus_last[GIT_DIR:$_p9k__git_dir]=""
  3475. else
  3476. local dir=$1
  3477. while true; do
  3478. # unset doesn't work if $dir contains weird shit
  3479. _p9k__gitstatus_last[$dir]=""
  3480. _p9k_git_slow[$dir]=""
  3481. [[ $dir == (/|.) ]] && break
  3482. dir=${dir:h}
  3483. done
  3484. fi
  3485. }
  3486. function _p9k_vcs_icon() {
  3487. case "$VCS_STATUS_REMOTE_URL" in
  3488. *github*) _p9k__ret=VCS_GIT_GITHUB_ICON;;
  3489. *bitbucket*) _p9k__ret=VCS_GIT_BITBUCKET_ICON;;
  3490. *stash*) _p9k__ret=VCS_GIT_BITBUCKET_ICON;;
  3491. *gitlab*) _p9k__ret=VCS_GIT_GITLAB_ICON;;
  3492. *) _p9k__ret=VCS_GIT_ICON;;
  3493. esac
  3494. }
  3495. function _p9k_vcs_render() {
  3496. local state
  3497. if (( $+_p9k__gitstatus_next_dir )); then
  3498. if _p9k_vcs_status_for_dir; then
  3499. _p9k_vcs_status_restore $_p9k__ret
  3500. state=LOADING
  3501. else
  3502. _p9k_prompt_segment prompt_vcs_LOADING "${__p9k_vcs_states[LOADING]}" "$_p9k_color1" VCS_LOADING_ICON 0 '' "$_POWERLEVEL9K_VCS_LOADING_TEXT"
  3503. return 0
  3504. fi
  3505. elif [[ $VCS_STATUS_RESULT != ok-* ]]; then
  3506. return 1
  3507. fi
  3508. if (( _POWERLEVEL9K_VCS_DISABLE_GITSTATUS_FORMATTING )); then
  3509. if [[ -z $state ]]; then
  3510. if [[ $VCS_STATUS_HAS_CONFLICTED == 1 && $_POWERLEVEL9K_VCS_CONFLICTED_STATE == 1 ]]; then
  3511. state=CONFLICTED
  3512. elif [[ $VCS_STATUS_HAS_STAGED != 0 || $VCS_STATUS_HAS_UNSTAGED != 0 ]]; then
  3513. state=MODIFIED
  3514. elif [[ $VCS_STATUS_HAS_UNTRACKED != 0 ]]; then
  3515. state=UNTRACKED
  3516. else
  3517. state=CLEAN
  3518. fi
  3519. fi
  3520. _p9k_vcs_icon
  3521. _p9k_prompt_segment prompt_vcs_$state "${__p9k_vcs_states[$state]}" "$_p9k_color1" "$_p9k__ret" 0 '' ""
  3522. return 0
  3523. fi
  3524. (( ${_POWERLEVEL9K_VCS_GIT_HOOKS[(I)git-untracked]} )) || VCS_STATUS_HAS_UNTRACKED=0
  3525. (( ${_POWERLEVEL9K_VCS_GIT_HOOKS[(I)git-aheadbehind]} )) || { VCS_STATUS_COMMITS_AHEAD=0 && VCS_STATUS_COMMITS_BEHIND=0 }
  3526. (( ${_POWERLEVEL9K_VCS_GIT_HOOKS[(I)git-stash]} )) || VCS_STATUS_STASHES=0
  3527. (( ${_POWERLEVEL9K_VCS_GIT_HOOKS[(I)git-remotebranch]} )) || VCS_STATUS_REMOTE_BRANCH=""
  3528. (( ${_POWERLEVEL9K_VCS_GIT_HOOKS[(I)git-tagname]} )) || VCS_STATUS_TAG=""
  3529. (( _POWERLEVEL9K_VCS_COMMITS_AHEAD_MAX_NUM >= 0 && VCS_STATUS_COMMITS_AHEAD > _POWERLEVEL9K_VCS_COMMITS_AHEAD_MAX_NUM )) &&
  3530. VCS_STATUS_COMMITS_AHEAD=$_POWERLEVEL9K_VCS_COMMITS_AHEAD_MAX_NUM
  3531. (( _POWERLEVEL9K_VCS_COMMITS_BEHIND_MAX_NUM >= 0 && VCS_STATUS_COMMITS_BEHIND > _POWERLEVEL9K_VCS_COMMITS_BEHIND_MAX_NUM )) &&
  3532. VCS_STATUS_COMMITS_BEHIND=$_POWERLEVEL9K_VCS_COMMITS_BEHIND_MAX_NUM
  3533. local -a cache_key=(
  3534. "$VCS_STATUS_LOCAL_BRANCH"
  3535. "$VCS_STATUS_REMOTE_BRANCH"
  3536. "$VCS_STATUS_REMOTE_URL"
  3537. "$VCS_STATUS_ACTION"
  3538. "$VCS_STATUS_NUM_STAGED"
  3539. "$VCS_STATUS_NUM_UNSTAGED"
  3540. "$VCS_STATUS_NUM_UNTRACKED"
  3541. "$VCS_STATUS_HAS_CONFLICTED"
  3542. "$VCS_STATUS_HAS_STAGED"
  3543. "$VCS_STATUS_HAS_UNSTAGED"
  3544. "$VCS_STATUS_HAS_UNTRACKED"
  3545. "$VCS_STATUS_COMMITS_AHEAD"
  3546. "$VCS_STATUS_COMMITS_BEHIND"
  3547. "$VCS_STATUS_STASHES"
  3548. "$VCS_STATUS_TAG"
  3549. "$VCS_STATUS_NUM_UNSTAGED_DELETED"
  3550. )
  3551. if [[ $_POWERLEVEL9K_SHOW_CHANGESET == 1 || -z $VCS_STATUS_LOCAL_BRANCH ]]; then
  3552. cache_key+=$VCS_STATUS_COMMIT
  3553. fi
  3554. if ! _p9k_cache_ephemeral_get "$state" "${(@)cache_key}"; then
  3555. local icon
  3556. local content
  3557. if (( ${_POWERLEVEL9K_VCS_GIT_HOOKS[(I)vcs-detect-changes]} )); then
  3558. if [[ $VCS_STATUS_HAS_CONFLICTED == 1 && $_POWERLEVEL9K_VCS_CONFLICTED_STATE == 1 ]]; then
  3559. : ${state:=CONFLICTED}
  3560. elif [[ $VCS_STATUS_HAS_STAGED != 0 || $VCS_STATUS_HAS_UNSTAGED != 0 ]]; then
  3561. : ${state:=MODIFIED}
  3562. elif [[ $VCS_STATUS_HAS_UNTRACKED != 0 ]]; then
  3563. : ${state:=UNTRACKED}
  3564. fi
  3565. # It's weird that removing vcs-detect-changes from POWERLEVEL9K_VCS_GIT_HOOKS gets rid
  3566. # of the GIT icon. That's what vcs_info does, so we do the same in the name of compatibility.
  3567. _p9k_vcs_icon
  3568. icon=$_p9k__ret
  3569. fi
  3570. : ${state:=CLEAN}
  3571. function _$0_fmt() {
  3572. _p9k_vcs_style $state $1
  3573. content+="$_p9k__ret$2"
  3574. }
  3575. local ws
  3576. if [[ $_POWERLEVEL9K_SHOW_CHANGESET == 1 || -z $VCS_STATUS_LOCAL_BRANCH ]]; then
  3577. _p9k_get_icon prompt_vcs_$state VCS_COMMIT_ICON
  3578. _$0_fmt COMMIT "$_p9k__ret${${VCS_STATUS_COMMIT:0:$_POWERLEVEL9K_CHANGESET_HASH_LENGTH}:-HEAD}"
  3579. ws=' '
  3580. fi
  3581. if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then
  3582. local branch=$ws
  3583. if (( !_POWERLEVEL9K_HIDE_BRANCH_ICON )); then
  3584. _p9k_get_icon prompt_vcs_$state VCS_BRANCH_ICON
  3585. branch+=$_p9k__ret
  3586. fi
  3587. if (( $+_POWERLEVEL9K_VCS_SHORTEN_LENGTH && $+_POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH &&
  3588. $#VCS_STATUS_LOCAL_BRANCH > _POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH &&
  3589. $#VCS_STATUS_LOCAL_BRANCH > _POWERLEVEL9K_VCS_SHORTEN_LENGTH )) &&
  3590. [[ $_POWERLEVEL9K_VCS_SHORTEN_STRATEGY == (truncate_middle|truncate_from_right) ]]; then
  3591. branch+=${VCS_STATUS_LOCAL_BRANCH[1,_POWERLEVEL9K_VCS_SHORTEN_LENGTH]//\%/%%}${_POWERLEVEL9K_VCS_SHORTEN_DELIMITER}
  3592. if [[ $_POWERLEVEL9K_VCS_SHORTEN_STRATEGY == truncate_middle ]]; then
  3593. _p9k_vcs_style $state BRANCH
  3594. branch+=${_p9k__ret}${VCS_STATUS_LOCAL_BRANCH[-_POWERLEVEL9K_VCS_SHORTEN_LENGTH,-1]//\%/%%}
  3595. fi
  3596. else
  3597. branch+=${VCS_STATUS_LOCAL_BRANCH//\%/%%}
  3598. fi
  3599. _$0_fmt BRANCH $branch
  3600. fi
  3601. if [[ $_POWERLEVEL9K_VCS_HIDE_TAGS == 0 && -n $VCS_STATUS_TAG ]]; then
  3602. _p9k_get_icon prompt_vcs_$state VCS_TAG_ICON
  3603. _$0_fmt TAG " $_p9k__ret${VCS_STATUS_TAG//\%/%%}"
  3604. fi
  3605. if [[ -n $VCS_STATUS_ACTION ]]; then
  3606. _$0_fmt ACTION " | ${VCS_STATUS_ACTION//\%/%%}"
  3607. else
  3608. if [[ -n $VCS_STATUS_REMOTE_BRANCH &&
  3609. $VCS_STATUS_LOCAL_BRANCH != $VCS_STATUS_REMOTE_BRANCH ]]; then
  3610. _p9k_get_icon prompt_vcs_$state VCS_REMOTE_BRANCH_ICON
  3611. _$0_fmt REMOTE_BRANCH " $_p9k__ret${VCS_STATUS_REMOTE_BRANCH//\%/%%}"
  3612. fi
  3613. if [[ $VCS_STATUS_HAS_STAGED == 1 || $VCS_STATUS_HAS_UNSTAGED == 1 || $VCS_STATUS_HAS_UNTRACKED == 1 ]]; then
  3614. _p9k_get_icon prompt_vcs_$state VCS_DIRTY_ICON
  3615. _$0_fmt DIRTY "$_p9k__ret"
  3616. if [[ $VCS_STATUS_HAS_STAGED == 1 ]]; then
  3617. _p9k_get_icon prompt_vcs_$state VCS_STAGED_ICON
  3618. (( _POWERLEVEL9K_VCS_STAGED_MAX_NUM != 1 )) && _p9k__ret+=$VCS_STATUS_NUM_STAGED
  3619. _$0_fmt STAGED " $_p9k__ret"
  3620. fi
  3621. if [[ $VCS_STATUS_HAS_UNSTAGED == 1 ]]; then
  3622. _p9k_get_icon prompt_vcs_$state VCS_UNSTAGED_ICON
  3623. (( _POWERLEVEL9K_VCS_UNSTAGED_MAX_NUM != 1 )) && _p9k__ret+=$VCS_STATUS_NUM_UNSTAGED
  3624. _$0_fmt UNSTAGED " $_p9k__ret"
  3625. fi
  3626. if [[ $VCS_STATUS_HAS_UNTRACKED == 1 ]]; then
  3627. _p9k_get_icon prompt_vcs_$state VCS_UNTRACKED_ICON
  3628. (( _POWERLEVEL9K_VCS_UNTRACKED_MAX_NUM != 1 )) && _p9k__ret+=$VCS_STATUS_NUM_UNTRACKED
  3629. _$0_fmt UNTRACKED " $_p9k__ret"
  3630. fi
  3631. fi
  3632. if [[ $VCS_STATUS_COMMITS_BEHIND -gt 0 ]]; then
  3633. _p9k_get_icon prompt_vcs_$state VCS_INCOMING_CHANGES_ICON
  3634. (( _POWERLEVEL9K_VCS_COMMITS_BEHIND_MAX_NUM != 1 )) && _p9k__ret+=$VCS_STATUS_COMMITS_BEHIND
  3635. _$0_fmt INCOMING_CHANGES " $_p9k__ret"
  3636. fi
  3637. if [[ $VCS_STATUS_COMMITS_AHEAD -gt 0 ]]; then
  3638. _p9k_get_icon prompt_vcs_$state VCS_OUTGOING_CHANGES_ICON
  3639. (( _POWERLEVEL9K_VCS_COMMITS_AHEAD_MAX_NUM != 1 )) && _p9k__ret+=$VCS_STATUS_COMMITS_AHEAD
  3640. _$0_fmt OUTGOING_CHANGES " $_p9k__ret"
  3641. fi
  3642. if [[ $VCS_STATUS_STASHES -gt 0 ]]; then
  3643. _p9k_get_icon prompt_vcs_$state VCS_STASH_ICON
  3644. _$0_fmt STASH " $_p9k__ret$VCS_STATUS_STASHES"
  3645. fi
  3646. fi
  3647. _p9k_cache_ephemeral_set "prompt_vcs_$state" "${__p9k_vcs_states[$state]}" "$_p9k_color1" "$icon" 0 '' "$content"
  3648. fi
  3649. _p9k_prompt_segment "$_p9k__cache_val[@]"
  3650. return 0
  3651. }
  3652. function _p9k_maybe_ignore_git_repo() {
  3653. if [[ $VCS_STATUS_RESULT == ok-* && $VCS_STATUS_WORKDIR == $~_POWERLEVEL9K_VCS_DISABLED_WORKDIR_PATTERN ]]; then
  3654. VCS_STATUS_RESULT=norepo${VCS_STATUS_RESULT#ok}
  3655. fi
  3656. }
  3657. function _p9k_vcs_resume() {
  3658. eval "$__p9k_intro"
  3659. _p9k_maybe_ignore_git_repo
  3660. if [[ $VCS_STATUS_RESULT == ok-async ]]; then
  3661. local latency=$((EPOCHREALTIME - _p9k__gitstatus_start_time))
  3662. if (( latency > _POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS )); then
  3663. _p9k_git_slow[${${_p9k__git_dir:+GIT_DIR:$_p9k__git_dir}:-$VCS_STATUS_WORKDIR}]=1
  3664. elif (( $1 && latency < 0.8 * _POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS )); then # 0.8 to avoid flip-flopping
  3665. _p9k_git_slow[${${_p9k__git_dir:+GIT_DIR:$_p9k__git_dir}:-$VCS_STATUS_WORKDIR}]=0
  3666. fi
  3667. _p9k_vcs_status_save
  3668. fi
  3669. if [[ -z $_p9k__gitstatus_next_dir ]]; then
  3670. unset _p9k__gitstatus_next_dir
  3671. case $VCS_STATUS_RESULT in
  3672. norepo-async) (( $1 )) && _p9k_vcs_status_purge $_p9k__cwd_a;;
  3673. ok-async) (( $1 )) || _p9k__gitstatus_next_dir=$_p9k__cwd_a;;
  3674. esac
  3675. fi
  3676. if [[ -n $_p9k__gitstatus_next_dir ]]; then
  3677. _p9k__git_dir=$GIT_DIR
  3678. if ! gitstatus_query_p9k_ -d $_p9k__gitstatus_next_dir -t 0 -c '_p9k_vcs_resume 1' POWERLEVEL9K; then
  3679. unset _p9k__gitstatus_next_dir
  3680. unset VCS_STATUS_RESULT
  3681. else
  3682. _p9k_maybe_ignore_git_repo
  3683. case $VCS_STATUS_RESULT in
  3684. tout) _p9k__gitstatus_next_dir=''; _p9k__gitstatus_start_time=$EPOCHREALTIME;;
  3685. norepo-sync) _p9k_vcs_status_purge $_p9k__gitstatus_next_dir; unset _p9k__gitstatus_next_dir;;
  3686. ok-sync) _p9k_vcs_status_save; unset _p9k__gitstatus_next_dir;;
  3687. esac
  3688. fi
  3689. fi
  3690. if (( _p9k_vcs_index && $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )); then
  3691. local _p9k__prompt _p9k__prompt_side=$_p9k_vcs_side _p9k__segment_name=vcs
  3692. local -i _p9k__has_upglob _p9k__segment_index=_p9k_vcs_index _p9k__line_index=_p9k_vcs_line_index
  3693. _p9k_vcs_render
  3694. typeset -g _p9k__vcs=$_p9k__prompt
  3695. else
  3696. _p9k__refresh_reason=gitstatus
  3697. _p9k_set_prompt
  3698. _p9k__refresh_reason=''
  3699. fi
  3700. _p9k_reset_prompt
  3701. }
  3702. function _p9k_vcs_gitstatus() {
  3703. if [[ $_p9k__refresh_reason == precmd ]] && (( !_p9k__vcs_called )); then
  3704. typeset -gi _p9k__vcs_called=1
  3705. if (( $+_p9k__gitstatus_next_dir )); then
  3706. _p9k__gitstatus_next_dir=$_p9k__cwd_a
  3707. else
  3708. local -F timeout=_POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS
  3709. if ! _p9k_vcs_status_for_dir; then
  3710. _p9k__git_dir=$GIT_DIR
  3711. gitstatus_query_p9k_ -d $_p9k__cwd_a -t $timeout -p -c '_p9k_vcs_resume 0' POWERLEVEL9K || return 1
  3712. _p9k_maybe_ignore_git_repo
  3713. case $VCS_STATUS_RESULT in
  3714. tout) _p9k__gitstatus_next_dir=''; _p9k__gitstatus_start_time=$EPOCHREALTIME; return 0;;
  3715. norepo-sync) return 0;;
  3716. ok-sync) _p9k_vcs_status_save;;
  3717. esac
  3718. else
  3719. if [[ -n $GIT_DIR ]]; then
  3720. [[ $_p9k_git_slow[GIT_DIR:$GIT_DIR] == 1 ]] && timeout=0
  3721. else
  3722. local dir=$_p9k__cwd_a
  3723. while true; do
  3724. case $_p9k_git_slow[$dir] in
  3725. "") [[ $dir == (/|.) ]] && break; dir=${dir:h};;
  3726. 0) break;;
  3727. 1) timeout=0; break;;
  3728. esac
  3729. done
  3730. fi
  3731. fi
  3732. (( _p9k__prompt_idx == 1 )) && timeout=0
  3733. _p9k__git_dir=$GIT_DIR
  3734. if (( _p9k_vcs_index && $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )); then
  3735. if ! gitstatus_query_p9k_ -d $_p9k__cwd_a -t 0 -c '_p9k_vcs_resume 1' POWERLEVEL9K; then
  3736. unset VCS_STATUS_RESULT
  3737. return 1
  3738. fi
  3739. typeset -gF _p9k__vcs_timeout=timeout
  3740. _p9k__gitstatus_next_dir=''
  3741. _p9k__gitstatus_start_time=$EPOCHREALTIME
  3742. return 0
  3743. fi
  3744. if ! gitstatus_query_p9k_ -d $_p9k__cwd_a -t $timeout -c '_p9k_vcs_resume 1' POWERLEVEL9K; then
  3745. unset VCS_STATUS_RESULT
  3746. return 1
  3747. fi
  3748. _p9k_maybe_ignore_git_repo
  3749. case $VCS_STATUS_RESULT in
  3750. tout) _p9k__gitstatus_next_dir=''; _p9k__gitstatus_start_time=$EPOCHREALTIME;;
  3751. norepo-sync) _p9k_vcs_status_purge $_p9k__cwd_a;;
  3752. ok-sync) _p9k_vcs_status_save;;
  3753. esac
  3754. fi
  3755. fi
  3756. return 0
  3757. }
  3758. ################################################################
  3759. # Segment to show VCS information
  3760. prompt_vcs() {
  3761. if (( _p9k_vcs_index && $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )); then
  3762. _p9k__prompt+='${(e)_p9k__vcs}'
  3763. return
  3764. fi
  3765. local -a backends=($_POWERLEVEL9K_VCS_BACKENDS)
  3766. if (( ${backends[(I)git]} && $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )) && _p9k_vcs_gitstatus; then
  3767. _p9k_vcs_render && return
  3768. backends=(${backends:#git})
  3769. fi
  3770. if (( $#backends )); then
  3771. VCS_WORKDIR_DIRTY=false
  3772. VCS_WORKDIR_HALF_DIRTY=false
  3773. local current_state=""
  3774. # Actually invoke vcs_info manually to gather all information.
  3775. zstyle ':vcs_info:*' enable ${backends}
  3776. vcs_info
  3777. local vcs_prompt="${vcs_info_msg_0_}"
  3778. if [[ -n "$vcs_prompt" ]]; then
  3779. if [[ "$VCS_WORKDIR_DIRTY" == true ]]; then
  3780. # $vcs_visual_identifier gets set in +vi-vcs-detect-changes in functions/vcs.zsh,
  3781. # as we have there access to vcs_info internal hooks.
  3782. current_state='MODIFIED'
  3783. else
  3784. if [[ "$VCS_WORKDIR_HALF_DIRTY" == true ]]; then
  3785. current_state='UNTRACKED'
  3786. else
  3787. current_state='CLEAN'
  3788. fi
  3789. fi
  3790. _p9k_prompt_segment "${0}_${${(U)current_state}//İ/I}" "${__p9k_vcs_states[$current_state]}" "$_p9k_color1" "$vcs_visual_identifier" 0 '' "$vcs_prompt"
  3791. fi
  3792. fi
  3793. }
  3794. ################################################################
  3795. # Vi Mode: show editing mode (NORMAL|INSERT|VISUAL)
  3796. prompt_vi_mode() {
  3797. local -i len=$#_p9k__prompt _p9k__has_upglob
  3798. if (( __p9k_sh_glob )); then
  3799. if (( $+_POWERLEVEL9K_VI_OVERWRITE_MODE_STRING )); then
  3800. if [[ -n $_POWERLEVEL9K_VI_INSERT_MODE_STRING ]]; then
  3801. _p9k_prompt_segment $0_INSERT "$_p9k_color1" blue '' 0 '${${${${${${:-$_p9k__keymap.$_p9k__zle_state}:#vicmd.*}:#vivis.*}:#vivli.*}:#*.*overwrite*}}' "$_POWERLEVEL9K_VI_INSERT_MODE_STRING"
  3802. fi
  3803. _p9k_prompt_segment $0_OVERWRITE "$_p9k_color1" blue '' 0 '${${${${${${:-$_p9k__keymap.$_p9k__zle_state}:#vicmd.*}:#vivis.*}:#vivli.*}:#*.*insert*}}' "$_POWERLEVEL9K_VI_OVERWRITE_MODE_STRING"
  3804. else
  3805. if [[ -n $_POWERLEVEL9K_VI_INSERT_MODE_STRING ]]; then
  3806. _p9k_prompt_segment $0_INSERT "$_p9k_color1" blue '' 0 '${${${${_p9k__keymap:#vicmd}:#vivis}:#vivli}}' "$_POWERLEVEL9K_VI_INSERT_MODE_STRING"
  3807. fi
  3808. fi
  3809. if (( $+_POWERLEVEL9K_VI_VISUAL_MODE_STRING )); then
  3810. _p9k_prompt_segment $0_NORMAL "$_p9k_color1" white '' 0 '${(M)${:-$_p9k__keymap$_p9k__region_active}:#vicmd0}' "$_POWERLEVEL9K_VI_COMMAND_MODE_STRING"
  3811. _p9k_prompt_segment $0_VISUAL "$_p9k_color1" white '' 0 '${$((! ${#${${${${:-$_p9k__keymap$_p9k__region_active}:#vicmd1}:#vivis?}:#vivli?}})):#0}' "$_POWERLEVEL9K_VI_VISUAL_MODE_STRING"
  3812. else
  3813. _p9k_prompt_segment $0_NORMAL "$_p9k_color1" white '' 0 '${$((! ${#${${${_p9k__keymap:#vicmd}:#vivis}:#vivli}})):#0}' "$_POWERLEVEL9K_VI_COMMAND_MODE_STRING"
  3814. fi
  3815. else
  3816. if (( $+_POWERLEVEL9K_VI_OVERWRITE_MODE_STRING )); then
  3817. if [[ -n $_POWERLEVEL9K_VI_INSERT_MODE_STRING ]]; then
  3818. _p9k_prompt_segment $0_INSERT "$_p9k_color1" blue '' 0 '${${:-$_p9k__keymap.$_p9k__zle_state}:#(vicmd.*|vivis.*|vivli.*|*.*overwrite*)}' "$_POWERLEVEL9K_VI_INSERT_MODE_STRING"
  3819. fi
  3820. _p9k_prompt_segment $0_OVERWRITE "$_p9k_color1" blue '' 0 '${${:-$_p9k__keymap.$_p9k__zle_state}:#(vicmd.*|vivis.*|vivli.*|*.*insert*)}' "$_POWERLEVEL9K_VI_OVERWRITE_MODE_STRING"
  3821. else
  3822. if [[ -n $_POWERLEVEL9K_VI_INSERT_MODE_STRING ]]; then
  3823. _p9k_prompt_segment $0_INSERT "$_p9k_color1" blue '' 0 '${_p9k__keymap:#(vicmd|vivis|vivli)}' "$_POWERLEVEL9K_VI_INSERT_MODE_STRING"
  3824. fi
  3825. fi
  3826. if (( $+_POWERLEVEL9K_VI_VISUAL_MODE_STRING )); then
  3827. _p9k_prompt_segment $0_NORMAL "$_p9k_color1" white '' 0 '${(M)${:-$_p9k__keymap$_p9k__region_active}:#vicmd0}' "$_POWERLEVEL9K_VI_COMMAND_MODE_STRING"
  3828. _p9k_prompt_segment $0_VISUAL "$_p9k_color1" white '' 0 '${(M)${:-$_p9k__keymap$_p9k__region_active}:#(vicmd1|vivis?|vivli?)}' "$_POWERLEVEL9K_VI_VISUAL_MODE_STRING"
  3829. else
  3830. _p9k_prompt_segment $0_NORMAL "$_p9k_color1" white '' 0 '${(M)_p9k__keymap:#(vicmd|vivis|vivli)}' "$_POWERLEVEL9K_VI_COMMAND_MODE_STRING"
  3831. fi
  3832. fi
  3833. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  3834. }
  3835. instant_prompt_vi_mode() {
  3836. if [[ -n $_POWERLEVEL9K_VI_INSERT_MODE_STRING ]]; then
  3837. _p9k_prompt_segment prompt_vi_mode_INSERT "$_p9k_color1" blue '' 0 '' "$_POWERLEVEL9K_VI_INSERT_MODE_STRING"
  3838. fi
  3839. }
  3840. # Chezmoi shell indicator: https://www.chezmoi.io/
  3841. prompt_chezmoi_shell() {
  3842. _p9k_prompt_segment $0 blue $_p9k_color1 CHEZMOI_ICON 0 '' ''
  3843. }
  3844. _p9k_prompt_chezmoi_shell_init() {
  3845. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$CHEZMOI'
  3846. }
  3847. function instant_prompt_chezmoi_shell() {
  3848. _p9k_prompt_segment prompt_chezmoi_shell blue $_p9k_color1 CHEZMOI_ICON 1 '$CHEZMOI_ICON' ''
  3849. }
  3850. ################################################################
  3851. # Virtualenv: current working virtualenv
  3852. # More information on virtualenv (Python):
  3853. # https://virtualenv.pypa.io/en/latest/
  3854. prompt_virtualenv() {
  3855. local msg=''
  3856. if (( _POWERLEVEL9K_VIRTUALENV_SHOW_PYTHON_VERSION )) && _p9k_python_version; then
  3857. msg="${_p9k__ret//\%/%%} "
  3858. fi
  3859. local v=${VIRTUAL_ENV:t}
  3860. if [[ $VIRTUAL_ENV_PROMPT == '('?*') ' && $VIRTUAL_ENV_PROMPT != "($v) " ]]; then
  3861. v=$VIRTUAL_ENV_PROMPT[2,-3]
  3862. elif [[ $v == $~_POWERLEVEL9K_VIRTUALENV_GENERIC_NAMES ]]; then
  3863. v=${VIRTUAL_ENV:h:t}
  3864. fi
  3865. msg+="$_POWERLEVEL9K_VIRTUALENV_LEFT_DELIMITER${v//\%/%%}$_POWERLEVEL9K_VIRTUALENV_RIGHT_DELIMITER"
  3866. case $_POWERLEVEL9K_VIRTUALENV_SHOW_WITH_PYENV in
  3867. false)
  3868. _p9k_prompt_segment "$0" "blue" "$_p9k_color1" 'PYTHON_ICON' 0 '${(M)${#P9K_PYENV_PYTHON_VERSION}:#0}' "$msg"
  3869. ;;
  3870. if-different)
  3871. _p9k_escape $v
  3872. _p9k_prompt_segment "$0" "blue" "$_p9k_color1" 'PYTHON_ICON' 0 '${${:-'$_p9k__ret'}:#$_p9k__pyenv_version}' "$msg"
  3873. ;;
  3874. *)
  3875. _p9k_prompt_segment "$0" "blue" "$_p9k_color1" 'PYTHON_ICON' 0 '' "$msg"
  3876. ;;
  3877. esac
  3878. }
  3879. _p9k_prompt_virtualenv_init() {
  3880. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$VIRTUAL_ENV'
  3881. }
  3882. # _p9k_read_pyenv_like_version_file <filepath> [prefix]
  3883. function _p9k_read_pyenv_like_version_file() {
  3884. local -a stat
  3885. zstat -A stat +mtime -- $1 2>/dev/null || stat=(-1)
  3886. local cached=$_p9k__read_pyenv_like_version_file_cache[$1:$2]
  3887. if [[ $cached == $stat[1]:* ]]; then
  3888. _p9k__ret=${cached#*:}
  3889. else
  3890. local fd content
  3891. {
  3892. { sysopen -r -u fd -- $1 && sysread -i $fd -s 1024 content } 2>/dev/null
  3893. } always {
  3894. [[ -n $fd ]] && exec {fd}>&-
  3895. }
  3896. local MATCH
  3897. local versions=(${${${${(f)content}/(#m)*/${MATCH[(w)1]}}##\#*}#$2})
  3898. _p9k__ret=${(j.:.)versions}
  3899. _p9k__read_pyenv_like_version_file_cache[$1:$2]=$stat[1]:$_p9k__ret
  3900. fi
  3901. [[ -n $_p9k__ret ]]
  3902. }
  3903. function _p9k_pyenv_global_version() {
  3904. _p9k_read_pyenv_like_version_file ${PYENV_ROOT:-$HOME/.pyenv}/version python- || _p9k__ret=system
  3905. }
  3906. function _p9k_pyenv_compute() {
  3907. unset P9K_PYENV_PYTHON_VERSION _p9k__pyenv_version
  3908. local v=${(j.:.)${(@)${(s.:.)PYENV_VERSION}#python-}}
  3909. if [[ -n $v ]]; then
  3910. (( ${_POWERLEVEL9K_PYENV_SOURCES[(I)shell]} )) || return
  3911. else
  3912. (( ${_POWERLEVEL9K_PYENV_SOURCES[(I)local|global]} )) || return
  3913. _p9k__ret=
  3914. if [[ $PYENV_DIR != (|.) ]]; then
  3915. [[ $PYENV_DIR == /* ]] && local dir=$PYENV_DIR || local dir="$_p9k__cwd_a/$PYENV_DIR"
  3916. dir=${dir:A}
  3917. if [[ $dir != $_p9k__cwd_a ]]; then
  3918. while true; do
  3919. if _p9k_read_pyenv_like_version_file $dir/.python-version python-; then
  3920. (( ${_POWERLEVEL9K_PYENV_SOURCES[(I)local]} )) || return
  3921. break
  3922. fi
  3923. [[ $dir == (/|.) ]] && break
  3924. dir=${dir:h}
  3925. done
  3926. fi
  3927. fi
  3928. if [[ -z $_p9k__ret ]]; then
  3929. _p9k_upglob .python-version -.
  3930. local -i idx=$?
  3931. if (( idx )) && _p9k_read_pyenv_like_version_file $_p9k__parent_dirs[idx]/.python-version python-; then
  3932. (( ${_POWERLEVEL9K_PYENV_SOURCES[(I)local]} )) || return
  3933. else
  3934. _p9k__ret=
  3935. fi
  3936. fi
  3937. if [[ -z $_p9k__ret ]]; then
  3938. (( _POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW )) || return
  3939. (( ${_POWERLEVEL9K_PYENV_SOURCES[(I)global]} )) || return
  3940. _p9k_pyenv_global_version
  3941. fi
  3942. v=$_p9k__ret
  3943. fi
  3944. if (( !_POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW )); then
  3945. _p9k_pyenv_global_version
  3946. [[ $v == $_p9k__ret ]] && return 1
  3947. fi
  3948. if (( !_POWERLEVEL9K_PYENV_SHOW_SYSTEM )); then
  3949. [[ $v == system ]] && return 1
  3950. fi
  3951. local versions=${PYENV_ROOT:-$HOME/.pyenv}/versions
  3952. versions=${versions:A}
  3953. local name version
  3954. for name in ${(s.:.)v}; do
  3955. version=$versions/$name
  3956. version=${version:A}
  3957. if [[ $version(#qN/) == (#b)$versions/([^/]##)* ]]; then
  3958. typeset -g P9K_PYENV_PYTHON_VERSION=$match[1]
  3959. break
  3960. fi
  3961. done
  3962. typeset -g _p9k__pyenv_version=$v
  3963. }
  3964. ################################################################
  3965. # Segment to display pyenv information
  3966. # https://github.com/pyenv/pyenv#choosing-the-python-version
  3967. prompt_pyenv() {
  3968. _p9k_pyenv_compute || return
  3969. _p9k_prompt_segment "$0" "blue" "$_p9k_color1" 'PYTHON_ICON' 0 '' "${_p9k__pyenv_version//\%/%%}"
  3970. }
  3971. _p9k_prompt_pyenv_init() {
  3972. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[pyenv]:-${${+functions[pyenv]}:#0}}'
  3973. }
  3974. function _p9k_goenv_global_version() {
  3975. _p9k_read_pyenv_like_version_file ${GOENV_ROOT:-$HOME/.goenv}/version go- || _p9k__ret=system
  3976. }
  3977. ################################################################
  3978. # Segment to display goenv information: https://github.com/syndbg/goenv
  3979. prompt_goenv() {
  3980. local v=${(j.:.)${(@)${(s.:.)GOENV_VERSION}#go-}}
  3981. if [[ -n $v ]]; then
  3982. (( ${_POWERLEVEL9K_GOENV_SOURCES[(I)shell]} )) || return
  3983. else
  3984. (( ${_POWERLEVEL9K_GOENV_SOURCES[(I)local|global]} )) || return
  3985. _p9k__ret=
  3986. if [[ $GOENV_DIR != (|.) ]]; then
  3987. [[ $GOENV_DIR == /* ]] && local dir=$GOENV_DIR || local dir="$_p9k__cwd_a/$GOENV_DIR"
  3988. dir=${dir:A}
  3989. if [[ $dir != $_p9k__cwd_a ]]; then
  3990. while true; do
  3991. if _p9k_read_pyenv_like_version_file $dir/.go-version go-; then
  3992. (( ${_POWERLEVEL9K_GOENV_SOURCES[(I)local]} )) || return
  3993. break
  3994. fi
  3995. [[ $dir == (/|.) ]] && break
  3996. dir=${dir:h}
  3997. done
  3998. fi
  3999. fi
  4000. if [[ -z $_p9k__ret ]]; then
  4001. _p9k_upglob .go-version -.
  4002. local -i idx=$?
  4003. if (( idx )) && _p9k_read_pyenv_like_version_file $_p9k__parent_dirs[idx]/.go-version go-; then
  4004. (( ${_POWERLEVEL9K_GOENV_SOURCES[(I)local]} )) || return
  4005. else
  4006. _p9k__ret=
  4007. fi
  4008. fi
  4009. if [[ -z $_p9k__ret ]]; then
  4010. (( _POWERLEVEL9K_GOENV_PROMPT_ALWAYS_SHOW )) || return
  4011. (( ${_POWERLEVEL9K_GOENV_SOURCES[(I)global]} )) || return
  4012. _p9k_goenv_global_version
  4013. fi
  4014. v=$_p9k__ret
  4015. fi
  4016. if (( !_POWERLEVEL9K_GOENV_PROMPT_ALWAYS_SHOW )); then
  4017. _p9k_goenv_global_version
  4018. [[ $v == $_p9k__ret ]] && return
  4019. fi
  4020. if (( !_POWERLEVEL9K_GOENV_SHOW_SYSTEM )); then
  4021. [[ $v == system ]] && return
  4022. fi
  4023. _p9k_prompt_segment "$0" "blue" "$_p9k_color1" 'GO_ICON' 0 '' "${v//\%/%%}"
  4024. }
  4025. _p9k_prompt_goenv_init() {
  4026. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[goenv]:-${${+functions[goenv]}:#0}}'
  4027. }
  4028. ################################################################
  4029. # Display openfoam information
  4030. prompt_openfoam() {
  4031. if [[ -z "$WM_FORK" ]] ; then
  4032. _p9k_prompt_segment "$0" "yellow" "$_p9k_color1" '' 0 '' "OF: ${${WM_PROJECT_VERSION:t}//\%/%%}"
  4033. else
  4034. _p9k_prompt_segment "$0" "yellow" "$_p9k_color1" '' 0 '' "F-X: ${${WM_PROJECT_VERSION:t}//\%/%%}"
  4035. fi
  4036. }
  4037. _p9k_prompt_openfoam_init() {
  4038. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$WM_PROJECT_VERSION'
  4039. }
  4040. ################################################################
  4041. # Segment to display Swift version
  4042. prompt_swift_version() {
  4043. _p9k_cached_cmd 0 '' swift --version || return
  4044. [[ $_p9k__ret == (#b)[^[:digit:]]#([[:digit:].]##)* ]] || return
  4045. _p9k_prompt_segment "$0" "magenta" "white" 'SWIFT_ICON' 0 '' "${match[1]//\%/%%}"
  4046. }
  4047. _p9k_prompt_swift_version_init() {
  4048. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[swift]'
  4049. }
  4050. ################################################################
  4051. # dir_writable: Display information about the user's permission to write in the current directory
  4052. prompt_dir_writable() {
  4053. if [[ ! -w "$_p9k__cwd_a" ]]; then
  4054. _p9k_prompt_segment "$0_FORBIDDEN" "red" "yellow1" 'LOCK_ICON' 0 '' ''
  4055. fi
  4056. }
  4057. instant_prompt_dir_writable() { prompt_dir_writable; }
  4058. ################################################################
  4059. # Kubernetes Current Context/Namespace
  4060. prompt_kubecontext() {
  4061. if ! _p9k_cache_stat_get $0 ${(s.:.)${KUBECONFIG:-$HOME/.kube/config}}; then
  4062. local name namespace cluster user cloud_name cloud_account cloud_zone cloud_cluster text state
  4063. () {
  4064. local cfg && cfg=(${(f)"$(kubectl config view -o=yaml 2>/dev/null)"}) || return
  4065. local qstr='"*"'
  4066. local str='([^"'\''|>]*|'$qstr')'
  4067. local ctx=(${(@M)cfg:#current-context: $~str})
  4068. (( $#ctx == 1 )) || return
  4069. name=${ctx[1]#current-context: }
  4070. local -i pos=${cfg[(i)contexts:]}
  4071. {
  4072. (( pos <= $#cfg )) || return
  4073. shift $pos cfg
  4074. pos=${cfg[(i) name: ${(b)name}]}
  4075. (( pos <= $#cfg )) || return
  4076. (( --pos ))
  4077. for ((; pos > 0; --pos)); do
  4078. local line=$cfg[pos]
  4079. if [[ $line == '- context:' ]]; then
  4080. return 0
  4081. elif [[ $line == (#b)' cluster: '($~str) ]]; then
  4082. cluster=$match[1]
  4083. [[ $cluster == $~qstr ]] && cluster=$cluster[2,-2]
  4084. elif [[ $line == (#b)' namespace: '($~str) ]]; then
  4085. namespace=$match[1]
  4086. [[ $namespace == $~qstr ]] && namespace=$namespace[2,-2]
  4087. elif [[ $line == (#b)' user: '($~str) ]]; then
  4088. user=$match[1]
  4089. [[ $user == $~qstr ]] && user=$user[2,-2]
  4090. fi
  4091. done
  4092. } always {
  4093. [[ $name == $~qstr ]] && name=$name[2,-2]
  4094. }
  4095. }
  4096. if [[ -n $name ]]; then
  4097. : ${namespace:=default}
  4098. # gke_my-account_us-east1-a_cluster-01
  4099. # gke_my-account_us-east1_cluster-01
  4100. if [[ $cluster == (#b)gke_(?*)_(asia|australia|europe|northamerica|southamerica|us)-([a-z]##<->)(-[a-z]|)_(?*) ]]; then
  4101. cloud_name=gke
  4102. cloud_account=$match[1]
  4103. cloud_zone=$match[2]-$match[3]$match[4]
  4104. cloud_cluster=$match[5]
  4105. if (( ${_POWERLEVEL9K_KUBECONTEXT_SHORTEN[(I)gke]} )); then
  4106. text=$cloud_cluster
  4107. fi
  4108. # arn:aws:eks:us-east-1:123456789012:cluster/cluster-01
  4109. elif [[ $cluster == (#b)arn:aws[[:alnum:]-]#:eks:([[:alnum:]-]##):([[:digit:]]##):cluster/(?*) ]]; then
  4110. cloud_name=eks
  4111. cloud_zone=$match[1]
  4112. cloud_account=$match[2]
  4113. cloud_cluster=$match[3]
  4114. if (( ${_POWERLEVEL9K_KUBECONTEXT_SHORTEN[(I)eks]} )); then
  4115. text=$cloud_cluster
  4116. fi
  4117. fi
  4118. if [[ -z $text ]]; then
  4119. text=$name
  4120. if [[ $_POWERLEVEL9K_KUBECONTEXT_SHOW_DEFAULT_NAMESPACE == 1 || $namespace != (default|$name) ]]; then
  4121. text+="/$namespace"
  4122. fi
  4123. fi
  4124. local pat class
  4125. for pat class in "${_POWERLEVEL9K_KUBECONTEXT_CLASSES[@]}"; do
  4126. if [[ $text == ${~pat} ]]; then
  4127. [[ -n $class ]] && state=_${${(U)class}//İ/I}
  4128. break
  4129. fi
  4130. done
  4131. fi
  4132. _p9k_cache_stat_set "${(g::)name}" "${(g::)namespace}" "${(g::)cluster}" "${(g::)user}" "${(g::)cloud_name}" "${(g::)cloud_account}" "${(g::)cloud_zone}" "${(g::)cloud_cluster}" "${(g::)text}" "$state"
  4133. fi
  4134. typeset -g P9K_KUBECONTEXT_NAME=$_p9k__cache_val[1]
  4135. typeset -g P9K_KUBECONTEXT_NAMESPACE=$_p9k__cache_val[2]
  4136. typeset -g P9K_KUBECONTEXT_CLUSTER=$_p9k__cache_val[3]
  4137. typeset -g P9K_KUBECONTEXT_USER=$_p9k__cache_val[4]
  4138. typeset -g P9K_KUBECONTEXT_CLOUD_NAME=$_p9k__cache_val[5]
  4139. typeset -g P9K_KUBECONTEXT_CLOUD_ACCOUNT=$_p9k__cache_val[6]
  4140. typeset -g P9K_KUBECONTEXT_CLOUD_ZONE=$_p9k__cache_val[7]
  4141. typeset -g P9K_KUBECONTEXT_CLOUD_CLUSTER=$_p9k__cache_val[8]
  4142. [[ -n $_p9k__cache_val[9] ]] || return
  4143. _p9k_prompt_segment $0$_p9k__cache_val[10] magenta white KUBERNETES_ICON 0 '' "${_p9k__cache_val[9]//\%/%%}"
  4144. }
  4145. _p9k_prompt_kubecontext_init() {
  4146. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[kubectl]'
  4147. }
  4148. ################################################################
  4149. # Dropbox status
  4150. prompt_dropbox() {
  4151. # The first column is just the directory, so cut it
  4152. local dropbox_status="$(dropbox-cli filestatus . | cut -d\ -f2-)"
  4153. # Only show if the folder is tracked and dropbox is running
  4154. if [[ "$dropbox_status" != 'unwatched' && "$dropbox_status" != "isn't running!" ]]; then
  4155. # If "up to date", only show the icon
  4156. if [[ "$dropbox_status" =~ 'up to date' ]]; then
  4157. dropbox_status=""
  4158. fi
  4159. _p9k_prompt_segment "$0" "white" "blue" "DROPBOX_ICON" 0 '' "${dropbox_status//\%/%%}"
  4160. fi
  4161. }
  4162. _p9k_prompt_dropbox_init() {
  4163. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[dropbox-cli]'
  4164. }
  4165. # print Java version number
  4166. prompt_java_version() {
  4167. if (( _POWERLEVEL9K_JAVA_VERSION_PROJECT_ONLY )); then
  4168. _p9k_upglob 'pom.xml|build.gradle.kts|build.sbt|deps.edn|project.clj|build.boot|*.(java|class|jar|gradle|clj|cljc)' -. && return
  4169. fi
  4170. local java=$commands[java]
  4171. if ! _p9k_cache_stat_get $0 $java ${JAVA_HOME:+$JAVA_HOME/release}; then
  4172. local v
  4173. v="$(java -fullversion 2>&1)" || v=
  4174. v=${${v#*\"}%\"*}
  4175. (( _POWERLEVEL9K_JAVA_VERSION_FULL )) || v=${v%%-*}
  4176. _p9k_cache_stat_set "${v//\%/%%}"
  4177. fi
  4178. [[ -n $_p9k__cache_val[1] ]] || return
  4179. _p9k_prompt_segment "$0" "red" "white" "JAVA_ICON" 0 '' $_p9k__cache_val[1]
  4180. }
  4181. _p9k_prompt_java_version_init() {
  4182. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[java]'
  4183. }
  4184. prompt_azure() {
  4185. local name cfg=${AZURE_CONFIG_DIR:-$HOME/.azure}/azureProfile.json
  4186. if _p9k_cache_stat_get $0 $cfg; then
  4187. name=$_p9k__cache_val[1]
  4188. else
  4189. if (( $+commands[jq] )) && name="$(jq -r '[.subscriptions[]|select(.isDefault==true)|.name][]|strings' $cfg 2>/dev/null)"; then
  4190. name=${name%%$'\n'*}
  4191. elif ! name="$(az account show --query name --output tsv 2>/dev/null)"; then
  4192. name=
  4193. fi
  4194. _p9k_cache_stat_set "$name"
  4195. fi
  4196. [[ -n $name ]] || return
  4197. local pat class state
  4198. for pat class in "${_POWERLEVEL9K_AZURE_CLASSES[@]}"; do
  4199. if [[ $name == ${~pat} ]]; then
  4200. [[ -n $class ]] && state=_${${(U)class}//İ/I}
  4201. break
  4202. fi
  4203. done
  4204. _p9k_prompt_segment "$0$state" "blue" "white" "AZURE_ICON" 0 '' "${name//\%/%%}"
  4205. }
  4206. _p9k_prompt_azure_init() {
  4207. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[az]'
  4208. }
  4209. prompt_gcloud() {
  4210. local -i len=$#_p9k__prompt _p9k__has_upglob
  4211. _p9k_prompt_segment \
  4212. $0_PARTIAL blue white GCLOUD_ICON 1 \
  4213. '${${(M)${#P9K_GCLOUD_PROJECT_NAME}:#0}:+$P9K_GCLOUD_ACCOUNT$P9K_GCLOUD_PROJECT_ID}' \
  4214. '${P9K_GCLOUD_ACCOUNT//\%/%%}:${P9K_GCLOUD_PROJECT_ID//\%/%%}'
  4215. _p9k_prompt_segment \
  4216. $0_COMPLETE blue white GCLOUD_ICON 1 \
  4217. '$P9K_GCLOUD_PROJECT_NAME' \
  4218. '${P9K_GCLOUD_ACCOUNT//\%/%%}:${P9K_GCLOUD_PROJECT_ID//\%/%%}'
  4219. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  4220. }
  4221. _p9k_gcloud_prefetch() {
  4222. # P9K_GCLOUD_PROJECT is deprecated; it's always equal to P9K_GCLOUD_PROJECT_ID
  4223. unset P9K_GCLOUD_CONFIGURATION P9K_GCLOUD_ACCOUNT P9K_GCLOUD_PROJECT P9K_GCLOUD_PROJECT_ID P9K_GCLOUD_PROJECT_NAME
  4224. (( $+commands[gcloud] )) || return
  4225. _p9k_read_word ${CLOUDSDK_CONFIG:-~/.config/gcloud}/active_config || return
  4226. P9K_GCLOUD_CONFIGURATION=$_p9k__ret
  4227. if ! _p9k_cache_stat_get $0 ${CLOUDSDK_CONFIG:-~/.config/gcloud}/configurations/config_$P9K_GCLOUD_CONFIGURATION; then
  4228. local pair account project_id
  4229. pair="$(gcloud config configurations describe $P9K_GCLOUD_CONFIGURATION \
  4230. --format=$'value[separator="\1"](properties.core.account,properties.core.project)')"
  4231. (( ! $? )) && IFS=$'\1' read account project_id <<<$pair
  4232. _p9k_cache_stat_set "$account" "$project_id"
  4233. fi
  4234. if [[ -n $_p9k__cache_val[1] ]]; then
  4235. P9K_GCLOUD_ACCOUNT=$_p9k__cache_val[1]
  4236. fi
  4237. if [[ -n $_p9k__cache_val[2] ]]; then
  4238. P9K_GCLOUD_PROJECT_ID=$_p9k__cache_val[2]
  4239. P9K_GCLOUD_PROJECT=$P9K_GCLOUD_PROJECT_ID # deprecated parameter; set for backward compatibility
  4240. fi
  4241. if [[ $P9K_GCLOUD_CONFIGURATION == $_p9k_gcloud_configuration &&
  4242. $P9K_GCLOUD_ACCOUNT == $_p9k_gcloud_account &&
  4243. $P9K_GCLOUD_PROJECT_ID == $_p9k_gcloud_project_id ]]; then
  4244. [[ -n $_p9k_gcloud_project_name ]] && P9K_GCLOUD_PROJECT_NAME=$_p9k_gcloud_project_name
  4245. if (( _POWERLEVEL9K_GCLOUD_REFRESH_PROJECT_NAME_SECONDS < 0 ||
  4246. _p9k__gcloud_last_fetch_ts + _POWERLEVEL9K_GCLOUD_REFRESH_PROJECT_NAME_SECONDS > EPOCHREALTIME )); then
  4247. return
  4248. fi
  4249. else
  4250. _p9k_gcloud_configuration=$P9K_GCLOUD_CONFIGURATION
  4251. _p9k_gcloud_account=$P9K_GCLOUD_ACCOUNT
  4252. _p9k_gcloud_project_id=$P9K_GCLOUD_PROJECT_ID
  4253. _p9k_gcloud_project_name=
  4254. _p9k__state_dump_scheduled=1
  4255. fi
  4256. [[ -n $P9K_GCLOUD_CONFIGURATION && -n $P9K_GCLOUD_ACCOUNT && -n $P9K_GCLOUD_PROJECT_ID ]] || return
  4257. _p9k__gcloud_last_fetch_ts=EPOCHREALTIME
  4258. _p9k_worker_invoke gcloud "_p9k_prompt_gcloud_compute ${(q)commands[gcloud]} ${(q)P9K_GCLOUD_CONFIGURATION} ${(q)P9K_GCLOUD_ACCOUNT} ${(q)P9K_GCLOUD_PROJECT_ID}"
  4259. }
  4260. _p9k_prompt_gcloud_init() {
  4261. _p9k__async_segments_compute+=_p9k_gcloud_prefetch
  4262. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[gcloud]'
  4263. }
  4264. _p9k_prompt_gcloud_compute() {
  4265. local gcloud=$1
  4266. P9K_GCLOUD_CONFIGURATION=$2
  4267. P9K_GCLOUD_ACCOUNT=$3
  4268. P9K_GCLOUD_PROJECT_ID=$4
  4269. _p9k_worker_async "_p9k_prompt_gcloud_async ${(q)gcloud}" _p9k_prompt_gcloud_sync
  4270. }
  4271. _p9k_prompt_gcloud_async() {
  4272. local gcloud=$1
  4273. $gcloud projects describe $P9K_GCLOUD_PROJECT_ID --configuration=$P9K_GCLOUD_CONFIGURATION \
  4274. --account=$P9K_GCLOUD_ACCOUNT --format='value(name)'
  4275. }
  4276. _p9k_prompt_gcloud_sync() {
  4277. _p9k_worker_reply "_p9k_prompt_gcloud_update ${(q)P9K_GCLOUD_CONFIGURATION} ${(q)P9K_GCLOUD_ACCOUNT} ${(q)P9K_GCLOUD_PROJECT_ID} ${(q)REPLY%$'\n'}"
  4278. }
  4279. _p9k_prompt_gcloud_update() {
  4280. [[ $1 == $P9K_GCLOUD_CONFIGURATION &&
  4281. $2 == $P9K_GCLOUD_ACCOUNT &&
  4282. $3 == $P9K_GCLOUD_PROJECT_ID &&
  4283. $4 != $P9K_GCLOUD_PROJECT_NAME ]] || return
  4284. [[ -n $4 ]] && P9K_GCLOUD_PROJECT_NAME=$4 || unset P9K_GCLOUD_PROJECT_NAME
  4285. _p9k_gcloud_project_name=$P9K_GCLOUD_PROJECT_NAME
  4286. _p9k__state_dump_scheduled=1
  4287. reset=1
  4288. }
  4289. prompt_google_app_cred() {
  4290. unset P9K_GOOGLE_APP_CRED_{TYPE,PROJECT_ID,CLIENT_EMAIL}
  4291. if ! _p9k_cache_stat_get $0 $GOOGLE_APPLICATION_CREDENTIALS; then
  4292. local -a lines
  4293. local q='[.type//"", .project_id//"", .client_email//"", 0][]'
  4294. if lines=("${(@f)$(jq -r $q <$GOOGLE_APPLICATION_CREDENTIALS 2>/dev/null)}") && (( $#lines == 4 )); then
  4295. local text="${(j.:.)lines[1,-2]}"
  4296. local pat class state
  4297. for pat class in "${_POWERLEVEL9K_GOOGLE_APP_CRED_CLASSES[@]}"; do
  4298. if [[ $text == ${~pat} ]]; then
  4299. [[ -n $class ]] && state=_${${(U)class}//İ/I}
  4300. break
  4301. fi
  4302. done
  4303. _p9k_cache_stat_set 1 "${(@)lines[1,-2]}" "$text" "$state"
  4304. else
  4305. _p9k_cache_stat_set 0
  4306. fi
  4307. fi
  4308. (( _p9k__cache_val[1] )) || return
  4309. P9K_GOOGLE_APP_CRED_TYPE=$_p9k__cache_val[2]
  4310. P9K_GOOGLE_APP_CRED_PROJECT_ID=$_p9k__cache_val[3]
  4311. P9K_GOOGLE_APP_CRED_CLIENT_EMAIL=$_p9k__cache_val[4]
  4312. _p9k_prompt_segment "$0$_p9k__cache_val[6]" "blue" "white" "GCLOUD_ICON" 0 '' "$_p9k__cache_val[5]"
  4313. }
  4314. _p9k_prompt_google_app_cred_init() {
  4315. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${GOOGLE_APPLICATION_CREDENTIALS:+$commands[jq]}'
  4316. }
  4317. typeset -gra __p9k_nordvpn_tag=(
  4318. P9K_NORDVPN_STATUS
  4319. P9K_NORDVPN_TECHNOLOGY
  4320. P9K_NORDVPN_PROTOCOL
  4321. P9K_NORDVPN_IP_ADDRESS
  4322. P9K_NORDVPN_SERVER
  4323. P9K_NORDVPN_COUNTRY
  4324. P9K_NORDVPN_CITY
  4325. )
  4326. function _p9k_fetch_nordvpn_status() {
  4327. setopt err_return no_multi_byte
  4328. local REPLY
  4329. zsocket /run/nordvpn/nordvpnd.sock
  4330. local -i fd=REPLY
  4331. {
  4332. print -nu $fd 'PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n\0\0\0\4\1\0\0\0\0\0\0;\1\4\0\0\0\1\203\206E\213b\270\327\2762\322z\230\326j\246A\206\240\344\35\23\235\t_\213\35u\320b\r&=LMedz\212\232\312\310\264\307`+\262\332\340@\2te\206M\2035\5\261\37\0\0\5\0\1\0\0\0\1\0\0\0\0\0\0\0\25\1\4\0\0\0\3\203\206E\215b\270\327\2762\322z\230\334\221\246\324\177\302\301\300\277\0\0\5\0\1\0\0\0\3\0\0\0\0\0'
  4333. local val
  4334. local -i len n wire tag
  4335. {
  4336. IFS='' read -t 0.25 -r val
  4337. val=$'\n'
  4338. while true; do
  4339. tag=$((#val))
  4340. wire='tag & 7'
  4341. (( (tag >>= 3) && tag <= $#__p9k_nordvpn_tag )) || break
  4342. if (( wire == 0 )); then
  4343. # varint
  4344. sysread -s 1 -t 0.25 val
  4345. n=$((#val))
  4346. (( n < 128 )) || break # bail on multi-byte varints
  4347. if (( tag == 2 )); then
  4348. # P9K_NORDVPN_TECHNOLOGY
  4349. case $n in
  4350. 1) typeset -g P9K_NORDVPN_TECHNOLOGY=OPENVPN;;
  4351. 2) typeset -g P9K_NORDVPN_TECHNOLOGY=NORDLYNX;;
  4352. 3) typeset -g P9K_NORDVPN_TECHNOLOGY=SKYLARK;;
  4353. *) typeset -g P9K_NORDVPN_TECHNOLOGY=UNKNOWN;;
  4354. esac
  4355. elif (( tag == 3 )); then
  4356. # P9K_NORDVPN_PROTOCOL
  4357. case $n in
  4358. 1) typeset -g P9K_NORDVPN_PROTOCOL=UDP;;
  4359. 2) typeset -g P9K_NORDVPN_PROTOCOL=TCP;;
  4360. *) typeset -g P9K_NORDVPN_PROTOCOL=UNKNOWN;;
  4361. esac
  4362. else
  4363. break
  4364. fi
  4365. else
  4366. # length-delimited
  4367. (( wire == 2 )) || break
  4368. (( tag != 2 && tag != 3 )) || break
  4369. [[ -t $fd ]] || true # https://www.zsh.org/mla/workers/2020/msg00207.html
  4370. sysread -s 1 -t 0.25 val
  4371. len=$((#val))
  4372. val=
  4373. while (( $#val < len )); do
  4374. [[ -t $fd ]] || true # https://www.zsh.org/mla/workers/2020/msg00207.html
  4375. sysread -s $(( len - $#val )) -t 0.25 'val[$#val+1]'
  4376. done
  4377. typeset -g $__p9k_nordvpn_tag[tag]=$val
  4378. fi
  4379. [[ -t $fd ]] || true # https://www.zsh.org/mla/workers/2020/msg00207.html
  4380. sysread -s 1 -t 0.25 val
  4381. done
  4382. } <&$fd
  4383. } always {
  4384. exec {fd}>&-
  4385. }
  4386. }
  4387. # Shows the state of NordVPN connection. Works only on Linux. Can be in the following 5 states.
  4388. #
  4389. # CONNECTED: NordVPN is connected. By default shows NORDVPN_ICON as icon and country code as
  4390. # content. In addition, the following variables are set for the use by
  4391. # POWERLEVEL9K_NORDVPN_CONNECTED_VISUAL_IDENTIFIER_EXPANSION and
  4392. # POWERLEVEL9K_NORDVPN_CONNECTED_CONTENT_EXPANSION:
  4393. #
  4394. # - P9K_NORDVPN_STATUS
  4395. # - P9K_NORDVPN_PROTOCOL
  4396. # - P9K_NORDVPN_TECHNOLOGY
  4397. # - P9K_NORDVPN_IP_ADDRESS
  4398. # - P9K_NORDVPN_SERVER
  4399. # - P9K_NORDVPN_COUNTRY
  4400. # - P9K_NORDVPN_CITY
  4401. # - P9K_NORDVPN_COUNTRY_CODE
  4402. #
  4403. # The last variable is trivially derived from P9K_NORDVPN_SERVER. The rest correspond to the output
  4404. # lines of `nordvpn status` command. Example of using these variables:
  4405. #
  4406. # # Display the name of the city where VPN servers are located when connected to NordVPN.
  4407. # POWERLEVEL9K_NORDVPN_CONNECTED_CONTENT_EXPANSION='${P9K_NORDVPN_CITY}'
  4408. #
  4409. # DISCONNECTED, CONNECTING, DISCONNECTING: NordVPN is disconnected/connecting/disconnecting. By
  4410. # default shows NORDVPN_ICON as icon and FAIL_ICON as content. In state CONNECTING the same
  4411. # P9K_NORDVPN_* variables are set as in CONNECTED. In states DISCONNECTED and DISCONNECTING only
  4412. # P9K_NORDVPN_STATUS is set. Example customizations:
  4413. #
  4414. # # Hide NordVPN segment when disconnected (segments with no icon and no content are not shown).
  4415. # POWERLEVEL9K_NORDVPN_DISCONNECTED_CONTENT_EXPANSION=
  4416. # POWERLEVEL9K_NORDVPN_DISCONNECTED_VISUAL_IDENTIFIER_EXPANSION=
  4417. #
  4418. # # When NordVPN is connecting, show country code on cyan background.
  4419. # POWERLEVEL9K_NORDVPN_CONNECTING_CONTENT_EXPANSION='${P9K_NORDVPN_COUNTRY_CODE}'
  4420. # POWERLEVEL9K_NORDVPN_CONNECTING_BACKGROUND=cyan
  4421. function prompt_nordvpn() {
  4422. unset $__p9k_nordvpn_tag P9K_NORDVPN_COUNTRY_CODE
  4423. [[ -e /run/nordvpn/nordvpnd.sock ]] || return
  4424. _p9k_fetch_nordvpn_status 2>/dev/null || return
  4425. if [[ $P9K_NORDVPN_SERVER == (#b)([[:alpha:]]##)[[:digit:]]##.nordvpn.com ]]; then
  4426. typeset -g P9K_NORDVPN_COUNTRY_CODE=${${(U)match[1]}//İ/I}
  4427. fi
  4428. case $P9K_NORDVPN_STATUS in
  4429. Connected)
  4430. _p9k_prompt_segment $0_CONNECTED blue white NORDVPN_ICON 0 '' "$P9K_NORDVPN_COUNTRY_CODE"
  4431. ;;
  4432. Disconnected|Connecting|Disconnecting)
  4433. local state=${${(U)P9K_NORDVPN_STATUS}//İ/I}
  4434. _p9k_get_icon $0_$state FAIL_ICON
  4435. _p9k_prompt_segment $0_$state yellow white NORDVPN_ICON 0 '' "$_p9k__ret"
  4436. ;;
  4437. *)
  4438. return
  4439. ;;
  4440. esac
  4441. }
  4442. _p9k_prompt_nordvpn_init() {
  4443. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[nordvpn]'
  4444. }
  4445. function prompt_ranger() {
  4446. _p9k_prompt_segment $0 $_p9k_color1 yellow RANGER_ICON 0 '' $RANGER_LEVEL
  4447. }
  4448. _p9k_prompt_ranger_init() {
  4449. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$RANGER_LEVEL'
  4450. }
  4451. function instant_prompt_ranger() {
  4452. _p9k_prompt_segment prompt_ranger $_p9k_color1 yellow RANGER_ICON 1 '$RANGER_LEVEL' '$RANGER_LEVEL'
  4453. }
  4454. function prompt_midnight_commander() {
  4455. local -i len=$#_p9k__prompt _p9k__has_upglob
  4456. _p9k_prompt_segment $0 $_p9k_color1 yellow MIDNIGHT_COMMANDER_ICON 0 '' ''
  4457. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  4458. }
  4459. _p9k_prompt_midnight_commander_init() {
  4460. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$MC_TMPDIR'
  4461. }
  4462. function instant_prompt_midnight_commander() {
  4463. _p9k_prompt_segment prompt_midnight_commander $_p9k_color1 yellow MIDNIGHT_COMMANDER_ICON 0 '$MC_TMPDIR' ''
  4464. }
  4465. function prompt_nnn() {
  4466. _p9k_prompt_segment $0 6 $_p9k_color1 NNN_ICON 0 '' $NNNLVL
  4467. }
  4468. _p9k_prompt_nnn_init() {
  4469. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${NNNLVL:#0}'
  4470. }
  4471. function instant_prompt_nnn() {
  4472. _p9k_prompt_segment prompt_nnn 6 $_p9k_color1 NNN_ICON 1 '${NNNLVL:#0}' '$NNNLVL'
  4473. }
  4474. function prompt_lf() {
  4475. _p9k_prompt_segment $0 6 $_p9k_color1 LF_ICON 0 '' $LF_LEVEL
  4476. }
  4477. _p9k_prompt_lf_init() {
  4478. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${LF_LEVEL:#0}'
  4479. }
  4480. function instant_prompt_lf() {
  4481. _p9k_prompt_segment prompt_lf 6 $_p9k_color1 LF_ICON 1 '${LF_LEVEL:#0}' '$LF_LEVEL'
  4482. }
  4483. function prompt_xplr() {
  4484. local -i len=$#_p9k__prompt _p9k__has_upglob
  4485. _p9k_prompt_segment $0 6 $_p9k_color1 XPLR_ICON 0 '' ''
  4486. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  4487. }
  4488. _p9k_prompt_xplr_init() {
  4489. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$XPLR_PID'
  4490. }
  4491. function instant_prompt_xplr() {
  4492. _p9k_prompt_segment prompt_xplr 6 $_p9k_color1 XPLR_ICON 0 '$XPLR_PID' ''
  4493. }
  4494. function prompt_vim_shell() {
  4495. local -i len=$#_p9k__prompt _p9k__has_upglob
  4496. _p9k_prompt_segment $0 green $_p9k_color1 VIM_ICON 0 '' ''
  4497. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  4498. }
  4499. _p9k_prompt_vim_shell_init() {
  4500. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$VIMRUNTIME'
  4501. }
  4502. function instant_prompt_vim_shell() {
  4503. _p9k_prompt_segment prompt_vim_shell green $_p9k_color1 VIM_ICON 0 '$VIMRUNTIME' ''
  4504. }
  4505. function prompt_nix_shell() {
  4506. _p9k_prompt_segment $0 4 $_p9k_color1 NIX_SHELL_ICON 0 '' "${(M)IN_NIX_SHELL:#(pure|impure)}"
  4507. }
  4508. _p9k_prompt_nix_shell_init() {
  4509. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k_nix_shell_cond
  4510. }
  4511. function instant_prompt_nix_shell() {
  4512. _p9k_prompt_segment prompt_nix_shell 4 $_p9k_color1 NIX_SHELL_ICON 1 "$_p9k_nix_shell_cond" '${(M)IN_NIX_SHELL:#(pure|impure)}'
  4513. }
  4514. function prompt_terraform() {
  4515. local ws=$TF_WORKSPACE
  4516. if [[ -z $TF_WORKSPACE ]]; then
  4517. _p9k_read_word ${${TF_DATA_DIR:-.terraform}:A}/environment && ws=$_p9k__ret
  4518. fi
  4519. [[ -z $ws || $ws == default && $_POWERLEVEL9K_TERRAFORM_SHOW_DEFAULT == 0 ]] && return
  4520. local pat class state
  4521. for pat class in "${_POWERLEVEL9K_TERRAFORM_CLASSES[@]}"; do
  4522. if [[ $ws == ${~pat} ]]; then
  4523. [[ -n $class ]] && state=_${${(U)class}//İ/I}
  4524. break
  4525. fi
  4526. done
  4527. _p9k_prompt_segment "$0$state" $_p9k_color1 blue TERRAFORM_ICON 0 '' $ws
  4528. }
  4529. _p9k_prompt_terraform_init() {
  4530. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[terraform]'
  4531. }
  4532. function prompt_terraform_version() {
  4533. _p9k_cached_cmd 0 '' terraform --version || return
  4534. local v=${_p9k__ret#Terraform v}
  4535. (( $#v < $#_p9k__ret )) || return
  4536. v=${v%%$'\n'*}
  4537. [[ -n $v ]] || return
  4538. _p9k_prompt_segment $0 $_p9k_color1 blue TERRAFORM_ICON 0 '' $v
  4539. }
  4540. _p9k_prompt_terraform_version_init() {
  4541. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[terraform]'
  4542. }
  4543. function prompt_proxy() {
  4544. local -U p=(
  4545. $all_proxy $http_proxy $https_proxy $ftp_proxy
  4546. $ALL_PROXY $HTTP_PROXY $HTTPS_PROXY $FTP_PROXY)
  4547. p=(${(@)${(@)${(@)p#*://}##*@}%%/*})
  4548. (( $#p == 1 )) || p=("")
  4549. _p9k_prompt_segment $0 $_p9k_color1 blue PROXY_ICON 0 '' "$p[1]"
  4550. }
  4551. _p9k_prompt_proxy_init() {
  4552. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$all_proxy$http_proxy$https_proxy$ftp_proxy$ALL_PROXY$HTTP_PROXY$HTTPS_PROXY$FTP_PROXY'
  4553. }
  4554. function prompt_direnv() {
  4555. local -i len=$#_p9k__prompt _p9k__has_upglob
  4556. _p9k_prompt_segment $0 $_p9k_color1 yellow DIRENV_ICON 0 '${DIRENV_DIR-}' ''
  4557. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  4558. }
  4559. _p9k_prompt_direnv_init() {
  4560. # DIRENV_DIR is set in a precmd hook. If our hook isn't the last, DIRENV_DIR might
  4561. # still get set before prompt is expanded.
  4562. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${DIRENV_DIR-${precmd_functions[-1]:#_p9k_precmd}}'
  4563. }
  4564. function instant_prompt_direnv() {
  4565. if [[ -n ${DIRENV_DIR:-} && $precmd_functions[-1] == _p9k_precmd ]]; then
  4566. _p9k_prompt_segment prompt_direnv $_p9k_color1 yellow DIRENV_ICON 0 '' ''
  4567. fi
  4568. }
  4569. function _p9k_timewarrior_clear() {
  4570. [[ -z $_p9k_timewarrior_dir ]] && return
  4571. _p9k_timewarrior_dir=
  4572. _p9k_timewarrior_dir_mtime=0
  4573. _p9k_timewarrior_file_mtime=0
  4574. _p9k_timewarrior_file_name=
  4575. unset _p9k_timewarrior_tags
  4576. _p9k__state_dump_scheduled=1
  4577. }
  4578. function prompt_timewarrior() {
  4579. local dir
  4580. [[ -n ${dir::=$TIMEWARRIORDB} || -n ${dir::=~/.timewarrior}(#qN/) ]] ||
  4581. dir=${XDG_DATA_HOME:-~/.local/share}/timewarrior
  4582. dir+=/data
  4583. local -a stat
  4584. [[ $dir == $_p9k_timewarrior_dir ]] || _p9k_timewarrior_clear
  4585. if [[ -n $_p9k_timewarrior_file_name ]]; then
  4586. zstat -A stat +mtime -- $dir $_p9k_timewarrior_file_name 2>/dev/null || stat=()
  4587. if [[ $stat[1] == $_p9k_timewarrior_dir_mtime && $stat[2] == $_p9k_timewarrior_file_mtime ]]; then
  4588. if (( $+_p9k_timewarrior_tags )); then
  4589. _p9k_prompt_segment $0 grey 255 TIMEWARRIOR_ICON 0 '' "${_p9k_timewarrior_tags//\%/%%}"
  4590. fi
  4591. return
  4592. fi
  4593. fi
  4594. if [[ ! -d $dir ]]; then
  4595. _p9k_timewarrior_clear
  4596. return
  4597. fi
  4598. _p9k_timewarrior_dir=$dir
  4599. if [[ $stat[1] != $_p9k_timewarrior_dir_mtime ]]; then
  4600. local -a files=($dir/<->-<->.data(.N))
  4601. if (( ! $#files )); then
  4602. if (( $#stat )) || zstat -A stat +mtime -- $dir 2>/dev/null; then
  4603. _p9k_timewarrior_dir_mtime=$stat[1]
  4604. _p9k_timewarrior_file_mtime=$stat[1]
  4605. _p9k_timewarrior_file_name=$dir # sic
  4606. unset _p9k_timewarrior_tags
  4607. _p9k__state_dump_scheduled=1
  4608. else
  4609. _p9k_timewarrior_clear
  4610. fi
  4611. return
  4612. fi
  4613. _p9k_timewarrior_file_name=${${(AO)files}[1]}
  4614. fi
  4615. if ! zstat -A stat +mtime -- $dir $_p9k_timewarrior_file_name 2>/dev/null; then
  4616. _p9k_timewarrior_clear
  4617. return
  4618. fi
  4619. _p9k_timewarrior_dir_mtime=$stat[1]
  4620. _p9k_timewarrior_file_mtime=$stat[2]
  4621. { local tail=${${(Af)"$(<$_p9k_timewarrior_file_name)"}[-1]} } 2>/dev/null
  4622. if [[ $tail == (#b)'inc '[^\ ]##(|\ #\#(*)) ]]; then
  4623. _p9k_timewarrior_tags=${${match[2]## #}%% #}
  4624. _p9k_prompt_segment $0 grey 255 TIMEWARRIOR_ICON 0 '' "${_p9k_timewarrior_tags//\%/%%}"
  4625. else
  4626. unset _p9k_timewarrior_tags
  4627. fi
  4628. _p9k__state_dump_scheduled=1
  4629. }
  4630. function _p9k_prompt_timewarrior_init() {
  4631. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[timew]'
  4632. }
  4633. function _p9k_taskwarrior_check_meta() {
  4634. [[ -n $_p9k_taskwarrior_meta_sig ]] || return
  4635. [[ -z $^_p9k_taskwarrior_meta_non_files(#qN) ]] || return
  4636. local -a stat
  4637. if (( $#_p9k_taskwarrior_meta_files )); then
  4638. zstat -A stat +mtime -- $_p9k_taskwarrior_meta_files 2>/dev/null || return
  4639. fi
  4640. [[ $_p9k_taskwarrior_meta_sig == ${(pj:\0:)stat}$'\0'$TASKRC$'\0'$TASKDATA ]] || return
  4641. }
  4642. function _p9k_taskwarrior_init_meta() {
  4643. local last_sig=$_p9k_taskwarrior_meta_sig
  4644. {
  4645. local cfg
  4646. cfg="$(command task show data.location rc.color=0 rc._forcecolor=0 </dev/null 2>/dev/null)" || return
  4647. local lines=(${(@M)${(f)cfg}:#data.location[[:space:]]##[^[:space:]]*})
  4648. (( $#lines == 1 )) || return
  4649. local dir=${lines[1]##data.location[[:space:]]#}
  4650. : ${dir::=$~dir} # `task` can give us path with `~`` in it; expand it
  4651. local -a stat files=(${TASKRC:-~/.taskrc})
  4652. _p9k_taskwarrior_meta_files=($^files(N))
  4653. _p9k_taskwarrior_meta_non_files=(${files:|_p9k_taskwarrior_meta_files})
  4654. if (( $#_p9k_taskwarrior_meta_files )); then
  4655. zstat -A stat +mtime -- $_p9k_taskwarrior_meta_files 2>/dev/null || stat=(-1)
  4656. fi
  4657. _p9k_taskwarrior_meta_sig=${(pj:\0:)stat}$'\0'$TASKRC$'\0'$TASKDATA
  4658. _p9k_taskwarrior_data_dir=$dir
  4659. } always {
  4660. if (( $? == 0 )); then
  4661. _p9k__state_dump_scheduled=1
  4662. return
  4663. fi
  4664. [[ -n $last_sig ]] && _p9k__state_dump_scheduled=1
  4665. _p9k_taskwarrior_meta_files=()
  4666. _p9k_taskwarrior_meta_non_files=()
  4667. _p9k_taskwarrior_meta_sig=
  4668. _p9k_taskwarrior_data_dir=
  4669. _p9k__taskwarrior_functional=
  4670. }
  4671. }
  4672. function _p9k_taskwarrior_check_data() {
  4673. [[ -n $_p9k_taskwarrior_data_sig ]] || return
  4674. [[ -z $^_p9k_taskwarrior_data_non_files(#qN) ]] || return
  4675. local -a stat
  4676. if (( $#_p9k_taskwarrior_data_files )); then
  4677. zstat -A stat +mtime -- $_p9k_taskwarrior_data_files 2>/dev/null || return
  4678. fi
  4679. [[ $_p9k_taskwarrior_data_sig == ${(pj:\0:)stat}$'\0'$TASKRC$'\0'$TASKDATA ]] || return
  4680. (( _p9k_taskwarrior_next_due == 0 || _p9k_taskwarrior_next_due > EPOCHSECONDS )) || return
  4681. }
  4682. function _p9k_taskwarrior_init_data() {
  4683. local -a stat files=($_p9k_taskwarrior_data_dir/{pending,completed}.data)
  4684. _p9k_taskwarrior_data_files=($^files(N))
  4685. _p9k_taskwarrior_data_non_files=(${files:|_p9k_taskwarrior_data_files})
  4686. if (( $#_p9k_taskwarrior_data_files )); then
  4687. zstat -A stat +mtime -- $_p9k_taskwarrior_data_files 2>/dev/null || stat=(-1)
  4688. _p9k_taskwarrior_data_sig=${(pj:\0:)stat}$'\0'
  4689. else
  4690. _p9k_taskwarrior_data_sig=
  4691. fi
  4692. _p9k_taskwarrior_data_files+=($_p9k_taskwarrior_meta_files)
  4693. _p9k_taskwarrior_data_non_files+=($_p9k_taskwarrior_meta_non_files)
  4694. _p9k_taskwarrior_data_sig+=$_p9k_taskwarrior_meta_sig
  4695. local name val
  4696. for name in PENDING OVERDUE; do
  4697. val="$(command task +$name count rc.color=0 rc._forcecolor=0 </dev/null 2>/dev/null)" || continue
  4698. [[ $val == <1-> ]] || continue
  4699. _p9k_taskwarrior_counters[$name]=$val
  4700. done
  4701. _p9k_taskwarrior_next_due=0
  4702. if (( _p9k_taskwarrior_counters[PENDING] > _p9k_taskwarrior_counters[OVERDUE] )); then
  4703. local -a ts
  4704. ts=($(command task +PENDING -OVERDUE list rc.verbose=nothing rc.color=0 rc._forcecolor=0 \
  4705. rc.report.list.labels= rc.report.list.columns=due.epoch </dev/null 2>/dev/null)) || ts=()
  4706. if (( $#ts )); then
  4707. _p9k_taskwarrior_next_due=${${(on)ts}[1]}
  4708. (( _p9k_taskwarrior_next_due > EPOCHSECONDS )) || _p9k_taskwarrior_next_due=$((EPOCHSECONDS+60))
  4709. fi
  4710. fi
  4711. _p9k__state_dump_scheduled=1
  4712. }
  4713. function prompt_taskwarrior() {
  4714. unset P9K_TASKWARRIOR_PENDING_COUNT P9K_TASKWARRIOR_OVERDUE_COUNT
  4715. if ! _p9k_taskwarrior_check_data; then
  4716. _p9k_taskwarrior_data_files=()
  4717. _p9k_taskwarrior_data_non_files=()
  4718. _p9k_taskwarrior_data_sig=
  4719. _p9k_taskwarrior_counters=()
  4720. _p9k_taskwarrior_next_due=0
  4721. _p9k_taskwarrior_check_meta || _p9k_taskwarrior_init_meta || return
  4722. _p9k_taskwarrior_init_data
  4723. fi
  4724. (( $#_p9k_taskwarrior_counters )) || return
  4725. local text c=$_p9k_taskwarrior_counters[OVERDUE]
  4726. if [[ -n $c ]]; then
  4727. typeset -g P9K_TASKWARRIOR_OVERDUE_COUNT=$c
  4728. text+="!$c"
  4729. fi
  4730. c=$_p9k_taskwarrior_counters[PENDING]
  4731. if [[ -n $c ]]; then
  4732. typeset -g P9K_TASKWARRIOR_PENDING_COUNT=$c
  4733. [[ -n $text ]] && text+='/'
  4734. text+=$c
  4735. fi
  4736. [[ -n $text ]] || return
  4737. _p9k_prompt_segment $0 6 $_p9k_color1 TASKWARRIOR_ICON 0 '' $text
  4738. }
  4739. function _p9k_prompt_taskwarrior_init() {
  4740. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[task]:+$_p9k__taskwarrior_functional}'
  4741. }
  4742. prompt_wifi() {
  4743. local -i len=$#_p9k__prompt _p9k__has_upglob
  4744. _p9k_prompt_segment $0 green $_p9k_color1 WIFI_ICON 1 '$_p9k__wifi_on' '$P9K_WIFI_LAST_TX_RATE Mbps'
  4745. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  4746. }
  4747. _p9k_prompt_wifi_init() {
  4748. if [[ -x /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport ||
  4749. -r /proc/net/wireless && -n $commands[iw] ]]; then
  4750. typeset -g _p9k__wifi_on=
  4751. typeset -g P9K_WIFI_LAST_TX_RATE=
  4752. typeset -g P9K_WIFI_SSID=
  4753. typeset -g P9K_WIFI_LINK_AUTH=
  4754. typeset -g P9K_WIFI_RSSI=
  4755. typeset -g P9K_WIFI_NOISE=
  4756. typeset -g P9K_WIFI_BARS=
  4757. _p9k__async_segments_compute+='_p9k_worker_invoke wifi _p9k_prompt_wifi_compute'
  4758. else
  4759. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${:-}'
  4760. fi
  4761. }
  4762. _p9k_prompt_wifi_compute() {
  4763. _p9k_worker_async _p9k_prompt_wifi_async _p9k_prompt_wifi_sync
  4764. }
  4765. _p9k_prompt_wifi_async() {
  4766. local airport=/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
  4767. local last_tx_rate ssid link_auth rssi noise bars on out line v state iface
  4768. {
  4769. if [[ -x $airport ]]; then
  4770. out="$($airport -I)" || return 0
  4771. for line in ${${${(f)out}##[[:space:]]#}%%[[:space:]]#}; do
  4772. v=${line#*: }
  4773. case $line[1,-$#v-3] in
  4774. agrCtlRSSI) rssi=$v;;
  4775. agrCtlNoise) noise=$v;;
  4776. state) state=$v;;
  4777. lastTxRate) last_tx_rate=$v;;
  4778. link\ auth) link_auth=$v;;
  4779. SSID) ssid=$v;;
  4780. esac
  4781. done
  4782. [[ $state == running && $rssi == (0|-<->) && $noise == (0|-<->) ]] || return 0
  4783. elif [[ -r /proc/net/wireless && -n $commands[iw] ]]; then
  4784. # Content example (https://github.com/romkatv/powerlevel10k/pull/973#issuecomment-680251804):
  4785. #
  4786. # Inter-| sta-| Quality | Discarded packets | Missed | WE
  4787. # face | tus | link level noise | nwid crypt frag retry misc | beacon | 22
  4788. # wlp3s0: 0000 58. -52. -256 0 0 0 0 76 0
  4789. local -a lines
  4790. lines=(${${(f)"$(</proc/net/wireless)"}:#*\|*}) || return 0
  4791. (( $#lines == 1 )) || return 0
  4792. local parts=(${=lines[1]})
  4793. iface=${parts[1]%:}
  4794. state=${parts[2]}
  4795. rssi=${parts[4]%.*}
  4796. noise=${parts[5]%.*}
  4797. [[ -n $iface && $state == 0## && $rssi == (0|-<->) && $noise == (0|-<->) ]] || return 0
  4798. # Output example (https://github.com/romkatv/powerlevel10k/pull/973#issuecomment-680251804):
  4799. #
  4800. # Connected to 74:83:c2:be:76:da (on wlp3s0)
  4801. # SSID: DailyGrindGuest1
  4802. # freq: 5745
  4803. # RX: 35192066 bytes (27041 packets)
  4804. # TX: 4090471 bytes (24287 packets)
  4805. # signal: -52 dBm
  4806. # rx bitrate: 243.0 MBit/s VHT-MCS 6 40MHz VHT-NSS 2
  4807. # tx bitrate: 240.0 MBit/s VHT-MCS 5 40MHz short GI VHT-NSS 2
  4808. #
  4809. # bss flags: short-slot-time
  4810. # dtim period: 1
  4811. # beacon int: 100
  4812. lines=(${(f)"$(command iw dev $iface link)"}) || return 0
  4813. local -a match mbegin mend
  4814. for line in $lines; do
  4815. if [[ $line == (#b)[[:space:]]#SSID:[[:space:]]##(*) ]]; then
  4816. ssid=$match[1]
  4817. elif [[ $line == (#b)[[:space:]]#'tx bitrate:'[[:space:]]##([^[:space:]]##)' MBit/s'* ]]; then
  4818. last_tx_rate=$match[1]
  4819. [[ $last_tx_rate == <->.<-> ]] && last_tx_rate=${${last_tx_rate%%0#}%.}
  4820. fi
  4821. done
  4822. [[ -n $ssid && -n $last_tx_rate ]] || return 0
  4823. else
  4824. return 0
  4825. fi
  4826. # https://www.speedguide.net/faq/how-to-read-rssisignal-and-snrnoise-ratings-440
  4827. # http://www.wireless-nets.com/resources/tutorials/define_SNR_values.html
  4828. local -i snr_margin='rssi - noise'
  4829. if (( snr_margin >= 40 )); then
  4830. bars=4
  4831. elif (( snr_margin >= 25 )); then
  4832. bars=3
  4833. elif (( snr_margin >= 15 )); then
  4834. bars=2
  4835. elif (( snr_margin >= 10 )); then
  4836. bars=1
  4837. else
  4838. bars=0
  4839. fi
  4840. on=1
  4841. } always {
  4842. if (( ! on )); then
  4843. rssi=
  4844. noise=
  4845. ssid=
  4846. last_tx_rate=
  4847. bars=
  4848. link_auth=
  4849. fi
  4850. if [[ $_p9k__wifi_on != $on ||
  4851. $P9K_WIFI_LAST_TX_RATE != $last_tx_rate ||
  4852. $P9K_WIFI_SSID != $ssid ||
  4853. $P9K_WIFI_LINK_AUTH != $link_auth ||
  4854. $P9K_WIFI_RSSI != $rssi ||
  4855. $P9K_WIFI_NOISE != $noise ||
  4856. $P9K_WIFI_BARS != $bars ]]; then
  4857. _p9k__wifi_on=$on
  4858. P9K_WIFI_LAST_TX_RATE=$last_tx_rate
  4859. P9K_WIFI_SSID=$ssid
  4860. P9K_WIFI_LINK_AUTH=$link_auth
  4861. P9K_WIFI_RSSI=$rssi
  4862. P9K_WIFI_NOISE=$noise
  4863. P9K_WIFI_BARS=$bars
  4864. _p9k_print_params \
  4865. _p9k__wifi_on \
  4866. P9K_WIFI_LAST_TX_RATE \
  4867. P9K_WIFI_SSID \
  4868. P9K_WIFI_LINK_AUTH \
  4869. P9K_WIFI_RSSI \
  4870. P9K_WIFI_NOISE \
  4871. P9K_WIFI_BARS
  4872. echo -E - 'reset=1'
  4873. fi
  4874. }
  4875. }
  4876. _p9k_prompt_wifi_sync() {
  4877. if [[ -n $REPLY ]]; then
  4878. eval $REPLY
  4879. _p9k_worker_reply $REPLY
  4880. fi
  4881. }
  4882. function _p9k_asdf_check_meta() {
  4883. [[ -n $_p9k_asdf_meta_sig ]] || return
  4884. [[ -z $^_p9k_asdf_meta_non_files(#qN) ]] || return
  4885. local -a stat
  4886. if (( $#_p9k_asdf_meta_files )); then
  4887. zstat -A stat +mtime -- $_p9k_asdf_meta_files 2>/dev/null || return
  4888. fi
  4889. [[ $_p9k_asdf_meta_sig == $ASDF_CONFIG_FILE$'\0'$ASDF_DATA_DIR$'\0'${(pj:\0:)stat} ]] || return
  4890. }
  4891. function _p9k_asdf_init_meta() {
  4892. local last_sig=$_p9k_asdf_meta_sig
  4893. {
  4894. local -a files
  4895. local -i legacy_enabled
  4896. _p9k_asdf_plugins=()
  4897. _p9k_asdf_file_info=()
  4898. local cfg=${ASDF_CONFIG_FILE:-~/.asdfrc}
  4899. files+=$cfg
  4900. if [[ -f $cfg && -r $cfg ]]; then
  4901. # Config parser in adsf is very strange.
  4902. #
  4903. # This gives "yes":
  4904. #
  4905. # legacy_version_file = yes = no
  4906. #
  4907. # This gives "no":
  4908. #
  4909. # legacy_version_file = yes
  4910. # legacy_version_file = yes
  4911. #
  4912. # We do the same.
  4913. local lines=(${(@M)${(@)${(f)"$(<$cfg)"}%$'\r'}:#[[:space:]]#legacy_version_file[[:space:]]#=*})
  4914. if [[ $#lines == 1 && ${${(s:=:)lines[1]}[2]} == [[:space:]]#yes[[:space:]]# ]]; then
  4915. legacy_enabled=1
  4916. fi
  4917. fi
  4918. local root=${ASDF_DATA_DIR:-~/.asdf}
  4919. files+=$root/plugins
  4920. if [[ -d $root/plugins ]]; then
  4921. local plugin
  4922. for plugin in $root/plugins/[^[:space:]]##(/N); do
  4923. files+=$root/installs/${plugin:t}
  4924. local -aU installed=($root/installs/${plugin:t}/[^[:space:]]##(/N:t) system)
  4925. _p9k_asdf_plugins[${plugin:t}]=${(j:|:)${(@b)installed}}
  4926. (( legacy_enabled )) || continue
  4927. if [[ ! -e $plugin/bin ]]; then
  4928. files+=$plugin/bin
  4929. else
  4930. local list_names=$plugin/bin/list-legacy-filenames
  4931. files+=$list_names
  4932. if [[ -x $list_names ]]; then
  4933. local parse=$plugin/bin/parse-legacy-file
  4934. local -i has_parse=0
  4935. files+=$parse
  4936. [[ -x $parse ]] && has_parse=1
  4937. local name
  4938. for name in ${$($list_names 2>/dev/null)%$'\r'}; do
  4939. [[ $name == (*/*|.tool-versions) ]] && continue
  4940. _p9k_asdf_file_info[$name]+="${plugin:t} $has_parse "
  4941. done
  4942. fi
  4943. fi
  4944. done
  4945. fi
  4946. _p9k_asdf_meta_files=($^files(N))
  4947. _p9k_asdf_meta_non_files=(${files:|_p9k_asdf_meta_files})
  4948. local -a stat
  4949. if (( $#_p9k_asdf_meta_files )); then
  4950. zstat -A stat +mtime -- $_p9k_asdf_meta_files 2>/dev/null || return
  4951. fi
  4952. _p9k_asdf_meta_sig=$ASDF_CONFIG_FILE$'\0'$ASDF_DATA_DIR$'\0'${(pj:\0:)stat}
  4953. _p9k__asdf_dir2files=()
  4954. _p9k_asdf_file2versions=()
  4955. } always {
  4956. if (( $? == 0 )); then
  4957. _p9k__state_dump_scheduled=1
  4958. return
  4959. fi
  4960. [[ -n $last_sig ]] && _p9k__state_dump_scheduled=1
  4961. _p9k_asdf_meta_files=()
  4962. _p9k_asdf_meta_non_files=()
  4963. _p9k_asdf_meta_sig=
  4964. _p9k_asdf_plugins=()
  4965. _p9k_asdf_file_info=()
  4966. _p9k__asdf_dir2files=()
  4967. _p9k_asdf_file2versions=()
  4968. }
  4969. }
  4970. # Usage: _p9k_asdf_parse_version_file <file> <is_legacy>
  4971. #
  4972. # Mutates `versions` on success.
  4973. function _p9k_asdf_parse_version_file() {
  4974. local file=$1
  4975. local is_legacy=$2
  4976. local -a stat
  4977. zstat -A stat +mtime $file 2>/dev/null || return
  4978. if (( is_legacy )); then
  4979. local plugin has_parse
  4980. for plugin has_parse in $=_p9k_asdf_file_info[$file:t]; do
  4981. local cached=$_p9k_asdf_file2versions[$plugin:$file]
  4982. if [[ $cached == $stat[1]:* ]]; then
  4983. local v=${cached#*:}
  4984. else
  4985. if (( has_parse )); then
  4986. local v=($(${ASDF_DATA_DIR:-~/.asdf}/plugins/$plugin/bin/parse-legacy-file $file 2>/dev/null))
  4987. else
  4988. { local v=($(<$file)) } 2>/dev/null
  4989. fi
  4990. v=(${v%$'\r'})
  4991. v=${v[(r)$_p9k_asdf_plugins[$plugin]]:-$v[1]}
  4992. _p9k_asdf_file2versions[$plugin:$file]=$stat[1]:"$v"
  4993. _p9k__state_dump_scheduled=1
  4994. fi
  4995. [[ -n $v ]] && : ${versions[$plugin]="$v"}
  4996. done
  4997. else
  4998. local cached=$_p9k_asdf_file2versions[:$file]
  4999. if [[ $cached == $stat[1]:* ]]; then
  5000. local file_versions=(${(0)${cached#*:}})
  5001. else
  5002. local file_versions=()
  5003. { local lines=(${(@)${(@)${(f)"$(<$file)"}%$'\r'}/\#*}) } 2>/dev/null
  5004. local line
  5005. for line in $lines; do
  5006. local words=($=line)
  5007. (( $#words > 1 )) || continue
  5008. local installed=$_p9k_asdf_plugins[$words[1]]
  5009. [[ -n $installed ]] || continue
  5010. file_versions+=($words[1] ${${words:1}[(r)$installed]:-$words[2]})
  5011. done
  5012. _p9k_asdf_file2versions[:$file]=$stat[1]:${(pj:\0:)file_versions}
  5013. _p9k__state_dump_scheduled=1
  5014. fi
  5015. local plugin version
  5016. for plugin version in $file_versions; do
  5017. : ${versions[$plugin]=$version}
  5018. done
  5019. fi
  5020. return 0
  5021. }
  5022. function prompt_asdf() {
  5023. _p9k_asdf_check_meta || _p9k_asdf_init_meta || return
  5024. local -A versions
  5025. local -a stat
  5026. local -i has_global
  5027. local dirs=($_p9k__parent_dirs)
  5028. local mtimes=($_p9k__parent_mtimes)
  5029. if [[ $dirs[-1] != ~ ]]; then
  5030. zstat -A stat +mtime ~ 2>/dev/null || return
  5031. dirs+=(~)
  5032. mtimes+=($stat[1])
  5033. fi
  5034. local elem
  5035. for elem in ${(@)${:-{1..$#dirs}}/(#m)*/${${:-$MATCH:$_p9k__asdf_dir2files[$dirs[MATCH]]}#$MATCH:$mtimes[MATCH]:}}; do
  5036. if [[ $elem == *:* ]]; then
  5037. local dir=$dirs[${elem%%:*}]
  5038. zstat -A stat +mtime $dir 2>/dev/null || return
  5039. local files=($dir/.tool-versions(N) $dir/${(k)^_p9k_asdf_file_info}(N))
  5040. _p9k__asdf_dir2files[$dir]=$stat[1]:${(pj:\0:)files}
  5041. else
  5042. local files=(${(0)elem})
  5043. fi
  5044. if [[ ${files[1]:h} == ~ ]]; then
  5045. has_global=1
  5046. local -A local_versions=(${(kv)versions})
  5047. versions=()
  5048. fi
  5049. local file
  5050. for file in $files; do
  5051. [[ $file == */.tool-versions ]]
  5052. _p9k_asdf_parse_version_file $file $? || return
  5053. done
  5054. done
  5055. if (( ! has_global )); then
  5056. has_global=1
  5057. local -A local_versions=(${(kv)versions})
  5058. versions=()
  5059. fi
  5060. if [[ -r $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME ]]; then
  5061. _p9k_asdf_parse_version_file $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME 0 || return
  5062. fi
  5063. local plugin
  5064. for plugin in ${(k)_p9k_asdf_plugins}; do
  5065. local upper=${${(U)plugin//-/_}//İ/I}
  5066. if (( $+parameters[_POWERLEVEL9K_ASDF_${upper}_SOURCES] )); then
  5067. local sources=(${(P)${:-_POWERLEVEL9K_ASDF_${upper}_SOURCES}})
  5068. else
  5069. local sources=($_POWERLEVEL9K_ASDF_SOURCES)
  5070. fi
  5071. local version="${(P)${:-ASDF_${upper}_VERSION}}"
  5072. if [[ -n $version ]]; then
  5073. (( $sources[(I)shell] )) || continue
  5074. else
  5075. version=$local_versions[$plugin]
  5076. if [[ -n $version ]]; then
  5077. (( $sources[(I)local] )) || continue
  5078. else
  5079. version=$versions[$plugin]
  5080. [[ -n $version ]] || continue
  5081. (( $sources[(I)global] )) || continue
  5082. fi
  5083. fi
  5084. if [[ $version == $versions[$plugin] ]]; then
  5085. if (( $+parameters[_POWERLEVEL9K_ASDF_${upper}_PROMPT_ALWAYS_SHOW] )); then
  5086. (( _POWERLEVEL9K_ASDF_${upper}_PROMPT_ALWAYS_SHOW )) || continue
  5087. else
  5088. (( _POWERLEVEL9K_ASDF_PROMPT_ALWAYS_SHOW )) || continue
  5089. fi
  5090. fi
  5091. if [[ $version == system ]]; then
  5092. if (( $+parameters[_POWERLEVEL9K_ASDF_${upper}_SHOW_SYSTEM] )); then
  5093. (( _POWERLEVEL9K_ASDF_${upper}_SHOW_SYSTEM )) || continue
  5094. else
  5095. (( _POWERLEVEL9K_ASDF_SHOW_SYSTEM )) || continue
  5096. fi
  5097. fi
  5098. _p9k_get_icon $0_$upper ${upper}_ICON $plugin
  5099. _p9k_prompt_segment $0_$upper green $_p9k_color1 $'\1'$_p9k__ret 0 '' ${version//\%/%%}
  5100. done
  5101. }
  5102. _p9k_prompt_asdf_init() {
  5103. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[asdf]:-${${+functions[asdf]}:#0}}'
  5104. }
  5105. _p9k_haskell_stack_version() {
  5106. if ! _p9k_cache_stat_get $0 $1 ${STACK_ROOT:-~/.stack}/{pantry/pantry.sqlite3,stack.sqlite3}; then
  5107. local v
  5108. v="$(STACK_YAML=$1 stack \
  5109. --silent \
  5110. --no-install-ghc \
  5111. --skip-ghc-check \
  5112. --no-terminal \
  5113. --color=never \
  5114. --lock-file=read-only \
  5115. query compiler actual)" || v=
  5116. _p9k_cache_stat_set "$v"
  5117. fi
  5118. _p9k__ret=$_p9k__cache_val[1]
  5119. }
  5120. prompt_haskell_stack() {
  5121. if [[ -n $STACK_YAML ]]; then
  5122. (( ${_POWERLEVEL9K_HASKELL_STACK_SOURCES[(I)shell]} )) || return
  5123. _p9k_haskell_stack_version $STACK_YAML
  5124. else
  5125. (( ${_POWERLEVEL9K_HASKELL_STACK_SOURCES[(I)local|global]} )) || return
  5126. if _p9k_upglob stack.yaml -.; then
  5127. (( _POWERLEVEL9K_HASKELL_STACK_PROMPT_ALWAYS_SHOW )) || return
  5128. (( ${_POWERLEVEL9K_HASKELL_STACK_SOURCES[(I)global]} )) || return
  5129. _p9k_haskell_stack_version ${STACK_ROOT:-~/.stack}/global-project/stack.yaml
  5130. else
  5131. local -i idx=$?
  5132. (( ${_POWERLEVEL9K_HASKELL_STACK_SOURCES[(I)local]} )) || return
  5133. _p9k_haskell_stack_version $_p9k__parent_dirs[idx]/stack.yaml
  5134. fi
  5135. fi
  5136. [[ -n $_p9k__ret ]] || return
  5137. local v=$_p9k__ret
  5138. if (( !_POWERLEVEL9K_HASKELL_STACK_PROMPT_ALWAYS_SHOW )); then
  5139. _p9k_haskell_stack_version ${STACK_ROOT:-~/.stack}/global-project/stack.yaml
  5140. [[ $v == $_p9k__ret ]] && return
  5141. fi
  5142. _p9k_prompt_segment "$0" "yellow" "$_p9k_color1" 'HASKELL_ICON' 0 '' "${v//\%/%%}"
  5143. }
  5144. _p9k_prompt_haskell_stack_init() {
  5145. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[stack]'
  5146. }
  5147. ################################################################
  5148. # CPU Architecture
  5149. prompt_cpu_arch() {
  5150. local -i len=$#_p9k__prompt _p9k__has_upglob
  5151. local state text
  5152. if _p9k_cache_ephemeral_get $0; then
  5153. state=$_p9k__cache_val[1]
  5154. text=$_p9k__cache_val[2]
  5155. else
  5156. local cmd
  5157. for cmd in machine arch; do
  5158. (( $+commands[$cmd] )) || continue
  5159. if text=$(command -- $cmd) 2>/dev/null && [[ $text == [a-zA-Z][a-zA-Z0-9_]# ]]; then
  5160. break
  5161. else
  5162. text=
  5163. fi
  5164. done
  5165. state=_${${(U)text}//İ/I}
  5166. _p9k_cache_ephemeral_set "$state" "$text"
  5167. fi
  5168. if [[ -n $text ]]; then
  5169. _p9k_prompt_segment "$0$state" "yellow" "$_p9k_color1" 'ARCH_ICON' 0 '' "$text"
  5170. fi
  5171. (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
  5172. }
  5173. _p9k_prompt_cpu_arch_init() {
  5174. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[machine]$commands[arch]'
  5175. }
  5176. ################################################################
  5177. # Oh My Zsh per-directory-history local/global indicator
  5178. prompt_per_directory_history() {
  5179. if [[ $_per_directory_history_is_global == true ]]; then
  5180. _p9k_prompt_segment ${0}_GLOBAL 3 $_p9k_color1 HISTORY_ICON 0 '' global
  5181. else
  5182. _p9k_prompt_segment ${0}_LOCAL 5 $_p9k_color1 HISTORY_ICON 0 '' local
  5183. fi
  5184. }
  5185. instant_prompt_per_directory_history() {
  5186. case $HISTORY_START_WITH_GLOBAL in
  5187. true)
  5188. _p9k_prompt_segment prompt_per_directory_history_GLOBAL 3 $_p9k_color1 HISTORY_ICON 0 '' global
  5189. ;;
  5190. ?*)
  5191. _p9k_prompt_segment prompt_per_directory_history_LOCAL 5 $_p9k_color1 HISTORY_ICON 0 '' local
  5192. ;;
  5193. esac
  5194. }
  5195. _p9k_prompt_per_directory_history_init() {
  5196. typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$PER_DIRECTORY_HISTORY_TOGGLE'
  5197. }
  5198. # Use two preexec hooks to survive https://github.com/MichaelAquilina/zsh-you-should-use with
  5199. # YSU_HARDCORE=1. See https://github.com/romkatv/powerlevel10k/issues/427.
  5200. _p9k_preexec1() {
  5201. _p9k_restore_special_params
  5202. unset __p9k_trapint
  5203. trap - INT
  5204. }
  5205. _p9k_preexec2() {
  5206. typeset -g _p9k__preexec_cmd=$2
  5207. _p9k__timer_start=EPOCHREALTIME
  5208. P9K_TTY=old
  5209. (( ! $+_p9k__iterm_cmd )) || _p9k_iterm2_preexec
  5210. }
  5211. function _p9k_prompt_net_iface_init() {
  5212. typeset -g _p9k__public_ip_vpn=
  5213. typeset -g _p9k__public_ip_not_vpn=
  5214. typeset -g P9K_IP_IP=
  5215. typeset -g P9K_IP_INTERFACE=
  5216. typeset -g P9K_IP_TX_BYTES=
  5217. typeset -g P9K_IP_RX_BYTES=
  5218. typeset -g P9K_IP_TX_BYTES_DELTA=
  5219. typeset -g P9K_IP_RX_BYTES_DELTA=
  5220. typeset -g P9K_IP_TX_RATE=
  5221. typeset -g P9K_IP_RX_RATE=
  5222. typeset -g _p9__ip_timestamp=
  5223. typeset -g _p9k__vpn_ip_ips=()
  5224. [[ -z $_POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ]] && _p9k__public_ip_not_vpn=1
  5225. _p9k__async_segments_compute+='_p9k_worker_invoke net_iface _p9k_prompt_net_iface_compute'
  5226. }
  5227. # reads `iface2ip` and sets `ifaces` and `ips`
  5228. function _p9k_prompt_net_iface_match() {
  5229. local iface_regex="^($1)\$" iface ip
  5230. ips=()
  5231. ifaces=()
  5232. for iface ip in "${(@)iface2ip}"; do
  5233. [[ $iface =~ $iface_regex ]] || continue
  5234. ifaces+=$iface
  5235. ips+=$ip
  5236. done
  5237. return $(($#ips == 0))
  5238. }
  5239. function _p9k_prompt_net_iface_compute() {
  5240. _p9k_worker_async _p9k_prompt_net_iface_async _p9k_prompt_net_iface_sync
  5241. }
  5242. function _p9k_prompt_net_iface_async() {
  5243. # netstat -inbI en0
  5244. local iface ip line var
  5245. typeset -a iface2ip ips ifaces
  5246. if (( $+commands[ip] )) && [[ $+commands[ifconfig] == 0 || $OSTYPE == linux* ]]; then
  5247. for line in ${(f)"$(command ip -4 a show 2>/dev/null)"}; do
  5248. if [[ $line == (#b)<->:[[:space:]]##([^:]##):[[:space:]]##\<([^\>]#)\>* ]]; then
  5249. [[ ,$match[2], == *,UP,* ]] && iface=$match[1] || iface=
  5250. elif [[ -n $iface && $line == (#b)[[:space:]]##inet[[:space:]]##([0-9.]##)* ]]; then
  5251. iface2ip+=($iface $match[1])
  5252. iface=
  5253. fi
  5254. done
  5255. elif (( $+commands[ifconfig] )); then
  5256. for line in ${(f)"$(command ifconfig 2>/dev/null)"}; do
  5257. if [[ $line == (#b)([^[:space:]]##):[[:space:]]##flags=([[:xdigit:]]##)'<'* ]]; then
  5258. [[ $match[2] == *[13579bdfBDF] ]] && iface=$match[1] || iface=
  5259. elif [[ -n $iface && $line == (#b)[[:space:]]##inet[[:space:]]##([0-9.]##)* ]]; then
  5260. iface2ip+=($iface $match[1])
  5261. iface=
  5262. fi
  5263. done
  5264. fi
  5265. if _p9k_prompt_net_iface_match $_POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE; then
  5266. local public_ip_vpn=1
  5267. local public_ip_not_vpn=
  5268. else
  5269. local public_ip_vpn=
  5270. local public_ip_not_vpn=1
  5271. fi
  5272. if _p9k_prompt_net_iface_match $_POWERLEVEL9K_IP_INTERFACE; then
  5273. local ip_ip=$ips[1] ip_interface=$ifaces[1] ip_timestamp=$EPOCHREALTIME
  5274. local ip_tx_bytes ip_rx_bytes ip_tx_rate ip_rx_rate
  5275. if [[ $_p9k_os == (Linux|Android) ]]; then
  5276. if [[ -r /sys/class/net/$ifaces[1]/statistics/tx_bytes &&
  5277. -r /sys/class/net/$ifaces[1]/statistics/rx_bytes ]]; then
  5278. _p9k_read_file /sys/class/net/$ifaces[1]/statistics/tx_bytes &&
  5279. [[ $_p9k__ret == <-> ]] && ip_tx_bytes=$_p9k__ret &&
  5280. _p9k_read_file /sys/class/net/$ifaces[1]/statistics/rx_bytes &&
  5281. [[ $_p9k__ret == <-> ]] && ip_rx_bytes=$_p9k__ret || { ip_tx_bytes=; ip_rx_bytes=; }
  5282. fi
  5283. elif [[ $_p9k_os == (BSD|OSX) && $+commands[netstat] == 1 ]]; then
  5284. local -a lines
  5285. if lines=(${(f)"$(netstat -inbI $ifaces[1])"}); then
  5286. local header=($=lines[1])
  5287. local -i rx_idx=$header[(Ie)Ibytes]
  5288. local -i tx_idx=$header[(Ie)Obytes]
  5289. if (( rx_idx && tx_idx )); then
  5290. ip_tx_bytes=0
  5291. ip_rx_bytes=0
  5292. for line in ${lines:1}; do
  5293. (( ip_rx_bytes += ${line[(w)rx_idx]} ))
  5294. (( ip_tx_bytes += ${line[(w)tx_idx]} ))
  5295. done
  5296. fi
  5297. fi
  5298. fi
  5299. if [[ -n $ip_rx_bytes ]]; then
  5300. if [[ $ip_ip == $P9K_IP_IP && $ifaces[1] == $P9K_IP_INTERFACE ]]; then
  5301. local -F t='ip_timestamp - _p9__ip_timestamp'
  5302. if (( t <= 0 )); then
  5303. ip_tx_rate=${P9K_IP_TX_RATE:-0 B/s}
  5304. ip_rx_rate=${P9K_IP_RX_RATE:-0 B/s}
  5305. else
  5306. _p9k_human_readable_bytes $(((ip_tx_bytes - P9K_IP_TX_BYTES) / t))
  5307. [[ $_p9k__ret == *B ]] && ip_tx_rate="$_p9k__ret[1,-2] B/s" || ip_tx_rate="$_p9k__ret[1,-2] $_p9k__ret[-1]iB/s"
  5308. _p9k_human_readable_bytes $(((ip_rx_bytes - P9K_IP_RX_BYTES) / t))
  5309. [[ $_p9k__ret == *B ]] && ip_rx_rate="$_p9k__ret[1,-2] B/s" || ip_rx_rate="$_p9k__ret[1,-2] $_p9k__ret[-1]iB/s"
  5310. fi
  5311. else
  5312. ip_tx_rate='0 B/s'
  5313. ip_rx_rate='0 B/s'
  5314. fi
  5315. fi
  5316. else
  5317. local ip_ip= ip_interface= ip_tx_bytes= ip_rx_bytes= ip_tx_rate= ip_rx_rate= ip_timestamp=
  5318. fi
  5319. if _p9k_prompt_net_iface_match $_POWERLEVEL9K_VPN_IP_INTERFACE; then
  5320. if (( _POWERLEVEL9K_VPN_IP_SHOW_ALL )); then
  5321. local vpn_ip_ips=($ips)
  5322. else
  5323. local vpn_ip_ips=($ips[1])
  5324. fi
  5325. else
  5326. local vpn_ip_ips=()
  5327. fi
  5328. [[ $_p9k__public_ip_vpn == $public_ip_vpn &&
  5329. $_p9k__public_ip_not_vpn == $public_ip_not_vpn &&
  5330. $P9K_IP_IP == $ip_ip &&
  5331. $P9K_IP_INTERFACE == $ip_interface &&
  5332. $P9K_IP_TX_BYTES == $ip_tx_bytes &&
  5333. $P9K_IP_RX_BYTES == $ip_rx_bytes &&
  5334. $P9K_IP_TX_RATE == $ip_tx_rate &&
  5335. $P9K_IP_RX_RATE == $ip_rx_rate &&
  5336. "$_p9k__vpn_ip_ips" == "$vpn_ip_ips" ]] && return 1
  5337. if [[ "$_p9k__vpn_ip_ips" == "$vpn_ip_ips" ]]; then
  5338. echo -n 0
  5339. else
  5340. echo -n 1
  5341. fi
  5342. _p9k__public_ip_vpn=$public_ip_vpn
  5343. _p9k__public_ip_not_vpn=$public_ip_not_vpn
  5344. P9K_IP_IP=$ip_ip
  5345. P9K_IP_INTERFACE=$ip_interface
  5346. if [[ -n $ip_tx_bytes && -n $P9K_IP_TX_BYTES ]]; then
  5347. P9K_IP_TX_BYTES_DELTA=$((ip_tx_bytes - P9K_IP_TX_BYTES))
  5348. else
  5349. P9K_IP_TX_BYTES_DELTA=
  5350. fi
  5351. if [[ -n $ip_rx_bytes && -n $P9K_IP_RX_BYTES ]]; then
  5352. P9K_IP_RX_BYTES_DELTA=$((ip_rx_bytes - P9K_IP_RX_BYTES))
  5353. else
  5354. P9K_IP_RX_BYTES_DELTA=
  5355. fi
  5356. P9K_IP_TX_BYTES=$ip_tx_bytes
  5357. P9K_IP_RX_BYTES=$ip_rx_bytes
  5358. P9K_IP_TX_RATE=$ip_tx_rate
  5359. P9K_IP_RX_RATE=$ip_rx_rate
  5360. _p9__ip_timestamp=$ip_timestamp
  5361. _p9k__vpn_ip_ips=($vpn_ip_ips)
  5362. _p9k_print_params \
  5363. _p9k__public_ip_vpn \
  5364. _p9k__public_ip_not_vpn \
  5365. P9K_IP_IP \
  5366. P9K_IP_INTERFACE \
  5367. P9K_IP_TX_BYTES \
  5368. P9K_IP_RX_BYTES \
  5369. P9K_IP_TX_BYTES_DELTA \
  5370. P9K_IP_RX_BYTES_DELTA \
  5371. P9K_IP_TX_RATE \
  5372. P9K_IP_RX_RATE \
  5373. _p9__ip_timestamp \
  5374. _p9k__vpn_ip_ips
  5375. echo -E - 'reset=1'
  5376. }
  5377. _p9k_prompt_net_iface_sync() {
  5378. local -i vpn_ip_changed=$REPLY[1]
  5379. REPLY[1]=""
  5380. eval $REPLY
  5381. (( vpn_ip_changed )) && REPLY+='; _p9k_vpn_ip_render'
  5382. _p9k_worker_reply $REPLY
  5383. }
  5384. function _p9k_set_prompt() {
  5385. local -i _p9k__vcs_called
  5386. PROMPT=
  5387. RPROMPT=
  5388. [[ $1 == instant_ ]] || PROMPT+='${$((_p9k_on_expand()))+}%{${_p9k__raw_msg-}${_p9k__raw_msg::=}%}'
  5389. PROMPT+=$_p9k_prompt_prefix_left
  5390. local -i _p9k__has_upglob
  5391. local -i left_idx=1 right_idx=1 num_lines=$#_p9k_line_segments_left
  5392. for _p9k__line_index in {1..$num_lines}; do
  5393. local right=
  5394. if (( !_POWERLEVEL9K_DISABLE_RPROMPT )); then
  5395. _p9k__dir=
  5396. _p9k__prompt=
  5397. _p9k__segment_index=right_idx
  5398. _p9k__prompt_side=right
  5399. if [[ $1 == instant_ ]]; then
  5400. for _p9k__segment_name in ${${(0)_p9k_line_segments_right[_p9k__line_index]}%_joined}; do
  5401. if (( $+functions[instant_prompt_$_p9k__segment_name] )); then
  5402. local disabled=_POWERLEVEL9K_${${(U)_p9k__segment_name}//İ/I}_DISABLED_DIR_PATTERN
  5403. if [[ $_p9k__cwd != ${(P)~disabled} ]]; then
  5404. local -i len=$#_p9k__prompt
  5405. _p9k__non_hermetic_expansion=0
  5406. instant_prompt_$_p9k__segment_name
  5407. if (( _p9k__non_hermetic_expansion )); then
  5408. _p9k__prompt[len+1,-1]=
  5409. fi
  5410. fi
  5411. fi
  5412. ((++_p9k__segment_index))
  5413. done
  5414. else
  5415. for _p9k__segment_name in ${${(0)_p9k_line_segments_right[_p9k__line_index]}%_joined}; do
  5416. local cond=$_p9k__segment_cond_right[_p9k__segment_index]
  5417. if [[ -z $cond || -n ${(e)cond} ]]; then
  5418. local disabled=_POWERLEVEL9K_${${(U)_p9k__segment_name}//İ/I}_DISABLED_DIR_PATTERN
  5419. if [[ $_p9k__cwd != ${(P)~disabled} ]]; then
  5420. local val=$_p9k__segment_val_right[_p9k__segment_index]
  5421. if [[ -n $val ]]; then
  5422. _p9k__prompt+=$val
  5423. else
  5424. if [[ $_p9k__segment_name == custom_* ]]; then
  5425. _p9k_custom_prompt $_p9k__segment_name[8,-1]
  5426. elif (( $+functions[prompt_$_p9k__segment_name] )); then
  5427. prompt_$_p9k__segment_name
  5428. fi
  5429. fi
  5430. fi
  5431. fi
  5432. ((++_p9k__segment_index))
  5433. done
  5434. fi
  5435. _p9k__prompt=${${_p9k__prompt//$' %{\b'/'%{%G'}//$' \b'}
  5436. right_idx=_p9k__segment_index
  5437. if [[ -n $_p9k__prompt || $_p9k_line_never_empty_right[_p9k__line_index] == 1 ]]; then
  5438. right=$_p9k_line_prefix_right[_p9k__line_index]$_p9k__prompt$_p9k_line_suffix_right[_p9k__line_index]
  5439. fi
  5440. fi
  5441. unset _p9k__dir
  5442. _p9k__prompt=$_p9k_line_prefix_left[_p9k__line_index]
  5443. _p9k__segment_index=left_idx
  5444. _p9k__prompt_side=left
  5445. if [[ $1 == instant_ ]]; then
  5446. for _p9k__segment_name in ${${(0)_p9k_line_segments_left[_p9k__line_index]}%_joined}; do
  5447. if (( $+functions[instant_prompt_$_p9k__segment_name] )); then
  5448. local disabled=_POWERLEVEL9K_${${(U)_p9k__segment_name}//İ/I}_DISABLED_DIR_PATTERN
  5449. if [[ $_p9k__cwd != ${(P)~disabled} ]]; then
  5450. local -i len=$#_p9k__prompt
  5451. _p9k__non_hermetic_expansion=0
  5452. instant_prompt_$_p9k__segment_name
  5453. if (( _p9k__non_hermetic_expansion )); then
  5454. _p9k__prompt[len+1,-1]=
  5455. fi
  5456. fi
  5457. fi
  5458. ((++_p9k__segment_index))
  5459. done
  5460. else
  5461. for _p9k__segment_name in ${${(0)_p9k_line_segments_left[_p9k__line_index]}%_joined}; do
  5462. local cond=$_p9k__segment_cond_left[_p9k__segment_index]
  5463. if [[ -z $cond || -n ${(e)cond} ]]; then
  5464. local disabled=_POWERLEVEL9K_${${(U)_p9k__segment_name}//İ/I}_DISABLED_DIR_PATTERN
  5465. if [[ $_p9k__cwd != ${(P)~disabled} ]]; then
  5466. local val=$_p9k__segment_val_left[_p9k__segment_index]
  5467. if [[ -n $val ]]; then
  5468. _p9k__prompt+=$val
  5469. else
  5470. if [[ $_p9k__segment_name == custom_* ]]; then
  5471. _p9k_custom_prompt $_p9k__segment_name[8,-1]
  5472. elif (( $+functions[prompt_$_p9k__segment_name] )); then
  5473. prompt_$_p9k__segment_name
  5474. fi
  5475. fi
  5476. fi
  5477. fi
  5478. ((++_p9k__segment_index))
  5479. done
  5480. fi
  5481. _p9k__prompt=${${_p9k__prompt//$' %{\b'/'%{%G'}//$' \b'}
  5482. left_idx=_p9k__segment_index
  5483. _p9k__prompt+=$_p9k_line_suffix_left[_p9k__line_index]
  5484. if (( $+_p9k__dir || (_p9k__line_index != num_lines && $#right) )); then
  5485. _p9k__prompt='${${:-${_p9k__d::=0}${_p9k__rprompt::='$right'}${_p9k__lprompt::='$_p9k__prompt'}}+}'
  5486. _p9k__prompt+=$_p9k_gap_pre
  5487. if (( $+_p9k__dir )); then
  5488. if (( _p9k__line_index == num_lines && (_POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS > 0 || _POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS_PCT > 0) )); then
  5489. local a=$_POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS
  5490. local f=$((0.01*_POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS_PCT))'*_p9k__clm'
  5491. _p9k__prompt+="\${\${_p9k__h::=$((($a<$f)*$f+($a>=$f)*$a))}+}"
  5492. else
  5493. _p9k__prompt+='${${_p9k__h::=0}+}'
  5494. fi
  5495. if [[ $_POWERLEVEL9K_DIR_MAX_LENGTH == <->('%'|) ]]; then
  5496. local lim=
  5497. if [[ $_POWERLEVEL9K_DIR_MAX_LENGTH[-1] == '%' ]]; then
  5498. lim="$_p9k__dir_len-$((0.01*$_POWERLEVEL9K_DIR_MAX_LENGTH[1,-2]))*_p9k__clm"
  5499. else
  5500. lim=$((_p9k__dir_len-_POWERLEVEL9K_DIR_MAX_LENGTH))
  5501. ((lim <= 0)) && lim=
  5502. fi
  5503. if [[ -n $lim ]]; then
  5504. _p9k__prompt+='${${${$((_p9k__h<_p9k__m+'$lim')):#1}:-${_p9k__h::=$((_p9k__m+'$lim'))}}+}'
  5505. fi
  5506. fi
  5507. _p9k__prompt+='${${_p9k__d::=$((_p9k__m-_p9k__h))}+}'
  5508. _p9k__prompt+='${_p9k__lprompt/\%\{d\%\}*\%\{d\%\}/${_p9k__'$_p9k__line_index'ldir-'$_p9k__dir'}}'
  5509. _p9k__prompt+='${${_p9k__m::=$((_p9k__d+_p9k__h))}+}'
  5510. else
  5511. _p9k__prompt+='${_p9k__lprompt}'
  5512. fi
  5513. ((_p9k__line_index != num_lines && $#right)) && _p9k__prompt+=$_p9k_line_gap_post[_p9k__line_index]
  5514. fi
  5515. if (( _p9k__line_index == num_lines )); then
  5516. [[ -n $right ]] && RPROMPT=$_p9k_prompt_prefix_right$right$_p9k_prompt_suffix_right
  5517. _p9k__prompt='${_p9k__'$_p9k__line_index'-'$_p9k__prompt'}'$_p9k_prompt_suffix_left
  5518. [[ $1 == instant_ ]] || PROMPT+=$_p9k__prompt
  5519. else
  5520. [[ -n $right ]] || _p9k__prompt+=$'\n'
  5521. PROMPT+='${_p9k__'$_p9k__line_index'-'$_p9k__prompt'}'
  5522. fi
  5523. done
  5524. _p9k__prompt_side=
  5525. (( $#_p9k_cache < _POWERLEVEL9K_MAX_CACHE_SIZE )) || _p9k_cache=()
  5526. (( $#_p9k__cache_ephemeral < _POWERLEVEL9K_MAX_CACHE_SIZE )) || _p9k__cache_ephemeral=()
  5527. [[ -n $RPROMPT ]] || unset RPROMPT
  5528. }
  5529. _p9k_set_instant_prompt() {
  5530. local saved_prompt=$PROMPT
  5531. local saved_rprompt=$RPROMPT
  5532. _p9k_set_prompt instant_
  5533. typeset -g _p9k__instant_prompt=$PROMPT$'\x1f'$_p9k__prompt$'\x1f'$RPROMPT
  5534. PROMPT=$saved_prompt
  5535. RPROMPT=$saved_rprompt
  5536. [[ -n $RPROMPT ]] || unset RPROMPT
  5537. }
  5538. typeset -gri __p9k_instant_prompt_version=47
  5539. _p9k_dump_instant_prompt() {
  5540. local user=${(%):-%n}
  5541. local root_dir=${__p9k_dump_file:h}
  5542. local prompt_dir=${root_dir}/p10k-$user
  5543. local root_file=$root_dir/p10k-instant-prompt-$user.zsh
  5544. local prompt_file=$prompt_dir/prompt-${#_p9k__cwd}
  5545. [[ -d $prompt_dir ]] || mkdir -p $prompt_dir || return
  5546. [[ -w $root_dir && -w $prompt_dir ]] || return
  5547. if [[ ! -e $root_file ]]; then
  5548. local tmp=$root_file.tmp.$$
  5549. local -i fd
  5550. sysopen -a -m 600 -o creat,trunc -u fd -- $tmp || return
  5551. {
  5552. [[ $TERM == (screen*|tmux*) ]] && local screen='-n' || local screen='-z'
  5553. local -a display_v=("${_p9k__display_v[@]}")
  5554. local -i i
  5555. for ((i = 6; i <= $#display_v; i+=2)); do display_v[i]=show; done
  5556. display_v[2]=hide
  5557. display_v[4]=hide
  5558. local gitstatus_dir=${${_POWERLEVEL9K_GITSTATUS_DIR:A}:-${__p9k_root_dir}/gitstatus}
  5559. local gitstatus_header
  5560. if [[ -r $gitstatus_dir/install.info ]]; then
  5561. IFS= read -r gitstatus_header <$gitstatus_dir/install.info || return
  5562. fi
  5563. >&$fd print -r -- '[[ -t 0 && -t 1 && -t 2 && -o interactive && -o zle && -o no_xtrace ]] &&
  5564. ! (( ${+__p9k_instant_prompt_disabled} || ZSH_SUBSHELL || ${+ZSH_SCRIPT} || ${+ZSH_EXECUTION_STRING} )) || return 0'
  5565. >&$fd print -r -- "() {
  5566. $__p9k_intro_no_locale
  5567. typeset -gi __p9k_instant_prompt_disabled=1
  5568. [[ \$ZSH_VERSION == ${(q)ZSH_VERSION} && \$ZSH_PATCHLEVEL == ${(q)ZSH_PATCHLEVEL} &&
  5569. $screen \${(M)TERM:#(screen*|tmux*)} &&
  5570. \${#\${(M)VTE_VERSION:#(<1-4602>|4801)}} == "${#${(M)VTE_VERSION:#(<1-4602>|4801)}}" &&
  5571. \$POWERLEVEL9K_DISABLE_INSTANT_PROMPT != 'true' &&
  5572. \$POWERLEVEL9K_INSTANT_PROMPT != 'off' ]] || return
  5573. typeset -g __p9k_instant_prompt_param_sig=${(q+)_p9k__param_sig}
  5574. local gitstatus_dir=${(q)gitstatus_dir}
  5575. local gitstatus_header=${(q)gitstatus_header}
  5576. local -i ZLE_RPROMPT_INDENT=${ZLE_RPROMPT_INDENT:-1}
  5577. local PROMPT_EOL_MARK=${(q)PROMPT_EOL_MARK-%B%S%#%s%b}
  5578. [[ -n \$SSH_CLIENT || -n \$SSH_TTY || -n \$SSH_CONNECTION ]] && local ssh=1 || local ssh=0
  5579. local cr=\$'\r' lf=\$'\n' esc=\$'\e[' rs=$'\x1e' us=$'\x1f'
  5580. local -i height=${_POWERLEVEL9K_INSTANT_PROMPT_COMMAND_LINES-1}
  5581. local prompt_dir=${(q)prompt_dir}"
  5582. if (( ! ${+_POWERLEVEL9K_INSTANT_PROMPT_COMMAND_LINES} )); then
  5583. >&$fd print -r -- '
  5584. (( _z4h_can_save_restore_screen == 1 )) && height=0'
  5585. fi
  5586. >&$fd print -r -- '
  5587. local real_gitstatus_header
  5588. if [[ -r $gitstatus_dir/install.info ]]; then
  5589. IFS= read -r real_gitstatus_header <$gitstatus_dir/install.info || real_gitstatus_header=borked
  5590. fi
  5591. [[ $real_gitstatus_header == $gitstatus_header ]] || return
  5592. zmodload zsh/langinfo zsh/terminfo zsh/system || return
  5593. if [[ $langinfo[CODESET] != (utf|UTF)(-|)8 ]]; then
  5594. local loc_cmd=$commands[locale]
  5595. [[ -z $loc_cmd ]] && loc_cmd='${(q)commands[locale]}'
  5596. if [[ -x $loc_cmd ]]; then
  5597. local -a locs
  5598. if locs=(${(@M)$(locale -a 2>/dev/null):#*.(utf|UTF)(-|)8}) && (( $#locs )); then
  5599. local loc=${locs[(r)(#i)C.UTF(-|)8]:-${locs[(r)(#i)en_US.UTF(-|)8]:-$locs[1]}}
  5600. [[ -n $LC_ALL ]] && local LC_ALL=$loc || local LC_CTYPE=$loc
  5601. fi
  5602. fi
  5603. fi
  5604. (( terminfo[colors] == '${terminfo[colors]:-0}' )) || return
  5605. (( $+terminfo[cuu] && $+terminfo[cuf] && $+terminfo[ed] && $+terminfo[sc] && $+terminfo[rc] )) || return
  5606. local pwd=${(%):-%/}
  5607. [[ $pwd == /* ]] || return
  5608. local prompt_file=$prompt_dir/prompt-${#pwd}
  5609. local key=$pwd:$ssh:${(%):-%#}
  5610. local content
  5611. if [[ ! -e $prompt_file ]]; then
  5612. typeset -gi __p9k_instant_prompt_sourced='$__p9k_instant_prompt_version'
  5613. return 1
  5614. fi
  5615. { content="$(<$prompt_file)" } 2>/dev/null || return
  5616. local tail=${content##*$rs$key$us}
  5617. if (( ${#tail} == ${#content} )); then
  5618. typeset -gi __p9k_instant_prompt_sourced='$__p9k_instant_prompt_version'
  5619. return 1
  5620. fi
  5621. local _p9k__ipe
  5622. local P9K_PROMPT=instant
  5623. if [[ -z $P9K_TTY || $P9K_TTY == old && -n ${_P9K_TTY:#$TTY} ]]; then'
  5624. if (( _POWERLEVEL9K_NEW_TTY_MAX_AGE_SECONDS < 0 )); then
  5625. >&$fd print -r -- ' typeset -gx P9K_TTY=new'
  5626. else
  5627. >&$fd print -r -- '
  5628. typeset -gx P9K_TTY=old
  5629. zmodload -F zsh/stat b:zstat || return
  5630. zmodload zsh/datetime || return
  5631. local -a stat
  5632. if zstat -A stat +ctime -- $TTY 2>/dev/null &&
  5633. (( EPOCHREALTIME - stat[1] < '$_POWERLEVEL9K_NEW_TTY_MAX_AGE_SECONDS' )); then
  5634. P9K_TTY=new
  5635. fi'
  5636. fi
  5637. >&$fd print -r -- ' fi
  5638. typeset -gx _P9K_TTY=$TTY
  5639. local -i _p9k__empty_line_i=3 _p9k__ruler_i=3
  5640. local -A _p9k_display_k=('${(j: :)${(@q)${(kv)_p9k_display_k}}}')
  5641. local -a _p9k__display_v=('${(j: :)${(@q)display_v}}')
  5642. function p10k() {
  5643. '$__p9k_intro'
  5644. [[ $1 == display ]] || return
  5645. shift
  5646. local -i k dump
  5647. local opt prev new pair list name var
  5648. while getopts ":ha" opt; do
  5649. case $opt in
  5650. a) dump=1;;
  5651. h) return 0;;
  5652. ?) return 1;;
  5653. esac
  5654. done
  5655. if (( dump )); then
  5656. reply=()
  5657. shift $((OPTIND-1))
  5658. (( ARGC )) || set -- "*"
  5659. for opt; do
  5660. for k in ${(u@)_p9k_display_k[(I)$opt]:/(#m)*/$_p9k_display_k[$MATCH]}; do
  5661. reply+=($_p9k__display_v[k,k+1])
  5662. done
  5663. done
  5664. return 0
  5665. fi
  5666. for opt in "${@:$OPTIND}"; do
  5667. pair=(${(s:=:)opt})
  5668. list=(${(s:,:)${pair[2]}})
  5669. if [[ ${(b)pair[1]} == $pair[1] ]]; then
  5670. local ks=($_p9k_display_k[$pair[1]])
  5671. else
  5672. local ks=(${(u@)_p9k_display_k[(I)$pair[1]]:/(#m)*/$_p9k_display_k[$MATCH]})
  5673. fi
  5674. for k in $ks; do
  5675. if (( $#list == 1 )); then
  5676. [[ $_p9k__display_v[k+1] == $list[1] ]] && continue
  5677. new=$list[1]
  5678. else
  5679. new=${list[list[(I)$_p9k__display_v[k+1]]+1]:-$list[1]}
  5680. [[ $_p9k__display_v[k+1] == $new ]] && continue
  5681. fi
  5682. _p9k__display_v[k+1]=$new
  5683. name=$_p9k__display_v[k]
  5684. if [[ $name == (empty_line|ruler) ]]; then
  5685. var=_p9k__${name}_i
  5686. [[ $new == hide ]] && typeset -gi $var=3 || unset $var
  5687. elif [[ $name == (#b)(<->)(*) ]]; then
  5688. var=_p9k__${match[1]}${${${${match[2]//\/}/#left/l}/#right/r}/#gap/g}
  5689. [[ $new == hide ]] && typeset -g $var= || unset $var
  5690. fi
  5691. done
  5692. done
  5693. }'
  5694. if (( _POWERLEVEL9K_PROMPT_ADD_NEWLINE )); then
  5695. >&$fd print -r -- ' [[ $P9K_TTY == old ]] && { unset _p9k__empty_line_i; _p9k__display_v[2]=print }'
  5696. fi
  5697. if (( _POWERLEVEL9K_SHOW_RULER )); then
  5698. >&$fd print -r -- '[[ $P9K_TTY == old ]] && { unset _p9k__ruler_i; _p9k__display_v[4]=print }'
  5699. fi
  5700. if (( $+functions[p10k-on-init] )); then
  5701. >&$fd print -r -- '
  5702. p10k-on-init() { '$functions[p10k-on-init]' }'
  5703. fi
  5704. if (( $+functions[p10k-on-pre-prompt] )); then
  5705. >&$fd print -r -- '
  5706. p10k-on-pre-prompt() { '$functions[p10k-on-pre-prompt]' }'
  5707. fi
  5708. if (( $+functions[p10k-on-post-prompt] )); then
  5709. >&$fd print -r -- '
  5710. p10k-on-post-prompt() { '$functions[p10k-on-post-prompt]' }'
  5711. fi
  5712. if (( $+functions[p10k-on-post-widget] )); then
  5713. >&$fd print -r -- '
  5714. p10k-on-post-widget() { '$functions[p10k-on-post-widget]' }'
  5715. fi
  5716. if (( $+functions[p10k-on-init] )); then
  5717. >&$fd print -r -- '
  5718. p10k-on-init'
  5719. fi
  5720. local pat idx var
  5721. for pat idx var in $_p9k_show_on_command; do
  5722. >&$fd print -r -- "
  5723. local $var=
  5724. _p9k__display_v[$idx]=hide"
  5725. done
  5726. if (( $+functions[p10k-on-pre-prompt] )); then
  5727. >&$fd print -r -- '
  5728. p10k-on-pre-prompt'
  5729. fi
  5730. if (( $+functions[p10k-on-init] )); then
  5731. >&$fd print -r -- '
  5732. unfunction p10k-on-init'
  5733. fi
  5734. if (( $+functions[p10k-on-pre-prompt] )); then
  5735. >&$fd print -r -- '
  5736. unfunction p10k-on-pre-prompt'
  5737. fi
  5738. if (( $+functions[p10k-on-post-prompt] )); then
  5739. >&$fd print -r -- '
  5740. unfunction p10k-on-post-prompt'
  5741. fi
  5742. if (( $+functions[p10k-on-post-widget] )); then
  5743. >&$fd print -r -- '
  5744. unfunction p10k-on-post-widget'
  5745. fi
  5746. >&$fd print -r -- '
  5747. () {
  5748. '$functions[_p9k_init_toolbox]'
  5749. }
  5750. trap "unset -m _p9k__\*; unfunction p10k" EXIT
  5751. local -a _p9k_t=("${(@ps:$us:)${tail%%$rs*}}")
  5752. if [[ $+VTE_VERSION == 1 || $TERM_PROGRAM == Hyper ]] && (( $+commands[stty] )); then
  5753. if [[ $TERM_PROGRAM == Hyper ]]; then
  5754. local bad_lines=40 bad_columns=100
  5755. else
  5756. local bad_lines=24 bad_columns=80
  5757. fi
  5758. if (( LINES == bad_lines && COLUMNS == bad_columns )); then
  5759. zmodload -F zsh/stat b:zstat || return
  5760. zmodload zsh/datetime || return
  5761. local -a tty_ctime
  5762. if ! zstat -A tty_ctime +ctime -- $TTY 2>/dev/null || (( tty_ctime[1] + 2 > EPOCHREALTIME )); then
  5763. local -F deadline=$((EPOCHREALTIME+0.025))
  5764. local tty_size
  5765. while true; do
  5766. if (( EPOCHREALTIME > deadline )) || ! tty_size="$(command stty size 2>/dev/null)" || [[ $tty_size != <->" "<-> ]]; then
  5767. (( $+_p9k__ruler_i )) || local -i _p9k__ruler_i=1
  5768. local _p9k__g= _p9k__'$#_p9k_line_segments_right'r= _p9k__'$#_p9k_line_segments_right'r_frame=
  5769. break
  5770. fi
  5771. if [[ $tty_size != "$bad_lines $bad_columns" ]]; then
  5772. local lines_columns=(${=tty_size})
  5773. local LINES=$lines_columns[1]
  5774. local COLUMNS=$lines_columns[2]
  5775. break
  5776. fi
  5777. done
  5778. fi
  5779. fi
  5780. fi'
  5781. (( __p9k_ksh_arrays )) && >&$fd print -r -- ' setopt ksh_arrays'
  5782. (( __p9k_sh_glob )) && >&$fd print -r -- ' setopt sh_glob'
  5783. >&$fd print -r -- ' typeset -ga __p9k_used_instant_prompt=("${(@e)_p9k_t[-3,-1]}")'
  5784. (( __p9k_ksh_arrays )) && >&$fd print -r -- ' unsetopt ksh_arrays'
  5785. (( __p9k_sh_glob )) && >&$fd print -r -- ' unsetopt sh_glob'
  5786. >&$fd print -r -- '
  5787. local -i prompt_height=${#${__p9k_used_instant_prompt[1]//[^$lf]}}
  5788. (( height += prompt_height ))
  5789. local _p9k__ret
  5790. function _p9k_prompt_length() {
  5791. local -i COLUMNS=1024
  5792. local -i x y=${#1} m
  5793. if (( y )); then
  5794. while (( ${${(%):-$1%$y(l.1.0)}[-1]} )); do
  5795. x=y
  5796. (( y *= 2 ))
  5797. done
  5798. while (( y > x + 1 )); do
  5799. (( m = x + (y - x) / 2 ))
  5800. (( ${${(%):-$1%$m(l.x.y)}[-1]} = m ))
  5801. done
  5802. fi
  5803. typeset -g _p9k__ret=$x
  5804. }
  5805. local out=${(%):-%b%k%f%s%u}
  5806. if [[ $P9K_TTY == old && ( $+VTE_VERSION == 0 && $TERM_PROGRAM != Hyper || $+_p9k__g == 0 ) ]]; then
  5807. local mark=${(e)PROMPT_EOL_MARK}
  5808. [[ $mark == "%B%S%#%s%b" ]] && _p9k__ret=1 || _p9k_prompt_length $mark
  5809. local -i fill=$((COLUMNS > _p9k__ret ? COLUMNS - _p9k__ret : 0))
  5810. out+="${(%):-$mark${(pl.$fill.. .)}$cr%b%k%f%s%u%E}"
  5811. else
  5812. out+="${(%):-$cr%E}"
  5813. fi
  5814. if (( _z4h_can_save_restore_screen != 1 )); then
  5815. (( height )) && out+="${(pl.$height..$lf.)}$esc${height}A"
  5816. out+="$terminfo[sc]"
  5817. fi
  5818. out+=${(%):-"$__p9k_used_instant_prompt[1]$__p9k_used_instant_prompt[2]"}
  5819. if [[ -n $__p9k_used_instant_prompt[3] ]]; then
  5820. _p9k_prompt_length "$__p9k_used_instant_prompt[2]"
  5821. local -i left_len=_p9k__ret
  5822. _p9k_prompt_length "$__p9k_used_instant_prompt[3]"
  5823. if (( _p9k__ret )); then
  5824. local -i gap=$((COLUMNS - left_len - _p9k__ret - ZLE_RPROMPT_INDENT))
  5825. if (( gap >= 40 )); then
  5826. out+="${(pl.$gap.. .)}${(%):-${__p9k_used_instant_prompt[3]}%b%k%f%s%u}$cr$esc${left_len}C"
  5827. fi
  5828. fi
  5829. fi
  5830. if (( _z4h_can_save_restore_screen == 1 )); then
  5831. if (( height )); then
  5832. out+="$cr${(pl:$((height-prompt_height))::\n:)}$esc${height}A$terminfo[sc]$out"
  5833. else
  5834. out+="$cr${(pl:$((height-prompt_height))::\n:)}$terminfo[sc]$out"
  5835. fi
  5836. fi
  5837. if [[ -n "$TMPDIR" && ( ( -d "$TMPDIR" && -w "$TMPDIR" ) || ! ( -d /tmp && -w /tmp ) ) ]]; then
  5838. local tmpdir=$TMPDIR
  5839. else
  5840. local tmpdir=/tmp
  5841. fi
  5842. typeset -g __p9k_instant_prompt_output=$tmpdir/p10k-instant-prompt-output-${(%):-%n}-$$
  5843. { : > $__p9k_instant_prompt_output } || return
  5844. print -rn -- "${out}${esc}?2004h" || return
  5845. if (( $+commands[stty] )); then
  5846. command stty -icanon 2>/dev/null
  5847. fi
  5848. local fd_null
  5849. sysopen -ru fd_null /dev/null || return
  5850. exec {__p9k_fd_0}<&0 {__p9k_fd_1}>&1 {__p9k_fd_2}>&2 0<&$fd_null 1>$__p9k_instant_prompt_output
  5851. exec 2>&1 {fd_null}>&-
  5852. typeset -gi __p9k_instant_prompt_active=1
  5853. if (( _z4h_can_save_restore_screen == 1 )); then
  5854. typeset -g _z4h_saved_screen
  5855. -z4h-save-screen
  5856. fi
  5857. typeset -g __p9k_instant_prompt_dump_file=${XDG_CACHE_HOME:-~/.cache}/p10k-dump-${(%):-%n}.zsh
  5858. if builtin source $__p9k_instant_prompt_dump_file 2>/dev/null && (( $+functions[_p9k_preinit] )); then
  5859. _p9k_preinit
  5860. fi
  5861. function _p9k_instant_prompt_cleanup() {
  5862. (( ZSH_SUBSHELL == 0 && ${+__p9k_instant_prompt_active} )) || return 0
  5863. '$__p9k_intro_no_locale'
  5864. unset __p9k_instant_prompt_active
  5865. exec 0<&$__p9k_fd_0 1>&$__p9k_fd_1 2>&$__p9k_fd_2 {__p9k_fd_0}>&- {__p9k_fd_1}>&- {__p9k_fd_2}>&-
  5866. unset __p9k_fd_0 __p9k_fd_1 __p9k_fd_2
  5867. typeset -gi __p9k_instant_prompt_erased=1
  5868. if (( _z4h_can_save_restore_screen == 1 && __p9k_instant_prompt_sourced >= 35 )); then
  5869. -z4h-restore-screen
  5870. unset _z4h_saved_screen
  5871. fi
  5872. print -rn -- $terminfo[rc]${(%):-%b%k%f%s%u}$terminfo[ed]
  5873. if [[ -s $__p9k_instant_prompt_output ]]; then
  5874. command cat $__p9k_instant_prompt_output 2>/dev/null
  5875. if (( $1 )); then
  5876. local _p9k__ret mark="${(e)${PROMPT_EOL_MARK-%B%S%#%s%b}}"
  5877. _p9k_prompt_length $mark
  5878. local -i fill=$((COLUMNS > _p9k__ret ? COLUMNS - _p9k__ret : 0))
  5879. echo -nE - "${(%):-%b%k%f%s%u$mark${(pl.$fill.. .)}$cr%b%k%f%s%u%E}"
  5880. fi
  5881. fi
  5882. zshexit_functions=(${zshexit_functions:#_p9k_instant_prompt_cleanup})
  5883. zmodload -F zsh/files b:zf_rm || return
  5884. local user=${(%):-%n}
  5885. local root_dir=${__p9k_instant_prompt_dump_file:h}
  5886. zf_rm -f -- $__p9k_instant_prompt_output $__p9k_instant_prompt_dump_file{,.zwc} $root_dir/p10k-instant-prompt-$user.zsh{,.zwc} $root_dir/p10k-$user/prompt-*(N) 2>/dev/null
  5887. }
  5888. function _p9k_instant_prompt_precmd_first() {
  5889. '$__p9k_intro'
  5890. function _p9k_instant_prompt_sched_last() {
  5891. (( ${+__p9k_instant_prompt_active} )) || return 0
  5892. _p9k_instant_prompt_cleanup 1
  5893. setopt no_local_options prompt_cr prompt_sp
  5894. }
  5895. zmodload zsh/sched
  5896. sched +0 _p9k_instant_prompt_sched_last
  5897. precmd_functions=(${(@)precmd_functions:#_p9k_instant_prompt_precmd_first})
  5898. }
  5899. zshexit_functions=(_p9k_instant_prompt_cleanup $zshexit_functions)
  5900. precmd_functions=(_p9k_instant_prompt_precmd_first $precmd_functions)
  5901. DISABLE_UPDATE_PROMPT=true
  5902. } && unsetopt prompt_cr prompt_sp && typeset -gi __p9k_instant_prompt_sourced='$__p9k_instant_prompt_version' ||
  5903. typeset -gi __p9k_instant_prompt_sourced=${__p9k_instant_prompt_sourced:-0}'
  5904. } always {
  5905. exec {fd}>&-
  5906. }
  5907. {
  5908. (( ! $? )) || return
  5909. # `zf_mv -f src dst` fails on NTFS if `dst` is not writable, hence `zf_rm`.
  5910. zf_rm -f -- $root_file.zwc || return
  5911. zf_mv -f -- $tmp $root_file || return
  5912. zcompile -R -- $tmp.zwc $root_file || return
  5913. zf_mv -f -- $tmp.zwc $root_file.zwc || return
  5914. } always {
  5915. (( $? )) && zf_rm -f -- $tmp $tmp.zwc 2>/dev/null
  5916. }
  5917. fi
  5918. local tmp=$prompt_file.tmp.$$
  5919. zf_mv -f -- $prompt_file $tmp 2>/dev/null
  5920. if [[ "$(<$tmp)" == *$'\x1e'$_p9k__instant_prompt_sig$'\x1f'* ]] 2>/dev/null; then
  5921. echo -n >$tmp || return
  5922. fi
  5923. local -i fd
  5924. sysopen -a -m 600 -o creat -u fd -- $tmp || return
  5925. {
  5926. {
  5927. print -rnu $fd -- $'\x1e'$_p9k__instant_prompt_sig$'\x1f'${(pj:\x1f:)_p9k_t}$'\x1f'$_p9k__instant_prompt || return
  5928. } always {
  5929. exec {fd}>&-
  5930. }
  5931. zf_mv -f -- $tmp $prompt_file || return
  5932. } always {
  5933. (( $? )) && zf_rm -f -- $tmp 2>/dev/null
  5934. }
  5935. }
  5936. typeset -gi __p9k_sh_glob
  5937. typeset -gi __p9k_ksh_arrays
  5938. typeset -gi __p9k_new_status
  5939. typeset -ga __p9k_new_pipestatus
  5940. _p9k_save_status() {
  5941. local -i pipe
  5942. if (( !$+_p9k__line_finished )); then
  5943. : # SIGINT
  5944. elif (( !$+_p9k__preexec_cmd )); then
  5945. # Empty line, comment or parse error.
  5946. #
  5947. # This case is handled incorrectly:
  5948. #
  5949. # true | false
  5950. # |
  5951. #
  5952. # Here status=1 and pipestatus=(0 1). Ideally we should ignore pipestatus but we won't.
  5953. #
  5954. # This works though (unless pipefail is set):
  5955. #
  5956. # false | true
  5957. # |
  5958. #
  5959. # We get status=1 and pipestatus=(1 0) and correctly ignore pipestatus.
  5960. (( _p9k__status == __p9k_new_status )) && return
  5961. elif (( $__p9k_new_pipestatus[(I)$__p9k_new_status] )); then # just in case
  5962. local cmd=(${(z)_p9k__preexec_cmd})
  5963. if [[ $#cmd != 0 && $cmd[1] != '!' && ${(Q)cmd[1]} != coproc ]]; then
  5964. local arg
  5965. for arg in ${(z)_p9k__preexec_cmd}; do
  5966. # '()' is for functions, *';' is for complex commands.
  5967. if [[ $arg == ('()'|'&&'|'||'|'&'|'&|'|'&!'|*';') ]]; then
  5968. pipe=0
  5969. break
  5970. elif [[ $arg == *('|'|'|&')* ]]; then
  5971. pipe=1
  5972. fi
  5973. done
  5974. fi
  5975. fi
  5976. _p9k__status=$__p9k_new_status
  5977. if (( pipe )); then
  5978. _p9k__pipestatus=($__p9k_new_pipestatus)
  5979. else
  5980. _p9k__pipestatus=($_p9k__status)
  5981. fi
  5982. }
  5983. function _p9k_dump_state() {
  5984. local dir=${__p9k_dump_file:h}
  5985. [[ -d $dir ]] || mkdir -p -- $dir || return
  5986. [[ -w $dir ]] || return
  5987. local tmp=$__p9k_dump_file.tmp.$$
  5988. local -i fd
  5989. sysopen -a -m 600 -o creat,trunc -u fd -- $tmp || return
  5990. {
  5991. {
  5992. typeset -g __p9k_cached_param_pat=$_p9k__param_pat
  5993. typeset -g __p9k_cached_param_sig=$_p9k__param_sig
  5994. typeset -pm __p9k_cached_param_pat __p9k_cached_param_sig >&$fd || return
  5995. unset __p9k_cached_param_pat __p9k_cached_param_sig
  5996. (( $+_p9k_preinit )) && { print -r -- $_p9k_preinit >&$fd || return }
  5997. print -r -- '_p9k_restore_state_impl() {' >&$fd || return
  5998. typeset -pm '_POWERLEVEL9K_*|_p9k_[^_]*|icons' >&$fd || return
  5999. print -r -- '}' >&$fd || return
  6000. } always {
  6001. exec {fd}>&-
  6002. }
  6003. # `zf_mv -f src dst` fails on NTFS if `dst` is not writable, hence `zf_rm`.
  6004. zf_rm -f -- $__p9k_dump_file.zwc || return
  6005. zf_mv -f -- $tmp $__p9k_dump_file || return
  6006. zcompile -R -- $tmp.zwc $__p9k_dump_file || return
  6007. zf_mv -f -- $tmp.zwc $__p9k_dump_file.zwc || return
  6008. } always {
  6009. (( $? )) && zf_rm -f -- $tmp $tmp.zwc 2>/dev/null
  6010. }
  6011. }
  6012. function _p9k_delete_instant_prompt() {
  6013. local user=${(%):-%n}
  6014. local root_dir=${__p9k_dump_file:h}
  6015. zf_rm -f -- $root_dir/p10k-instant-prompt-$user.zsh{,.zwc} ${root_dir}/p10k-$user/prompt-*(N) 2>/dev/null
  6016. }
  6017. function _p9k_restore_state() {
  6018. {
  6019. [[ $__p9k_cached_param_pat == $_p9k__param_pat && $__p9k_cached_param_sig == $_p9k__param_sig ]] || return
  6020. (( $+functions[_p9k_restore_state_impl] )) || return
  6021. _p9k_restore_state_impl
  6022. return 0
  6023. } always {
  6024. if (( $? )); then
  6025. if (( $+functions[_p9k_preinit] )); then
  6026. unfunction _p9k_preinit
  6027. (( $+functions[gitstatus_stop_p9k_] )) && gitstatus_stop_p9k_ POWERLEVEL9K
  6028. fi
  6029. _p9k_delete_instant_prompt
  6030. zf_rm -f -- $__p9k_dump_file{,.zwc} 2>/dev/null
  6031. elif [[ $__p9k_instant_prompt_param_sig != $_p9k__param_sig ]]; then
  6032. _p9k_delete_instant_prompt
  6033. _p9k_dumped_instant_prompt_sigs=()
  6034. fi
  6035. unset __p9k_cached_param_sig
  6036. }
  6037. }
  6038. function _p9k_clear_instant_prompt() {
  6039. if (( $+__p9k_fd_0 )); then
  6040. exec 0<&$__p9k_fd_0 {__p9k_fd_0}>&-
  6041. unset __p9k_fd_0
  6042. fi
  6043. exec 1>&$__p9k_fd_1 2>&$__p9k_fd_2 {__p9k_fd_1}>&- {__p9k_fd_2}>&-
  6044. unset __p9k_fd_1 __p9k_fd_2
  6045. zshexit_functions=(${zshexit_functions:#_p9k_instant_prompt_cleanup})
  6046. if (( _p9k__can_hide_cursor )); then
  6047. echoti civis
  6048. _p9k__cursor_hidden=1
  6049. fi
  6050. if [[ -s $__p9k_instant_prompt_output ]]; then
  6051. {
  6052. local content
  6053. [[ $_POWERLEVEL9K_INSTANT_PROMPT == verbose ]] && content="$(<$__p9k_instant_prompt_output)"
  6054. local mark="${(e)${PROMPT_EOL_MARK-%B%S%#%s%b}}"
  6055. _p9k_prompt_length $mark
  6056. local -i fill=$((COLUMNS > _p9k__ret ? COLUMNS - _p9k__ret : 0))
  6057. local cr=$'\r'
  6058. local sp="${(%):-%b%k%f%s%u$mark${(pl.$fill.. .)}$cr%b%k%f%s%u%E}"
  6059. if (( _z4h_can_save_restore_screen == 1 && __p9k_instant_prompt_sourced >= 35 )); then
  6060. -z4h-restore-screen
  6061. unset _z4h_saved_screen
  6062. fi
  6063. print -rn -- $terminfo[rc]${(%):-%b%k%f%s%u}$terminfo[ed]
  6064. local unexpected=${${content//$'\e[?'<->'c'}//$'\e['<->' q'}
  6065. unexpected=${(S)unexpected//$'\eP'*[^$'\e']#($'\e\\')}
  6066. unexpected=${(S)unexpected//$'\e'[^$'\a\e']#($'\a'|$'\e\\')}
  6067. # Visual Studio Code prints this garbage.
  6068. unexpected=${${unexpected//$'\033[1;32mShell integration activated\033[0m\n'}//$'\r'}
  6069. typeset -g P9K_STARTUP_CONSOLE_OUTPUT=("$content" "$unexpected")
  6070. if [[ -n $unexpected ]]; then
  6071. local omz1='[Oh My Zsh] Would you like to update? [Y/n]: '
  6072. local omz2='Updating Oh My Zsh'
  6073. local omz3='https://shop.planetargon.com/collections/oh-my-zsh'
  6074. local omz4='There was an error updating. Try again later?'
  6075. if [[ $unexpected != ($omz1|)$omz2*($omz3|$omz4)[^$'\n']#($'\n'|) ]]; then
  6076. echo -E - ""
  6077. echo -E - "${(%):-[%3FWARNING%f]: Console output during zsh initialization detected.}"
  6078. echo -E - ""
  6079. echo -E - "${(%):-When using Powerlevel10k with instant prompt, console output during zsh}"
  6080. echo -E - "${(%):-initialization may indicate issues.}"
  6081. echo -E - ""
  6082. echo -E - "${(%):-You can:}"
  6083. echo -E - ""
  6084. echo -E - "${(%):- - %BRecommended%b: Change %B$__p9k_zshrc_u%b so that it does not perform console I/O}"
  6085. echo -E - "${(%):- after the instant prompt preamble. See the link below for details.}"
  6086. echo -E - ""
  6087. echo -E - "${(%):- * You %Bwill not%b see this error message again.}"
  6088. echo -E - "${(%):- * Zsh will start %Bquickly%b and prompt will update %Bsmoothly%b.}"
  6089. echo -E - ""
  6090. echo -E - "${(%):- - Suppress this warning either by running %Bp10k configure%b or by manually}"
  6091. echo -E - "${(%):- defining the following parameter:}"
  6092. echo -E - ""
  6093. echo -E - "${(%):- %3Ftypeset%f -g POWERLEVEL9K_INSTANT_PROMPT=quiet}"
  6094. echo -E - ""
  6095. echo -E - "${(%):- * You %Bwill not%b see this error message again.}"
  6096. echo -E - "${(%):- * Zsh will start %Bquickly%b but prompt will %Bjump down%b after initialization.}"
  6097. echo -E - ""
  6098. echo -E - "${(%):- - Disable instant prompt either by running %Bp10k configure%b or by manually}"
  6099. echo -E - "${(%):- defining the following parameter:}"
  6100. echo -E - ""
  6101. echo -E - "${(%):- %3Ftypeset%f -g POWERLEVEL9K_INSTANT_PROMPT=off}"
  6102. echo -E - ""
  6103. echo -E - "${(%):- * You %Bwill not%b see this error message again.}"
  6104. echo -E - "${(%):- * Zsh will start %Bslowly%b.}"
  6105. echo -E - ""
  6106. echo -E - "${(%):- - Do nothing.}"
  6107. echo -E - ""
  6108. echo -E - "${(%):- * You %Bwill%b see this error message every time you start zsh.}"
  6109. echo -E - "${(%):- * Zsh will start %Bquickly%b but prompt will %Bjump down%b after initialization.}"
  6110. echo -E - ""
  6111. echo -E - "${(%):-For details, see:}"
  6112. if (( _p9k_term_has_href )); then
  6113. echo - "${(%):-\e]8;;https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt\ahttps://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt\e]8;;\a}"
  6114. else
  6115. echo - "${(%):-https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt}"
  6116. fi
  6117. echo -E - ""
  6118. echo - "${(%):-%3F-- console output produced during zsh initialization follows --%f}"
  6119. echo -E - ""
  6120. fi
  6121. fi
  6122. command cat -- $__p9k_instant_prompt_output
  6123. echo -nE - $sp
  6124. zf_rm -f -- $__p9k_instant_prompt_output
  6125. } 2>/dev/null
  6126. else
  6127. zf_rm -f -- $__p9k_instant_prompt_output 2>/dev/null
  6128. if (( _z4h_can_save_restore_screen == 1 && __p9k_instant_prompt_sourced >= 35 )); then
  6129. -z4h-restore-screen
  6130. unset _z4h_saved_screen
  6131. fi
  6132. print -rn -- $terminfo[rc]${(%):-%b%k%f%s%u}$terminfo[ed]
  6133. fi
  6134. prompt_opts=(percent subst sp cr)
  6135. if [[ $_POWERLEVEL9K_DISABLE_INSTANT_PROMPT == 0 && $__p9k_instant_prompt_active == 2 ]]; then
  6136. >&2 echo -E - ""
  6137. >&2 echo -E - "${(%):-[%1FERROR%f]: When using Powerlevel10k with instant prompt, %Bprompt_cr%b must be unset.}"
  6138. >&2 echo -E - ""
  6139. >&2 echo -E - "${(%):-You can:}"
  6140. >&2 echo -E - ""
  6141. >&2 echo -E - "${(%):- - %BRecommended%b: call %Bp10k finalize%b at the end of %B$__p9k_zshrc_u%b.}"
  6142. >&2 echo -E - "${(%):- You can do this by running the following command:}"
  6143. >&2 echo -E - ""
  6144. >&2 echo -E - "${(%):- %2Fecho%f %3F'(( ! \${+functions[p10k]\} )) || p10k finalize'%f >>! $__p9k_zshrc_u}"
  6145. >&2 echo -E - ""
  6146. >&2 echo -E - "${(%):- * You %Bwill not%b see this error message again.}"
  6147. >&2 echo -E - "${(%):- * Zsh will start %Bquickly%b and %Bwithout%b prompt flickering.}"
  6148. >&2 echo -E - ""
  6149. >&2 echo -E - "${(%):- - Find where %Bprompt_cr%b option gets sets in your zsh configs and stop setting it.}"
  6150. >&2 echo -E - ""
  6151. >&2 echo -E - "${(%):- * You %Bwill not%b see this error message again.}"
  6152. >&2 echo -E - "${(%):- * Zsh will start %Bquickly%b and %Bwithout%b prompt flickering.}"
  6153. >&2 echo -E - ""
  6154. >&2 echo -E - "${(%):- - Disable instant prompt either by running %Bp10k configure%b or by manually}"
  6155. >&2 echo -E - "${(%):- defining the following parameter:}"
  6156. >&2 echo -E - ""
  6157. >&2 echo -E - "${(%):- %3Ftypeset%f -g POWERLEVEL9K_INSTANT_PROMPT=off}"
  6158. >&2 echo -E - ""
  6159. >&2 echo -E - "${(%):- * You %Bwill not%b see this error message again.}"
  6160. >&2 echo -E - "${(%):- * Zsh will start %Bslowly%b.}"
  6161. >&2 echo -E - ""
  6162. >&2 echo -E - "${(%):- - Do nothing.}"
  6163. >&2 echo -E - ""
  6164. >&2 echo -E - "${(%):- * You %Bwill%b see this error message every time you start zsh.}"
  6165. >&2 echo -E - "${(%):- * Zsh will start %Bquckly%b but %Bwith%b prompt flickering.}"
  6166. >&2 echo -E - ""
  6167. fi
  6168. }
  6169. function _p9k_do_dump() {
  6170. eval "$__p9k_intro"
  6171. zle -F $1
  6172. exec {1}>&-
  6173. (( _p9k__state_dump_fd )) || return
  6174. if (( ! _p9k__instant_prompt_disabled )); then
  6175. _p9k__instant_prompt_sig=$_p9k__cwd:$P9K_SSH:${(%):-%#}
  6176. _p9k_set_instant_prompt
  6177. _p9k_dump_instant_prompt
  6178. _p9k_dumped_instant_prompt_sigs[$_p9k__instant_prompt_sig]=1
  6179. fi
  6180. _p9k_dump_state
  6181. _p9k__state_dump_scheduled=0
  6182. _p9k__state_dump_fd=0
  6183. }
  6184. function _p9k_should_dump() {
  6185. (( __p9k_dumps_enabled && ! _p9k__state_dump_fd )) || return
  6186. (( _p9k__state_dump_scheduled || _p9k__prompt_idx == 1 )) && return
  6187. _p9k__instant_prompt_sig=$_p9k__cwd:$P9K_SSH:${(%):-%#}
  6188. (( ! $+_p9k_dumped_instant_prompt_sigs[$_p9k__instant_prompt_sig] ))
  6189. }
  6190. # Must not run under `eval "$__p9k_intro_locale"`. Safe to run with any options.
  6191. function _p9k_restore_special_params() {
  6192. (( ! ${+_p9k__real_zle_rprompt_indent} )) || {
  6193. [[ -n "$_p9k__real_zle_rprompt_indent" ]] &&
  6194. ZLE_RPROMPT_INDENT="$_p9k__real_zle_rprompt_indent" ||
  6195. unset ZLE_RPROMPT_INDENT
  6196. unset _p9k__real_zle_rprompt_indent
  6197. }
  6198. (( ! ${+_p9k__real_lc_ctype} )) || {
  6199. LC_CTYPE="$_p9k__real_lc_ctype"
  6200. unset _p9k__real_lc_ctype
  6201. }
  6202. (( ! ${+_p9k__real_lc_all} )) || {
  6203. LC_ALL="$_p9k__real_lc_all"
  6204. unset _p9k__real_lc_all
  6205. }
  6206. }
  6207. function _p9k_on_expand() {
  6208. (( _p9k__expanded && ! ${+__p9k_instant_prompt_active} )) && [[ "${langinfo[CODESET]}" == (utf|UTF)(-|)8 ]] && return
  6209. eval "$__p9k_intro_no_locale"
  6210. if [[ $langinfo[CODESET] != (utf|UTF)(-|)8 ]]; then
  6211. _p9k_restore_special_params
  6212. if [[ $langinfo[CODESET] != (utf|UTF)(-|)8 ]] && _p9k_init_locale; then
  6213. if [[ -n $LC_ALL ]]; then
  6214. _p9k__real_lc_all=$LC_ALL
  6215. LC_ALL=$__p9k_locale
  6216. else
  6217. _p9k__real_lc_ctype=$LC_CTYPE
  6218. LC_CTYPE=$__p9k_locale
  6219. fi
  6220. fi
  6221. fi
  6222. (( _p9k__expanded && ! $+__p9k_instant_prompt_active )) && return
  6223. eval "$__p9k_intro_locale"
  6224. if (( ! _p9k__expanded )); then
  6225. if _p9k_should_dump; then
  6226. sysopen -o cloexec -ru _p9k__state_dump_fd /dev/null
  6227. zle -F $_p9k__state_dump_fd _p9k_do_dump
  6228. fi
  6229. if [[ -z $P9K_TTY || $P9K_TTY == old && -n ${_P9K_TTY:#$TTY} ]]; then
  6230. typeset -gx P9K_TTY=old
  6231. if (( _POWERLEVEL9K_NEW_TTY_MAX_AGE_SECONDS < 0 )); then
  6232. P9K_TTY=new
  6233. else
  6234. local -a stat
  6235. if zstat -A stat +ctime -- $TTY 2>/dev/null &&
  6236. (( EPOCHREALTIME - stat[1] < _POWERLEVEL9K_NEW_TTY_MAX_AGE_SECONDS )); then
  6237. P9K_TTY=new
  6238. fi
  6239. fi
  6240. fi
  6241. typeset -gx _P9K_TTY=$TTY
  6242. __p9k_reset_state=1
  6243. if (( _POWERLEVEL9K_PROMPT_ADD_NEWLINE )); then
  6244. if [[ $P9K_TTY == new ]]; then
  6245. _p9k__empty_line_i=3
  6246. _p9k__display_v[2]=hide
  6247. elif [[ -z $_p9k_transient_prompt && $+functions[p10k-on-post-prompt] == 0 ]]; then
  6248. _p9k__empty_line_i=3
  6249. _p9k__display_v[2]=print
  6250. else
  6251. unset _p9k__empty_line_i
  6252. _p9k__display_v[2]=show
  6253. fi
  6254. fi
  6255. if (( _POWERLEVEL9K_SHOW_RULER )); then
  6256. if [[ $P9K_TTY == new ]]; then
  6257. _p9k__ruler_i=3
  6258. _p9k__display_v[4]=hide
  6259. elif [[ -z $_p9k_transient_prompt && $+functions[p10k-on-post-prompt] == 0 ]]; then
  6260. _p9k__ruler_i=3
  6261. _p9k__display_v[4]=print
  6262. else
  6263. unset _p9k__ruler_i
  6264. _p9k__display_v[4]=show
  6265. fi
  6266. fi
  6267. (( _p9k__fully_initialized )) || _p9k_wrap_widgets
  6268. fi
  6269. if (( $+__p9k_instant_prompt_active )); then
  6270. _p9k_clear_instant_prompt
  6271. unset __p9k_instant_prompt_active
  6272. fi
  6273. if (( ! _p9k__expanded )); then
  6274. _p9k__expanded=1
  6275. (( _p9k__fully_initialized || ! $+functions[p10k-on-init] )) || p10k-on-init
  6276. local pat idx var
  6277. for pat idx var in $_p9k_show_on_command; do
  6278. _p9k_display_segment $idx $var hide
  6279. done
  6280. (( $+functions[p10k-on-pre-prompt] )) && p10k-on-pre-prompt
  6281. if zle; then
  6282. local -a P9K_COMMANDS=($_p9k__last_commands)
  6283. local pat idx var
  6284. for pat idx var in $_p9k_show_on_command; do
  6285. if (( $P9K_COMMANDS[(I)$pat] )); then
  6286. _p9k_display_segment $idx $var show
  6287. else
  6288. _p9k_display_segment $idx $var hide
  6289. fi
  6290. done
  6291. if (( $+functions[p10k-on-post-widget] )); then
  6292. local -h WIDGET
  6293. unset WIDGET
  6294. p10k-on-post-widget
  6295. fi
  6296. else
  6297. if [[ $_p9k__display_v[2] == print && -n $_p9k_t[_p9k_empty_line_idx] ]]; then
  6298. print -rnP -- '%b%k%f%E'$_p9k_t[_p9k_empty_line_idx]
  6299. fi
  6300. if [[ $_p9k__display_v[4] == print ]]; then
  6301. () {
  6302. local ruler=$_p9k_t[_p9k_ruler_idx]
  6303. local -i _p9k__clm=COLUMNS _p9k__ind=${ZLE_RPROMPT_INDENT:-1}
  6304. (( __p9k_ksh_arrays )) && setopt ksh_arrays
  6305. (( __p9k_sh_glob )) && setopt sh_glob
  6306. setopt prompt_subst
  6307. print -rnP -- '%b%k%f%E'$ruler
  6308. }
  6309. fi
  6310. fi
  6311. __p9k_reset_state=0
  6312. _p9k__fully_initialized=1
  6313. fi
  6314. }
  6315. functions -M _p9k_on_expand
  6316. _p9k_precmd_impl() {
  6317. eval "$__p9k_intro"
  6318. (( __p9k_enabled )) || return
  6319. if ! zle || [[ -z $_p9k__param_sig ]]; then
  6320. if zle; then
  6321. __p9k_new_status=0
  6322. __p9k_new_pipestatus=(0)
  6323. else
  6324. _p9k__must_restore_prompt=0
  6325. fi
  6326. if _p9k_must_init; then
  6327. local -i instant_prompt_disabled
  6328. if (( !__p9k_configured )); then
  6329. __p9k_configured=1
  6330. if [[ -z "${parameters[(I)POWERLEVEL9K_*~POWERLEVEL9K_(MODE|CONFIG_FILE|GITSTATUS_DIR)]}" ]]; then
  6331. _p9k_can_configure -q
  6332. local -i ret=$?
  6333. if (( ret == 2 && $+__p9k_instant_prompt_active )); then
  6334. _p9k_clear_instant_prompt
  6335. unset __p9k_instant_prompt_active
  6336. _p9k_delete_instant_prompt
  6337. zf_rm -f -- $__p9k_dump_file{,.zwc} 2>/dev/null
  6338. () {
  6339. local key
  6340. while true; do
  6341. [[ -t 2 ]]
  6342. read -t0 -k key || break
  6343. done 2>/dev/null
  6344. }
  6345. _p9k_can_configure -q
  6346. ret=$?
  6347. fi
  6348. if (( ret == 0 )); then
  6349. if (( $+commands[git] )); then
  6350. (
  6351. local -i pid
  6352. {
  6353. { /bin/sh "$__p9k_root_dir"/gitstatus/install </dev/null &>/dev/null & } && pid=$!
  6354. ( builtin source "$__p9k_root_dir"/internal/wizard.zsh )
  6355. } always {
  6356. if (( pid )); then
  6357. kill -- $pid 2>/dev/null
  6358. wait -- $pid 2>/dev/null
  6359. fi
  6360. }
  6361. )
  6362. else
  6363. ( builtin source "$__p9k_root_dir"/internal/wizard.zsh )
  6364. fi
  6365. if (( $? )); then
  6366. instant_prompt_disabled=1
  6367. else
  6368. builtin source "$__p9k_cfg_path"
  6369. _p9k__force_must_init=1
  6370. _p9k_must_init
  6371. fi
  6372. fi
  6373. fi
  6374. fi
  6375. typeset -gi _p9k__instant_prompt_disabled=instant_prompt_disabled
  6376. _p9k_init
  6377. fi
  6378. if (( _p9k__timer_start )); then
  6379. typeset -gF P9K_COMMAND_DURATION_SECONDS=$((EPOCHREALTIME - _p9k__timer_start))
  6380. else
  6381. unset P9K_COMMAND_DURATION_SECONDS
  6382. fi
  6383. _p9k_save_status
  6384. if [[ $_p9k__preexec_cmd == [[:space:]]#(clear([[:space:]]##-(|x)(|T[a-zA-Z0-9-_\'\"]#))#|reset)[[:space:]]# &&
  6385. $_p9k__status == 0 ]]; then
  6386. P9K_TTY=new
  6387. elif [[ $P9K_TTY == new && $_p9k__fully_initialized == 1 ]] && ! zle; then
  6388. P9K_TTY=old
  6389. fi
  6390. _p9k__timer_start=0
  6391. _p9k__region_active=0
  6392. unset _p9k__line_finished _p9k__preexec_cmd
  6393. _p9k__keymap=main
  6394. _p9k__zle_state=insert
  6395. (( ++_p9k__prompt_idx ))
  6396. if (( $+_p9k__iterm_cmd )); then
  6397. _p9k_iterm2_precmd $__p9k_new_status
  6398. fi
  6399. fi
  6400. _p9k_fetch_cwd
  6401. _p9k__refresh_reason=precmd
  6402. __p9k_reset_state=1
  6403. local -i fast_vcs
  6404. if (( _p9k_vcs_index && $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )); then
  6405. if [[ $_p9k__cwd != $~_POWERLEVEL9K_VCS_DISABLED_DIR_PATTERN ]]; then
  6406. local -F start_time=EPOCHREALTIME
  6407. unset _p9k__vcs
  6408. unset _p9k__vcs_timeout
  6409. local -i _p9k__vcs_called
  6410. _p9k_vcs_gitstatus
  6411. local -i fast_vcs=1
  6412. fi
  6413. fi
  6414. (( $+functions[_p9k_async_segments_compute] )) && _p9k_async_segments_compute
  6415. _p9k__expanded=0
  6416. _p9k_set_prompt
  6417. _p9k__refresh_reason=''
  6418. if [[ $precmd_functions[1] != _p9k_do_nothing && $precmd_functions[(I)_p9k_do_nothing] != 0 ]]; then
  6419. precmd_functions=(_p9k_do_nothing ${(@)precmd_functions:#_p9k_do_nothing})
  6420. fi
  6421. if [[ $precmd_functions[-1] != _p9k_precmd && $precmd_functions[(I)_p9k_precmd] != 0 ]]; then
  6422. precmd_functions=(${(@)precmd_functions:#_p9k_precmd} _p9k_precmd)
  6423. fi
  6424. if [[ $preexec_functions[1] != _p9k_preexec1 && $preexec_functions[(I)_p9k_preexec1] != 0 ]]; then
  6425. preexec_functions=(_p9k_preexec1 ${(@)preexec_functions:#_p9k_preexec1})
  6426. fi
  6427. if [[ $preexec_functions[-1] != _p9k_preexec2 && $preexec_functions[(I)_p9k_preexec2] != 0 ]]; then
  6428. preexec_functions=(${(@)preexec_functions:#_p9k_preexec2} _p9k_preexec2)
  6429. fi
  6430. if (( fast_vcs && _p9k_vcs_index && $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )); then
  6431. if (( $+_p9k__vcs_timeout )); then
  6432. (( _p9k__vcs_timeout = _POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS + start_time - EPOCHREALTIME ))
  6433. (( _p9k__vcs_timeout >= 0 )) || (( _p9k__vcs_timeout = 0 ))
  6434. gitstatus_process_results_p9k_ -t $_p9k__vcs_timeout POWERLEVEL9K
  6435. fi
  6436. if (( ! $+_p9k__vcs )); then
  6437. local _p9k__prompt _p9k__prompt_side=$_p9k_vcs_side _p9k__segment_name=vcs
  6438. local -i _p9k__has_upglob _p9k__segment_index=_p9k_vcs_index _p9k__line_index=_p9k_vcs_line_index
  6439. _p9k_vcs_render
  6440. typeset -g _p9k__vcs=$_p9k__prompt
  6441. fi
  6442. fi
  6443. _p9k_worker_receive
  6444. __p9k_reset_state=0
  6445. }
  6446. _p9k_trapint() {
  6447. if (( __p9k_enabled )); then
  6448. eval "$__p9k_intro"
  6449. _p9k_deschedule_redraw
  6450. zle && _p9k_on_widget_zle-line-finish int
  6451. fi
  6452. return 0
  6453. }
  6454. _p9k_precmd() {
  6455. __p9k_new_status=$?
  6456. __p9k_new_pipestatus=($pipestatus)
  6457. trap ":" INT
  6458. [[ -o ksh_arrays ]] && __p9k_ksh_arrays=1 || __p9k_ksh_arrays=0
  6459. [[ -o sh_glob ]] && __p9k_sh_glob=1 || __p9k_sh_glob=0
  6460. _p9k_restore_special_params
  6461. _p9k_precmd_impl
  6462. [[ ${+__p9k_instant_prompt_active} == 0 || -o no_prompt_cr ]] || __p9k_instant_prompt_active=2
  6463. setopt no_local_options no_prompt_bang prompt_percent prompt_subst prompt_cr prompt_sp
  6464. # See https://www.zsh.org/mla/workers/2020/msg00612.html for the reason behind __p9k_trapint.
  6465. typeset -g __p9k_trapint='_p9k_trapint; return 130'
  6466. trap "$__p9k_trapint" INT
  6467. : ${(%):-%b%k%s%u}
  6468. }
  6469. function _p9k_reset_prompt() {
  6470. if (( __p9k_reset_state != 1 )) && zle && [[ -z $_p9k__line_finished ]]; then
  6471. __p9k_reset_state=0
  6472. setopt prompt_subst
  6473. (( __p9k_ksh_arrays )) && setopt ksh_arrays
  6474. (( __p9k_sh_glob )) && setopt sh_glob
  6475. {
  6476. (( _p9k__can_hide_cursor )) && echoti civis
  6477. zle .reset-prompt
  6478. (( ${+functions[z4h]} )) || zle -R
  6479. } always {
  6480. (( _p9k__can_hide_cursor )) && print -rn -- $_p9k__cnorm
  6481. _p9k__cursor_hidden=0
  6482. }
  6483. fi
  6484. }
  6485. # Does ZSH have a certain off-by-one bug that triggers when PROMPT overflows to a new line?
  6486. #
  6487. # Bug: https://github.com/zsh-users/zsh/commit/d8d9fee137a5aa2cf9bf8314b06895bfc2a05518.
  6488. # ZSH_PATCHLEVEL=zsh-5.4.2-159-gd8d9fee13. Released in 5.5.
  6489. #
  6490. # Fix: https://github.com/zsh-users/zsh/commit/64d13738357c9b9c212adbe17f271716abbcf6ea.
  6491. # ZSH_PATCHLEVEL=zsh-5.7.1-50-g64d137383. Released in 5.7.2.
  6492. #
  6493. # Test: PROMPT="${(pl:$((COLUMNS))::-:)}<%1(l.%2(l.FAIL.PASS).FAIL)> " zsh -dfis <<<exit
  6494. # Workaround: PROMPT="${(pl:$((COLUMNS))::-:)}%{%G%}<%1(l.%2(l.FAIL.PASS).FAIL)> " zsh -dfis <<<exit
  6495. function _p9k_prompt_overflow_bug() {
  6496. [[ $ZSH_PATCHLEVEL =~ '^zsh-5\.4\.2-([0-9]+)-' ]] && return $(( match[1] < 159 ))
  6497. [[ $ZSH_PATCHLEVEL =~ '^zsh-5\.7\.1-([0-9]+)-' ]] && return $(( match[1] >= 50 ))
  6498. [[ $ZSH_VERSION == 5.<5-7>* && $ZSH_VERSION != 5.7.<2->* ]]
  6499. }
  6500. typeset -g _p9k__param_pat
  6501. typeset -g _p9k__param_sig
  6502. _p9k_init_vars() {
  6503. typeset -gF _p9k__gcloud_last_fetch_ts
  6504. typeset -g _p9k_gcloud_configuration
  6505. typeset -g _p9k_gcloud_account
  6506. typeset -g _p9k_gcloud_project_id
  6507. typeset -g _p9k_gcloud_project_name
  6508. typeset -gi _p9k_term_has_href
  6509. typeset -gi _p9k_vcs_index
  6510. typeset -gi _p9k_vcs_line_index
  6511. typeset -g _p9k_vcs_side
  6512. typeset -ga _p9k_taskwarrior_meta_files
  6513. typeset -ga _p9k_taskwarrior_meta_non_files
  6514. typeset -g _p9k_taskwarrior_meta_sig
  6515. typeset -g _p9k_taskwarrior_data_dir
  6516. typeset -g _p9k__taskwarrior_functional=1
  6517. typeset -ga _p9k_taskwarrior_data_files
  6518. typeset -ga _p9k_taskwarrior_data_non_files
  6519. typeset -g _p9k_taskwarrior_data_sig
  6520. typeset -gA _p9k_taskwarrior_counters
  6521. typeset -gF _p9k_taskwarrior_next_due
  6522. typeset -ga _p9k_asdf_meta_files
  6523. typeset -ga _p9k_asdf_meta_non_files
  6524. typeset -g _p9k_asdf_meta_sig
  6525. # plugin => installed_version_pattern
  6526. # example: (ruby '2.7.0|2.6.3|system' lua 'system' chubaka '1.0.0|system')
  6527. typeset -gA _p9k_asdf_plugins
  6528. # example: (.ruby-version "ruby 1 chubaka 0")
  6529. #
  6530. # - "1" means parse-legacy-file is present
  6531. # - "chubaka" is another plugin that claims to be able to parse .ruby-version
  6532. typeset -gA _p9k_asdf_file_info
  6533. # dir => mtime ':' ${(pj:\0:)files}
  6534. typeset -gA _p9k__asdf_dir2files
  6535. # :file => mtime ':' ${(pj:\0:)tool_versions}
  6536. # plugin:file => mtime ':' version
  6537. typeset -gA _p9k_asdf_file2versions
  6538. # filepath => mtime ':' word
  6539. typeset -gA _p9k__read_word_cache
  6540. # filepath:prefix => mtime ':' versions
  6541. typeset -gA _p9k__read_pyenv_like_version_file_cache
  6542. # _p9k__parent_dirs and _p9k__parent_mtimes are parallel arrays. They are updated
  6543. # together with _p9k__cwd. _p9k__parent_mtimes[i] is mtime for _p9k__parent_dirs[i].
  6544. #
  6545. # When _p9k__cwd is / or ~, both arrays are empty. When _p9k__cwd is ~/foo/bar,
  6546. # _p9k__parent_dirs is (/home/user/foo/bar /home/user/foo). When _p9k__cwd is
  6547. # /foo/bar, it's (/foo/bar /foo).
  6548. #
  6549. # $_p9k__parent_mtimes_i[i] == "$i:$_p9k__parent_mtimes[i]"
  6550. # $_p9k__parent_mtimes_s == "$_p9k__parent_mtimes_i".
  6551. typeset -ga _p9k__parent_dirs
  6552. typeset -ga _p9k__parent_mtimes
  6553. typeset -ga _p9k__parent_mtimes_i
  6554. typeset -g _p9k__parent_mtimes_s
  6555. typeset -g _p9k__cwd
  6556. typeset -g _p9k__cwd_a
  6557. # dir/pattern => dir mtime ':' num_matches
  6558. typeset -gA _p9k__glob_cache
  6559. # dir/pattern => space-separated parent dir mtimes ' :' the first matching parent dir
  6560. # Note: ' :' is indeed the delimiter.
  6561. typeset -gA _p9k__upsearch_cache
  6562. typeset -g _p9k_timewarrior_dir
  6563. typeset -gi _p9k_timewarrior_dir_mtime
  6564. typeset -gi _p9k_timewarrior_file_mtime
  6565. typeset -g _p9k_timewarrior_file_name
  6566. typeset -gA _p9k__prompt_char_saved
  6567. typeset -g _p9k__worker_pid
  6568. typeset -g _p9k__worker_req_fd
  6569. typeset -g _p9k__worker_resp_fd
  6570. typeset -g _p9k__worker_shell_pid
  6571. typeset -g _p9k__worker_file_prefix
  6572. typeset -gA _p9k__worker_request_map
  6573. typeset -ga _p9k__segment_cond_left
  6574. typeset -ga _p9k__segment_cond_right
  6575. typeset -ga _p9k__segment_val_left
  6576. typeset -ga _p9k__segment_val_right
  6577. typeset -ga _p9k_show_on_command
  6578. typeset -g _p9k__last_buffer
  6579. typeset -ga _p9k__last_commands
  6580. typeset -gi _p9k__fully_initialized
  6581. typeset -gi _p9k__must_restore_prompt
  6582. typeset -gi _p9k__restore_prompt_fd
  6583. typeset -gi _p9k__redraw_fd
  6584. typeset -gi _p9k__can_hide_cursor=$(( $+terminfo[civis] && $+terminfo[cnorm] ))
  6585. if (( _p9k__can_hide_cursor )); then
  6586. # See https://github.com/romkatv/powerlevel10k/issues/1699
  6587. if [[ $terminfo[cnorm] == *$'\e[?25h'(|'\e'*) ]]; then
  6588. typeset -g _p9k__cnorm=$'\e[?25h'
  6589. else
  6590. typeset -g _p9k__cnorm=$terminfo[cnorm]
  6591. fi
  6592. fi
  6593. typeset -gi _p9k__cursor_hidden
  6594. typeset -gi _p9k__non_hermetic_expansion
  6595. typeset -g _p9k__time
  6596. typeset -g _p9k__date
  6597. typeset -gA _p9k_dumped_instant_prompt_sigs
  6598. typeset -g _p9k__instant_prompt_sig
  6599. typeset -g _p9k__instant_prompt
  6600. typeset -gi _p9k__state_dump_scheduled
  6601. typeset -gi _p9k__state_dump_fd
  6602. typeset -gi _p9k__prompt_idx
  6603. typeset -gi _p9k_reset_on_line_finish
  6604. typeset -gF _p9k__timer_start
  6605. typeset -gi _p9k__status
  6606. typeset -ga _p9k__pipestatus
  6607. typeset -g _p9k__ret
  6608. typeset -g _p9k__cache_key
  6609. typeset -ga _p9k__cache_val
  6610. typeset -g _p9k__cache_stat_meta
  6611. typeset -g _p9k__cache_stat_fprint
  6612. typeset -g _p9k__cache_fprint_key
  6613. typeset -gA _p9k_cache
  6614. typeset -gA _p9k__cache_ephemeral
  6615. typeset -ga _p9k_t
  6616. typeset -g _p9k__n
  6617. typeset -gi _p9k__i
  6618. typeset -g _p9k__bg
  6619. typeset -ga _p9k_left_join
  6620. typeset -ga _p9k_right_join
  6621. typeset -g _p9k__public_ip
  6622. typeset -g _p9k__todo_command
  6623. typeset -g _p9k__todo_file
  6624. typeset -g _p9k__git_dir
  6625. # git workdir => 1 if gitstatus is slow on it, 0 if it's fast.
  6626. typeset -gA _p9k_git_slow
  6627. # git workdir => the last state we've seen for it
  6628. typeset -gA _p9k__gitstatus_last
  6629. typeset -gF _p9k__gitstatus_start_time
  6630. typeset -g _p9k__prompt
  6631. typeset -g _p9k__rprompt
  6632. typeset -g _p9k__lprompt
  6633. typeset -g _p9k__prompt_side
  6634. typeset -g _p9k__segment_name
  6635. typeset -gi _p9k__segment_index
  6636. typeset -gi _p9k__line_index
  6637. typeset -g _p9k__refresh_reason
  6638. typeset -gi _p9k__region_active
  6639. typeset -ga _p9k_line_segments_left
  6640. typeset -ga _p9k_line_segments_right
  6641. typeset -ga _p9k_line_prefix_left
  6642. typeset -ga _p9k_line_prefix_right
  6643. typeset -ga _p9k_line_suffix_left
  6644. typeset -ga _p9k_line_suffix_right
  6645. typeset -ga _p9k_line_never_empty_right
  6646. typeset -ga _p9k_line_gap_post
  6647. typeset -g _p9k__xy
  6648. typeset -g _p9k__clm
  6649. typeset -g _p9k__p
  6650. typeset -gi _p9k__x
  6651. typeset -gi _p9k__y
  6652. typeset -gi _p9k__m
  6653. typeset -gi _p9k__d
  6654. typeset -gi _p9k__h
  6655. typeset -gi _p9k__ind
  6656. typeset -g _p9k_gap_pre
  6657. typeset -gi _p9k__ruler_i=3
  6658. typeset -gi _p9k_ruler_idx
  6659. typeset -gi _p9k__empty_line_i=3
  6660. typeset -gi _p9k_empty_line_idx
  6661. typeset -g _p9k_prompt_prefix_left
  6662. typeset -g _p9k_prompt_prefix_right
  6663. typeset -g _p9k_prompt_suffix_left
  6664. typeset -g _p9k_prompt_suffix_right
  6665. typeset -gi _p9k_emulate_zero_rprompt_indent
  6666. typeset -gA _p9k_battery_states
  6667. typeset -g _p9k_os
  6668. typeset -g _p9k_os_icon
  6669. typeset -g _p9k_color1
  6670. typeset -g _p9k_color2
  6671. typeset -g _p9k__s
  6672. typeset -g _p9k__ss
  6673. typeset -g _p9k__sss
  6674. typeset -g _p9k__v
  6675. typeset -g _p9k__c
  6676. typeset -g _p9k__e
  6677. typeset -g _p9k__w
  6678. typeset -gi _p9k__dir_len
  6679. typeset -gi _p9k_num_cpus
  6680. typeset -g _p9k__keymap
  6681. typeset -g _p9k__zle_state
  6682. typeset -g _p9k_uname
  6683. typeset -g _p9k_uname_o
  6684. typeset -g _p9k_uname_m
  6685. typeset -g _p9k_transient_prompt
  6686. typeset -g _p9k__last_prompt_pwd
  6687. typeset -gA _p9k_display_k
  6688. typeset -ga _p9k__display_v
  6689. typeset -gA _p9k__dotnet_stat_cache
  6690. typeset -gA _p9k__dir_stat_cache
  6691. typeset -gi _p9k__expanded
  6692. typeset -gi _p9k__force_must_init
  6693. typeset -g P9K_VISUAL_IDENTIFIER
  6694. typeset -g P9K_CONTENT
  6695. typeset -g P9K_GAP
  6696. typeset -g P9K_PROMPT=regular
  6697. }
  6698. _p9k_init_params() {
  6699. _p9k_declare -F POWERLEVEL9K_GCLOUD_REFRESH_PROJECT_NAME_SECONDS 60
  6700. # invarint: _POWERLEVEL9K_INSTANT_PROMPT == (verbose|quiet|off)
  6701. # invariant: [[ ($_POWERLEVEL9K_INSTANT_PROMPT == off) == $_POWERLEVEL9K_DISABLE_INSTANT_PROMPT ]]
  6702. _p9k_declare -s POWERLEVEL9K_INSTANT_PROMPT # verbose, quiet, off
  6703. if [[ $_POWERLEVEL9K_INSTANT_PROMPT == off ]]; then
  6704. typeset -gi _POWERLEVEL9K_DISABLE_INSTANT_PROMPT=1
  6705. else
  6706. _p9k_declare -b POWERLEVEL9K_DISABLE_INSTANT_PROMPT 0
  6707. if (( _POWERLEVEL9K_DISABLE_INSTANT_PROMPT )); then
  6708. _POWERLEVEL9K_INSTANT_PROMPT=off
  6709. elif [[ $_POWERLEVEL9K_INSTANT_PROMPT != quiet ]]; then
  6710. _POWERLEVEL9K_INSTANT_PROMPT=verbose
  6711. fi
  6712. fi
  6713. (( _POWERLEVEL9K_DISABLE_INSTANT_PROMPT )) && _p9k__instant_prompt_disabled=1
  6714. _p9k_declare -s POWERLEVEL9K_TRANSIENT_PROMPT off
  6715. [[ $_POWERLEVEL9K_TRANSIENT_PROMPT == (off|always|same-dir) ]] || _POWERLEVEL9K_TRANSIENT_PROMPT=off
  6716. _p9k_declare -b POWERLEVEL9K_TERM_SHELL_INTEGRATION 0
  6717. if [[ __p9k_force_term_shell_integration -eq 1 || $ITERM_SHELL_INTEGRATION_INSTALLED == Yes ]]; then
  6718. _POWERLEVEL9K_TERM_SHELL_INTEGRATION=1
  6719. fi
  6720. _p9k_declare -s POWERLEVEL9K_WORKER_LOG_LEVEL
  6721. _p9k_declare -i POWERLEVEL9K_COMMANDS_MAX_TOKEN_COUNT 64
  6722. _p9k_declare -a POWERLEVEL9K_HOOK_WIDGETS --
  6723. _p9k_declare -b POWERLEVEL9K_TODO_HIDE_ZERO_TOTAL 0
  6724. _p9k_declare -b POWERLEVEL9K_TODO_HIDE_ZERO_FILTERED 0
  6725. _p9k_declare -b POWERLEVEL9K_DISABLE_HOT_RELOAD 0
  6726. _p9k_declare -F POWERLEVEL9K_NEW_TTY_MAX_AGE_SECONDS 5
  6727. _p9k_declare -i POWERLEVEL9K_INSTANT_PROMPT_COMMAND_LINES
  6728. _p9k_declare -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS -- context dir vcs
  6729. _p9k_declare -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS -- status root_indicator background_jobs history time
  6730. _p9k_declare -b POWERLEVEL9K_DISABLE_RPROMPT 0
  6731. _p9k_declare -b POWERLEVEL9K_PROMPT_ADD_NEWLINE 0
  6732. _p9k_declare -b POWERLEVEL9K_PROMPT_ON_NEWLINE 0
  6733. _p9k_declare -b POWERLEVEL9K_RPROMPT_ON_NEWLINE 0
  6734. _p9k_declare -b POWERLEVEL9K_SHOW_RULER 0
  6735. _p9k_declare -i POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT 1
  6736. _p9k_declare -s POWERLEVEL9K_COLOR_SCHEME dark
  6737. _p9k_declare -s POWERLEVEL9K_GITSTATUS_DIR ""
  6738. _p9k_declare -s POWERLEVEL9K_VCS_DISABLED_WORKDIR_PATTERN
  6739. _p9k_declare -b POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY 0
  6740. _p9k_declare -i POWERLEVEL9K_VCS_SHORTEN_LENGTH
  6741. _p9k_declare -i POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH
  6742. _p9k_declare -s POWERLEVEL9K_VCS_SHORTEN_STRATEGY
  6743. if [[ $langinfo[CODESET] == (utf|UTF)(-|)8 ]]; then
  6744. _p9k_declare -e POWERLEVEL9K_VCS_SHORTEN_DELIMITER '\u2026'
  6745. else
  6746. _p9k_declare -e POWERLEVEL9K_VCS_SHORTEN_DELIMITER '..'
  6747. fi
  6748. _p9k_declare -b POWERLEVEL9K_VCS_CONFLICTED_STATE 0
  6749. _p9k_declare -b POWERLEVEL9K_HIDE_BRANCH_ICON 0
  6750. _p9k_declare -b POWERLEVEL9K_VCS_HIDE_TAGS 0
  6751. _p9k_declare -i POWERLEVEL9K_CHANGESET_HASH_LENGTH 8
  6752. # Specifies the maximum number of elements in the cache. When the cache grows over this limit,
  6753. # it gets cleared. This is meant to avoid memory leaks when a rogue prompt is filling the cache
  6754. # with data.
  6755. _p9k_declare -i POWERLEVEL9K_MAX_CACHE_SIZE 10000
  6756. _p9k_declare -e POWERLEVEL9K_ANACONDA_LEFT_DELIMITER "("
  6757. _p9k_declare -e POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER ")"
  6758. _p9k_declare -b POWERLEVEL9K_ANACONDA_SHOW_PYTHON_VERSION 1
  6759. _p9k_declare -b POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE 1
  6760. _p9k_declare -b POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE_ALWAYS 0
  6761. _p9k_declare -b POWERLEVEL9K_DISK_USAGE_ONLY_WARNING 0
  6762. _p9k_declare -i POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL 90
  6763. _p9k_declare -i POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL 95
  6764. _p9k_declare -i POWERLEVEL9K_BATTERY_LOW_THRESHOLD 10
  6765. _p9k_declare -i POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD 999
  6766. _p9k_declare -b POWERLEVEL9K_BATTERY_VERBOSE 1
  6767. _p9k_declare -a POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND --
  6768. _p9k_declare -a POWERLEVEL9K_BATTERY_LEVEL_FOREGROUND --
  6769. case $parameters[POWERLEVEL9K_BATTERY_STAGES] in
  6770. scalar*) typeset -ga _POWERLEVEL9K_BATTERY_STAGES=("${(@s::)${(g::)POWERLEVEL9K_BATTERY_STAGES}}");;
  6771. array*) typeset -ga _POWERLEVEL9K_BATTERY_STAGES=("${(@g::)POWERLEVEL9K_BATTERY_STAGES}");;
  6772. *) typeset -ga _POWERLEVEL9K_BATTERY_STAGES=();;
  6773. esac
  6774. local state
  6775. for state in CHARGED CHARGING LOW DISCONNECTED; do
  6776. _p9k_declare -i POWERLEVEL9K_BATTERY_${state}_HIDE_ABOVE_THRESHOLD $_POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD
  6777. local var=POWERLEVEL9K_BATTERY_${state}_STAGES
  6778. case $parameters[$var] in
  6779. scalar*) eval "typeset -ga _$var=(${(@qq)${(@s::)${(g::)${(P)var}}}})";;
  6780. array*) eval "typeset -ga _$var=(${(@qq)${(@g::)${(@P)var}}})";;
  6781. *) eval "typeset -ga _$var=(${(@qq)_POWERLEVEL9K_BATTERY_STAGES})";;
  6782. esac
  6783. local var=POWERLEVEL9K_BATTERY_${state}_LEVEL_BACKGROUND
  6784. case $parameters[$var] in
  6785. array*) eval "typeset -ga _$var=(${(@qq)${(@P)var}})";;
  6786. *) eval "typeset -ga _$var=(${(@qq)_POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND})";;
  6787. esac
  6788. local var=POWERLEVEL9K_BATTERY_${state}_LEVEL_FOREGROUND
  6789. case $parameters[$var] in
  6790. array*) eval "typeset -ga _$var=(${(@qq)${(@P)var}})";;
  6791. *) eval "typeset -ga _$var=(${(@qq)_POWERLEVEL9K_BATTERY_LEVEL_FOREGROUND})";;
  6792. esac
  6793. done
  6794. _p9k_declare -F POWERLEVEL9K_PUBLIC_IP_TIMEOUT 300
  6795. _p9k_declare -a POWERLEVEL9K_PUBLIC_IP_METHODS -- dig curl wget
  6796. _p9k_declare -e POWERLEVEL9K_PUBLIC_IP_NONE ""
  6797. _p9k_declare -s POWERLEVEL9K_PUBLIC_IP_HOST "https://v4.ident.me/"
  6798. _p9k_declare -s POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ""
  6799. _p9k_segment_in_use public_ip || _POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE=
  6800. _p9k_declare -b POWERLEVEL9K_ALWAYS_SHOW_CONTEXT 0
  6801. _p9k_declare -b POWERLEVEL9K_ALWAYS_SHOW_USER 0
  6802. _p9k_declare -e POWERLEVEL9K_CONTEXT_TEMPLATE "%n@%m"
  6803. _p9k_declare -e POWERLEVEL9K_USER_TEMPLATE "%n"
  6804. _p9k_declare -e POWERLEVEL9K_HOST_TEMPLATE "%m"
  6805. _p9k_declare -F POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD 3
  6806. _p9k_declare -i POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION 2
  6807. # Other options: "d h m s".
  6808. _p9k_declare -s POWERLEVEL9K_COMMAND_EXECUTION_TIME_FORMAT "H:M:S"
  6809. _p9k_declare -e POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~"
  6810. _p9k_declare -b POWERLEVEL9K_DIR_PATH_ABSOLUTE 0
  6811. _p9k_declare -s POWERLEVEL9K_DIR_SHOW_WRITABLE ''
  6812. case $_POWERLEVEL9K_DIR_SHOW_WRITABLE in
  6813. true) _POWERLEVEL9K_DIR_SHOW_WRITABLE=1;;
  6814. v2) _POWERLEVEL9K_DIR_SHOW_WRITABLE=2;;
  6815. v3) _POWERLEVEL9K_DIR_SHOW_WRITABLE=3;;
  6816. *) _POWERLEVEL9K_DIR_SHOW_WRITABLE=0;;
  6817. esac
  6818. typeset -gi _POWERLEVEL9K_DIR_SHOW_WRITABLE
  6819. _p9k_declare -b POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER 0
  6820. _p9k_declare -b POWERLEVEL9K_DIR_HYPERLINK 0
  6821. _p9k_declare -s POWERLEVEL9K_SHORTEN_STRATEGY ""
  6822. local markers=(
  6823. .bzr
  6824. .citc
  6825. .git
  6826. .hg
  6827. .node-version
  6828. .python-version
  6829. .ruby-version
  6830. .shorten_folder_marker
  6831. .svn
  6832. .terraform
  6833. CVS
  6834. Cargo.toml
  6835. composer.json
  6836. go.mod
  6837. package.json
  6838. )
  6839. _p9k_declare -s POWERLEVEL9K_SHORTEN_FOLDER_MARKER "(${(j:|:)markers})"
  6840. # Shorten directory if it's longer than this even if there is space for it.
  6841. # The value can be either absolute (e.g., '80') or a percentage of terminal
  6842. # width (e.g, '50%'). If empty, directory will be shortened only when prompt
  6843. # doesn't fit. Applies only when POWERLEVEL9K_SHORTEN_STRATEGY=truncate_to_unique.
  6844. _p9k_declare -s POWERLEVEL9K_DIR_MAX_LENGTH 0
  6845. # Individual elements are patterns. They are expanded with the options set
  6846. # by `emulate zsh && setopt extended_glob`.
  6847. _p9k_declare -a POWERLEVEL9K_DIR_PACKAGE_FILES -- package.json composer.json
  6848. # When dir is on the last prompt line, try to shorten it enough to leave at least this many
  6849. # columns for typing commands. Applies only when POWERLEVEL9K_SHORTEN_STRATEGY=truncate_to_unique.
  6850. _p9k_declare -i POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS 40
  6851. # When dir is on the last prompt line, try to shorten it enough to leave at least
  6852. # COLUMNS * POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS_PCT * 0.01 columns for typing commands. Applies
  6853. # only when POWERLEVEL9K_SHORTEN_STRATEGY=truncate_to_unique.
  6854. _p9k_declare -F POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS_PCT 50
  6855. # POWERLEVEL9K_DIR_CLASSES allow you to specify custom styling and icons for different
  6856. # directories.
  6857. #
  6858. # POWERLEVEL9K_DIR_CLASSES must be an array with 3 * N elements. Each triplet consists of:
  6859. #
  6860. # 1. A pattern against which the current directory is matched. Matching is done with
  6861. # extended_glob option enabled.
  6862. # 2. Directory class for the purpose of styling.
  6863. # 3. Icon.
  6864. #
  6865. # Triplets are tried in order. The first triplet whose pattern matches $PWD wins. If there are no
  6866. # matches, there will be no icon and the styling is done according to POWERLEVEL9K_DIR_BACKGROUND,
  6867. # POWERLEVEL9K_DIR_FOREGROUND, etc.
  6868. #
  6869. # Example:
  6870. #
  6871. # POWERLEVEL9K_DIR_CLASSES=(
  6872. # '~/work(/*)#' WORK '(╯°□°)╯︵ ┻━┻'
  6873. # '~(/*)#' HOME '⌂'
  6874. # '*' DEFAULT '')
  6875. #
  6876. # POWERLEVEL9K_DIR_WORK_BACKGROUND=red
  6877. # POWERLEVEL9K_DIR_HOME_BACKGROUND=blue
  6878. # POWERLEVEL9K_DIR_DEFAULT_BACKGROUND=yellow
  6879. #
  6880. # With these settings, the current directory in the prompt may look like this:
  6881. #
  6882. # (╯°□°)╯︵ ┻━┻ ~/work/projects/important/urgent
  6883. #
  6884. # ⌂ ~/best/powerlevel10k
  6885. _p9k_declare -a POWERLEVEL9K_DIR_CLASSES
  6886. _p9k_declare -i POWERLEVEL9K_SHORTEN_DELIMITER_LENGTH
  6887. _p9k_declare -e POWERLEVEL9K_SHORTEN_DELIMITER
  6888. _p9k_declare -s POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER ''
  6889. case $_POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER in
  6890. first|last) _POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER+=:0;;
  6891. (first|last):(|-)<->);;
  6892. *) _POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER=;;
  6893. esac
  6894. [[ -z $_POWERLEVEL9K_SHORTEN_FOLDER_MARKER ]] && _POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER=
  6895. _p9k_declare -i POWERLEVEL9K_SHORTEN_DIR_LENGTH
  6896. _p9k_declare -s POWERLEVEL9K_IP_INTERFACE ""
  6897. : ${_POWERLEVEL9K_IP_INTERFACE:='.*'}
  6898. _p9k_segment_in_use ip || _POWERLEVEL9K_IP_INTERFACE=
  6899. _p9k_declare -s POWERLEVEL9K_VPN_IP_INTERFACE "(gpd|wg|(.*tun)|tailscale)[0-9]*|(zt.*)"
  6900. : ${_POWERLEVEL9K_VPN_IP_INTERFACE:='.*'}
  6901. _p9k_segment_in_use vpn_ip || _POWERLEVEL9K_VPN_IP_INTERFACE=
  6902. _p9k_declare -b POWERLEVEL9K_VPN_IP_SHOW_ALL 0
  6903. _p9k_declare -i POWERLEVEL9K_LOAD_WHICH 5
  6904. case $_POWERLEVEL9K_LOAD_WHICH in
  6905. 1) _POWERLEVEL9K_LOAD_WHICH=1;;
  6906. 15) _POWERLEVEL9K_LOAD_WHICH=3;;
  6907. *) _POWERLEVEL9K_LOAD_WHICH=2;;
  6908. esac
  6909. _p9k_declare -F POWERLEVEL9K_LOAD_WARNING_PCT 50
  6910. _p9k_declare -F POWERLEVEL9K_LOAD_CRITICAL_PCT 70
  6911. _p9k_declare -b POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY 0
  6912. _p9k_declare -b POWERLEVEL9K_PHP_VERSION_PROJECT_ONLY 0
  6913. _p9k_declare -b POWERLEVEL9K_DOTNET_VERSION_PROJECT_ONLY 1
  6914. _p9k_declare -b POWERLEVEL9K_GO_VERSION_PROJECT_ONLY 1
  6915. _p9k_declare -b POWERLEVEL9K_RUST_VERSION_PROJECT_ONLY 1
  6916. _p9k_declare -b POWERLEVEL9K_PERLBREW_PROJECT_ONLY 1
  6917. _p9k_declare -b POWERLEVEL9K_PERLBREW_SHOW_PREFIX 0
  6918. _p9k_declare -b POWERLEVEL9K_JAVA_VERSION_PROJECT_ONLY 0
  6919. _p9k_declare -b POWERLEVEL9K_NODENV_PROMPT_ALWAYS_SHOW 0
  6920. _p9k_declare -a POWERLEVEL9K_NODENV_SOURCES -- shell local global
  6921. _p9k_declare -b POWERLEVEL9K_NODENV_SHOW_SYSTEM 1
  6922. _p9k_declare -b POWERLEVEL9K_NVM_PROMPT_ALWAYS_SHOW 0
  6923. _p9k_declare -b POWERLEVEL9K_NVM_SHOW_SYSTEM 1
  6924. _p9k_declare -b POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW 0
  6925. _p9k_declare -a POWERLEVEL9K_RBENV_SOURCES -- shell local global
  6926. _p9k_declare -b POWERLEVEL9K_RBENV_SHOW_SYSTEM 1
  6927. _p9k_declare -b POWERLEVEL9K_SCALAENV_PROMPT_ALWAYS_SHOW 0
  6928. _p9k_declare -a POWERLEVEL9K_SCALAENV_SOURCES -- shell local global
  6929. _p9k_declare -b POWERLEVEL9K_SCALAENV_SHOW_SYSTEM 1
  6930. _p9k_declare -b POWERLEVEL9K_PHPENV_PROMPT_ALWAYS_SHOW 0
  6931. _p9k_declare -a POWERLEVEL9K_PHPENV_SOURCES -- shell local global
  6932. _p9k_declare -b POWERLEVEL9K_PHPENV_SHOW_SYSTEM 1
  6933. _p9k_declare -b POWERLEVEL9K_LUAENV_PROMPT_ALWAYS_SHOW 0
  6934. _p9k_declare -a POWERLEVEL9K_LUAENV_SOURCES -- shell local global
  6935. _p9k_declare -b POWERLEVEL9K_LUAENV_SHOW_SYSTEM 1
  6936. _p9k_declare -b POWERLEVEL9K_JENV_PROMPT_ALWAYS_SHOW 0
  6937. _p9k_declare -a POWERLEVEL9K_JENV_SOURCES -- shell local global
  6938. _p9k_declare -b POWERLEVEL9K_JENV_SHOW_SYSTEM 1
  6939. _p9k_declare -b POWERLEVEL9K_PLENV_PROMPT_ALWAYS_SHOW 0
  6940. _p9k_declare -a POWERLEVEL9K_PLENV_SOURCES -- shell local global
  6941. _p9k_declare -b POWERLEVEL9K_PLENV_SHOW_SYSTEM 1
  6942. _p9k_declare -b POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW 0
  6943. _p9k_declare -b POWERLEVEL9K_PYENV_SHOW_SYSTEM 1
  6944. _p9k_declare -a POWERLEVEL9K_PYENV_SOURCES -- shell local global
  6945. _p9k_declare -b POWERLEVEL9K_GOENV_PROMPT_ALWAYS_SHOW 0
  6946. _p9k_declare -a POWERLEVEL9K_GOENV_SOURCES -- shell local global
  6947. _p9k_declare -b POWERLEVEL9K_GOENV_SHOW_SYSTEM 1
  6948. _p9k_declare -b POWERLEVEL9K_ASDF_PROMPT_ALWAYS_SHOW 0
  6949. _p9k_declare -b POWERLEVEL9K_ASDF_SHOW_SYSTEM 1
  6950. _p9k_declare -a POWERLEVEL9K_ASDF_SOURCES -- shell local global
  6951. local var
  6952. for var in ${parameters[(I)POWERLEVEL9K_ASDF_*_PROMPT_ALWAYS_SHOW]}; do
  6953. _p9k_declare -b $var $_POWERLEVEL9K_ASDF_PROMPT_ALWAYS_SHOW
  6954. done
  6955. for var in ${parameters[(I)POWERLEVEL9K_ASDF_*_SHOW_SYSTEM]}; do
  6956. _p9k_declare -b $var $_POWERLEVEL9K_ASDF_SHOW_SYSTEM
  6957. done
  6958. for var in ${parameters[(I)POWERLEVEL9K_ASDF_*_SOURCES]}; do
  6959. _p9k_declare -a $var -- $_POWERLEVEL9K_ASDF_SOURCES
  6960. done
  6961. _p9k_declare -b POWERLEVEL9K_HASKELL_STACK_PROMPT_ALWAYS_SHOW 1
  6962. _p9k_declare -a POWERLEVEL9K_HASKELL_STACK_SOURCES -- shell local
  6963. _p9k_declare -b POWERLEVEL9K_RVM_SHOW_GEMSET 0
  6964. _p9k_declare -b POWERLEVEL9K_RVM_SHOW_PREFIX 0
  6965. _p9k_declare -b POWERLEVEL9K_CHRUBY_SHOW_VERSION 1
  6966. _p9k_declare -b POWERLEVEL9K_CHRUBY_SHOW_ENGINE 1
  6967. _p9k_declare -s POWERLEVEL9K_CHRUBY_SHOW_ENGINE_PATTERN
  6968. if (( _POWERLEVEL9K_CHRUBY_SHOW_ENGINE )); then
  6969. : ${_POWERLEVEL9K_CHRUBY_SHOW_ENGINE_PATTERN=*}
  6970. fi
  6971. _p9k_declare -b POWERLEVEL9K_STATUS_CROSS 0
  6972. _p9k_declare -b POWERLEVEL9K_STATUS_OK 1
  6973. _p9k_declare -b POWERLEVEL9K_STATUS_OK_PIPE 1
  6974. _p9k_declare -b POWERLEVEL9K_STATUS_ERROR 1
  6975. _p9k_declare -b POWERLEVEL9K_STATUS_ERROR_PIPE 1
  6976. _p9k_declare -b POWERLEVEL9K_STATUS_ERROR_SIGNAL 1
  6977. _p9k_declare -b POWERLEVEL9K_STATUS_SHOW_PIPESTATUS 1
  6978. _p9k_declare -b POWERLEVEL9K_STATUS_HIDE_SIGNAME 0
  6979. _p9k_declare -b POWERLEVEL9K_STATUS_VERBOSE_SIGNAME 1
  6980. _p9k_declare -b POWERLEVEL9K_STATUS_EXTENDED_STATES 0
  6981. _p9k_declare -b POWERLEVEL9K_STATUS_VERBOSE 1
  6982. _p9k_declare -b POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE 0
  6983. _p9k_declare -e POWERLEVEL9K_DATE_FORMAT "%D{%d.%m.%y}"
  6984. _p9k_declare -s POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND 1
  6985. _p9k_declare -b POWERLEVEL9K_SHOW_CHANGESET 0
  6986. _p9k_declare -e POWERLEVEL9K_VCS_LOADING_TEXT loading
  6987. _p9k_declare -a POWERLEVEL9K_VCS_GIT_HOOKS -- vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname
  6988. _p9k_declare -a POWERLEVEL9K_VCS_HG_HOOKS -- vcs-detect-changes
  6989. _p9k_declare -a POWERLEVEL9K_VCS_SVN_HOOKS -- vcs-detect-changes svn-detect-changes
  6990. # If it takes longer than this to fetch git repo status, display the prompt with a greyed out
  6991. # vcs segment and fix it asynchronously when the results come it.
  6992. _p9k_declare -F POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS 0.01
  6993. (( POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS >= 0 )) || (( POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS = 0 ))
  6994. _p9k_declare -a POWERLEVEL9K_VCS_BACKENDS -- git
  6995. (( $+commands[git] )) || _POWERLEVEL9K_VCS_BACKENDS=(${_POWERLEVEL9K_VCS_BACKENDS:#git})
  6996. _p9k_declare -b POWERLEVEL9K_VCS_DISABLE_GITSTATUS_FORMATTING 0
  6997. _p9k_declare -i POWERLEVEL9K_VCS_MAX_INDEX_SIZE_DIRTY -1
  6998. _p9k_declare -i POWERLEVEL9K_VCS_STAGED_MAX_NUM 1
  6999. _p9k_declare -i POWERLEVEL9K_VCS_UNSTAGED_MAX_NUM 1
  7000. _p9k_declare -i POWERLEVEL9K_VCS_UNTRACKED_MAX_NUM 1
  7001. _p9k_declare -i POWERLEVEL9K_VCS_CONFLICTED_MAX_NUM 1
  7002. _p9k_declare -i POWERLEVEL9K_VCS_COMMITS_AHEAD_MAX_NUM -1
  7003. _p9k_declare -i POWERLEVEL9K_VCS_COMMITS_BEHIND_MAX_NUM -1
  7004. _p9k_declare -b POWERLEVEL9K_VCS_RECURSE_UNTRACKED_DIRS 0
  7005. _p9k_declare -F POWERLEVEL9K_GITSTATUS_INIT_TIMEOUT_SEC 10
  7006. _p9k_declare -b POWERLEVEL9K_DISABLE_GITSTATUS 0
  7007. _p9k_declare -e POWERLEVEL9K_VI_INSERT_MODE_STRING "INSERT"
  7008. _p9k_declare -e POWERLEVEL9K_VI_COMMAND_MODE_STRING "NORMAL"
  7009. # VISUAL mode is shown as NORMAL unless POWERLEVEL9K_VI_VISUAL_MODE_STRING is explicitly set.
  7010. _p9k_declare -e POWERLEVEL9K_VI_VISUAL_MODE_STRING
  7011. # OVERWRITE mode is shown as INSERT unless POWERLEVEL9K_VI_OVERWRITE_MODE_STRING is explicitly set.
  7012. _p9k_declare -e POWERLEVEL9K_VI_OVERWRITE_MODE_STRING
  7013. _p9k_declare -s POWERLEVEL9K_VIRTUALENV_SHOW_WITH_PYENV true
  7014. _p9k_declare -b POWERLEVEL9K_VIRTUALENV_SHOW_PYTHON_VERSION 1
  7015. _p9k_declare -e POWERLEVEL9K_VIRTUALENV_LEFT_DELIMITER "("
  7016. _p9k_declare -e POWERLEVEL9K_VIRTUALENV_RIGHT_DELIMITER ")"
  7017. _p9k_declare -a POWERLEVEL9K_VIRTUALENV_GENERIC_NAMES -- virtualenv venv .venv env
  7018. _POWERLEVEL9K_VIRTUALENV_GENERIC_NAMES="${(j.|.)_POWERLEVEL9K_VIRTUALENV_GENERIC_NAMES}"
  7019. _p9k_declare -b POWERLEVEL9K_NODEENV_SHOW_NODE_VERSION 1
  7020. _p9k_declare -e POWERLEVEL9K_NODEENV_LEFT_DELIMITER "["
  7021. _p9k_declare -e POWERLEVEL9K_NODEENV_RIGHT_DELIMITER "]"
  7022. _p9k_declare -b POWERLEVEL9K_KUBECONTEXT_SHOW_DEFAULT_NAMESPACE 1
  7023. _p9k_declare -a POWERLEVEL9K_KUBECONTEXT_SHORTEN --
  7024. # Defines context classes for the purpose of applying different styling to different contexts.
  7025. #
  7026. # POWERLEVEL9K_KUBECONTEXT_CLASSES must be an array with even number of elements. The first
  7027. # element in each pair defines a pattern against which the current context (in the format it is
  7028. # displayed in the prompt) gets matched. The second element defines context class. Patterns are
  7029. # tried in order. The first match wins.
  7030. #
  7031. # If a non-empty class <C> is assigned to a context, the segment is styled with
  7032. # POWERLEVEL9K_KUBECONTEXT_<U>_BACKGROUND and POWERLEVEL9K_KUBECONTEXT_<U>_FOREGROUND where <U> is
  7033. # uppercased <C>. Otherwise with POWERLEVEL9K_KUBECONTEXT_BACKGROUND and
  7034. # POWERLEVEL9K_KUBECONTEXT_FOREGROUND.
  7035. #
  7036. # Example: Use red background for contexts containing "prod", green for "testing" and yellow for
  7037. # everything else.
  7038. #
  7039. # POWERLEVEL9K_KUBECONTEXT_CLASSES=(
  7040. # '*prod*' prod
  7041. # '*testing*' testing
  7042. # '*' other)
  7043. #
  7044. # POWERLEVEL9K_KUBECONTEXT_PROD_BACKGROUND=red
  7045. # POWERLEVEL9K_KUBECONTEXT_TESTING_BACKGROUND=green
  7046. # POWERLEVEL9K_KUBECONTEXT_OTHER_BACKGROUND=yellow
  7047. _p9k_declare -a POWERLEVEL9K_KUBECONTEXT_CLASSES --
  7048. _p9k_declare -a POWERLEVEL9K_AWS_CLASSES --
  7049. _p9k_declare -a POWERLEVEL9K_AZURE_CLASSES --
  7050. _p9k_declare -a POWERLEVEL9K_TERRAFORM_CLASSES --
  7051. _p9k_declare -b POWERLEVEL9K_TERRAFORM_SHOW_DEFAULT 0
  7052. _p9k_declare -a POWERLEVEL9K_GOOGLE_APP_CRED_CLASSES -- 'service_account:*' SERVICE_ACCOUNT
  7053. # Specifies the format of java version.
  7054. #
  7055. # POWERLEVEL9K_JAVA_VERSION_FULL=true => 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03
  7056. # POWERLEVEL9K_JAVA_VERSION_FULL=false => 1.8.0_212
  7057. #
  7058. # These correspond to `java -fullversion` and `java -version` respectively.
  7059. _p9k_declare -b POWERLEVEL9K_JAVA_VERSION_FULL 1
  7060. _p9k_declare -b POWERLEVEL9K_PROMPT_CHAR_OVERWRITE_STATE 0
  7061. # Format for the current time: 09:51:02. See `man 3 strftime`.
  7062. _p9k_declare -e POWERLEVEL9K_TIME_FORMAT "%D{%H:%M:%S}"
  7063. # If set to true, time will update when you hit enter. This way prompts for the past
  7064. # commands will contain the start times of their commands as opposed to the default
  7065. # behavior where they contain the end times of their preceding commands.
  7066. _p9k_declare -b POWERLEVEL9K_TIME_UPDATE_ON_COMMAND 0
  7067. # If set to true, time will update every second.
  7068. _p9k_declare -b POWERLEVEL9K_EXPERIMENTAL_TIME_REALTIME 0
  7069. _p9k_declare -b POWERLEVEL9K_NIX_SHELL_INFER_FROM_PATH 0
  7070. typeset -g _p9k_nix_shell_cond='${IN_NIX_SHELL:#0}'
  7071. if (( _POWERLEVEL9K_NIX_SHELL_INFER_FROM_PATH )); then
  7072. _p9k_nix_shell_cond+='${path[(r)/nix/store/*]}'
  7073. fi
  7074. local -i i=1
  7075. while (( i <= $#_POWERLEVEL9K_LEFT_PROMPT_ELEMENTS )); do
  7076. local segment=${${(U)_POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[i]}//İ/I}
  7077. local var=POWERLEVEL9K_${segment}_LEFT_DISABLED
  7078. (( $+parameters[$var] )) || var=POWERLEVEL9K_${segment}_DISABLED
  7079. if [[ ${(P)var} == true ]]; then
  7080. _POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[i,i]=()
  7081. else
  7082. (( ++i ))
  7083. fi
  7084. done
  7085. local -i i=1
  7086. while (( i <= $#_POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS )); do
  7087. local segment=${${(U)_POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[i]}//İ/I}
  7088. local var=POWERLEVEL9K_${segment}_RIGHT_DISABLED
  7089. (( $+parameters[$var] )) || var=POWERLEVEL9K_${segment}_DISABLED
  7090. if [[ ${(P)var} == true ]]; then
  7091. _POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[i,i]=()
  7092. else
  7093. (( ++i ))
  7094. fi
  7095. done
  7096. local var
  7097. for var in ${(@)${parameters[(I)POWERLEVEL9K_*]}/(#m)*/${(M)${parameters[_$MATCH]-$MATCH}:#$MATCH}}; do
  7098. case $parameters[$var] in
  7099. (scalar|integer|float)*) typeset -g _$var=${(P)var};;
  7100. array*) eval 'typeset -ga '_$var'=("${'$var'[@]}")';;
  7101. esac
  7102. done
  7103. }
  7104. function _p9k_on_widget_zle-keymap-select() { _p9k_check_visual_mode; __p9k_reset_state=2; }
  7105. function _p9k_on_widget_overwrite-mode() { _p9k_check_visual_mode; __p9k_reset_state=2; }
  7106. function _p9k_on_widget_vi-replace() { _p9k_check_visual_mode; __p9k_reset_state=2; }
  7107. if [[ $ZSH_VERSION == (5.<3->*|<6->.*) ]]; then
  7108. function _p9k_check_visual_mode() {
  7109. [[ ${KEYMAP:-} == vicmd ]] || return 0
  7110. local region=${${REGION_ACTIVE:-0}/2/1}
  7111. [[ $region != $_p9k__region_active ]] || return 0
  7112. _p9k__region_active=$region
  7113. __p9k_reset_state=2
  7114. }
  7115. else
  7116. function _p9k_check_visual_mode() {}
  7117. fi
  7118. function _p9k_on_widget_visual-mode() { _p9k_check_visual_mode; }
  7119. function _p9k_on_widget_visual-line-mode() { _p9k_check_visual_mode; }
  7120. function _p9k_on_widget_deactivate-region() { _p9k_check_visual_mode; }
  7121. function _p9k_on_widget_zle-line-init() {
  7122. (( _p9k__cursor_hidden )) || return 0
  7123. _p9k__cursor_hidden=0
  7124. print -rn -- $_p9k__cnorm
  7125. }
  7126. function _p9k_on_widget_zle-line-finish() {
  7127. (( $+_p9k__line_finished )) && return
  7128. local P9K_PROMPT=transient
  7129. _p9k__line_finished=
  7130. (( _p9k_reset_on_line_finish )) && __p9k_reset_state=2
  7131. (( $+functions[p10k-on-post-prompt] )) && p10k-on-post-prompt
  7132. local -i optimized
  7133. if [[ -n $_p9k_transient_prompt ]]; then
  7134. if [[ $_POWERLEVEL9K_TRANSIENT_PROMPT == always || $_p9k__cwd == $_p9k__last_prompt_pwd ]]; then
  7135. optimized=1
  7136. __p9k_reset_state=2
  7137. else
  7138. _p9k__last_prompt_pwd=$_p9k__cwd
  7139. fi
  7140. fi
  7141. if [[ $1 == int ]]; then
  7142. _p9k__must_restore_prompt=1
  7143. if (( !_p9k__restore_prompt_fd )); then
  7144. sysopen -o cloexec -ru _p9k__restore_prompt_fd /dev/null
  7145. zle -F $_p9k__restore_prompt_fd _p9k_restore_prompt
  7146. fi
  7147. fi
  7148. if (( __p9k_reset_state == 2 )); then
  7149. if (( optimized )); then
  7150. RPROMPT= PROMPT=$_p9k_transient_prompt _p9k_reset_prompt
  7151. else
  7152. _p9k_reset_prompt
  7153. fi
  7154. fi
  7155. _p9k__line_finished='%{%}'
  7156. }
  7157. function _p9k_on_widget_send-break() {
  7158. _p9k_on_widget_zle-line-finish int
  7159. }
  7160. # Usage example: _p9k_display_segment 58 _p9k__1rkubecontext hide
  7161. function _p9k_display_segment() {
  7162. [[ $_p9k__display_v[$1] == $3 ]] && return
  7163. _p9k__display_v[$1]=$3
  7164. [[ $3 == hide ]] && typeset -g $2= || unset $2
  7165. __p9k_reset_state=2
  7166. }
  7167. function _p9k_redraw() {
  7168. zle -F $1
  7169. exec {1}>&-
  7170. _p9k__redraw_fd=0
  7171. () {
  7172. local -h WIDGET=zle-line-pre-redraw
  7173. _p9k_widget_hook ''
  7174. }
  7175. }
  7176. function _p9k_deschedule_redraw() {
  7177. (( _p9k__redraw_fd )) || return
  7178. zle -F $_p9k__redraw_fd
  7179. exec {_p9k__redraw_fd}>&-
  7180. _p9k__redraw_fd=0
  7181. }
  7182. function _p9k_widget_hook() {
  7183. _p9k_deschedule_redraw
  7184. if (( ${+functions[p10k-on-post-widget]} || ${#_p9k_show_on_command} )); then
  7185. local -a P9K_COMMANDS
  7186. if [[ "$_p9k__last_buffer" == "$PREBUFFER$BUFFER" ]]; then
  7187. P9K_COMMANDS=(${_p9k__last_commands[@]})
  7188. else
  7189. _p9k__last_buffer="$PREBUFFER$BUFFER"
  7190. if [[ -n "$_p9k__last_buffer" ]]; then
  7191. # this must run with user options
  7192. _p9k_parse_buffer "$_p9k__last_buffer" $_POWERLEVEL9K_COMMANDS_MAX_TOKEN_COUNT
  7193. fi
  7194. _p9k__last_commands=(${P9K_COMMANDS[@]})
  7195. fi
  7196. fi
  7197. eval "$__p9k_intro"
  7198. (( _p9k__restore_prompt_fd )) && _p9k_restore_prompt $_p9k__restore_prompt_fd
  7199. if [[ $1 == (clear-screen|z4h-clear-screen-*-top) ]]; then
  7200. P9K_TTY=new
  7201. _p9k__expanded=0
  7202. _p9k_reset_prompt
  7203. fi
  7204. __p9k_reset_state=1
  7205. _p9k_check_visual_mode
  7206. local pat idx var
  7207. for pat idx var in $_p9k_show_on_command; do
  7208. if (( $P9K_COMMANDS[(I)$pat] )); then
  7209. _p9k_display_segment $idx $var show
  7210. else
  7211. _p9k_display_segment $idx $var hide
  7212. fi
  7213. done
  7214. (( $+functions[p10k-on-post-widget] )) && p10k-on-post-widget "${@:2}"
  7215. (( $+functions[_p9k_on_widget_$1] )) && _p9k_on_widget_$1
  7216. (( __p9k_reset_state == 2 )) && _p9k_reset_prompt
  7217. __p9k_reset_state=0
  7218. }
  7219. function _p9k_widget() {
  7220. local f=${widgets[._p9k_orig_$1]:-}
  7221. local -i res
  7222. [[ -z $f ]] || {
  7223. [[ $f == user:-z4h-* ]] && {
  7224. "${f#user:}" "${@:2}"
  7225. res=$?
  7226. } || {
  7227. zle ._p9k_orig_$1 -- "${@:2}"
  7228. res=$?
  7229. }
  7230. }
  7231. (( ! __p9k_enabled )) || [[ $CONTEXT != start ]] || _p9k_widget_hook "$@"
  7232. return res
  7233. }
  7234. function _p9k_widget_zle-line-pre-redraw-impl() {
  7235. (( __p9k_enabled )) && [[ $CONTEXT == start ]] || return 0
  7236. ! (( ${+functions[p10k-on-post-widget]} || ${#_p9k_show_on_command} || _p9k__restore_prompt_fd || _p9k__redraw_fd )) &&
  7237. [[ ${KEYMAP:-} != vicmd ]] &&
  7238. return
  7239. (( PENDING || KEYS_QUEUED_COUNT )) && {
  7240. (( _p9k__redraw_fd )) || {
  7241. sysopen -o cloexec -ru _p9k__redraw_fd /dev/null
  7242. zle -F $_p9k__redraw_fd _p9k_redraw
  7243. }
  7244. return
  7245. }
  7246. _p9k_widget_hook zle-line-pre-redraw
  7247. }
  7248. function _p9k_widget_send-break() {
  7249. (( ! __p9k_enabled )) || [[ $CONTEXT != start ]] || {
  7250. _p9k_widget_hook send-break "$@"
  7251. }
  7252. local f=${widgets[._p9k_orig_send-break]:-}
  7253. [[ -z $f ]] || zle ._p9k_orig_send-break -- "$@"
  7254. }
  7255. typeset -gi __p9k_widgets_wrapped=0
  7256. function _p9k_wrap_widgets() {
  7257. (( __p9k_widgets_wrapped )) && return
  7258. typeset -gir __p9k_widgets_wrapped=1
  7259. local -a widget_list
  7260. if [[ $ZSH_VERSION == (5.<3->*|<6->.*) ]]; then
  7261. local -aU widget_list=(
  7262. zle-line-pre-redraw
  7263. zle-line-init
  7264. zle-line-finish
  7265. zle-keymap-select
  7266. overwrite-mode
  7267. vi-replace
  7268. visual-mode
  7269. visual-line-mode
  7270. deactivate-region
  7271. clear-screen
  7272. z4h-clear-screen-soft-top
  7273. z4h-clear-screen-hard-top
  7274. send-break
  7275. $_POWERLEVEL9K_HOOK_WIDGETS
  7276. )
  7277. else
  7278. # There is no zle-line-pre-redraw in zsh < 5.3, so we have to wrap all widgets
  7279. # with key bindings. This costs extra 3ms: 1.5ms to fetch the list of widgets and
  7280. # another 1.5ms to wrap them.
  7281. if [[ -n "$TMPDIR" && ( ( -d "$TMPDIR" && -w "$TMPDIR" ) || ! ( -d /tmp && -w /tmp ) ) ]]; then
  7282. local tmpdir=$TMPDIR
  7283. else
  7284. local tmpdir=/tmp
  7285. fi
  7286. local keymap tmp=$tmpdir/p10k.bindings.$sysparams[pid]
  7287. {
  7288. for keymap in $keymaps; do bindkey -M $keymap; done >$tmp
  7289. local -aU widget_list=(
  7290. zle-isearch-exit
  7291. zle-isearch-update
  7292. zle-line-init
  7293. zle-line-finish
  7294. zle-history-line-set
  7295. zle-keymap-select
  7296. send-break
  7297. $_POWERLEVEL9K_HOOK_WIDGETS
  7298. ${${${(f)"$(<$tmp)"}##* }:#(*\"|.*)}
  7299. )
  7300. } always {
  7301. zf_rm -f -- $tmp
  7302. }
  7303. fi
  7304. local widget
  7305. for widget in $widget_list; do
  7306. if (( ! $+functions[_p9k_widget_$widget] )); then
  7307. functions[_p9k_widget_$widget]='_p9k_widget '${(q)widget}' "$@"'
  7308. fi
  7309. if [[ $widget == zle-* &&
  7310. $widgets[$widget] == user:azhw:* &&
  7311. $functions[add-zle-hook-widget] ]]; then
  7312. add-zle-hook-widget $widget _p9k_widget_$widget
  7313. else
  7314. # The leading dot is to work around bugs in zsh-syntax-highlighting.
  7315. zle -A $widget ._p9k_orig_$widget
  7316. zle -N $widget _p9k_widget_$widget
  7317. fi
  7318. done 2>/dev/null # `zle -A` fails for inexisting widgets and complains to stderr
  7319. case ${widgets[._p9k_orig_zle-line-pre-redraw]:-} in
  7320. user:-z4h-zle-line-pre-redraw)
  7321. function _p9k_widget_zle-line-pre-redraw() {
  7322. -z4h-zle-line-pre-redraw "$@"
  7323. _p9k_widget_zle-line-pre-redraw-impl
  7324. }
  7325. ;;
  7326. ?*)
  7327. function _p9k_widget_zle-line-pre-redraw() {
  7328. zle ._p9k_orig_zle-line-pre-redraw -- "$@"
  7329. local -i res=$?
  7330. _p9k_widget_zle-line-pre-redraw-impl
  7331. return res
  7332. }
  7333. ;;
  7334. '')
  7335. function _p9k_widget_zle-line-pre-redraw() {
  7336. _p9k_widget_zle-line-pre-redraw-impl
  7337. }
  7338. ;;
  7339. esac
  7340. }
  7341. function _p9k_restore_prompt() {
  7342. eval "$__p9k_intro"
  7343. zle -F $1
  7344. exec {1}>&-
  7345. _p9k__restore_prompt_fd=0
  7346. (( _p9k__must_restore_prompt )) || return 0
  7347. _p9k__must_restore_prompt=0
  7348. unset _p9k__line_finished
  7349. _p9k__refresh_reason=restore
  7350. _p9k_set_prompt
  7351. _p9k__refresh_reason=
  7352. _p9k__expanded=0
  7353. _p9k_reset_prompt
  7354. }
  7355. prompt__p9k_internal_nothing() { _p9k__prompt+='${_p9k__sss::=}'; }
  7356. instant_prompt__p9k_internal_nothing() { prompt__p9k_internal_nothing; }
  7357. # _p9k_build_gap_post line_number
  7358. _p9k_build_gap_post() {
  7359. if [[ $1 == 1 ]]; then
  7360. local kind_l=first kind_u=FIRST
  7361. else
  7362. local kind_l=newline kind_u=NEWLINE
  7363. fi
  7364. _p9k_get_icon '' MULTILINE_${kind_u}_PROMPT_GAP_CHAR
  7365. local char=${_p9k__ret:- }
  7366. _p9k_prompt_length $char
  7367. if (( _p9k__ret != 1 || $#char != 1 )); then
  7368. >&2 print -rP -- "%F{red}WARNING!%f %BMULTILINE_${kind_u}_PROMPT_GAP_CHAR%b is not one character long. Will use ' '."
  7369. >&2 print -rP -- "Either change the value of %BPOWERLEVEL9K_MULTILINE_${kind_u}_PROMPT_GAP_CHAR%b or remove it."
  7370. char=' '
  7371. fi
  7372. local style
  7373. _p9k_color prompt_multiline_${kind_l}_prompt_gap BACKGROUND ""
  7374. [[ -n $_p9k__ret ]] && _p9k_background $_p9k__ret
  7375. style+=$_p9k__ret
  7376. _p9k_color prompt_multiline_${kind_l}_prompt_gap FOREGROUND ""
  7377. [[ -n $_p9k__ret ]] && _p9k_foreground $_p9k__ret
  7378. style+=$_p9k__ret
  7379. _p9k_escape_style $style
  7380. style=$_p9k__ret
  7381. local exp=_POWERLEVEL9K_MULTILINE_${kind_u}_PROMPT_GAP_EXPANSION
  7382. (( $+parameters[$exp] )) && exp=${(P)exp} || exp='${P9K_GAP}'
  7383. [[ $char == '.' ]] && local s=',' || local s='.'
  7384. _p9k__ret=$'${${_p9k__g+\n}:-'$style'${${${_p9k__m:#-*}:+'
  7385. _p9k__ret+='${${_p9k__'$1'g+${(pl.$((_p9k__m+1)).. .)}}:-'
  7386. if [[ $exp == '${P9K_GAP}' ]]; then
  7387. _p9k__ret+='${(pl'$s'$((_p9k__m+1))'$s$s$char$s')}'
  7388. else
  7389. _p9k__ret+='${${P9K_GAP::=${(pl'$s'$((_p9k__m+1))'$s$s$char$s')}}+}'
  7390. _p9k__ret+='${:-"'$exp'"}'
  7391. style=1
  7392. fi
  7393. _p9k__ret+='}'
  7394. if (( __p9k_ksh_arrays )); then
  7395. _p9k__ret+=$'$_p9k__rprompt${_p9k_t[$((!_p9k__ind))]}}:-\n}'
  7396. else
  7397. _p9k__ret+=$'$_p9k__rprompt${_p9k_t[$((1+!_p9k__ind))]}}:-\n}'
  7398. fi
  7399. [[ -n $style ]] && _p9k__ret+='%b%k%f'
  7400. _p9k__ret+='}'
  7401. }
  7402. _p9k_init_lines() {
  7403. local -a left_segments=($_POWERLEVEL9K_LEFT_PROMPT_ELEMENTS)
  7404. local -a right_segments=($_POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS)
  7405. if (( _POWERLEVEL9K_PROMPT_ON_NEWLINE )); then
  7406. left_segments+=(newline _p9k_internal_nothing)
  7407. fi
  7408. local -i num_left_lines=$((1 + ${#${(@M)left_segments:#newline}}))
  7409. local -i num_right_lines=$((1 + ${#${(@M)right_segments:#newline}}))
  7410. if (( num_right_lines > num_left_lines )); then
  7411. repeat $((num_right_lines - num_left_lines)) left_segments=(newline $left_segments)
  7412. local -i num_lines=num_right_lines
  7413. else
  7414. if (( _POWERLEVEL9K_RPROMPT_ON_NEWLINE )); then
  7415. repeat $((num_left_lines - num_right_lines)) right_segments=(newline $right_segments)
  7416. else
  7417. repeat $((num_left_lines - num_right_lines)) right_segments+=newline
  7418. fi
  7419. local -i num_lines=num_left_lines
  7420. fi
  7421. local -i i
  7422. for i in {1..$num_lines}; do
  7423. local -i left_end=${left_segments[(i)newline]}
  7424. local -i right_end=${right_segments[(i)newline]}
  7425. _p9k_line_segments_left+="${(pj:\0:)left_segments[1,left_end-1]}"
  7426. _p9k_line_segments_right+="${(pj:\0:)right_segments[1,right_end-1]}"
  7427. (( left_end > $#left_segments )) && left_segments=() || shift left_end left_segments
  7428. (( right_end > $#right_segments )) && right_segments=() || shift right_end right_segments
  7429. _p9k_get_icon '' LEFT_SEGMENT_SEPARATOR
  7430. _p9k_get_icon 'prompt_empty_line' LEFT_PROMPT_LAST_SEGMENT_END_SYMBOL $_p9k__ret
  7431. _p9k_escape $_p9k__ret
  7432. _p9k_line_prefix_left+='${_p9k__'$i'l-${${:-${_p9k__bg::=NONE}${_p9k__i::=0}${_p9k__sss::=%f'$_p9k__ret'}}+}'
  7433. _p9k_line_suffix_left+='%b%k$_p9k__sss%b%k%f'
  7434. _p9k_escape ${(g::)_POWERLEVEL9K_EMPTY_LINE_RIGHT_PROMPT_FIRST_SEGMENT_START_SYMBOL}
  7435. [[ -n $_p9k__ret ]] && _p9k_line_never_empty_right+=1 || _p9k_line_never_empty_right+=0
  7436. _p9k_line_prefix_right+='${_p9k__'$i'r-${${:-${_p9k__bg::=NONE}${_p9k__i::=0}${_p9k__sss::='$_p9k__ret'}}+}'
  7437. _p9k_line_suffix_right+='$_p9k__sss%b%k%f}' # gets overridden for _p9k_emulate_zero_rprompt_indent
  7438. if (( i == num_lines )); then
  7439. # it's safe to use _p9k_prompt_length on the last line because it cannot have prompt connection
  7440. _p9k_prompt_length ${(e)_p9k__ret}
  7441. (( _p9k__ret )) || _p9k_line_never_empty_right[-1]=0
  7442. fi
  7443. done
  7444. _p9k_get_icon '' LEFT_SEGMENT_END_SEPARATOR
  7445. if [[ -n $_p9k__ret ]]; then
  7446. _p9k__ret+=%b%k%f
  7447. # Not escaped for historical reasons.
  7448. _p9k__ret='${:-"'$_p9k__ret'"}'
  7449. if (( _POWERLEVEL9K_PROMPT_ON_NEWLINE )); then
  7450. _p9k_line_suffix_left[-2]+=$_p9k__ret
  7451. else
  7452. _p9k_line_suffix_left[-1]+=$_p9k__ret
  7453. fi
  7454. fi
  7455. for i in {1..$num_lines}; do _p9k_line_suffix_left[i]+='}'; done
  7456. if (( num_lines > 1 )); then
  7457. for i in {1..$((num_lines-1))}; do
  7458. _p9k_build_gap_post $i
  7459. _p9k_line_gap_post+=$_p9k__ret
  7460. done
  7461. if [[ $+_POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX == 1 || $_POWERLEVEL9K_PROMPT_ON_NEWLINE == 1 ]]; then
  7462. _p9k_get_icon '' MULTILINE_FIRST_PROMPT_PREFIX
  7463. if [[ -n $_p9k__ret ]]; then
  7464. [[ _p9k__ret == *%* ]] && _p9k__ret+=%b%k%f
  7465. # Not escaped for historical reasons.
  7466. _p9k__ret='${_p9k__1l_frame-"'$_p9k__ret'"}'
  7467. _p9k_line_prefix_left[1]=$_p9k__ret$_p9k_line_prefix_left[1]
  7468. fi
  7469. fi
  7470. if [[ $+_POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX == 1 || $_POWERLEVEL9K_PROMPT_ON_NEWLINE == 1 ]]; then
  7471. _p9k_get_icon '' MULTILINE_LAST_PROMPT_PREFIX
  7472. if [[ -n $_p9k__ret ]]; then
  7473. [[ _p9k__ret == *%* ]] && _p9k__ret+=%b%k%f
  7474. # Not escaped for historical reasons.
  7475. _p9k__ret='${_p9k__'$num_lines'l_frame-"'$_p9k__ret'"}'
  7476. _p9k_line_prefix_left[-1]=$_p9k__ret$_p9k_line_prefix_left[-1]
  7477. fi
  7478. fi
  7479. _p9k_get_icon '' MULTILINE_FIRST_PROMPT_SUFFIX
  7480. if [[ -n $_p9k__ret ]]; then
  7481. [[ _p9k__ret == *%* ]] && _p9k__ret+=%b%k%f
  7482. _p9k_line_suffix_right[1]+='${_p9k__1r_frame-'${(qqq)_p9k__ret}'}'
  7483. _p9k_line_never_empty_right[1]=1
  7484. fi
  7485. _p9k_get_icon '' MULTILINE_LAST_PROMPT_SUFFIX
  7486. if [[ -n $_p9k__ret ]]; then
  7487. [[ _p9k__ret == *%* ]] && _p9k__ret+=%b%k%f
  7488. _p9k_line_suffix_right[-1]+='${_p9k__'$num_lines'r_frame-'${(qqq)_p9k__ret}'}'
  7489. # it's safe to use _p9k_prompt_length on the last line because it cannot have prompt connection
  7490. _p9k_prompt_length $_p9k__ret
  7491. (( _p9k__ret )) && _p9k_line_never_empty_right[-1]=1
  7492. fi
  7493. if (( num_lines > 2 )); then
  7494. if [[ $+_POWERLEVEL9K_MULTILINE_NEWLINE_PROMPT_PREFIX == 1 || $_POWERLEVEL9K_PROMPT_ON_NEWLINE == 1 ]]; then
  7495. _p9k_get_icon '' MULTILINE_NEWLINE_PROMPT_PREFIX
  7496. if [[ -n $_p9k__ret ]]; then
  7497. [[ _p9k__ret == *%* ]] && _p9k__ret+=%b%k%f
  7498. for i in {2..$((num_lines-1))}; do
  7499. # Not escaped for historical reasons.
  7500. _p9k_line_prefix_left[i]='${_p9k__'$i'l_frame-"'$_p9k__ret'"}'$_p9k_line_prefix_left[i]
  7501. done
  7502. fi
  7503. fi
  7504. _p9k_get_icon '' MULTILINE_NEWLINE_PROMPT_SUFFIX
  7505. if [[ -n $_p9k__ret ]]; then
  7506. [[ _p9k__ret == *%* ]] && _p9k__ret+=%b%k%f
  7507. for i in {2..$((num_lines-1))}; do
  7508. _p9k_line_suffix_right[i]+='${_p9k__'$i'r_frame-'${(qqq)_p9k__ret}'}'
  7509. done
  7510. _p9k_line_never_empty_right[2,-2]=${(@)_p9k_line_never_empty_right[2,-2]/0/1}
  7511. fi
  7512. fi
  7513. fi
  7514. }
  7515. _p9k_all_params_eq() {
  7516. local key
  7517. for key in ${parameters[(I)${~1}]}; do
  7518. [[ ${(P)key} == $2 ]] || return
  7519. done
  7520. }
  7521. _p9k_init_display() {
  7522. _p9k_display_k=(empty_line 1 ruler 3)
  7523. local -i n=3 i
  7524. local name
  7525. for i in {1..$#_p9k_line_segments_left}; do
  7526. local -i j=$((-$#_p9k_line_segments_left+i-1))
  7527. _p9k_display_k+=(
  7528. $i $((n+=2)) $j $n
  7529. $i/left_frame $((n+=2)) $j/left_frame $n
  7530. $i/right_frame $((n+=2)) $j/right_frame $n
  7531. $i/left $((n+=2)) $j/left $n
  7532. $i/right $((n+=2)) $j/right $n
  7533. $i/gap $((n+=2)) $j/gap $n)
  7534. for name in ${${(@0)_p9k_line_segments_left[i]}%_joined}; do
  7535. _p9k_display_k+=($i/left/$name $((n+=2)) $j/left/$name $n)
  7536. done
  7537. for name in ${${(@0)_p9k_line_segments_right[i]}%_joined}; do
  7538. _p9k_display_k+=($i/right/$name $((n+=2)) $j/right/$name $n)
  7539. done
  7540. done
  7541. }
  7542. _p9k_init_prompt() {
  7543. _p9k_t=($'\n' $'%{\n%}' '')
  7544. _p9k_prompt_overflow_bug && _p9k_t[2]=$'%{%G\n%}'
  7545. _p9k_init_lines
  7546. _p9k_gap_pre='${${:-${_p9k__x::=0}${_p9k__y::=1024}${_p9k__p::=$_p9k__lprompt$_p9k__rprompt}'
  7547. repeat 10; do
  7548. _p9k_gap_pre+='${_p9k__m::=$(((_p9k__x+_p9k__y)/2))}'
  7549. _p9k_gap_pre+='${_p9k__xy::=${${(%):-$_p9k__p%$_p9k__m(l./$_p9k__m;$_p9k__y./$_p9k__x;$_p9k__m)}##*/}}'
  7550. _p9k_gap_pre+='${_p9k__x::=${_p9k__xy%;*}}'
  7551. _p9k_gap_pre+='${_p9k__y::=${_p9k__xy#*;}}'
  7552. done
  7553. _p9k_gap_pre+='${_p9k__m::=$((_p9k__clm-_p9k__x-_p9k__ind-1))}'
  7554. _p9k_gap_pre+='}+}'
  7555. _p9k_prompt_prefix_left='${${_p9k__clm::=$COLUMNS}+}${${COLUMNS::=1024}+}'
  7556. _p9k_prompt_prefix_right='${_p9k__'$#_p9k_line_segments_left'-${${_p9k__clm::=$COLUMNS}+}${${COLUMNS::=1024}+}'
  7557. _p9k_prompt_suffix_left='${${COLUMNS::=$_p9k__clm}+}'
  7558. _p9k_prompt_suffix_right='${${COLUMNS::=$_p9k__clm}+}}'
  7559. if _p9k_segment_in_use vi_mode || _p9k_segment_in_use prompt_char; then
  7560. _p9k_prompt_prefix_left+='${${_p9k__keymap::=${KEYMAP:-$_p9k__keymap}}+}'
  7561. fi
  7562. if { _p9k_segment_in_use vi_mode && (( $+_POWERLEVEL9K_VI_OVERWRITE_MODE_STRING )) } ||
  7563. { _p9k_segment_in_use prompt_char && (( _POWERLEVEL9K_PROMPT_CHAR_OVERWRITE_STATE )) }; then
  7564. _p9k_prompt_prefix_left+='${${_p9k__zle_state::=${ZLE_STATE:-$_p9k__zle_state}}+}'
  7565. fi
  7566. _p9k_prompt_prefix_left+='%b%k%f'
  7567. # Bug fixed in: https://github.com/zsh-users/zsh/commit/3eea35d0853bddae13fa6f122669935a01618bf9.
  7568. # If affects most terminals when RPROMPT is non-empty and ZLE_RPROMPT_INDENT is zero.
  7569. # We can work around it as long as RPROMPT ends with a space.
  7570. if [[ -n $_p9k_line_segments_right[-1] && $_p9k_line_never_empty_right[-1] == 0 &&
  7571. $ZLE_RPROMPT_INDENT == 0 ]] &&
  7572. _p9k_all_params_eq '_POWERLEVEL9K_*WHITESPACE_BETWEEN_RIGHT_SEGMENTS' ' ' &&
  7573. _p9k_all_params_eq '_POWERLEVEL9K_*RIGHT_RIGHT_WHITESPACE' ' ' &&
  7574. _p9k_all_params_eq '_POWERLEVEL9K_*RIGHT_PROMPT_LAST_SEGMENT_END_SYMBOL' '' &&
  7575. [[ $ZSH_VERSION != (5.7.<2->*|5.<8->*|<6->.*) ]]; then
  7576. _p9k_emulate_zero_rprompt_indent=1
  7577. _p9k_prompt_prefix_left+='${${:-${_p9k__real_zle_rprompt_indent:=$ZLE_RPROMPT_INDENT}${ZLE_RPROMPT_INDENT::=1}${_p9k__ind::=0}}+}'
  7578. _p9k_line_suffix_right[-1]='${_p9k__sss:+${_p9k__sss% }%E}}'
  7579. else
  7580. _p9k_emulate_zero_rprompt_indent=0
  7581. _p9k_prompt_prefix_left+='${${_p9k__ind::=${${ZLE_RPROMPT_INDENT:-1}/#-*/0}}+}'
  7582. fi
  7583. if (( _POWERLEVEL9K_TERM_SHELL_INTEGRATION )); then
  7584. _p9k_prompt_prefix_left+=$'%{\e]133;A\a%}'
  7585. _p9k_prompt_suffix_left+=$'%{\e]133;B\a%}'
  7586. if [[ $TERM_PROGRAM == WarpTerminal ]]; then
  7587. _p9k_prompt_prefix_right=$'%{\e]133;P;k=r\a%}'$_p9k_prompt_prefix_right
  7588. _p9k_prompt_suffix_right+=$'%{\e]133;B\a%}'
  7589. fi
  7590. if (( $+_z4h_iterm_cmd && _z4h_can_save_restore_screen == 1 )); then
  7591. _p9k_prompt_prefix_left+=$'%{\ePtmux;\e\e]133;A\a\e\\%}'
  7592. _p9k_prompt_suffix_left+=$'%{\ePtmux;\e\e]133;B\a\e\\%}'
  7593. if [[ $TERM_PROGRAM == WarpTerminal ]]; then
  7594. _p9k_prompt_prefix_right=$'%{\ePtmux;\e\e]133;P;k=r\a\e\\%}'$_p9k_prompt_prefix_right
  7595. _p9k_prompt_suffix_right+=$'%{\ePtmux;\e\e]133;B\a\e\\%}'
  7596. fi
  7597. fi
  7598. fi
  7599. if (( _POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT > 0 )); then
  7600. _p9k_t+=${(pl.$_POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT..\n.)}
  7601. else
  7602. _p9k_t+=''
  7603. fi
  7604. _p9k_empty_line_idx=$#_p9k_t
  7605. if (( __p9k_ksh_arrays )); then
  7606. _p9k_prompt_prefix_left+='${_p9k_t[${_p9k__empty_line_i:-'$#_p9k_t'}-1]}'
  7607. else
  7608. _p9k_prompt_prefix_left+='${_p9k_t[${_p9k__empty_line_i:-'$#_p9k_t'}]}'
  7609. fi
  7610. local -i num_lines=$#_p9k_line_segments_left
  7611. if (( $+terminfo[cuu1] )); then
  7612. _p9k_escape $terminfo[cuu1]
  7613. if (( __p9k_ksh_arrays )); then
  7614. local scroll=$'${_p9k_t[${_p9k__ruler_i:-1}-1]:+\n'$_p9k__ret'}'
  7615. else
  7616. local scroll=$'${_p9k_t[${_p9k__ruler_i:-1}]:+\n'$_p9k__ret'}'
  7617. fi
  7618. if (( num_lines > 1 )); then
  7619. local -i line_index=
  7620. for line_index in {1..$((num_lines-1))}; do
  7621. scroll='${_p9k__'$line_index-$'\n}'$scroll'${_p9k__'$line_index-$_p9k__ret'}'
  7622. done
  7623. fi
  7624. _p9k_prompt_prefix_left+='%{${_p9k__ipe-'$scroll'}%}'
  7625. fi
  7626. _p9k_get_icon '' RULER_CHAR
  7627. local ruler_char=$_p9k__ret
  7628. _p9k_prompt_length $ruler_char
  7629. (( _p9k__ret == 1 && $#ruler_char == 1 )) || ruler_char=' '
  7630. _p9k_color prompt_ruler BACKGROUND ""
  7631. if [[ -z $_p9k__ret && $ruler_char == ' ' ]]; then
  7632. local ruler=$'\n'
  7633. else
  7634. _p9k_background $_p9k__ret
  7635. local ruler=%b$_p9k__ret
  7636. _p9k_color prompt_ruler FOREGROUND ""
  7637. _p9k_foreground $_p9k__ret
  7638. ruler+=$_p9k__ret
  7639. [[ $ruler_char == '.' ]] && local sep=',' || local sep='.'
  7640. ruler+='${(pl'$sep'${$((_p9k__clm-_p9k__ind))/#-*/0}'$sep$sep$ruler_char$sep')}%k%f'
  7641. if (( __p9k_ksh_arrays )); then
  7642. ruler+='${_p9k_t[$((!_p9k__ind))]}'
  7643. else
  7644. ruler+='${_p9k_t[$((1+!_p9k__ind))]}'
  7645. fi
  7646. fi
  7647. _p9k_t+=$ruler
  7648. _p9k_ruler_idx=$#_p9k_t
  7649. if (( __p9k_ksh_arrays )); then
  7650. _p9k_prompt_prefix_left+='${(e)_p9k_t[${_p9k__ruler_i:-'$#_p9k_t'}-1]}'
  7651. else
  7652. _p9k_prompt_prefix_left+='${(e)_p9k_t[${_p9k__ruler_i:-'$#_p9k_t'}]}'
  7653. fi
  7654. ( _p9k_segment_in_use time && (( _POWERLEVEL9K_TIME_UPDATE_ON_COMMAND )) )
  7655. _p9k_reset_on_line_finish=$((!$?))
  7656. _p9k_t+=$_p9k_gap_pre
  7657. _p9k_gap_pre='${(e)_p9k_t['$(($#_p9k_t - __p9k_ksh_arrays))']}'
  7658. _p9k_t+=$_p9k_prompt_prefix_left
  7659. _p9k_prompt_prefix_left='${(e)_p9k_t['$(($#_p9k_t - __p9k_ksh_arrays))']}'
  7660. }
  7661. _p9k_init_ssh() {
  7662. # The following code is based on Pure:
  7663. # https://github.com/sindresorhus/pure/blob/e8abf9d37185ec9b7b4398ca9c5eba555a1028eb/pure.zsh.
  7664. #
  7665. # License: https://github.com/sindresorhus/pure/blob/e8abf9d37185ec9b7b4398ca9c5eba555a1028eb/license.
  7666. [[ -n $P9K_SSH && $_P9K_SSH_TTY == $TTY ]] && return
  7667. typeset -gix P9K_SSH=0
  7668. typeset -gx _P9K_SSH_TTY=$TTY
  7669. if [[ -n $SSH_CLIENT || -n $SSH_TTY || -n $SSH_CONNECTION ]]; then
  7670. P9K_SSH=1
  7671. return 0
  7672. fi
  7673. # When changing user on a remote system, the $SSH_CONNECTION environment variable can be lost.
  7674. # Attempt detection via `who`.
  7675. (( $+commands[who] )) || return
  7676. local ipv6='(([0-9a-fA-F]+:)|:){2,}[0-9a-fA-F]+' # Simplified, only checks partial pattern.
  7677. local ipv4='([0-9]{1,3}\.){3}[0-9]+' # Simplified, allows invalid ranges.
  7678. # Assume two non-consecutive periods represents a hostname. Matches `x.y.z`, but not `x.y`.
  7679. local hostname='([.][^. ]+){2}'
  7680. local w
  7681. w="$(who -m 2>/dev/null)" || w=${(@M)${(f)"$(who 2>/dev/null)"}:#*[[:space:]]${TTY#/dev/}[[:space:]]*}
  7682. # Usually the remote address is surrounded by parenthesis but not on all systems (e.g., Busybox).
  7683. [[ $w =~ "\(?($ipv4|$ipv6|$hostname)\)?\$" ]] && P9K_SSH=1
  7684. }
  7685. _p9k_init_toolbox() {
  7686. [[ -z $P9K_TOOLBOX_NAME ]] || return 0
  7687. if [[ -f /run/.containerenv && -r /run/.containerenv ]]; then
  7688. local name=(${(Q)${${(@M)${(f)"$(</run/.containerenv)"}:#name=*}#name=}})
  7689. [[ ${#name} -eq 1 && -n ${name[1]} ]] || return 0
  7690. typeset -g P9K_TOOLBOX_NAME=${name[1]}
  7691. elif [[ -n $DISTROBOX_ENTER_PATH ]]; then
  7692. local name=${(%):-%m}
  7693. # $NAME can be empty, see https://github.com/romkatv/powerlevel10k/pull/1916.
  7694. if [[ -n $name && $name == $NAME* ]]; then
  7695. typeset -g P9K_TOOLBOX_NAME=$name
  7696. fi
  7697. fi
  7698. }
  7699. _p9k_must_init() {
  7700. (( _POWERLEVEL9K_DISABLE_HOT_RELOAD && !_p9k__force_must_init )) && return 1
  7701. _p9k__force_must_init=0
  7702. local IFS sig
  7703. if [[ -n $_p9k__param_sig ]]; then
  7704. IFS=$'\2' sig="${(e)_p9k__param_pat}"
  7705. [[ $sig == $_p9k__param_sig ]] && return 1
  7706. _p9k_deinit
  7707. fi
  7708. _p9k__param_pat=${(q)P9K_VERSION}$'\1'${(q)ZSH_VERSION}$'\1'${(q)ZSH_PATCHLEVEL}$'\1'
  7709. _p9k__param_pat+=$__p9k_force_term_shell_integration$'\1'${(q)TERM_PROGRAM}$'\1'
  7710. _p9k__param_pat+=$'${#parameters[(I)POWERLEVEL9K_*]}\1${(%):-%n%#}\1$GITSTATUS_LOG_LEVEL\1'
  7711. _p9k__param_pat+=$'$GITSTATUS_ENABLE_LOGGING\1$GITSTATUS_DAEMON\1$GITSTATUS_NUM_THREADS\1'
  7712. _p9k__param_pat+=$'$GITSTATUS_CACHE_DIR\1$GITSTATUS_AUTO_INSTALL\1${ZLE_RPROMPT_INDENT:-1}\1'
  7713. _p9k__param_pat+=$'$__p9k_sh_glob\1$__p9k_ksh_arrays\1$ITERM_SHELL_INTEGRATION_INSTALLED\1'
  7714. _p9k__param_pat+=$'${PROMPT_EOL_MARK-%B%S%#%s%b}\1$+commands[locale]\1$langinfo[CODESET]\1'
  7715. _p9k__param_pat+=$'${(M)VTE_VERSION:#(<1-4602>|4801)}\1$DEFAULT_USER\1$P9K_SSH\1$+commands[uname]\1'
  7716. _p9k__param_pat+=$'$__p9k_root_dir\1$functions[p10k-on-init]\1$functions[p10k-on-pre-prompt]\1'
  7717. _p9k__param_pat+=$'$functions[p10k-on-post-widget]\1$functions[p10k-on-post-prompt]\1'
  7718. _p9k__param_pat+=$'$+commands[git]\1$terminfo[colors]\1${+_z4h_iterm_cmd}\1'
  7719. _p9k__param_pat+=$'$_z4h_can_save_restore_screen'
  7720. local MATCH
  7721. IFS=$'\1' _p9k__param_pat+="${(@)${(@o)parameters[(I)POWERLEVEL9K_*]}:/(#m)*/\${${(q)MATCH}-$IFS\}}"
  7722. IFS=$'\2' _p9k__param_sig="${(e)_p9k__param_pat}"
  7723. }
  7724. function _p9k_set_os() {
  7725. _p9k_os=$1
  7726. _p9k_get_icon prompt_os_icon $2
  7727. _p9k_os_icon=$_p9k__ret
  7728. }
  7729. function _p9k_init_cacheable() {
  7730. _p9k_init_icons
  7731. _p9k_init_params
  7732. _p9k_init_prompt
  7733. _p9k_init_display
  7734. # https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda#backward-compatibility
  7735. if [[ $VTE_VERSION != (<1-4602>|4801) ]]; then
  7736. _p9k_term_has_href=1
  7737. fi
  7738. local elem func
  7739. local -i i=0
  7740. for i in {1..$#_p9k_line_segments_left}; do
  7741. for elem in ${${${(@0)_p9k_line_segments_left[i]}%_joined}//-/_}; do
  7742. local var=POWERLEVEL9K_${${(U)elem}//İ/I}_SHOW_ON_COMMAND
  7743. (( $+parameters[$var] )) || continue
  7744. _p9k_show_on_command+=(
  7745. $'(|*[/\0])('${(j.|.)${(P)var}}')'
  7746. $((1+_p9k_display_k[$i/left/$elem]))
  7747. _p9k__${i}l$elem)
  7748. done
  7749. for elem in ${${${(@0)_p9k_line_segments_right[i]}%_joined}//-/_}; do
  7750. local var=POWERLEVEL9K_${${(U)elem}//İ/I}_SHOW_ON_COMMAND
  7751. (( $+parameters[$var] )) || continue
  7752. local cmds=(${(P)var})
  7753. _p9k_show_on_command+=(
  7754. $'(|*[/\0])('${(j.|.)${(P)var}}')'
  7755. $((1+$_p9k_display_k[$i/right/$elem]))
  7756. _p9k__${i}r$elem)
  7757. done
  7758. done
  7759. if [[ $_POWERLEVEL9K_TRANSIENT_PROMPT != off ]]; then
  7760. local sep=$'\1'
  7761. _p9k_transient_prompt='%b%k%s%u%(?'$sep
  7762. _p9k_color prompt_prompt_char_OK_VIINS FOREGROUND 76
  7763. _p9k_foreground $_p9k__ret
  7764. _p9k_transient_prompt+=$_p9k__ret
  7765. _p9k_transient_prompt+='${${P9K_CONTENT::="❯"}+}'
  7766. _p9k_param prompt_prompt_char_OK_VIINS CONTENT_EXPANSION '${P9K_CONTENT}'
  7767. _p9k_transient_prompt+='${:-"'$_p9k__ret'"}'
  7768. _p9k_transient_prompt+=$sep
  7769. _p9k_color prompt_prompt_char_ERROR_VIINS FOREGROUND 196
  7770. _p9k_foreground $_p9k__ret
  7771. _p9k_transient_prompt+=$_p9k__ret
  7772. _p9k_transient_prompt+='${${P9K_CONTENT::="❯"}+}'
  7773. _p9k_param prompt_prompt_char_ERROR_VIINS CONTENT_EXPANSION '${P9K_CONTENT}'
  7774. _p9k_transient_prompt+='${:-"'$_p9k__ret'"}'
  7775. _p9k_transient_prompt+=')%b%k%f%s%u'
  7776. _p9k_get_icon '' LEFT_SEGMENT_END_SEPARATOR
  7777. if [[ $_p9k__ret != (| ) ]]; then
  7778. _p9k__ret+=%b%k%f
  7779. # Not escaped for historical reasons.
  7780. _p9k__ret='${:-"'$_p9k__ret'"}'
  7781. fi
  7782. _p9k_transient_prompt+=$_p9k__ret
  7783. if (( _POWERLEVEL9K_TERM_SHELL_INTEGRATION )); then
  7784. _p9k_transient_prompt=$'%{\e]133;A\a%}'$_p9k_transient_prompt$'%{\e]133;B\a%}'
  7785. if (( $+_z4h_iterm_cmd && _z4h_can_save_restore_screen == 1 )); then
  7786. _p9k_transient_prompt=$'%{\ePtmux;\e\e]133;A\a\e\\%}'$_p9k_transient_prompt$'%{\ePtmux;\e\e]133;B\a\e\\%}'
  7787. fi
  7788. fi
  7789. fi
  7790. _p9k_uname="$(uname)"
  7791. [[ $_p9k_uname == Linux ]] && _p9k_uname_o="$(uname -o 2>/dev/null)"
  7792. _p9k_uname_m="$(uname -m)"
  7793. if [[ $_p9k_uname == Linux && $_p9k_uname_o == Android ]]; then
  7794. _p9k_set_os Android ANDROID_ICON
  7795. else
  7796. case $_p9k_uname in
  7797. SunOS) _p9k_set_os Solaris SUNOS_ICON;;
  7798. Darwin) _p9k_set_os OSX APPLE_ICON;;
  7799. CYGWIN*|MSYS*|MINGW*) _p9k_set_os Windows WINDOWS_ICON;;
  7800. FreeBSD|OpenBSD|DragonFly) _p9k_set_os BSD FREEBSD_ICON;;
  7801. Linux)
  7802. _p9k_os='Linux'
  7803. local os_release_id
  7804. if [[ -r /etc/os-release ]]; then
  7805. local lines=(${(f)"$(</etc/os-release)"})
  7806. lines=(${(@M)lines:#ID=*})
  7807. (( $#lines == 1 )) && os_release_id=${(Q)${lines[1]#ID=}}
  7808. elif [[ -e /etc/artix-release ]]; then
  7809. os_release_id=artix
  7810. fi
  7811. case $os_release_id in
  7812. *arch*) _p9k_set_os Linux LINUX_ARCH_ICON;;
  7813. *debian*) _p9k_set_os Linux LINUX_DEBIAN_ICON;;
  7814. *raspbian*) _p9k_set_os Linux LINUX_RASPBIAN_ICON;;
  7815. *ubuntu*) _p9k_set_os Linux LINUX_UBUNTU_ICON;;
  7816. *elementary*) _p9k_set_os Linux LINUX_ELEMENTARY_ICON;;
  7817. *fedora*) _p9k_set_os Linux LINUX_FEDORA_ICON;;
  7818. *coreos*) _p9k_set_os Linux LINUX_COREOS_ICON;;
  7819. *kali*) _p9k_set_os Linux LINUX_KALI_ICON;;
  7820. *gentoo*) _p9k_set_os Linux LINUX_GENTOO_ICON;;
  7821. *mageia*) _p9k_set_os Linux LINUX_MAGEIA_ICON;;
  7822. *centos*) _p9k_set_os Linux LINUX_CENTOS_ICON;;
  7823. *opensuse*|*tumbleweed*) _p9k_set_os Linux LINUX_OPENSUSE_ICON;;
  7824. *sabayon*) _p9k_set_os Linux LINUX_SABAYON_ICON;;
  7825. *slackware*) _p9k_set_os Linux LINUX_SLACKWARE_ICON;;
  7826. *linuxmint*) _p9k_set_os Linux LINUX_MINT_ICON;;
  7827. *alpine*) _p9k_set_os Linux LINUX_ALPINE_ICON;;
  7828. *aosc*) _p9k_set_os Linux LINUX_AOSC_ICON;;
  7829. *nixos*) _p9k_set_os Linux LINUX_NIXOS_ICON;;
  7830. *devuan*) _p9k_set_os Linux LINUX_DEVUAN_ICON;;
  7831. *manjaro*) _p9k_set_os Linux LINUX_MANJARO_ICON;;
  7832. *void*) _p9k_set_os Linux LINUX_VOID_ICON;;
  7833. *artix*) _p9k_set_os Linux LINUX_ARTIX_ICON;;
  7834. *rhel*) _p9k_set_os Linux LINUX_RHEL_ICON;;
  7835. amzn) _p9k_set_os Linux LINUX_AMZN_ICON;;
  7836. endeavouros) _p9k_set_os Linux LINUX_ENDEAVOUROS_ICON;;
  7837. rocky) _p9k_set_os Linux LINUX_ROCKY_ICON;;
  7838. *) _p9k_set_os Linux LINUX_ICON;;
  7839. esac
  7840. ;;
  7841. esac
  7842. fi
  7843. if [[ $_POWERLEVEL9K_COLOR_SCHEME == light ]]; then
  7844. _p9k_color1=7
  7845. _p9k_color2=0
  7846. else
  7847. _p9k_color1=0
  7848. _p9k_color2=7
  7849. fi
  7850. _p9k_battery_states=(
  7851. 'LOW' 'red'
  7852. 'CHARGING' 'yellow'
  7853. 'CHARGED' 'green'
  7854. 'DISCONNECTED' "$_p9k_color2"
  7855. )
  7856. # This simpler construct doesn't work on zsh-5.1 with multi-line prompt:
  7857. #
  7858. # ${(@0)_p9k_line_segments_left[@]}
  7859. local -a left_segments=(${(@0)${(pj:\0:)_p9k_line_segments_left}})
  7860. _p9k_left_join=(1)
  7861. for ((i = 2; i <= $#left_segments; ++i)); do
  7862. elem=$left_segments[i]
  7863. if [[ $elem == *_joined ]]; then
  7864. _p9k_left_join+=$_p9k_left_join[((i-1))]
  7865. else
  7866. _p9k_left_join+=$i
  7867. fi
  7868. done
  7869. local -a right_segments=(${(@0)${(pj:\0:)_p9k_line_segments_right}})
  7870. _p9k_right_join=(1)
  7871. for ((i = 2; i <= $#right_segments; ++i)); do
  7872. elem=$right_segments[i]
  7873. if [[ $elem == *_joined ]]; then
  7874. _p9k_right_join+=$_p9k_right_join[((i-1))]
  7875. else
  7876. _p9k_right_join+=$i
  7877. fi
  7878. done
  7879. case $_p9k_os in
  7880. OSX) (( $+commands[sysctl] )) && _p9k_num_cpus="$(sysctl -n hw.logicalcpu 2>/dev/null)";;
  7881. BSD) (( $+commands[sysctl] )) && _p9k_num_cpus="$(sysctl -n hw.ncpu 2>/dev/null)";;
  7882. *) (( $+commands[nproc] )) && _p9k_num_cpus="$(nproc 2>/dev/null)";;
  7883. esac
  7884. (( _p9k_num_cpus )) || _p9k_num_cpus=1
  7885. if _p9k_segment_in_use dir; then
  7886. if (( $+_POWERLEVEL9K_DIR_CLASSES )); then
  7887. local -i i=3
  7888. for ((; i <= $#_POWERLEVEL9K_DIR_CLASSES; i+=3)); do
  7889. _POWERLEVEL9K_DIR_CLASSES[i]=${(g::)_POWERLEVEL9K_DIR_CLASSES[i]}
  7890. done
  7891. else
  7892. typeset -ga _POWERLEVEL9K_DIR_CLASSES=()
  7893. _p9k_get_icon prompt_dir_ETC ETC_ICON
  7894. _POWERLEVEL9K_DIR_CLASSES+=('/etc|/etc/*' ETC "$_p9k__ret")
  7895. _p9k_get_icon prompt_dir_HOME HOME_ICON
  7896. _POWERLEVEL9K_DIR_CLASSES+=('~' HOME "$_p9k__ret")
  7897. _p9k_get_icon prompt_dir_HOME_SUBFOLDER HOME_SUB_ICON
  7898. _POWERLEVEL9K_DIR_CLASSES+=('~/*' HOME_SUBFOLDER "$_p9k__ret")
  7899. _p9k_get_icon prompt_dir_DEFAULT FOLDER_ICON
  7900. _POWERLEVEL9K_DIR_CLASSES+=('*' DEFAULT "$_p9k__ret")
  7901. fi
  7902. fi
  7903. if _p9k_segment_in_use status; then
  7904. typeset -g _p9k_exitcode2str=({0..255})
  7905. local -i i=2
  7906. if (( !_POWERLEVEL9K_STATUS_HIDE_SIGNAME )); then
  7907. for ((; i <= $#signals; ++i)); do
  7908. local sig=$signals[i]
  7909. (( _POWERLEVEL9K_STATUS_VERBOSE_SIGNAME )) && sig="SIG${sig}($((i-1)))"
  7910. _p9k_exitcode2str[$((128+i))]=$sig
  7911. done
  7912. fi
  7913. fi
  7914. if [[ $#_POWERLEVEL9K_VCS_BACKENDS == 1 && $_POWERLEVEL9K_VCS_BACKENDS[1] == git ]]; then
  7915. local elem line
  7916. local -i i=0 line_idx=0
  7917. for line in $_p9k_line_segments_left; do
  7918. (( ++line_idx ))
  7919. for elem in ${${(0)line}%_joined}; do
  7920. (( ++i ))
  7921. if [[ $elem == vcs ]]; then
  7922. if (( _p9k_vcs_index )); then
  7923. _p9k_vcs_index=-1
  7924. else
  7925. _p9k_vcs_index=i
  7926. _p9k_vcs_line_index=line_idx
  7927. _p9k_vcs_side=left
  7928. fi
  7929. fi
  7930. done
  7931. done
  7932. i=0
  7933. line_idx=0
  7934. for line in $_p9k_line_segments_right; do
  7935. (( ++line_idx ))
  7936. for elem in ${${(0)line}%_joined}; do
  7937. (( ++i ))
  7938. if [[ $elem == vcs ]]; then
  7939. if (( _p9k_vcs_index )); then
  7940. _p9k_vcs_index=-1
  7941. else
  7942. _p9k_vcs_index=i
  7943. _p9k_vcs_line_index=line_idx
  7944. _p9k_vcs_side=right
  7945. fi
  7946. fi
  7947. done
  7948. done
  7949. if (( _p9k_vcs_index > 0 )); then
  7950. local state
  7951. for state in ${(k)__p9k_vcs_states}; do
  7952. _p9k_param prompt_vcs_$state CONTENT_EXPANSION x
  7953. if [[ -z $_p9k__ret ]]; then
  7954. _p9k_vcs_index=-1
  7955. break
  7956. fi
  7957. done
  7958. fi
  7959. if (( _p9k_vcs_index == -1 )); then
  7960. _p9k_vcs_index=0
  7961. _p9k_vcs_line_index=0
  7962. _p9k_vcs_side=
  7963. fi
  7964. fi
  7965. }
  7966. _p9k_init_vcs() {
  7967. if ! _p9k_segment_in_use vcs || (( ! $#_POWERLEVEL9K_VCS_BACKENDS )); then
  7968. (( $+functions[gitstatus_stop_p9k_] )) && gitstatus_stop_p9k_ POWERLEVEL9K
  7969. unset _p9k_preinit
  7970. return
  7971. fi
  7972. _p9k_vcs_info_init
  7973. if (( $+functions[_p9k_preinit] )); then
  7974. if (( $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )); then
  7975. () {
  7976. trap 'return 130' INT
  7977. {
  7978. gitstatus_start_p9k_ -t $_POWERLEVEL9K_GITSTATUS_INIT_TIMEOUT_SEC POWERLEVEL9K
  7979. } always {
  7980. trap ':' INT
  7981. }
  7982. }
  7983. fi
  7984. (( $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )) || _p9k__instant_prompt_disabled=1
  7985. return 0
  7986. fi
  7987. (( _POWERLEVEL9K_DISABLE_GITSTATUS )) && return
  7988. (( $_POWERLEVEL9K_VCS_BACKENDS[(I)git] )) || return
  7989. local gitstatus_dir=${_POWERLEVEL9K_GITSTATUS_DIR:-${__p9k_root_dir}/gitstatus}
  7990. typeset -g _p9k_preinit="function _p9k_preinit() {
  7991. (( $+commands[git] )) || { unfunction _p9k_preinit; return 1 }
  7992. [[ \$ZSH_VERSION == ${(q)ZSH_VERSION} ]] || return
  7993. [[ -r ${(q)gitstatus_dir}/gitstatus.plugin.zsh ]] || return
  7994. builtin source ${(q)gitstatus_dir}/gitstatus.plugin.zsh _p9k_ || return
  7995. GITSTATUS_AUTO_INSTALL=${(q)GITSTATUS_AUTO_INSTALL} \
  7996. GITSTATUS_DAEMON=${(q)GITSTATUS_DAEMON} \
  7997. GITSTATUS_CACHE_DIR=${(q)GITSTATUS_CACHE_DIR} \
  7998. GITSTATUS_NUM_THREADS=${(q)GITSTATUS_NUM_THREADS} \
  7999. GITSTATUS_LOG_LEVEL=${(q)GITSTATUS_LOG_LEVEL} \
  8000. GITSTATUS_ENABLE_LOGGING=${(q)GITSTATUS_ENABLE_LOGGING} \
  8001. gitstatus_start_p9k_ \
  8002. -s $_POWERLEVEL9K_VCS_STAGED_MAX_NUM \
  8003. -u $_POWERLEVEL9K_VCS_UNSTAGED_MAX_NUM \
  8004. -d $_POWERLEVEL9K_VCS_UNTRACKED_MAX_NUM \
  8005. -c $_POWERLEVEL9K_VCS_CONFLICTED_MAX_NUM \
  8006. -m $_POWERLEVEL9K_VCS_MAX_INDEX_SIZE_DIRTY \
  8007. ${${_POWERLEVEL9K_VCS_RECURSE_UNTRACKED_DIRS:#0}:+-e} \
  8008. -a POWERLEVEL9K
  8009. }"
  8010. builtin source $gitstatus_dir/gitstatus.plugin.zsh _p9k_ || return
  8011. () {
  8012. trap 'return 130' INT
  8013. {
  8014. gitstatus_start_p9k_ \
  8015. -s $_POWERLEVEL9K_VCS_STAGED_MAX_NUM \
  8016. -u $_POWERLEVEL9K_VCS_UNSTAGED_MAX_NUM \
  8017. -d $_POWERLEVEL9K_VCS_UNTRACKED_MAX_NUM \
  8018. -c $_POWERLEVEL9K_VCS_CONFLICTED_MAX_NUM \
  8019. -m $_POWERLEVEL9K_VCS_MAX_INDEX_SIZE_DIRTY \
  8020. -t $_POWERLEVEL9K_GITSTATUS_INIT_TIMEOUT_SEC \
  8021. ${${_POWERLEVEL9K_VCS_RECURSE_UNTRACKED_DIRS:#0}:+-e} \
  8022. POWERLEVEL9K
  8023. } always {
  8024. trap ':' INT
  8025. }
  8026. }
  8027. (( $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )) || _p9k__instant_prompt_disabled=1
  8028. }
  8029. function _p9k_iterm2_precmd() {
  8030. builtin zle && return
  8031. if (( _p9k__iterm_cmd )) && [[ -t 1 ]]; then
  8032. (( _p9k__iterm_cmd == 1 )) && builtin print -n '\e]133;C;\a'
  8033. builtin printf '\e]133;D;%s\a' $1
  8034. fi
  8035. typeset -gi _p9k__iterm_cmd=1
  8036. }
  8037. function _p9k_iterm2_preexec() {
  8038. [[ -t 1 ]] && builtin print -n '\e]133;C;\a'
  8039. typeset -gi _p9k__iterm_cmd=2
  8040. }
  8041. _p9k_init() {
  8042. _p9k_init_vars
  8043. _p9k_restore_state || _p9k_init_cacheable
  8044. typeset -g P9K_OS_ICON=$_p9k_os_icon
  8045. local -a _p9k__async_segments_compute
  8046. local -i i
  8047. local elem
  8048. _p9k__prompt_side=left
  8049. _p9k__segment_index=1
  8050. for i in {1..$#_p9k_line_segments_left}; do
  8051. for elem in ${${(@0)_p9k_line_segments_left[i]}%_joined}; do
  8052. local f_init=_p9k_prompt_${elem}_init
  8053. (( $+functions[$f_init] )) && $f_init
  8054. (( ++_p9k__segment_index ))
  8055. done
  8056. done
  8057. _p9k__prompt_side=right
  8058. _p9k__segment_index=1
  8059. for i in {1..$#_p9k_line_segments_right}; do
  8060. for elem in ${${(@0)_p9k_line_segments_right[i]}%_joined}; do
  8061. local f_init=_p9k_prompt_${elem}_init
  8062. (( $+functions[$f_init] )) && $f_init
  8063. (( ++_p9k__segment_index ))
  8064. done
  8065. done
  8066. if [[ -n $_POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ||
  8067. -n $_POWERLEVEL9K_IP_INTERFACE ||
  8068. -n $_POWERLEVEL9K_VPN_IP_INTERFACE ]]; then
  8069. _p9k_prompt_net_iface_init
  8070. fi
  8071. if [[ -n $_p9k__async_segments_compute ]]; then
  8072. functions[_p9k_async_segments_compute]=${(pj:\n:)_p9k__async_segments_compute}
  8073. _p9k_worker_start
  8074. fi
  8075. local k v
  8076. for k v in ${(kv)_p9k_display_k}; do
  8077. [[ $k == -* ]] && continue
  8078. _p9k__display_v[v]=$k
  8079. _p9k__display_v[v+1]=show
  8080. done
  8081. _p9k__display_v[2]=hide
  8082. _p9k__display_v[4]=hide
  8083. if (( $+functions[iterm2_decorate_prompt] )); then
  8084. _p9k__iterm2_decorate_prompt=$functions[iterm2_decorate_prompt]
  8085. function iterm2_decorate_prompt() {
  8086. typeset -g ITERM2_PRECMD_PS1=$PROMPT
  8087. typeset -g ITERM2_SHOULD_DECORATE_PROMPT=
  8088. }
  8089. fi
  8090. if (( $+functions[iterm2_precmd] )); then
  8091. _p9k__iterm2_precmd=$functions[iterm2_precmd]
  8092. functions[iterm2_precmd]='local _p9k_status=$?; zle && return; () { return $_p9k_status; }; '$_p9k__iterm2_precmd
  8093. fi
  8094. if (( _POWERLEVEL9K_TERM_SHELL_INTEGRATION &&
  8095. ! $+_z4h_iterm_cmd &&
  8096. ! $+functions[iterm2_decorate_prompt] &&
  8097. ! $+functions[iterm2_precmd] )); then
  8098. typeset -gi _p9k__iterm_cmd=0
  8099. fi
  8100. if _p9k_segment_in_use todo; then
  8101. if [[ -n ${_p9k__todo_command::=${commands[todo.sh]}} ]]; then
  8102. local todo_global=/etc/todo/config
  8103. elif [[ -n ${_p9k__todo_command::=${commands[todo-txt]}} ]]; then
  8104. local todo_global=/etc/todo-txt/config
  8105. fi
  8106. if [[ -n $_p9k__todo_command ]]; then
  8107. _p9k__todo_file="$(exec -a $_p9k__todo_command ${commands[bash]:-:} 3>&1 &>/dev/null -c "
  8108. [ -e \"\$TODOTXT_CFG_FILE\" ] || TODOTXT_CFG_FILE=\$HOME/.todo/config
  8109. [ -e \"\$TODOTXT_CFG_FILE\" ] || TODOTXT_CFG_FILE=\$HOME/todo.cfg
  8110. [ -e \"\$TODOTXT_CFG_FILE\" ] || TODOTXT_CFG_FILE=\$HOME/.todo.cfg
  8111. [ -e \"\$TODOTXT_CFG_FILE\" ] || TODOTXT_CFG_FILE=\${XDG_CONFIG_HOME:-\$HOME/.config}/todo/config
  8112. [ -e \"\$TODOTXT_CFG_FILE\" ] || TODOTXT_CFG_FILE=${(qqq)_p9k__todo_command:h}/todo.cfg
  8113. [ -e \"\$TODOTXT_CFG_FILE\" ] || TODOTXT_CFG_FILE=\${TODOTXT_GLOBAL_CFG_FILE:-${(qqq)todo_global}}
  8114. [ -r \"\$TODOTXT_CFG_FILE\" ] || exit
  8115. source \"\$TODOTXT_CFG_FILE\"
  8116. printf "%s" \"\$TODO_FILE\" >&3")"
  8117. fi
  8118. fi
  8119. if _p9k_segment_in_use dir &&
  8120. [[ $_POWERLEVEL9K_SHORTEN_STRATEGY == truncate_with_package_name && $+commands[jq] == 0 ]]; then
  8121. print -rP -- '%F{yellow}WARNING!%f %BPOWERLEVEL9K_SHORTEN_STRATEGY=truncate_with_package_name%b requires %F{green}jq%f.'
  8122. print -rP -- 'Either install %F{green}jq%f or change the value of %BPOWERLEVEL9K_SHORTEN_STRATEGY%b.'
  8123. fi
  8124. _p9k_init_vcs
  8125. if (( _p9k__instant_prompt_disabled )); then
  8126. (( _POWERLEVEL9K_DISABLE_INSTANT_PROMPT )) && unset __p9k_instant_prompt_erased
  8127. _p9k_delete_instant_prompt
  8128. _p9k_dumped_instant_prompt_sigs=()
  8129. fi
  8130. if (( $+__p9k_instant_prompt_sourced && __p9k_instant_prompt_sourced != __p9k_instant_prompt_version )); then
  8131. _p9k_delete_instant_prompt
  8132. _p9k_dumped_instant_prompt_sigs=()
  8133. fi
  8134. if (( $+__p9k_instant_prompt_erased )); then
  8135. unset __p9k_instant_prompt_erased
  8136. if [[ -w $TTY ]]; then
  8137. local tty=$TTY
  8138. elif [[ -w /dev/tty ]]; then
  8139. local tty=/dev/tty
  8140. else
  8141. local tty=/dev/null
  8142. fi
  8143. {
  8144. >&2 echo -E - ""
  8145. >&2 echo -E - "${(%):-[%1FERROR%f]: When using instant prompt, Powerlevel10k must be loaded before the first prompt.}"
  8146. >&2 echo -E - ""
  8147. >&2 echo -E - "${(%):-You can:}"
  8148. >&2 echo -E - ""
  8149. >&2 echo -E - "${(%):- - %BRecommended%b: Change the way Powerlevel10k is loaded from %B$__p9k_zshrc_u%b.}"
  8150. if (( _p9k_term_has_href )); then
  8151. >&2 echo - "${(%):- See \e]8;;https://github.com/romkatv/powerlevel10k/blob/master/README.md#installation\ahttps://github.com/romkatv/powerlevel10k/blob/master/README.md#installation\e]8;;\a.}"
  8152. else
  8153. >&2 echo - "${(%):- See https://github.com/romkatv/powerlevel10k/blob/master/README.md#installation.}"
  8154. fi
  8155. if (( $+zsh_defer_options )); then
  8156. >&2 echo -E - ""
  8157. >&2 echo -E - "${(%):- NOTE: Do not use %1Fzsh-defer%f to load %Upowerlevel10k.zsh-theme%u.}"
  8158. elif (( $+functions[zinit] )); then
  8159. >&2 echo -E - ""
  8160. >&2 echo -E - "${(%):- NOTE: If using %2Fzinit%f to load %3F'romkatv/powerlevel10k'%f, %Bdo not apply%b %1Fice wait%f.}"
  8161. elif (( $+functions[zplugin] )); then
  8162. >&2 echo -E - ""
  8163. >&2 echo -E - "${(%):- NOTE: If using %2Fzplugin%f to load %3F'romkatv/powerlevel10k'%f, %Bdo not apply%b %1Fice wait%f.}"
  8164. fi
  8165. >&2 echo -E - ""
  8166. >&2 echo -E - "${(%):- * You %Bwill not%b see this error message again.}"
  8167. >&2 echo -E - "${(%):- * Zsh will start %Bquickly%b.}"
  8168. >&2 echo -E - ""
  8169. >&2 echo -E - "${(%):- - Disable instant prompt either by running %Bp10k configure%b or by manually}"
  8170. >&2 echo -E - "${(%):- defining the following parameter:}"
  8171. >&2 echo -E - ""
  8172. >&2 echo -E - "${(%):- %3Ftypeset%f -g POWERLEVEL9K_INSTANT_PROMPT=off}"
  8173. >&2 echo -E - ""
  8174. >&2 echo -E - "${(%):- * You %Bwill not%b see this error message again.}"
  8175. >&2 echo -E - "${(%):- * Zsh will start %Bslowly%b.}"
  8176. >&2 echo -E - ""
  8177. >&2 echo -E - "${(%):- - Do nothing.}"
  8178. >&2 echo -E - ""
  8179. >&2 echo -E - "${(%):- * You %Bwill%b see this error message every time you start zsh.}"
  8180. >&2 echo -E - "${(%):- * Zsh will start %Bslowly%b.}"
  8181. >&2 echo -E - ""
  8182. } 2>>$tty
  8183. fi
  8184. }
  8185. _p9k_deinit() {
  8186. (( $+functions[_p9k_preinit] )) && unfunction _p9k_preinit
  8187. (( $+functions[gitstatus_stop_p9k_] )) && gitstatus_stop_p9k_ POWERLEVEL9K
  8188. _p9k_worker_stop
  8189. if (( _p9k__state_dump_fd )); then
  8190. zle -F $_p9k__state_dump_fd
  8191. exec {_p9k__state_dump_fd}>&-
  8192. fi
  8193. if (( _p9k__restore_prompt_fd )); then
  8194. zle -F $_p9k__restore_prompt_fd
  8195. exec {_p9k__restore_prompt_fd}>&-
  8196. fi
  8197. if (( _p9k__redraw_fd )); then
  8198. zle -F $_p9k__redraw_fd
  8199. exec {_p9k__redraw_fd}>&-
  8200. fi
  8201. (( $+_p9k__iterm2_precmd )) && functions[iterm2_precmd]=$_p9k__iterm2_precmd
  8202. (( $+_p9k__iterm2_decorate_prompt )) && functions[iterm2_decorate_prompt]=$_p9k__iterm2_decorate_prompt
  8203. unset -m '(_POWERLEVEL9K_|P9K_|_p9k_)*~(P9K_SSH|_P9K_SSH_TTY|P9K_TOOLBOX_NAME|P9K_TTY|_P9K_TTY)'
  8204. [[ -n $__p9k_locale ]] || unset __p9k_locale
  8205. }
  8206. typeset -gi __p9k_enabled=0
  8207. typeset -gi __p9k_configured=0
  8208. typeset -gri __p9k_instant_prompt_disabled=1
  8209. # `typeset -g` doesn't roundtrip in zsh prior to 5.4.
  8210. if [[ $ZSH_VERSION == (5.<4->*|<6->.*) ]]; then
  8211. typeset -gri __p9k_dumps_enabled=1
  8212. else
  8213. typeset -gri __p9k_dumps_enabled=0
  8214. fi
  8215. _p9k_do_nothing() { true; }
  8216. _p9k_precmd_first() {
  8217. eval "$__p9k_intro"
  8218. if [[ -n $KITTY_SHELL_INTEGRATION && KITTY_SHELL_INTEGRATION[(wIe)no-prompt-mark] -eq 0 ]]; then
  8219. KITTY_SHELL_INTEGRATION+=' no-prompt-mark'
  8220. (( $+__p9k_force_term_shell_integration )) || typeset -gri __p9k_force_term_shell_integration=1
  8221. elif [[ $TERM_PROGRAM == WarpTerminal ]]; then
  8222. (( $+__p9k_force_term_shell_integration )) || typeset -gri __p9k_force_term_shell_integration=1
  8223. fi
  8224. typeset -ga precmd_functions=(${precmd_functions:#_p9k_precmd_first})
  8225. }
  8226. _p9k_setup() {
  8227. (( __p9k_enabled )) && return
  8228. prompt_opts=(percent subst)
  8229. if (( ! $+__p9k_instant_prompt_active )); then
  8230. prompt_opts+=sp
  8231. prompt_opts+=cr
  8232. fi
  8233. prompt_powerlevel9k_teardown
  8234. __p9k_enabled=1
  8235. typeset -ga preexec_functions=(_p9k_preexec1 $preexec_functions _p9k_preexec2)
  8236. typeset -ga precmd_functions=(_p9k_do_nothing _p9k_precmd_first $precmd_functions _p9k_precmd)
  8237. }
  8238. prompt_powerlevel9k_setup() {
  8239. _p9k_restore_special_params
  8240. eval "$__p9k_intro"
  8241. _p9k_setup
  8242. }
  8243. prompt_powerlevel9k_teardown() {
  8244. _p9k_restore_special_params
  8245. eval "$__p9k_intro"
  8246. add-zsh-hook -D precmd '(_p9k_|powerlevel9k_)*'
  8247. add-zsh-hook -D preexec '(_p9k_|powerlevel9k_)*'
  8248. PROMPT='%m%# '
  8249. RPROMPT=
  8250. if (( __p9k_enabled )); then
  8251. _p9k_deinit
  8252. __p9k_enabled=0
  8253. fi
  8254. }
  8255. typeset -gr __p9k_p10k_usage="Usage: %2Fp10k%f %Bcommand%b [options]
  8256. Commands:
  8257. %Bconfigure%b run interactive configuration wizard
  8258. %Breload%b reload configuration
  8259. %Bsegment%b print a user-defined prompt segment
  8260. %Bdisplay%b show, hide or toggle prompt parts
  8261. %Bhelp%b print this help message
  8262. Print help for a specific command:
  8263. %2Fp10k%f %Bhelp%b command"
  8264. typeset -gr __p9k_p10k_segment_usage="Usage: %2Fp10k%f %Bsegment%b [-h] [{+|-}re] [-s state] [-b bg] [-f fg] [-i icon] [-c cond] [-t text]
  8265. Print a user-defined prompt segment. Can be called only during prompt rendering.
  8266. Options:
  8267. -t text segment's main content; will undergo prompt expansion: '%%F{blue}%%*%%f' will
  8268. show as %F{blue}%*%f; default is empty
  8269. -i icon segment's icon; default is empty
  8270. -r icon is a symbolic reference that needs to be resolved; for example, 'LOCK_ICON'
  8271. +r icon is already resolved and should be printed literally; for example, '⭐';
  8272. this is the default; you can also use \$'\u2B50' if you don't want to have
  8273. non-ascii characters in source code
  8274. -b bg background color; for example, 'blue', '4', or '#0000ff'; empty value means
  8275. transparent background, as in '%%k'; default is black
  8276. -f fg foreground color; for example, 'blue', '4', or '#0000ff'; empty value means
  8277. default foreground color, as in '%%f'; default is empty
  8278. -s state segment's state for the purpose of applying styling options; if you want to
  8279. to be able to use POWERLEVEL9K parameters to specify different colors or icons
  8280. depending on some property, use different states for different values of that
  8281. property
  8282. -c condition; if empty after parameter expansion and process substitution, the
  8283. segment is hidden; this is an advanced feature, use with caution; default is '1'
  8284. -e segment's main content will undergo parameter expansion and process
  8285. substitution; the content will be surrounded with double quotes and thus
  8286. should quote its own double quotes; this is an advanced feature, use with
  8287. caution
  8288. +e segment's main content should not undergo parameter expansion and process
  8289. substitution; this is the default
  8290. -h print this help message
  8291. Example: 'core' segment tells you if there is a file name 'core' in the current directory.
  8292. - Segment's icon is '⭐'.
  8293. - Segment's text is the file's size in bytes.
  8294. - If you have permissions to delete the file, state is DELETABLE. If not, it's PROTECTED.
  8295. zmodload -F zsh/stat b:zstat
  8296. function prompt_core() {
  8297. local size=()
  8298. if ! zstat -A size +size core 2>/dev/null; then
  8299. # No 'core' file in the current directory.
  8300. return
  8301. fi
  8302. if [[ -w . ]]; then
  8303. local state=DELETABLE
  8304. else
  8305. local state=PROTECTED
  8306. fi
  8307. p10k segment -s \$state -i '⭐' -f blue -t \${size[1]}b
  8308. }
  8309. To enable this segment, add 'core' to POWERLEVEL9K_LEFT_PROMPT_ELEMENTS or
  8310. POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS.
  8311. Example customizations:
  8312. # Override default foreground.
  8313. POWERLEVEL9K_CORE_FOREGROUND=red
  8314. # Override foreground when DELETABLE.
  8315. POWERLEVEL9K_CORE_DELETABLE_BACKGROUND=green
  8316. # Override icon when PROTECTED.
  8317. POWERLEVEL9K_CORE_PROTECTED_VISUAL_IDENTIFIER_EXPANSION='❎'
  8318. # Don't show file size when PROTECTED.
  8319. POWERLEVEL9K_CORE_PROTECTED_CONTENT_EXPANSION=''"
  8320. typeset -gr __p9k_p10k_configure_usage="Usage: %2Fp10k%f %Bconfigure%b
  8321. Run interactive configuration wizard."
  8322. typeset -gr __p9k_p10k_reload_usage="Usage: %2Fp10k%f %Breload%b
  8323. Reload configuration."
  8324. typeset -gr __p9k_p10k_finalize_usage="Usage: %2Fp10k%f %Bfinalize%b
  8325. Perform the final stage of initialization. Must be called at the very end of zshrc."
  8326. typeset -gr __p9k_p10k_display_usage="Usage: %2Fp10k%f %Bdisplay%b part-pattern=state-list...
  8327. Show, hide or toggle prompt parts. If called from zle, the current
  8328. prompt is refreshed.
  8329. Usage: %2Fp10k%f %Bdisplay%b -a [part-pattern]...
  8330. Populate array \`reply\` with states of prompt parts matching the patterns.
  8331. If no patterns are supplied, assume \`*\`.
  8332. Usage: %2Fp10k%f %Bdisplay%b -r
  8333. Redisplay prompt.
  8334. Parts:
  8335. empty_line empty line (duh)
  8336. ruler ruler; if POWERLEVEL9K_RULER_CHAR=' ', it's essentially another
  8337. new_line
  8338. N prompt line number N, 1-based; counting from the top if positive,
  8339. from the bottom if negative
  8340. N/left_frame left frame on the Nth line
  8341. N/left left prompt on the Nth line
  8342. N/gap gap between left and right prompts on the Nth line
  8343. N/right right prompt on the Nth line
  8344. N/right_frame right frame on the Nth line
  8345. N/left/S segment S within N/left (dir, time, etc.)
  8346. N/right/S segment S within N/right (dir, time, etc.)
  8347. Part States:
  8348. show the part is displayed
  8349. hide the part is not displayed
  8350. print the part is printed in precmd; only applicable to empty_line and
  8351. ruler; unlike show, the effects of print cannot be undone with hide;
  8352. print used to look better after \`clear\` but this is no longer the
  8353. case; it's best to avoid it unless you know what you are doing
  8354. part-pattern is a glob pattern for parts. Examples:
  8355. */kubecontext all kubecontext prompt segments, regardless of where
  8356. they are
  8357. 1/(right|right_frame) all prompt segments and frame from the right side of
  8358. the first line
  8359. state-list is a comma-separated list of states. Must have at least one element.
  8360. If more than one, states will rotate.
  8361. Example: Bind Ctrl+P to toggle right prompt.
  8362. function toggle-right-prompt() { p10k display '*/right'=hide,show; }
  8363. zle -N toggle-right-prompt
  8364. bindkey '^P' toggle-right-prompt
  8365. Example: Print the current state of all prompt parts:
  8366. typeset -A reply
  8367. p10k display -a '*'
  8368. printf '%%-32s = %%q\n' \${(@kv)reply} | sort
  8369. "
  8370. # 0 -- reset-prompt not blocked
  8371. # 1 -- reset-prompt blocked and not needed
  8372. # 2 -- reset-prompt blocked and needed
  8373. typeset -gi __p9k_reset_state
  8374. function p10k() {
  8375. [[ $# != 1 || $1 != finalize ]] || { p10k-instant-prompt-finalize; return 0 }
  8376. eval "$__p9k_intro_no_reply"
  8377. if (( !ARGC )); then
  8378. print -rP -- $__p9k_p10k_usage >&2
  8379. return 1
  8380. fi
  8381. case $1 in
  8382. segment)
  8383. local REPLY
  8384. local -a reply
  8385. shift
  8386. local -i OPTIND
  8387. local OPTARG opt state bg=0 fg icon cond text ref=0 expand=0
  8388. while getopts ':s:b:f:i:c:t:reh' opt; do
  8389. case $opt in
  8390. s) state=$OPTARG;;
  8391. b) bg=$OPTARG;;
  8392. f) fg=$OPTARG;;
  8393. i) icon=$OPTARG;;
  8394. c) cond=${OPTARG:-'${:-}'};;
  8395. t) text=$OPTARG;;
  8396. r) ref=1;;
  8397. e) expand=1;;
  8398. +r) ref=0;;
  8399. +e) expand=0;;
  8400. h) print -rP -- $__p9k_p10k_segment_usage; return 0;;
  8401. ?) print -rP -- $__p9k_p10k_segment_usage >&2; return 1;;
  8402. esac
  8403. done
  8404. if (( OPTIND <= ARGC )); then
  8405. print -rP -- $__p9k_p10k_segment_usage >&2
  8406. return 1
  8407. fi
  8408. if [[ -z $_p9k__prompt_side ]]; then
  8409. print -rP -- "%1F[ERROR]%f %Bp10k segment%b: can be called only during prompt rendering." >&2
  8410. if (( !ARGC )); then
  8411. print -rP -- ""
  8412. print -rP -- "For help, type:" >&2
  8413. print -rP -- ""
  8414. print -rP -- " %2Fp10k%f %Bhelp%b %Bsegment%b" >&2
  8415. fi
  8416. return 1
  8417. fi
  8418. (( ref )) || icon=$'\1'$icon
  8419. typeset -i _p9k__has_upglob
  8420. "_p9k_${_p9k__prompt_side}_prompt_segment" "prompt_${_p9k__segment_name}${state:+_${${(U)state}//İ/I}}" \
  8421. "$bg" "${fg:-$_p9k_color1}" "$icon" "$expand" "$cond" "$text"
  8422. return 0
  8423. ;;
  8424. display)
  8425. if (( ARGC == 1 )); then
  8426. print -rP -- $__p9k_p10k_display_usage >&2
  8427. return 1
  8428. fi
  8429. shift
  8430. local -i k dump
  8431. local opt prev new pair list name var
  8432. while getopts ':har' opt; do
  8433. case $opt in
  8434. r)
  8435. if (( __p9k_reset_state > 0 )); then
  8436. __p9k_reset_state=2
  8437. else
  8438. __p9k_reset_state=-1
  8439. fi
  8440. ;;
  8441. a) dump=1;;
  8442. h) print -rP -- $__p9k_p10k_display_usage; return 0;;
  8443. ?) print -rP -- $__p9k_p10k_display_usage >&2; return 1;;
  8444. esac
  8445. done
  8446. if (( dump )); then
  8447. reply=()
  8448. shift $((OPTIND-1))
  8449. (( ARGC )) || set -- '*'
  8450. for opt; do
  8451. for k in ${(u@)_p9k_display_k[(I)$opt]:/(#m)*/$_p9k_display_k[$MATCH]}; do
  8452. reply+=($_p9k__display_v[k,k+1])
  8453. done
  8454. done
  8455. if (( __p9k_reset_state == -1 )); then
  8456. _p9k_reset_prompt
  8457. fi
  8458. return 0
  8459. fi
  8460. local REPLY
  8461. local -a reply
  8462. for opt in "${@:$OPTIND}"; do
  8463. pair=(${(s:=:)opt})
  8464. list=(${(s:,:)${pair[2]}})
  8465. if [[ ${(b)pair[1]} == $pair[1] ]]; then # this branch is purely for optimization
  8466. local ks=($_p9k_display_k[$pair[1]])
  8467. else
  8468. local ks=(${(u@)_p9k_display_k[(I)$pair[1]]:/(#m)*/$_p9k_display_k[$MATCH]})
  8469. fi
  8470. for k in $ks; do
  8471. if (( $#list == 1 )); then # this branch is purely for optimization
  8472. [[ $_p9k__display_v[k+1] == $list[1] ]] && continue
  8473. new=$list[1]
  8474. else
  8475. new=${list[list[(I)$_p9k__display_v[k+1]]+1]:-$list[1]}
  8476. [[ $_p9k__display_v[k+1] == $new ]] && continue
  8477. fi
  8478. _p9k__display_v[k+1]=$new
  8479. name=$_p9k__display_v[k]
  8480. if [[ $name == (empty_line|ruler) ]]; then
  8481. var=_p9k__${name}_i
  8482. [[ $new == show ]] && unset $var || typeset -gi $var=3
  8483. elif [[ $name == (#b)(<->)(*) ]]; then
  8484. var=_p9k__${match[1]}${${${${match[2]//\/}/#left/l}/#right/r}/#gap/g}
  8485. [[ $new == hide ]] && typeset -g $var= || unset $var
  8486. fi
  8487. if (( __p9k_reset_state > 0 )); then
  8488. __p9k_reset_state=2
  8489. else
  8490. __p9k_reset_state=-1
  8491. fi
  8492. done
  8493. done
  8494. if (( __p9k_reset_state == -1 )); then
  8495. _p9k_reset_prompt
  8496. fi
  8497. ;;
  8498. configure)
  8499. if (( ARGC > 1 )); then
  8500. print -rP -- $__p9k_p10k_configure_usage >&2
  8501. return 1
  8502. fi
  8503. local REPLY
  8504. local -a reply
  8505. p9k_configure "$@" || return
  8506. ;;
  8507. reload)
  8508. if (( ARGC > 1 )); then
  8509. print -rP -- $__p9k_p10k_reload_usage >&2
  8510. return 1
  8511. fi
  8512. (( $+_p9k__force_must_init )) || return 0
  8513. _p9k__force_must_init=1
  8514. ;;
  8515. help)
  8516. local var=__p9k_p10k_$2_usage
  8517. if (( $+parameters[$var] )); then
  8518. print -rP -- ${(P)var}
  8519. return 0
  8520. elif (( ARGC == 1 )); then
  8521. print -rP -- $__p9k_p10k_usage
  8522. return 0
  8523. else
  8524. print -rP -- $__p9k_p10k_usage >&2
  8525. return 1
  8526. fi
  8527. ;;
  8528. finalize)
  8529. print -rP -- $__p9k_p10k_finalize_usage >&2
  8530. return 1
  8531. ;;
  8532. clear-instant-prompt)
  8533. if (( $+__p9k_instant_prompt_active )); then
  8534. _p9k_clear_instant_prompt
  8535. unset __p9k_instant_prompt_active
  8536. fi
  8537. return 0
  8538. ;;
  8539. *)
  8540. print -rP -- $__p9k_p10k_usage >&2
  8541. return 1
  8542. ;;
  8543. esac
  8544. }
  8545. # Hook for zplugin.
  8546. powerlevel10k_plugin_unload() { prompt_powerlevel9k_teardown; }
  8547. function p10k-instant-prompt-finalize() {
  8548. unsetopt local_options
  8549. (( ${+__p9k_instant_prompt_active} )) && unsetopt prompt_cr prompt_sp || setopt prompt_cr prompt_sp
  8550. }
  8551. autoload -Uz add-zsh-hook
  8552. zmodload zsh/datetime
  8553. zmodload zsh/mathfunc
  8554. zmodload zsh/parameter 2>/dev/null # https://github.com/romkatv/gitstatus/issues/58#issuecomment-553407177
  8555. zmodload zsh/system
  8556. zmodload zsh/termcap
  8557. zmodload zsh/terminfo
  8558. zmodload zsh/zleparameter
  8559. zmodload -F zsh/stat b:zstat
  8560. zmodload -F zsh/net/socket b:zsocket
  8561. zmodload -F zsh/files b:zf_mv b:zf_rm
  8562. if [[ $__p9k_dump_file != $__p9k_instant_prompt_dump_file && -n $__p9k_instant_prompt_dump_file ]]; then
  8563. _p9k_delete_instant_prompt
  8564. zf_rm -f -- $__p9k_dump_file{,.zwc} 2>/dev/null
  8565. zf_rm -f -- $__p9k_instant_prompt_dump_file{,.zwc} 2>/dev/null
  8566. fi
  8567. typeset -g P9K_VERSION=1.19.6
  8568. unset VSCODE_SHELL_INTEGRATION
  8569. _p9k_init_ssh
  8570. _p9k_init_toolbox
  8571. prompt_powerlevel9k_setup