You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error(index+': directory stack index out of range');
878
+
}
879
+
}else{
880
+
error(index+': invalid number');
881
+
}
882
+
}
883
+
884
+
function_actualDirStack(){
885
+
return[process.cwd()].concat(_dirStack);
886
+
}
887
+
888
+
//@
889
+
//@ ### dirs([options | '+N' | '-N'])
890
+
//@
891
+
//@ Available options:
892
+
//@ + `-c`: Clears the directory stack by deleting all of the elements.
893
+
//@ + `-p`: Causes dirs to print the directory stack with one entry per line.
894
+
//@ + `-v`: Causes dirs to print the directory stack with one entry per line, prefixing each entry with its index in the stack.
895
+
//@
896
+
//@ Arguments:
897
+
//@ + `+N`: Displays the Nth directory (counting from the left of the list printed by dirs when invoked without options), starting with zero.
898
+
//@ + `-N`: Displays the Nth directory (counting from the right of the list printed by dirs when invoked without options), starting with zero.
899
+
//@
900
+
//@ Display the list of currently remembered directories. Returns an array of paths in the stack, or a single path if +N or -N was specified.
901
+
//@
902
+
//@ See also: pushd, popd
903
+
function_dirs(options,index){
904
+
if(_isStackIndex(options)){
905
+
index=options;
906
+
options='';
907
+
}
908
+
909
+
options=parseOptions(options,{
910
+
'c' : 'clear',
911
+
'v' : 'verbose',
912
+
'p' : 'pretty'
913
+
});
914
+
915
+
if(options['clear']){
916
+
return(_dirStack=[]);
917
+
}
918
+
919
+
varstack=_actualDirStack();
920
+
921
+
if(index){
922
+
index=_parseStackIndex(index);
923
+
924
+
if(index<0){
925
+
index=stack.length+index;
926
+
}
927
+
928
+
log(stack[index]);
929
+
returnstack[index];
930
+
}
931
+
932
+
if(options['verbose']||options['pretty']){
933
+
stack.forEach(function(dir,index){
934
+
if(options['verbose']){
935
+
log('',index,dir);
936
+
}else{
937
+
log(dir);
938
+
}
939
+
});
940
+
}else{
941
+
log(stack.join(' '));
942
+
}
943
+
944
+
returnstack;
945
+
}
946
+
exports.dirs=wrap("dirs",_dirs);
947
+
948
+
//@
949
+
//@ ### pushd([options,] [dir | '-N' | '+N'])
950
+
//@
951
+
//@ Available options:
952
+
//@ + `-n`: Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated.
953
+
//@
954
+
//@ Arguments
955
+
//@ + `dir`: Makes the current working directory be the top of the stack, and then executes the equivalent of `cd dir`.
956
+
//@ + `+N`: Brings the Nth directory (counting from the left of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.
957
+
//@ + `-N`: Brings the Nth directory (counting from the right of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.
958
+
//@
959
+
//@ Examples:
960
+
//@ ```javascript
961
+
//@ // process.cwd() === '/usr'
962
+
//@ pushd('/etc'); // Returns /etc /usr
963
+
//@ pushd('+1'); // Returns /usr /etc
964
+
//@ ```
965
+
//@
966
+
//@ Save the current directory on the top of the directory stack and then cd to `dir`. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack.
967
+
function_pushd(options,dir){
968
+
if(_isStackIndex(options)){
969
+
dir=options;
970
+
options='';
971
+
}
972
+
973
+
options=parseOptions(options,{
974
+
'n' : 'no-cd'
975
+
});
976
+
977
+
vardirs=_actualDirStack();
978
+
979
+
if(dir==='+0'){
980
+
returndirs;// +0 is a noop
981
+
}elseif(!dir){
982
+
if(dirs.length>1){
983
+
dirs=dirs.splice(1,1).concat(dirs);
984
+
}else{
985
+
returnerror('no other directory');
986
+
}
987
+
}elseif(_isStackIndex(dir)){
988
+
varn=_parseStackIndex(dir);
989
+
dirs=dirs.slice(n).concat(dirs.slice(0,n));
990
+
}else{
991
+
if(options['no-cd']){
992
+
dirs.splice(1,0,dir);
993
+
}else{
994
+
dirs.unshift(dir);
995
+
}
996
+
}
997
+
998
+
if(options['no-cd']){
999
+
dirs=dirs.slice(1);
1000
+
}else{
1001
+
dir=path.resolve(dirs.shift());
1002
+
_cd('',dir);
1003
+
}
1004
+
1005
+
_dirStack=dirs;
1006
+
return_dirs('');
1007
+
}
1008
+
exports.pushd=wrap('pushd',_pushd);
1009
+
1010
+
//@
1011
+
//@ ### popd([options,] ['-N' | '+N'])
1012
+
//@
1013
+
//@ Available options:
1014
+
//@ + `-n`: Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated.
1015
+
//@
1016
+
//@ Arguments:
1017
+
//@ + `+N`: Removes the Nth directory (counting from the left of the list printed by dirs), starting with zero.
1018
+
//@ + `-N`: Removes the Nth directory (counting from the right of the list printed by dirs), starting with zero.
1019
+
//@
1020
+
//@ Examples:
1021
+
//@ ```javascript
1022
+
//@ echo(process.cwd()); // '/usr'
1023
+
//@ pushd('/etc'); // '/etc /usr'
1024
+
//@ echo(process.cwd()); // '/etc'
1025
+
//@ popd(); // '/usr'
1026
+
//@ echo(process.cwd()); // '/usr'
1027
+
//@ ```
1028
+
//@
1029
+
//@ When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.
0 commit comments