repo
string
commit
string
message
string
diff
string
ahmednuaman/AS3
bb63b660bfe7d2ce27d7dfbf0b9c5fbe33a84e1d
added unmute
diff --git a/com/firestartermedia/lib/as3/sound/component/SoundPlayer.as b/com/firestartermedia/lib/as3/sound/component/SoundPlayer.as index 49b91d5..2f1e72d 100644 --- a/com/firestartermedia/lib/as3/sound/component/SoundPlayer.as +++ b/com/firestartermedia/lib/as3/sound/component/SoundPlayer.as @@ -1,160 +1,174 @@ /** * @author Ahmed Nuaman (http://www.ahmednuaman.com) * @langversion 3 * * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. */ package com.firestartermedia.lib.as3.sound.component { import com.firestartermedia.lib.as3.events.SoundPlayerEvent; import flash.events.Event; import flash.events.EventDispatcher; import flash.events.IEventDispatcher; import flash.events.IOErrorEvent; import flash.events.ProgressEvent; import flash.media.Sound; import flash.media.SoundChannel; import flash.media.SoundLoaderContext; import flash.media.SoundTransform; import flash.net.URLRequest; public class SoundPlayer extends EventDispatcher implements IEventDispatcher { public var autoPlay:Boolean = true; public var bufferTime:Number = 2; private var context:SoundLoaderContext = new SoundLoaderContext(); private var currentPosition:Number = 0; private var cuePoints:Array = [ ]; private var isPlaying:Boolean = false; private var lastFiredCuePoint:Number = 0; private var channel:SoundChannel; private var sound:Sound; public function SoundPlayer() { super( this ); sound.addEventListener( ProgressEvent.PROGRESS, handleSoundProgress ); sound.addEventListener( IOErrorEvent.IO_ERROR, handleSoundFault ); sound.addEventListener( Event.ID3, handleSoundDataReady ); sound.addEventListener( Event.COMPLETE, handleSoundComplete ); } private function handleSoundProgress(e:ProgressEvent):void { dispatchEvent( new SoundPlayerEvent( SoundPlayerEvent.LOADING, loadingProgress ) ); } private function handleSoundFault(e:*):void { dispatchEvent( new SoundPlayerEvent( SoundPlayerEvent.FAILED ) ); } private function handleSoundDataReady(e:Event):void { dispatchEvent( new SoundPlayerEvent( SoundPlayerEvent.ID3_READY, sound.id3 ) ); } private function handleSoundComplete(e:Event):void { if ( autoPlay ) { resume(); } } public function play(url:String):void { var request:URLRequest = new URLRequest( url ); context.bufferTime = 2; currentPosition = 0; if ( channel ) { channel = null; } if ( sound ) { sound.close(); } sound = new Sound(); sound.load( request, context ); channel = sound.play(); } public function resume():void { if ( !channel ) { channel = sound.play(); } sound.play( currentPosition ); isPlaying = true; } public function pause():void { if ( channel ) { currentPosition = channel.position; channel.stop(); isPlaying = false; } else { throw new Error( 'There\'s nothing to pause!' ); } } public function mute():void { var t:SoundTransform = new SoundTransform( 0, 0 ); if ( channel ) { channel.soundTransform = t; } else { throw new Error( 'There\'s nothing to mute!' ); } } + public function unmute():void + { + var t:SoundTransform = new SoundTransform( 1, 0 ); + + if ( channel ) + { + channel.soundTransform = t; + } + else + { + throw new Error( 'There\'s nothing to unmute!' ); + } + } + public function get loadingProgress():Object { var progress:Object = { }; progress.total = sound.bytesLoaded / sound.bytesTotal; progress.bytesLoaded = sound.bytesLoaded; progress.bytesTotal = sound.bytesTotal; return progress; } public function get playingTime():Object { var time:Object = { }; time.current = channel.position / 1000; time.total = sound.length / 1000; time.formatted = NumberUtil.toTimeString( Math.round( time.current ) ) + ' / ' + NumberUtil.toTimeString( Math.round( time.total ) ); return time; } } } \ No newline at end of file
ahmednuaman/AS3
7ff2603f2082dac3db85672c4149898e198cf209
added mute func
diff --git a/com/firestartermedia/lib/as3/sound/component/SoundPlayer.as b/com/firestartermedia/lib/as3/sound/component/SoundPlayer.as index f22bc11..49b91d5 100644 --- a/com/firestartermedia/lib/as3/sound/component/SoundPlayer.as +++ b/com/firestartermedia/lib/as3/sound/component/SoundPlayer.as @@ -1,143 +1,160 @@ /** * @author Ahmed Nuaman (http://www.ahmednuaman.com) * @langversion 3 * * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. */ package com.firestartermedia.lib.as3.sound.component { import com.firestartermedia.lib.as3.events.SoundPlayerEvent; import flash.events.Event; import flash.events.EventDispatcher; import flash.events.IEventDispatcher; import flash.events.IOErrorEvent; import flash.events.ProgressEvent; import flash.media.Sound; import flash.media.SoundChannel; import flash.media.SoundLoaderContext; + import flash.media.SoundTransform; import flash.net.URLRequest; public class SoundPlayer extends EventDispatcher implements IEventDispatcher { public var autoPlay:Boolean = true; public var bufferTime:Number = 2; private var context:SoundLoaderContext = new SoundLoaderContext(); private var currentPosition:Number = 0; private var cuePoints:Array = [ ]; private var isPlaying:Boolean = false; private var lastFiredCuePoint:Number = 0; private var channel:SoundChannel; private var sound:Sound; public function SoundPlayer() { super( this ); sound.addEventListener( ProgressEvent.PROGRESS, handleSoundProgress ); sound.addEventListener( IOErrorEvent.IO_ERROR, handleSoundFault ); sound.addEventListener( Event.ID3, handleSoundDataReady ); sound.addEventListener( Event.COMPLETE, handleSoundComplete ); } private function handleSoundProgress(e:ProgressEvent):void { dispatchEvent( new SoundPlayerEvent( SoundPlayerEvent.LOADING, loadingProgress ) ); } private function handleSoundFault(e:*):void { dispatchEvent( new SoundPlayerEvent( SoundPlayerEvent.FAILED ) ); } private function handleSoundDataReady(e:Event):void { dispatchEvent( new SoundPlayerEvent( SoundPlayerEvent.ID3_READY, sound.id3 ) ); } private function handleSoundComplete(e:Event):void { if ( autoPlay ) { resume(); } } public function play(url:String):void { var request:URLRequest = new URLRequest( url ); context.bufferTime = 2; currentPosition = 0; if ( channel ) { channel = null; } if ( sound ) { sound.close(); } - sound = new Sound(); + sound = new Sound(); sound.load( request, context ); + + channel = sound.play(); } public function resume():void { if ( !channel ) { channel = sound.play(); } sound.play( currentPosition ); isPlaying = true; } public function pause():void { if ( channel ) { currentPosition = channel.position; channel.stop(); isPlaying = false; } else { throw new Error( 'There\'s nothing to pause!' ); } } + public function mute():void + { + var t:SoundTransform = new SoundTransform( 0, 0 ); + + if ( channel ) + { + channel.soundTransform = t; + } + else + { + throw new Error( 'There\'s nothing to mute!' ); + } + } + public function get loadingProgress():Object { var progress:Object = { }; progress.total = sound.bytesLoaded / sound.bytesTotal; progress.bytesLoaded = sound.bytesLoaded; progress.bytesTotal = sound.bytesTotal; return progress; } public function get playingTime():Object { var time:Object = { }; time.current = channel.position / 1000; time.total = sound.length / 1000; time.formatted = NumberUtil.toTimeString( Math.round( time.current ) ) + ' / ' + NumberUtil.toTimeString( Math.round( time.total ) ); return time; } } } \ No newline at end of file
ahmednuaman/AS3
4d684c87e09799f496fff18763018a3411eae333
added time obj
diff --git a/com/firestartermedia/lib/as3/sound/component/SoundPlayer.as b/com/firestartermedia/lib/as3/sound/component/SoundPlayer.as index 993f09a..f22bc11 100644 --- a/com/firestartermedia/lib/as3/sound/component/SoundPlayer.as +++ b/com/firestartermedia/lib/as3/sound/component/SoundPlayer.as @@ -1,143 +1,143 @@ /** * @author Ahmed Nuaman (http://www.ahmednuaman.com) * @langversion 3 * * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. */ package com.firestartermedia.lib.as3.sound.component { import com.firestartermedia.lib.as3.events.SoundPlayerEvent; import flash.events.Event; import flash.events.EventDispatcher; import flash.events.IEventDispatcher; import flash.events.IOErrorEvent; import flash.events.ProgressEvent; import flash.media.Sound; import flash.media.SoundChannel; import flash.media.SoundLoaderContext; import flash.net.URLRequest; public class SoundPlayer extends EventDispatcher implements IEventDispatcher { public var autoPlay:Boolean = true; public var bufferTime:Number = 2; private var context:SoundLoaderContext = new SoundLoaderContext(); private var currentPosition:Number = 0; private var cuePoints:Array = [ ]; private var isPlaying:Boolean = false; private var lastFiredCuePoint:Number = 0; private var channel:SoundChannel; private var sound:Sound; public function SoundPlayer() { super( this ); sound.addEventListener( ProgressEvent.PROGRESS, handleSoundProgress ); sound.addEventListener( IOErrorEvent.IO_ERROR, handleSoundFault ); sound.addEventListener( Event.ID3, handleSoundDataReady ); sound.addEventListener( Event.COMPLETE, handleSoundComplete ); } private function handleSoundProgress(e:ProgressEvent):void { dispatchEvent( new SoundPlayerEvent( SoundPlayerEvent.LOADING, loadingProgress ) ); } private function handleSoundFault(e:*):void { dispatchEvent( new SoundPlayerEvent( SoundPlayerEvent.FAILED ) ); } private function handleSoundDataReady(e:Event):void { dispatchEvent( new SoundPlayerEvent( SoundPlayerEvent.ID3_READY, sound.id3 ) ); } private function handleSoundComplete(e:Event):void { if ( autoPlay ) { resume(); } } public function play(url:String):void { var request:URLRequest = new URLRequest( url ); context.bufferTime = 2; currentPosition = 0; if ( channel ) { channel = null; } if ( sound ) { sound.close(); } sound = new Sound(); sound.load( request, context ); } public function resume():void { if ( !channel ) { channel = sound.play(); } sound.play( currentPosition ); isPlaying = true; } public function pause():void { if ( channel ) { currentPosition = channel.position; channel.stop(); isPlaying = false; } else { throw new Error( 'There\'s nothing to pause!' ); } } public function get loadingProgress():Object { var progress:Object = { }; progress.total = sound.bytesLoaded / sound.bytesTotal; progress.bytesLoaded = sound.bytesLoaded; progress.bytesTotal = sound.bytesTotal; return progress; } public function get playingTime():Object { var time:Object = { }; - /*time.current = stream.time; - time.total = metaData.duration; - time.formatted = NumberUtil.toTimeString( Math.round( stream.time ) ) + ' / ' + NumberUtil.toTimeString( Math.round( metaData.duration ) ); */ + time.current = channel.position / 1000; + time.total = sound.length / 1000; + time.formatted = NumberUtil.toTimeString( Math.round( time.current ) ) + ' / ' + NumberUtil.toTimeString( Math.round( time.total ) ); return time; } } } \ No newline at end of file
ahmednuaman/AS3
a646d3109463f9da99e3fcb9712d5c3d3ae5b955
added nicer mediator adding
diff --git a/com/firestartermedia/lib/puremvc/patterns/ApplicationMediator.as b/com/firestartermedia/lib/puremvc/patterns/ApplicationMediator.as index 5d1da22..56e571e 100644 --- a/com/firestartermedia/lib/puremvc/patterns/ApplicationMediator.as +++ b/com/firestartermedia/lib/puremvc/patterns/ApplicationMediator.as @@ -1,107 +1,108 @@ package com.firestartermedia.lib.puremvc.patterns { import com.firestartermedia.lib.as3.utils.ArrayUtil; import flash.utils.getDefinitionByName; import org.puremvc.as3.interfaces.IMediator; import org.puremvc.as3.interfaces.INotification; public class ApplicationMediator extends Mediator implements IMediator { protected var classPath:String = 'com.firestartermedia.view.'; protected var excludedMediators:Array = [ ]; protected var tabbedMediators:Array = [ ]; protected var viewNamingHide:String = 'Hide'; protected var viewNamingMediator:String = 'Mediator'; protected var viewNamingShow:String = 'Show'; protected var currentMediator:String; public function ApplicationMediator(name:String=null, viewComponent:Object=null) { super( name, viewComponent ); } protected function addMediator(mediator:Object, data:Object=null):void { var m:Object; if ( !mediator.hasOwnProperty( 'NAME' ) ) { mediator = getDefinitionByName( classPath + mediator.toString().split( '-' )[ 0 ] ) as Class } if ( !facade.hasMediator( mediator.NAME ) ) { removeOtherMediators( mediator.NAME ); facade.registerMediator( new mediator() ); m = facade.retrieveMediator( mediator.NAME ); view.addChild( m.getViewComponent() ); if ( m.hasOwnProperty( 'data' ) ) { m.data = data; } currentMediator = mediator.NAME; } } protected function removeMediator(mediator:Object):void { var m:Object; if ( !mediator.hasOwnProperty( 'NAME' ) ) { mediator = getDefinitionByName( classPath + mediator.toString().split( '-' )[ 0 ] ) as Class } if ( facade.hasMediator( mediator.NAME ) ) { m = facade.retrieveMediator( mediator.NAME ); view.removeChild( m.getViewComponent() ); facade.removeMediator( mediator.NAME ); } } protected function removeOtherMediators(mediator:String=''):void { if ( ( ArrayUtil.search( excludedMediators, mediator ) === -1 && ArrayUtil.search( tabbedMediators, mediator ) !== -1 ) || mediator === '' ) { for each ( var m:String in tabbedMediators ) { if ( m !== mediator ) { removeMediator( getDefinitionByName( classPath + m ) as Class ); } } } } protected function handleSectionChange(notification:INotification):void { var name:String = notification.getName(); + var data:Object = notification.getBody(); var mediator:String = name.replace( viewNamingHide, '' ).replace( viewNamingShow, '' ) + viewNamingMediator; if ( name.indexOf( viewNamingHide ) !== -1 ) { removeMediator( mediator ); } else { - addMediator( mediator ); + addMediator( mediator, data ); } } protected function mediator(name:String):* { return facade.retrieveMediator( name ); } } } \ No newline at end of file
ahmednuaman/AS3
a6aba0d1c1d7cc99dcb7aee940336a826419c17e
set a default class path, for my own use :D
diff --git a/com/firestartermedia/lib/puremvc/patterns/ApplicationMediator.as b/com/firestartermedia/lib/puremvc/patterns/ApplicationMediator.as index b253b4c..5d1da22 100644 --- a/com/firestartermedia/lib/puremvc/patterns/ApplicationMediator.as +++ b/com/firestartermedia/lib/puremvc/patterns/ApplicationMediator.as @@ -1,107 +1,107 @@ package com.firestartermedia.lib.puremvc.patterns { import com.firestartermedia.lib.as3.utils.ArrayUtil; import flash.utils.getDefinitionByName; import org.puremvc.as3.interfaces.IMediator; import org.puremvc.as3.interfaces.INotification; public class ApplicationMediator extends Mediator implements IMediator { + protected var classPath:String = 'com.firestartermedia.view.'; protected var excludedMediators:Array = [ ]; protected var tabbedMediators:Array = [ ]; protected var viewNamingHide:String = 'Hide'; protected var viewNamingMediator:String = 'Mediator'; protected var viewNamingShow:String = 'Show'; - protected var classPath:String; protected var currentMediator:String; public function ApplicationMediator(name:String=null, viewComponent:Object=null) { super( name, viewComponent ); } protected function addMediator(mediator:Object, data:Object=null):void { var m:Object; if ( !mediator.hasOwnProperty( 'NAME' ) ) { mediator = getDefinitionByName( classPath + mediator.toString().split( '-' )[ 0 ] ) as Class } if ( !facade.hasMediator( mediator.NAME ) ) { removeOtherMediators( mediator.NAME ); facade.registerMediator( new mediator() ); m = facade.retrieveMediator( mediator.NAME ); view.addChild( m.getViewComponent() ); if ( m.hasOwnProperty( 'data' ) ) { m.data = data; } currentMediator = mediator.NAME; } } protected function removeMediator(mediator:Object):void { var m:Object; if ( !mediator.hasOwnProperty( 'NAME' ) ) { mediator = getDefinitionByName( classPath + mediator.toString().split( '-' )[ 0 ] ) as Class } if ( facade.hasMediator( mediator.NAME ) ) { m = facade.retrieveMediator( mediator.NAME ); view.removeChild( m.getViewComponent() ); facade.removeMediator( mediator.NAME ); } } protected function removeOtherMediators(mediator:String=''):void { if ( ( ArrayUtil.search( excludedMediators, mediator ) === -1 && ArrayUtil.search( tabbedMediators, mediator ) !== -1 ) || mediator === '' ) { for each ( var m:String in tabbedMediators ) { if ( m !== mediator ) { removeMediator( getDefinitionByName( classPath + m ) as Class ); } } } } protected function handleSectionChange(notification:INotification):void { var name:String = notification.getName(); var mediator:String = name.replace( viewNamingHide, '' ).replace( viewNamingShow, '' ) + viewNamingMediator; if ( name.indexOf( viewNamingHide ) !== -1 ) { removeMediator( mediator ); } else { addMediator( mediator ); } } protected function mediator(name:String):* { return facade.retrieveMediator( name ); } } } \ No newline at end of file
ahmednuaman/AS3
b9dc3c5cc81b630cff7269a6f93199a5b0bbd875
added nice little section change helper func
diff --git a/com/firestartermedia/lib/puremvc/patterns/ApplicationMediator.as b/com/firestartermedia/lib/puremvc/patterns/ApplicationMediator.as index 3749af3..b253b4c 100644 --- a/com/firestartermedia/lib/puremvc/patterns/ApplicationMediator.as +++ b/com/firestartermedia/lib/puremvc/patterns/ApplicationMediator.as @@ -1,88 +1,107 @@ package com.firestartermedia.lib.puremvc.patterns { import com.firestartermedia.lib.as3.utils.ArrayUtil; import flash.utils.getDefinitionByName; import org.puremvc.as3.interfaces.IMediator; + import org.puremvc.as3.interfaces.INotification; public class ApplicationMediator extends Mediator implements IMediator { protected var excludedMediators:Array = [ ]; protected var tabbedMediators:Array = [ ]; + protected var viewNamingHide:String = 'Hide'; + protected var viewNamingMediator:String = 'Mediator'; + protected var viewNamingShow:String = 'Show'; protected var classPath:String; protected var currentMediator:String; public function ApplicationMediator(name:String=null, viewComponent:Object=null) { super( name, viewComponent ); } protected function addMediator(mediator:Object, data:Object=null):void { var m:Object; if ( !mediator.hasOwnProperty( 'NAME' ) ) { mediator = getDefinitionByName( classPath + mediator.toString().split( '-' )[ 0 ] ) as Class } if ( !facade.hasMediator( mediator.NAME ) ) { removeOtherMediators( mediator.NAME ); facade.registerMediator( new mediator() ); m = facade.retrieveMediator( mediator.NAME ); view.addChild( m.getViewComponent() ); if ( m.hasOwnProperty( 'data' ) ) { m.data = data; } currentMediator = mediator.NAME; } } protected function removeMediator(mediator:Object):void { var m:Object; if ( !mediator.hasOwnProperty( 'NAME' ) ) { mediator = getDefinitionByName( classPath + mediator.toString().split( '-' )[ 0 ] ) as Class } if ( facade.hasMediator( mediator.NAME ) ) { m = facade.retrieveMediator( mediator.NAME ); view.removeChild( m.getViewComponent() ); facade.removeMediator( mediator.NAME ); } } protected function removeOtherMediators(mediator:String=''):void { if ( ( ArrayUtil.search( excludedMediators, mediator ) === -1 && ArrayUtil.search( tabbedMediators, mediator ) !== -1 ) || mediator === '' ) { for each ( var m:String in tabbedMediators ) { if ( m !== mediator ) { removeMediator( getDefinitionByName( classPath + m ) as Class ); } } } } + protected function handleSectionChange(notification:INotification):void + { + var name:String = notification.getName(); + var mediator:String = name.replace( viewNamingHide, '' ).replace( viewNamingShow, '' ) + viewNamingMediator; + + if ( name.indexOf( viewNamingHide ) !== -1 ) + { + removeMediator( mediator ); + } + else + { + addMediator( mediator ); + } + } + protected function mediator(name:String):* { return facade.retrieveMediator( name ); } } } \ No newline at end of file
ahmednuaman/AS3
36664f0f41bb8b146fd9a374ba92bd4975358158
tidied up the setting of notification interests
diff --git a/com/firestartermedia/lib/puremvc/patterns/Mediator.as b/com/firestartermedia/lib/puremvc/patterns/Mediator.as index 557ea14..cb04fca 100644 --- a/com/firestartermedia/lib/puremvc/patterns/Mediator.as +++ b/com/firestartermedia/lib/puremvc/patterns/Mediator.as @@ -1,100 +1,109 @@ /** * @author Ahmed Nuaman (http://www.ahmednuaman.com) * @langversion 3 * * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. */ package com.firestartermedia.lib.puremvc.patterns { import com.adobe.utils.ArrayUtil; + import com.firestartermedia.lib.puremvc.vo.MediatorNotificationInterestVO; import flash.utils.Dictionary; import org.puremvc.as3.interfaces.INotification; import org.puremvc.as3.patterns.mediator.Mediator; public class Mediator extends org.puremvc.as3.patterns.mediator.Mediator { protected var notificationInterests:Array = [ ]; protected var notificationHandlers:Dictionary = new Dictionary(); protected var view:Object; public function Mediator(name:String=null, viewComponent:Object=null) { super( name, viewComponent ); view = viewComponent; declareNotificationInterest( 'ApplicationFacadeResize', handleResize ); trackEvent( 'Created ' + mediatorName ); } override public function onRegister():void { trackEvent( 'Registered ' + mediatorName ); } override public function onRemove():void { trackEvent( 'Removed ' + mediatorName ); onReset(); } private function onReset():void { if ( view.hasOwnProperty( 'handleReset' ) ) { trackEvent( 'Reset ' + mediatorName ); view.handleReset(); } } public function trackEvent(event:String):void { sendNotification( 'ApplicationFacadeTrack', event ); } public function sendEvent(event:*):void { sendNotification( event.type, event.data ); } - public function declareNotificationInterest(notificationName:String, func:Function):void + public function declareNotificationInterest(notification:String, func:Function):void { - notificationInterests.push( notificationName ); + notificationInterests.push( notification ); notificationInterests = ArrayUtil.createUniqueCopy( notificationInterests ); - notificationHandlers[ notificationName ] = func; + notificationHandlers[ notification ] = func; + } + + public function declareNotificationInterests(interests:Array):void + { + for each ( var interest:MediatorNotificationInterestVO in interests ) + { + declareNotificationInterest( interest.notification, interest.func ); + } } override public function listNotificationInterests():Array { return notificationInterests; } override public function handleNotification(notification:INotification):void { notificationHandlers[ notification.getName() ].apply( null, [ notification ] ); } public function handleReset(n:INotification):void { onReset(); } public function handleResize(n:INotification):void { if ( view.hasOwnProperty( 'handleResize' ) ) { view.handleResize( n.getBody() ); } } } } \ No newline at end of file diff --git a/com/firestartermedia/lib/puremvc/vo/MediatorNotificationInterestVO.as b/com/firestartermedia/lib/puremvc/vo/MediatorNotificationInterestVO.as new file mode 100644 index 0000000..7b0da1d --- /dev/null +++ b/com/firestartermedia/lib/puremvc/vo/MediatorNotificationInterestVO.as @@ -0,0 +1,14 @@ +package com.firestartermedia.lib.puremvc.vo +{ + public class MediatorNotificationInterestVO + { + public var func:Function; + public var notification:String; + + public function MediatorNotificationInterestVO(notification:String, func:Function) + { + this.func = func; + this.notification = notification; + } + } +} \ No newline at end of file
ahmednuaman/AS3
c25583f7219b1fb62426acb3685389cf15f8dc51
added flickr service
diff --git a/com/firestartermedia/lib/as3/data/flickr/FlickrDataService.as b/com/firestartermedia/lib/as3/data/flickr/FlickrDataService.as new file mode 100644 index 0000000..ce32b0a --- /dev/null +++ b/com/firestartermedia/lib/as3/data/flickr/FlickrDataService.as @@ -0,0 +1,34 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. + */ +package com.firestartermedia.lib.as3.data.flickr +{ + import com.firestartermedia.lib.as3.data.DataService; + import com.firestartermedia.lib.as3.events.DataServiceEvent; + + import flash.net.URLRequest; + + public class FlickrDataService extends DataService + { + public static const FLICKR_URL:String = 'http://api.flickr.com/services/rest/?format=json&nojsoncallback=1&api_key=API_KEY&method='; + + public static const METHOD_GET_PUBLIC_PHOTOS:String = 'flickr.people.getPublicPhotos'; + + public function FlickrDataService() + { + super( DataServiceEvent.LOADING, DataServiceEvent.LOADED, DataServiceEvent.READY, DataService.TYPE_JSON ); + } + + public function getPublicPhotos(userId:String, apiKey:String, extras:String=''):void + { + var request:URLRequest = new URLRequest( FLICKR_URL.replace( 'API_KEY', apiKey ) + METHOD_GET_PUBLIC_PHOTOS + '&user_id=' + userId + '&extras=' + extras ); + + loader.load( request ); + } + } +} \ No newline at end of file
ahmednuaman/AS3
9ec08ffa42cac6f0a1a1f34770edcb196db98427
fixed scaling
diff --git a/com/firestartermedia/lib/as3/utils/DisplayObjectUtil.as b/com/firestartermedia/lib/as3/utils/DisplayObjectUtil.as index f0562e3..bb831a4 100644 --- a/com/firestartermedia/lib/as3/utils/DisplayObjectUtil.as +++ b/com/firestartermedia/lib/as3/utils/DisplayObjectUtil.as @@ -1,135 +1,146 @@ /** * @author Ahmed Nuaman (http://www.ahmednuaman.com) * @langversion 3 * * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. */ package com.firestartermedia.lib.as3.utils { import flash.display.DisplayObject; import flash.display.DisplayObjectContainer; import flash.display.Loader; import flash.events.Event; import flash.geom.ColorTransform; import flash.geom.Matrix; import flash.geom.Point; import flash.net.URLRequest; import flash.system.ApplicationDomain; import flash.system.LoaderContext; public class DisplayObjectUtil { public static function removeChildren(target:DisplayObjectContainer):void { while ( target.numChildren ) { target.removeChildAt( target.numChildren - 1 ); } } public static function addChildren(target:DisplayObjectContainer, ...children):void { for each ( var child:DisplayObject in children ) { target.addChild( child ); } } public static function getChildren(target:DisplayObjectContainer):Array { var children:Array = [ ]; for ( var i:Number; target.numChildren < i; i++ ) { children.push( target.getChildAt( i ) ); } return children; } public static function loadMovie(url:String, parent:DisplayObjectContainer=null, completeFunction:Function=null, applicationDomain:ApplicationDomain=null, checkPolicyFile:Boolean=false):Loader { var request:URLRequest = new URLRequest( url ); var context:LoaderContext = new LoaderContext( checkPolicyFile, ( applicationDomain ||= ApplicationDomain.currentDomain ) ); var loader:Loader = new Loader(); if ( parent != null ) { parent.addChild( loader ); } if ( completeFunction != null ) { loader.contentLoaderInfo.addEventListener( Event.COMPLETE, completeFunction ); } try { loader.load( request, context ); } catch (e:*) { } return loader; } public static function scale(target:DisplayObject, width:Number=0, height:Number=0):void { - var targetHeight:Number = ( height > 0 ? height : target.height ); + /*var targetHeight:Number = ( height > 0 ? height : target.height ); var targetWidth:Number = targetHeight * ( target.width / target.height ); if ( targetWidth > target.width ) { targetWidth = ( width > 0 ? width : target.width ); targetHeight = targetWidth * ( target.height / target.width ); } target.height = targetHeight; - target.width = targetWidth; + target.width = targetWidth;*/ + + var scaleHeight:Number = height / target.height; + var scaleWidth:Number = width / target.width; + var scale:Number = ( scaleHeight <= scaleWidth ? scaleHeight : scaleWidth ); + + /*target.scaleX = scale; + target.scaleY = scale;*/ + + target.height = target.height * scale; + target.width = target.width * scale; + } public static function eachChild(target:DisplayObjectContainer, func:Function):Array { var funcReturn:Array = [ ]; for ( var i:Number = 0; i < target.numChildren; i++ ) { funcReturn.push( func.apply( null, [ target.getChildAt( i ) ] ) ); } return funcReturn; } public static function centerRotate(target:DisplayObject, center:Point, degrees:Number):void { var m:Matrix = target.transform.matrix; m.tx -= center.x; m.ty -= center.y; m.rotate( NumberUtil.toRadians( degrees ) ); m.tx += center.x; m.ty += center.y; target.transform.matrix = m; } public static function changeColour(target:DisplayObject, colour:*):void { var trans:ColorTransform = target.transform.colorTransform; var c:uint = ( colour is uint ? colour : NumberUtil.toUint( colour ) ); trans.color = c; target.transform.colorTransform = trans; } public static function revertColour(target:DisplayObject):void { target.transform.colorTransform = new ColorTransform(); } } } \ No newline at end of file
ahmednuaman/AS3
3fa797c3aaaa9e3e9b733916104743ff86d2c0e7
added mediator removing by string
diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..5e6c0ce --- /dev/null +++ b/README.txt @@ -0,0 +1,19 @@ +Hello everything! This a set of very useful day-to-day AS3 classes. They range from YouTube helpers and players to static Math functions and DisplayObject helpers. Check them out, fork and let me know. + +Dependencies: +A lot of the code here depends of the following libraries: + +as3corelib : Adobe's AS3 Core Library, get the code here: http://github.com/mikechambers/as3corelib +TweenMax : Greensocks pretty awesome and industry standard tweening class, get the code here: http://www.greensock.com/tweenmax/ +SWFBridge : Although this actually isn't needed anymore as it was used for the old-skool AS3-AS2 YouTube player, you may want to use it: http://www.gskinner.com/blog/archives/2007/07/swfbridge_easie.html + +Also... +I've done a lot of customisations for PureMVC so you can get that code from: http://trac.puremvc.org/PureMVC_AS3/ + +Support and what not: +I'm bad. I haven't commented any of the code and nor have I really explained how it's used. Although, I kinda have on my blog (http://www.ahmednuaman.com/blog) but it's not good enough. + +I do need to go through this and comment it all, add examples, but this rock and roll life of a freelancer is just taking its toll! So please don't worry about dropping me a message, I'll happily explain my 1am coding logic! + +And next in line: +Well, I'm doing a lot of work with lots of new (and old, abandoned) APIs so there'll always been new code coming up! Let me know if you have something you want me to crack! \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/data/DataService.as b/com/firestartermedia/lib/as3/data/DataService.as new file mode 100644 index 0000000..5edd096 --- /dev/null +++ b/com/firestartermedia/lib/as3/data/DataService.as @@ -0,0 +1,112 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.data +{ + import com.adobe.serialization.json.JSON; + import com.firestartermedia.lib.as3.events.DataServiceEvent; + + import flash.events.Event; + import flash.events.EventDispatcher; + import flash.events.HTTPStatusEvent; + import flash.events.IOErrorEvent; + import flash.events.ProgressEvent; + import flash.net.URLLoader; + import flash.net.URLRequest; + import flash.net.URLRequestMethod; + import flash.net.URLVariables; + + public class DataService extends EventDispatcher + { + public static const TYPE_XML:String = 'xml'; + public static const TYPE_JSON:String = 'json'; + + public var handleReady:Boolean = true; + + public var data:Object; + public var loader:URLLoader; + public var rawData:Object; + + private var loadingEvent:String; + private var loadedEvent:String; + private var readyEvent:String; + private var dataType:String + + public function DataService(loadingEvent:String='', loadedEvent:String='', readyEvent:String='', dataType:String='xml') + { + this.loadingEvent = loadingEvent; + this.loadedEvent = loadedEvent; + this.readyEvent = readyEvent; + this.dataType = dataType; + + loader = new URLLoader(); + + loader.addEventListener( Event.OPEN, handleLoaderStarted ); + loader.addEventListener( HTTPStatusEvent.HTTP_STATUS, handleGenericEvent ); + loader.addEventListener( IOErrorEvent.IO_ERROR, handleGenericEvent ); + loader.addEventListener( ProgressEvent.PROGRESS, handleGenericEvent ); + loader.addEventListener( Event.COMPLETE, handleLoaderComplete ); + } + + public function send(url:String, data:URLVariables=null, method:String='GET'):void + { + var request:URLRequest = new URLRequest( url ); + + request.data = data; + request.method = method; + + try + { + loader.load( request ); + + dispatchEvent( new DataServiceEvent( DataServiceEvent.LOADING ) ); + } + catch (e:*) + { } + } + + public function sendPost(url:String, data:URLVariables=null):void + { + send( url, data, URLRequestMethod.POST ); + } + + public function handleLoaderStarted(e:Event):void + { + dispatchEvent( new DataServiceEvent( loadingEvent ) ); + } + + public function handleGenericEvent(e:*):void + { + dispatchEvent( e ); + } + + public function handleLoaderComplete(e:Event):void + { + rawData = e.target.data; + + dispatchEvent( new DataServiceEvent( loadedEvent, rawData, rawData ) ); + + if ( handleReady ) + { + if ( e.target.data.toString().length > 0 ) + { + data = ( dataType == TYPE_XML ? new XML( e.target.data ) : JSON.decode( e.target.data ) ); + } + + handleLoaderDataReady( data ); + } + } + + public function handleLoaderDataReady(data:Object):void + { + this.data = data; + + dispatchEvent( new DataServiceEvent( readyEvent, data, rawData ) ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/data/JSONDataService.as b/com/firestartermedia/lib/as3/data/JSONDataService.as new file mode 100644 index 0000000..6ffa402 --- /dev/null +++ b/com/firestartermedia/lib/as3/data/JSONDataService.as @@ -0,0 +1,20 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.data +{ + import com.firestartermedia.lib.as3.events.DataServiceEvent; + + public class JSONDataService extends DataService + { + public function JSONDataService() + { + super( DataServiceEvent.LOADING, DataServiceEvent.LOADED, DataServiceEvent.READY, DataService.TYPE_JSON ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/data/RemoteConnectionService.as b/com/firestartermedia/lib/as3/data/RemoteConnectionService.as new file mode 100644 index 0000000..c4ab7b5 --- /dev/null +++ b/com/firestartermedia/lib/as3/data/RemoteConnectionService.as @@ -0,0 +1,81 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.data +{ + import com.adobe.serialization.json.JSON; + import com.firestartermedia.lib.as3.events.RemoteConnectionServiceEvent; + + import flash.events.NetStatusEvent; + import flash.net.NetConnection; + import flash.net.Responder; + + public class RemoteConnectionService extends NetConnection + { + public var handleReady:Boolean = true; + + public var data:Object; + public var gatewayURL:String; + public var responder:Responder; + + private var loadedEvent:String; + private var readyEvent:String; + private var faultEvent:String; + + public function RemoteConnectionService(gatewayURL:String, loadedEvent:String='', readyEvent:String='', faultEvent:String='', encoding:uint=3) + { + this.gatewayURL = gatewayURL; + this.loadedEvent = loadedEvent; + this.readyEvent = readyEvent; + this.faultEvent = faultEvent; + + objectEncoding = encoding; + + if ( gatewayURL ) + { + responder = new Responder( handleResponseResult, handleResponseFault ); + + addEventListener( NetStatusEvent.NET_STATUS, handleNetEvent ); + + connect( gatewayURL ); + } + } + + public function send(method:String, ... args):void + { + call.apply( null, [ method, responder ].concat( args ) ); + } + + private function handleNetEvent(e:NetStatusEvent):void + { + dispatchEvent( new RemoteConnectionServiceEvent( faultEvent, e.info.code ) ); + } + + private function handleResponseResult(data:Object):void + { + dispatchEvent( new RemoteConnectionServiceEvent( loadedEvent, data ) ); + + if ( handleReady ) + { + handleLoaderDataReady( data ); + } + } + + public function handleLoaderDataReady(data:Object):void + { + this.data = data; + + dispatchEvent( new RemoteConnectionServiceEvent( readyEvent, data ) ); + } + + private function handleResponseFault(data:Object):void + { + dispatchEvent( new RemoteConnectionServiceEvent( faultEvent, data ) ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/data/XMLDataService.as b/com/firestartermedia/lib/as3/data/XMLDataService.as new file mode 100644 index 0000000..fba7b03 --- /dev/null +++ b/com/firestartermedia/lib/as3/data/XMLDataService.as @@ -0,0 +1,20 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.data +{ + import com.firestartermedia.lib.as3.events.DataServiceEvent; + + public class XMLDataService extends DataService + { + public function XMLDataService() + { + super( DataServiceEvent.LOADING, DataServiceEvent.LOADED, DataServiceEvent.READY, DataService.TYPE_XML ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/data/amfphp/AMFPHPService.as b/com/firestartermedia/lib/as3/data/amfphp/AMFPHPService.as new file mode 100644 index 0000000..b84f007 --- /dev/null +++ b/com/firestartermedia/lib/as3/data/amfphp/AMFPHPService.as @@ -0,0 +1,41 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.data.amfphp +{ + import com.firestartermedia.lib.as3.data.RemoteConnectionService; + import com.firestartermedia.lib.as3.events.RemoteConnectionServiceEvent; + + import flash.net.ObjectEncoding; + + public class AMFPHPService extends RemoteConnectionService + { + protected var ciMethod:String; + protected var ciPath:String; + + public function AMFPHPService( url:String, ciMethod:String=null, ciPath:String=null ) + { + super( url, RemoteConnectionServiceEvent.LOADED, RemoteConnectionServiceEvent.READY, RemoteConnectionServiceEvent.FAULT, ObjectEncoding.AMF3 ); + + this.ciMethod = ciMethod; + this.ciPath = ciPath; + } + + public function ciSend(...args):void + { + if ( ciMethod && ciPath ) + { + send.apply( null, [ ciMethod, ciPath ].concat( args ) ); + } + else + { + throw new ArgumentError('You need to specify the ciMethod and ciPath'); + } + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/data/gdata/YouTubeGDataService.as b/com/firestartermedia/lib/as3/data/gdata/YouTubeGDataService.as new file mode 100644 index 0000000..d9b8223 --- /dev/null +++ b/com/firestartermedia/lib/as3/data/gdata/YouTubeGDataService.as @@ -0,0 +1,213 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.data.gdata +{ + import com.firestartermedia.lib.as3.data.DataService; + import com.firestartermedia.lib.as3.events.DataServiceEvent; + import com.firestartermedia.lib.as3.utils.YouTubeUtil; + + import flash.net.URLRequest; + import flash.net.URLRequestHeader; + import flash.net.URLRequestMethod; + import flash.net.URLVariables; + + public class YouTubeGDataService extends DataService + { + public var GDATA_URL:String = 'http://gdata.youtube.com/feeds/api/'; + public var PLAYLISTS_URL:String = GDATA_URL + 'playlists'; + public var USERS_URL:String = GDATA_URL + 'users'; + public var VIDEOS_URL:String = GDATA_URL + 'videos'; + + private var currentPlaylistEntries:Number; + private var playlistEntries:Array; + private var playlistId:String; + private var playlistSearch:String; + + public function YouTubeGDataService() + { + super( DataServiceEvent.LOADING, DataServiceEvent.LOADED, DataServiceEvent.READY ); + } + + public function getVideoData(videoId:String):void + { + var request:URLRequest = new URLRequest( VIDEOS_URL + '/' + videoId ); + + load( request ); + } + + public function getPlaylistData(playlistId:String, startIndex:Number=1):void + { + var request:URLRequest = new URLRequest( PLAYLISTS_URL + '/' + playlistId + '?v=2&max-results=50&start-index=' + startIndex ); + + load( request ); + } + + public function searchPlaylistData(playlistId:String, playlistSearch:String):void + { + this.playlistId = playlistId; + this.playlistSearch = playlistSearch; + + handleReady = false; + + currentPlaylistEntries = 1; + + playlistEntries = [ ]; + + addEventListener( DataServiceEvent.LOADED, handleSearchPlaylistDataComplete ); + + getPlaylistData( playlistId ); + } + + private function handleSearchPlaylistDataComplete(e:DataServiceEvent):void + { + var data:XML = e.data as XML; + var length:Number = data..*::itemsPerPage; + var total:Number = data..*::totalResults; + var entries:Array = YouTubeUtil.cleanGDataFeed( data ); + + for each ( var entry:Object in entries ) + { + if ( playlistEntries.length <= total ) + { + playlistEntries.push( entry ); + } + } + + currentPlaylistEntries += length; + + if ( currentPlaylistEntries >= total ) + { + searchThroughPlaylistData(); + } + else + { + getPlaylistData( playlistId, currentPlaylistEntries ); + } + } + + private function searchThroughPlaylistData():void + { + var matchEntries:Array = [ ]; + + for each ( var entry:Object in playlistEntries ) + { + if ( + entry.title.toLowerCase().search( playlistSearch.toLowerCase() ) != -1 || + entry.description.toLowerCase().search( playlistSearch.toLowerCase() ) != -1 || + entry.keywords.toLowerCase().search( playlistSearch.toLowerCase() ) != -1 + ) + { + matchEntries.push( entry ); + } + } + + dispatchEvent( new DataServiceEvent( DataServiceEvent.READY, { entries: matchEntries } ) ); + } + + public function getUserVideos(username:String, startIndex:Number=1, max:Number=50):void + { + var request:URLRequest = new URLRequest( VIDEOS_URL + '?v=2&max-results=' + max + '&start-index=' + startIndex + '&author=' + username ); + + load( request ); + } + + public function getAuthedUserVideos(token:String, devkey:String, startIndex:Number=1, max:Number=50):void + { + var request:URLRequest = new URLRequest( USERS_URL + '/default/uploads' ); + + request.contentType = 'application/atom+xml; charset=UTF-8'; + request.method = URLRequestMethod.POST; + request.requestHeaders = [ new URLRequestHeader( 'X-HTTP-Method-Override', 'GET' ), + new URLRequestHeader( 'Authorization', 'AuthSub token="' + token + '"' ), + new URLRequestHeader( 'GData-Version', '2' ), + new URLRequestHeader( 'X-GData-Key', 'key=' + devkey ) ]; + request.data = new URLVariables( 'key=' + devkey ); + + load( request ); + } + + public function subscribeToUser(username:String, token:String, devkey:String):void + { + var request:URLRequest = new URLRequest( USERS_URL + '/default/subscriptions' ); + + request.contentType = 'application/atom+xml; charset=UTF-8'; + request.method = URLRequestMethod.POST; + request.requestHeaders = [ /* new URLRequestHeader( 'X-HTTP-Method-Override', 'GET' ), */ + new URLRequestHeader( 'Authorization', 'AuthSub token="' + token + '"' ), + new URLRequestHeader( 'GData-Version', '2' ), + new URLRequestHeader( 'X-GData-Key', 'key=' + devkey ) ]; + request.data = '<?xml version="1.0" encoding="UTF-8"?>' + + '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:yt="http://gdata.youtube.com/schemas/2007">' + + '<category scheme="http://gdata.youtube.com/schemas/2007/subscriptiontypes.cat" term="channel"/>' + + '<yt:username>' + username + '</yt:username>' + + '</entry>'; + + load( request ); + } + + public function rateVideo(videoId:String, rating:Number, token:String, devkey:String):void + { + var request:URLRequest = new URLRequest( VIDEOS_URL + '/' + videoId + '/ratings' ); + + request.contentType = 'application/atom+xml; charset=UTF-8'; + request.method = URLRequestMethod.POST; + request.requestHeaders = [ /* new URLRequestHeader( 'X-HTTP-Method-Override', 'GET' ), */ + new URLRequestHeader( 'Authorization', 'AuthSub token="' + token + '"' ), + new URLRequestHeader( 'GData-Version', '2' ), + new URLRequestHeader( 'X-GData-Key', 'key=' + devkey ) ]; + request.data = '<?xml version="1.0" encoding="UTF-8"?>' + + '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005">' + + '<gd:rating value="' + rating + '" min="1" max="5"/>' + + '</entry>'; + + load( request ); + } + + public function exchangeForSessionToken(token:String):void + { + var request:URLRequest = new URLRequest( 'https://accounts.googleapis.com/accounts/AuthSubSessionToken' ); + + request.contentType = 'application/x-www-form-urlencoded'; + request.method = URLRequestMethod.POST; + request.requestHeaders = [ /* new URLRequestHeader( 'X-HTTP-Method-Override', 'GET' ), */ + new URLRequestHeader( 'Authorization', 'AuthSub token="' + token + '"' ) ]; + request.data = new URLVariables( 'foo=bar' ); + + load( request ); + } + + public function getUploadToken(token:String, devkey:String, title:String, description:String, category:String, keywords:String):void + { + var request:URLRequest = new URLRequest( GDATA_URL.replace( '/feeds/api/', '/action/GetUploadToken' ) ); + + request.contentType = 'application/atom+xml; charset=UTF-8'; + request.method = URLRequestMethod.POST; + request.requestHeaders = [ /* new URLRequestHeader( 'X-HTTP-Method-Override', 'GET' ), */ + new URLRequestHeader( 'Authorization', 'AuthSub token="' + token + '"' ), + new URLRequestHeader( 'GData-Version', '2' ), + new URLRequestHeader( 'X-GData-Key', 'key=' + devkey ) ]; + request.data = '<?xml version="1.0" encoding="UTF-8"?>' + + '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007">' + + '<media:group><media:title type="plain">' + title + '</media:title>' + + '<media:description type="plain">' + description + '</media:description>' + + '<media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">' + category + '</media:category>' + + '<media:keywords>' + keywords + '</media:keywords>' + + '</media:group></entry>'; + + load( request ); + } + + private function load(request:URLRequest):void + { + loader.load( request ); + + dispatchEvent( new DataServiceEvent( DataServiceEvent.LOADING ) ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/data/twitter/TwitterDataService.as b/com/firestartermedia/lib/as3/data/twitter/TwitterDataService.as new file mode 100644 index 0000000..f727632 --- /dev/null +++ b/com/firestartermedia/lib/as3/data/twitter/TwitterDataService.as @@ -0,0 +1,33 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.data.twitter +{ + import com.firestartermedia.lib.as3.data.DataService; + import com.firestartermedia.lib.as3.events.DataServiceEvent; + + import flash.net.URLRequest; + + public class TwitterDataService extends DataService + { + public static const TWITTER_URL:String = 'http://twitter.com/'; + public static const STATUS_URL:String = TWITTER_URL + 'statuses/user_timeline/'; + + public function TwitterDataService() + { + super( DataServiceEvent.LOADING, DataServiceEvent.LOADED, DataServiceEvent.READY ); + } + + public function getUserStatues(userId:String):void + { + var request:URLRequest = new URLRequest( STATUS_URL + userId + '.rss' ); + + loader.load( request ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/component/Ball.as b/com/firestartermedia/lib/as3/display/component/Ball.as new file mode 100644 index 0000000..d07bd13 --- /dev/null +++ b/com/firestartermedia/lib/as3/display/component/Ball.as @@ -0,0 +1,26 @@ +package com.firestartermedia.lib.as3.display.component +{ + import flash.display.Shape; + import flash.display.Sprite; + + public class Ball extends Sprite + { + private var ball:Shape = new Shape(); + + private var startY:Number; + + public function Ball() + { + init(); + } + + private function init():void + { + ball.graphics.beginFill( 0xFF0000 ); + ball.graphics.drawCircle( 0, 0, 100 ); + ball.graphics.endFill(); + + addChild( ball ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/component/Countdown.as b/com/firestartermedia/lib/as3/display/component/Countdown.as new file mode 100644 index 0000000..851b8b0 --- /dev/null +++ b/com/firestartermedia/lib/as3/display/component/Countdown.as @@ -0,0 +1,125 @@ +package com.firestartermedia.lib.as3.display.component +{ + import com.firestartermedia.lib.as3.events.CountdownEvent; + + import flash.display.Sprite; + import flash.events.Event; + import flash.text.TextFormat; + + public class Countdown extends Sprite + { + private var currentDate:Date = new Date(); + + private var buildCountdown:Boolean; + private var targetDate:Date; + private var textFormat:TextFormat; + private var visualTargets:Object; + + private var _decades:Number; + private var _years:Number; + private var _months:Number; + private var _weeks:Number; + private var _days:Number; + private var _hours:Number; + private var _mins:Number; + private var _secs:Number; + private var _mSecs:Number; + + public function Countdown(targetDate:Date, buildCountdown:Boolean=false, visualTargets:Object=null) + { + this.buildCountdown = buildCountdown; + this.targetDate = targetDate; + this.visualTargets = visualTargets; + + init(); + } + + private function init():void + { + if ( buildCountdown ) + { + // build(); + } + else + { + addEventListener( Event.ENTER_FRAME, applyTimes ); + } + } + + private function applyTimes(e:Event):void + { + var diff:Number = targetDate.getTime() - currentDate.getTime(); + + if ( visualTargets.hasOwnProperty( 'decades' ) ) + { + + } + + if ( visualTargets.hasOwnProperty( 'years' ) ) + { + + } + + if ( visualTargets.hasOwnProperty( 'months' ) ) + { + + } + + if ( visualTargets.hasOwnProperty( 'weeks' ) ) + { + + } + + if ( visualTargets.hasOwnProperty( 'days' ) ) + { + _days = Math.floor( diff / 86400000 ); + + diff -= ( _days * 86400000 ); + } + + if ( visualTargets.hasOwnProperty( 'hours' ) ) + { + _hours = Math.floor( diff / 3600000 ); + + diff -= ( _hours * 3600000 ); + } + + if ( visualTargets.hasOwnProperty( 'mins' ) ) + { + _mins = Math.floor( diff / 60000 ); + + diff -= ( _mins * 60000 ); + } + + if ( visualTargets.hasOwnProperty( 'secs' ) ) + { + _secs = Math.floor( diff / 1000 ); + + diff -= ( _secs * 1000 ); + } + + if ( visualTargets.hasOwnProperty( 'mSecs' ) ) + { + _mSecs = diff; + } + + dispatchEvent( new CountdownEvent( CountdownEvent.TIME, + { + diff: targetDate.getTime() - currentDate.getTime(), + decades: _decades, + years: _years, + months: _months, + weeks: _weeks, + days: _days, + hours: _hours, + mins: _mins, + secs: _secs, + mSecs: _mSecs + } + ) + ); + + currentDate = new Date(); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/component/LoaderProgressBar.as b/com/firestartermedia/lib/as3/display/component/LoaderProgressBar.as new file mode 100644 index 0000000..5d4401d --- /dev/null +++ b/com/firestartermedia/lib/as3/display/component/LoaderProgressBar.as @@ -0,0 +1,99 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.display.component +{ + import com.firestartermedia.lib.as3.events.LoaderProgressEvent; + import com.greensock.TweenLite; + import com.greensock.easing.Strong; + + import flash.display.DisplayObject; + import flash.display.Sprite; + + public class LoaderProgressBar extends Sprite + { + private var bar:DisplayObject; + private var maxWidth:Number; + + public function LoaderProgressBar(bar:DisplayObject=null, maxWidth:Number=200) + { + this.maxWidth = ( bar ? bar.width : maxWidth ); + + if ( !bar ) + { + bar = createBar(); + } + + this.bar = bar; + + createMask(); + + init(); + } + + private function init():void + { + bar.width = 0; + + alpha = 0; + + addChild( bar ); + } + + public function show():void + { + TweenLite.to( this, .5, { alpha: 1 } ); + + dispatchEvent( new LoaderProgressEvent( LoaderProgressEvent.SHOW, true ) ); + } + + public function update(percent:Number):void + { + TweenLite.to( bar, .5, { width: ( percent / 100 ) * maxWidth, ease: Strong.easeOut, onComplete: checkComplete, onCompleteParams: [ percent ] } ); + + dispatchEvent( new LoaderProgressEvent( LoaderProgressEvent.UPDATE, percent, true ) ); + } + + private function checkComplete(percent:Number):void + { + if ( percent == 100 ) + { + dispatchEvent( new LoaderProgressEvent( LoaderProgressEvent.COMPLETE, null, true ) ); + } + } + + public function hide():void + { + TweenLite.to( this, .5, { alpha: 0 } ); + + dispatchEvent( new LoaderProgressEvent( LoaderProgressEvent.HIDE, true ) ); + } + + private function createBar():Sprite + { + var bar:Sprite = new Sprite(); + + bar.graphics.beginFill( 0xFFFFFF ); + bar.graphics.drawRect( 0, 0, maxWidth, 10 ); + bar.graphics.endFill(); + + return bar; + } + + private function createMask():void + { + var mask:Sprite = new Sprite(); + + mask.graphics.beginFill( 0xFFFFFF, 0 ); + mask.graphics.drawRect( 0, 0, maxWidth, bar.height ); + mask.graphics.endFill(); + + addChild( mask ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/component/LoaderProgressText.as b/com/firestartermedia/lib/as3/display/component/LoaderProgressText.as new file mode 100644 index 0000000..80d916c --- /dev/null +++ b/com/firestartermedia/lib/as3/display/component/LoaderProgressText.as @@ -0,0 +1,93 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.display.component +{ + import com.firestartermedia.lib.as3.events.LoaderProgressEvent; + + import flash.display.Sprite; + import flash.text.TextField; + import flash.text.TextFieldAutoSize; + import flash.text.TextFormat; + + import com.greensock.TweenMax; + import com.greensock.easing.Strong; + + public class LoaderProgressText extends Sprite + { + public var yMargin:Number = 50; + public var xMargin:Number = 0; + + private var field:TextField; + private var format:TextFormat; + private var loadingPrefix:String; + + public function LoaderProgressText(format:TextFormat, filters:Array=null, loadingPrefix:String='Loading') + { + this.format = format; + this.filters = filters; + this.loadingPrefix = loadingPrefix; + + alpha = 0; + + init(); + } + + private function init():void + { + field = new TextField(); + + field.autoSize = TextFieldAutoSize.CENTER; + field.defaultTextFormat = format; + field.embedFonts = true; + field.mouseEnabled = false; + field.text = loadingPrefix + ' 0%'; + field.wordWrap = false; + + addChild( field ); + } + + public function show():void + { + field.text = loadingPrefix + ' 0%'; + field.x = -xMargin; + field.y = -yMargin; + + TweenMax.to( field, .5, { y: 0, ease: Strong.easeOut } ); + TweenMax.to( this, .5, { autoAlpha: 1, ease: Strong.easeOut } ); + + dispatchEvent( new LoaderProgressEvent( LoaderProgressEvent.SHOW, true ) ); + } + + public function update(percent:Number):void + { + field.text = loadingPrefix + ' ' +percent.toString() + '%'; + + width = field.width; + height = field.height; + + dispatchEvent( new LoaderProgressEvent( LoaderProgressEvent.UPDATE, percent, true ) ); + + if ( percent == 100 ) + { + dispatchEvent( new LoaderProgressEvent( LoaderProgressEvent.COMPLETE, null, true ) ); + } + } + + public function hide():void + { + TweenMax.killTweensOf( field ); + TweenMax.killTweensOf( this ); + + TweenMax.to( field, .5, { y: yMargin, ease: Strong.easeOut } ); + TweenMax.to( this, .5, { autoAlpha: 0, ease: Strong.easeOut } ); + + dispatchEvent( new LoaderProgressEvent( LoaderProgressEvent.HIDE, true ) ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/component/Reflection.as b/com/firestartermedia/lib/as3/display/component/Reflection.as new file mode 100644 index 0000000..aa9e79a --- /dev/null +++ b/com/firestartermedia/lib/as3/display/component/Reflection.as @@ -0,0 +1,61 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.display.component +{ + import flash.display.BitmapData; + import flash.display.DisplayObject; + import flash.display.GradientType; + import flash.display.Sprite; + import flash.geom.Matrix; + import flash.geom.Point; + + public class Reflection extends Sprite + { + public var target:DisplayObject; + + public function Reflection(target:DisplayObject) + { + this.target = target; + + init(); + } + + private function init():void + { + var targetBitmap:BitmapData = new BitmapData( target.width, target.height, true, 0x00FFFFFF ); + var reflection:Sprite = new Sprite(); + var reflectionMatrix:Matrix = new Matrix(); + var gradient:Sprite = new Sprite(); + var gradientMatrix:Matrix = new Matrix(); + + reflectionMatrix.translate( 0, -target.height ); + reflectionMatrix.scale( 1, -1 ); + + gradientMatrix.createGradientBox( target.width, target.height, Math.PI * 1.5, 0, ( target.height / 1.5 ) * -1 ); + + targetBitmap.draw( target, reflectionMatrix ); + + reflection.graphics.beginBitmapFill( targetBitmap ); + reflection.graphics.drawRect( 0, 0, target.width, target.height ); + reflection.graphics.endFill(); + + gradient.graphics.beginGradientFill( GradientType.LINEAR, [ 0xFFFFFF, 0xFFFFFF ], [ 0, .8 ], [ 0, 255 ], gradientMatrix ); + gradient.graphics.drawRect( 0, 0, target.width, target.height ); + gradient.graphics.endFill(); + + reflection.cacheAsBitmap = true; + gradient.cacheAsBitmap = true; + + addChild( reflection ); + addChild( gradient ); + + reflection.mask = gradient; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/component/interaction/ButtonSimple.as b/com/firestartermedia/lib/as3/display/component/interaction/ButtonSimple.as new file mode 100644 index 0000000..2619ed1 --- /dev/null +++ b/com/firestartermedia/lib/as3/display/component/interaction/ButtonSimple.as @@ -0,0 +1,123 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.display.component.interaction +{ + import flash.display.DisplayObject; + import flash.display.GradientType; + import flash.display.SimpleButton; + import flash.display.Sprite; + import flash.geom.Matrix; + import flash.geom.Rectangle; + import flash.text.TextField; + import flash.text.TextFieldAutoSize; + import flash.text.TextFormat; + + public class ButtonSimple extends SimpleButton + { + public var bgColourDown:* = 0x000000; + public var bgColourOver:* = 0x666666; + public var bgColourUp:* = 0x333333; + public var border:Boolean = true; + public var borderColourDown:uint = 0x333333; + public var borderColourOver:uint = 0x333333; + public var borderColourUp:uint = 0x333333; + public var borderCornerRadius:Number = 5; + public var borderWidth:Number = 1; + public var buttonPaddingX:Number = 10; + public var buttonPaddingY:Number = 5; + public var buttonText:String = 'Click on me!'; + public var textColourDown:uint = 0xCCCCCC; + public var textColourOver:uint = 0xFFFFFF; + public var textColourUp:uint = 0xFFFFFF; + public var textEmbedFonts:Boolean = true; + + public var textFormat:TextFormat; + + public function ButtonSimple(upState:DisplayObject=null, overState:DisplayObject=null, downState:DisplayObject=null, hitTestState:DisplayObject=null) + { + super( upState, overState, downState, hitTestState ); + + textFormat = new TextFormat(); + + textFormat.font = 'Arial'; + textFormat.size = 10; + } + + public function draw():void + { + upState = createState( textColourUp, bgColourUp, borderColourUp ); + overState = createState( textColourOver, bgColourOver, borderColourOver ); + downState = createState( textColourDown, bgColourDown, borderColourDown ); + + hitTestState = upState; + } + + private function createState(textColour:uint, bgColour:*, borderColour:uint):Sprite + { + var container:Sprite = new Sprite(); + var button:Sprite = new Sprite(); + var field:TextField = new TextField(); + var matrix:Matrix; + var bgGradientAlphas:Array; + var bgGradientRatios:Array; + + if ( typeof bgColour == 'object' ) + { + matrix = new Matrix(); + + matrix.createGradientBox( 100, 100, Math.PI * .5 ); + + bgGradientAlphas = [ ]; + + bgGradientRatios = [ ]; + + for ( var i:Number = 0; i < bgColour.length; i++ ) + { + bgGradientAlphas.push( 1 ); + + bgGradientRatios.push( ( ( i + 1 ) / bgColour.length ) * 255 ); + } + + button.graphics.beginGradientFill( GradientType.LINEAR, bgColour, bgGradientAlphas, bgGradientRatios, matrix ); + } + else + { + button.graphics.beginFill( bgColour ); + } + + if ( border ) + { + button.graphics.lineStyle( borderWidth, borderColour ); + } + + button.graphics.drawRoundRect( 0, 0, 300, 30, borderCornerRadius, borderCornerRadius ); + button.graphics.endFill(); + button.scale9Grid = new Rectangle( borderCornerRadius, borderCornerRadius, 300 - ( borderCornerRadius * 2 ), 30 - ( borderCornerRadius * 2 ) ); + + container.addChild( button ); + + field.autoSize = TextFieldAutoSize.CENTER; + field.condenseWhite = true; + field.defaultTextFormat = textFormat; + field.embedFonts = textEmbedFonts; + field.textColor = textColour; + field.text = buttonText; + + button.height = field.height + ( buttonPaddingY * 2 ); + button.width = field.width + ( buttonPaddingX * 2 ); + + field.x = ( button.width / 2 ) - ( field.width / 2 ); + field.y = ( button.height / 2 ) - ( field.height / 2 ); + + container.addChild( field ); + + return container; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/component/interaction/ScrollBar.as b/com/firestartermedia/lib/as3/display/component/interaction/ScrollBar.as new file mode 100644 index 0000000..26e3896 --- /dev/null +++ b/com/firestartermedia/lib/as3/display/component/interaction/ScrollBar.as @@ -0,0 +1,37 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.display.component.interaction +{ + import flash.display.DisplayObject; + import flash.display.Sprite; + + public class ScrollBar extends Sprite + { + public var bar:DisplayObject; + public var buttonDown:DisplayObject; + public var buttonUp:DisplayObject; + public var mask:DisplayObject; + public var target:DisplayObject; + + public function ScrollBar(target:DisplayObject, mask:DisplayObject, bar:DisplayObject, buttonUp:DisplayObject, buttonDown:DisplayObject) + { + this.target = target; + this.bar = bar; + this.buttonUp = buttonUp; + this.buttonDown = buttonDown; + + init(); + } + + private function init():void + { + + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/component/video/VideoPlayerChromless.as b/com/firestartermedia/lib/as3/display/component/video/VideoPlayerChromless.as new file mode 100644 index 0000000..2a4e9e7 --- /dev/null +++ b/com/firestartermedia/lib/as3/display/component/video/VideoPlayerChromless.as @@ -0,0 +1,353 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.display.component.video +{ + import com.firestartermedia.lib.as3.events.VideoPlayerEvent; + import com.firestartermedia.lib.as3.utils.ArrayUtil; + import com.firestartermedia.lib.as3.utils.NumberUtil; + + import flash.display.Sprite; + import flash.events.Event; + import flash.events.NetStatusEvent; + import flash.media.SoundTransform; + import flash.media.Video; + import flash.net.NetConnection; + import flash.net.NetStream; + import flash.utils.clearInterval; + import flash.utils.setInterval; + import flash.utils.setTimeout; + + public class VideoPlayerChromless extends Sprite + { + public var autoPlay:Boolean = true; + public var bufferTime:Number = 2; + public var loop:Boolean = false; + + private var cuePoints:Array = [ ]; + private var lastFiredCuePoint:Number = 0; + private var loadedBytes:Number = 0; + private var metaData:Object = { }; + private var video:Video = new Video(); + + private var frameInterval:Number; + private var isLoaded:Boolean; + private var isOverHalfWay:Boolean; + private var isPlaying:Boolean; + private var rawHeight:Number; + private var rawWidth:Number; + private var stream:NetStream; + private var totalSize:Number; + private var videoHeight:Number; + private var videoWidth:Number; + + public function VideoPlayerChromless() + { + var connection:NetConnection = new NetConnection(); + + connection.addEventListener( NetStatusEvent.NET_STATUS, handleNetStatus ); + + connection.connect( null ); + + stream = new NetStream( connection ); + + stream.client = { onMetaData: handleOnMetaData }; + + stream.addEventListener( NetStatusEvent.NET_STATUS, handleNetStatus ); + + video.smoothing = true; + + video.attachNetStream( stream ); + + addChild( video ); + } + + public function play(url:String):void + { + stream.bufferTime = bufferTime; + + stream.close(); + + stream.play( url ); + + isLoaded = false; + + isOverHalfWay = false; + + isPlaying = true; + + //addEventListener( Event.ENTER_FRAME, handleEnterFrame ); + + createInterval(); + } + + private function createInterval():void + { + if ( !frameInterval ) + { + frameInterval = setInterval( handleEnterFrame, 250 ); + } + } + + private function deleteInterval():void + { + clearInterval( frameInterval ); + + frameInterval = 0; + } + + public function stop():void + { + stream.close(); + + isPlaying = false; + + video.alpha = 0; + + deleteInterval(); + } + + public function seekTo(seconds:Number):void + { + stream.seek( seconds ); + } + + public function setVolume(volume:Number):void + { + var sound:SoundTransform = new SoundTransform( volume ); + + stream.soundTransform = sound; + } + + private function handleEnterFrame(e:Event=null):void + { + if ( !isLoaded ) + { + checkLoadingStatus(); + } + + if ( cuePoints.length > 0 ) + { + checkForCuePoints(); + } + } + + private function checkLoadingStatus():void + { + var progress:Object = loadingProgress; + + trace( loadedBytes, stream.bytesLoaded ); + + if ( progress.total === 1 && loadedBytes === stream.bytesLoaded ) + { + isLoaded = true; + + dispatchEvent( new VideoPlayerEvent( VideoPlayerEvent.LOADED ) ); + + if ( !autoPlay ) + { + pause(); + } + } + else + { + dispatchEvent( new VideoPlayerEvent( VideoPlayerEvent.LOADING, progress ) ); + + loadedBytes = stream.bytesLoaded; + + isLoaded = false; + } + } + + private function checkForCuePoints():void + { + var time:Number = playingTime.current; + var checkTime:Number = Math.floor( time ); + var test:Number = ArrayUtil.search( cuePoints, checkTime ); + var cuePoint:Number; + + if ( test > -1 ) + { + cuePoint = cuePoints[ test ]; + + if ( cuePoint > lastFiredCuePoint ) + { + dispatchEvent( new VideoPlayerEvent( VideoPlayerEvent.CUE_POINT, { point: cuePoint, halfway: false, finished: false, duration: playingTime.total } ) ); + + lastFiredCuePoint = cuePoint; + } + } + + if ( !isOverHalfWay && time > ( playingTime.total / 2 ) ) + { + isOverHalfWay = true; + + dispatchEvent( new VideoPlayerEvent( VideoPlayerEvent.HALF_WAY, { point: checkTime, halfway: true, finished: false, duration: playingTime.total } ) ); + } + } + + public function addCuePoint(seconds:Number):void + { + cuePoints.push( seconds ); + } + + public function addCuePoints(points:Array):void + { + for each ( var point:Number in points ) + { + addCuePoint( point ); + } + } + + public function pause():void + { + stream.pause(); + + isPlaying = false; + + deleteInterval(); + + dispatchEvent( new VideoPlayerEvent( VideoPlayerEvent.PAUSED ) ); + } + + public function resume():void + { + stream.resume(); + + isPlaying = true; + + createInterval(); + + dispatchEvent( new VideoPlayerEvent( VideoPlayerEvent.PLAYING ) ); + } + + private function handleNetStatus(e:NetStatusEvent):void + { + var code:String = e.info.code; + + switch ( code ) + { + case 'NetStream.Play.Start': + dispatchEvent( new VideoPlayerEvent( VideoPlayerEvent.BUFFERING ) ); + dispatchEvent( new VideoPlayerEvent( VideoPlayerEvent.STARTED ) ); + + createInterval(); + + break; + + case 'NetStream.Buffer.Full': + dispatchEvent( new VideoPlayerEvent( VideoPlayerEvent.PLAYING ) ); + + createInterval(); + + video.alpha = 1; + + break; + + case 'NetStream.Play.Stop': + dispatchEvent( new VideoPlayerEvent( VideoPlayerEvent.ENDED, { point: playingTime.total, halfway: false, finished: true } ) ); + + deleteInterval(); + + if ( loop ) + { + seekTo( 0 ); + + resume(); + } + + break; + + case 'NetStream.Seek.InvalidTime': + //dispatchEvent( new VideoPlayerEvent( VideoPlayerEvent.BUFFERING ) ); + + break; + + case 'NetStream.Seek.Notify': + dispatchEvent( new VideoPlayerEvent( VideoPlayerEvent.BUFFERING ) ); + + createInterval(); + + break; + + case 'NetStream.Play.StreamNotFound': + case 'NetStream.Play.Failed': + dispatchEvent( new VideoPlayerEvent( VideoPlayerEvent.FAILED ) ); + + deleteInterval(); + + break; + } + } + + private function handleOnMetaData(info:Object):void + { + metaData = info; + } + + public function resize(width:Number=0, height:Number=0):void + { + rawHeight = height; + rawWidth = width; + + if ( metaData.hasOwnProperty( 'height') && metaData.hasOwnProperty( 'width' ) ) + { + doResize( width, height ); + } + else + { + video.visible = false; + + setTimeout( resize, 250, width, height ); + } + } + + private function doResize(width:Number, height:Number):void + { + var targetHeight:Number = ( height > 0 ? height : videoHeight ); + var targetWidth:Number = targetHeight * ( metaData.width / metaData.height ); + + if ( targetWidth > width ) + { + targetWidth = ( width > 0 ? width : videoWidth ); + targetHeight = targetWidth * ( metaData.height / metaData.width ); + } + + videoHeight = targetHeight; + videoWidth = targetWidth; + + video.height = targetHeight; + video.width = targetWidth; + video.visible = true; + video.x = ( width / 2 ) - ( targetWidth / 2 ); + video.y = ( height / 2 ) - ( targetHeight / 2 ); + } + + public function get loadingProgress():Object + { + var progress:Object = { }; + + progress.total = stream.bytesLoaded / stream.bytesTotal; + progress.bytesLoaded = stream.bytesLoaded; + progress.bytesTotal = stream.bytesTotal; + + return progress; + } + + public function get playingTime():Object + { + var time:Object = { }; + + time.current = stream.time; + time.total = metaData.duration; + time.formatted = NumberUtil.toTimeString( Math.round( stream.time ) ) + ' / ' + NumberUtil.toTimeString( Math.round( metaData.duration ) ); + + return time; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/component/video/WebCam.as b/com/firestartermedia/lib/as3/display/component/video/WebCam.as new file mode 100644 index 0000000..4bc426c --- /dev/null +++ b/com/firestartermedia/lib/as3/display/component/video/WebCam.as @@ -0,0 +1,236 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.display.component.video +{ + import com.firestartermedia.lib.as3.events.WebCamEvent; + import com.firestartermedia.lib.as3.utils.BitmapUtil; + import com.firestartermedia.lib.as3.utils.DateUtil; + + import flash.display.Bitmap; + import flash.display.BitmapData; + import flash.display.Sprite; + import flash.events.NetStatusEvent; + import flash.events.StatusEvent; + import flash.geom.Rectangle; + import flash.media.Camera; + import flash.media.Microphone; + import flash.media.Video; + import flash.net.NetConnection; + import flash.net.NetStream; + + public class WebCam extends Sprite + { + public var recordingName:String = 'Recording' + DateUtil.toNumericalTimestamp( new Date() ); + + private var hasBeenDenyed:Boolean = false; + private var isRecording:Boolean = false; + + public var captureURL:String; + + private var bandwidth:Number; + private var camera:Camera; + private var cameraHeight:Number; + private var cameraWidth:Number; + private var connection:NetConnection; + private var microphone:Microphone; + private var quality:Number; + private var stream:NetStream; + private var video:Video; + + public function WebCam(width:Number=320, height:Number=240, bandwidth:Number=0, quality:Number=90) + { + cameraHeight = height; + cameraWidth = width; + + this.bandwidth = bandwidth; + this.quality = quality; + } + + public function init():void + { + var index:int = 0; + + for ( var i:int = 0; i < Camera.names.length; i++ ) + { + if ( Camera.names[ i ] == 'USB Video Class Video' ) + { + index = i; + } + } + + camera = Camera.getCamera( index.toString() ); + + if ( camera == null ) + { + dispatchEvent( new WebCamEvent( WebCamEvent.NO_WEBCAM ) ); + + return; + } + + if ( camera.muted && hasBeenDenyed ) + { + dispatchEvent( new WebCamEvent( WebCamEvent.NO_WEBCAM ) ); + + return; + } + + camera.addEventListener( StatusEvent.STATUS, handleCameraStatus ); + + camera.setMode( cameraWidth, cameraHeight, 20, true ); + camera.setQuality( bandwidth, quality ); + + microphone = Microphone.getMicrophone(); + + video = new Video( cameraWidth, cameraHeight ); + + video.smoothing = true; + + video.attachCamera( camera ); + + addChild( video ); + } + + private function handleCameraStatus(e:StatusEvent):void + { + if ( e.code == 'Camera.Muted' ) + { + hasBeenDenyed = true; + + dispatchEvent( new WebCamEvent( WebCamEvent.NO_WEBCAM ) ); + } + } + + public function captureImage():Bitmap + { + var image:Bitmap = new Bitmap( bitmapData ); + + return image; + } + + public function captureVideo():void + { + if ( captureURL ) + { + connection = new NetConnection(); + + connection.addEventListener( NetStatusEvent.NET_STATUS, handleNetStatus ); + + dispatchEvent( new WebCamEvent( WebCamEvent.CONNECTING ) ); + + connection.connect( captureURL ); + } + else + { + throw new ArgumentError( 'You need to specify the captureURL before you start recording' ); + } + } + + private function handleNetStatus(e:NetStatusEvent):void + { + var name:String = e.info.code; + + switch ( name ) + { + case 'NetConnection.Connect.Failed': + case 'NetConnection.Connect.Rejected': + case 'NetConnection.Connect.InvalidApp': + case 'NetConnection.Connect.AppShutdown': + throw new Error( 'Can\'t connect to the application!' ); + + break; + + case 'NetConnection.Connect.Success': + dispatchEvent( new WebCamEvent( WebCamEvent.CONNECTED ) ); + + startRecording(); + + break; + + case 'NetConnection.Connect.Closed': + dispatchEvent( new WebCamEvent( WebCamEvent.CONNECTION_FAILED ) ); + + break; + + case 'NetStream.Record.NoAccess': + case 'NetStream.Record.Failed': + throw new Error( 'Can\'t record stream!' ); + + break; + + case 'NetStream.Record.Start': + dispatchEvent( new WebCamEvent( WebCamEvent.RECORDING_STARTED ) ); + + isRecording = true; + + break; + + case 'NetStream.Record.Stop': + dispatchEvent( new WebCamEvent( WebCamEvent.RECORDING_STOPPED ) ); + + isRecording = false; + + break; + + case 'NetStream.Unpublish.Success': + dispatchEvent( new WebCamEvent( WebCamEvent.RECORDING_FINISHED ) ); + + break; + } + } + + private function startRecording():void + { + stream = new NetStream( connection ); + + stream.addEventListener( NetStatusEvent.NET_STATUS, handleNetStatus ); + + stream.attachAudio( microphone ); + stream.attachCamera( camera ); + + stream.publish( recordingName, 'record' ); + } + + public function captureVideoStop():void + { + if ( isRecording ) + { + stream.close(); + } + else + { + throw new Error( 'Nothing\'s recording!' ); + } + } + + public function get bitmapData():BitmapData + { + return BitmapUtil.grab( video, new Rectangle( 0, 0, cameraWidth, cameraHeight ), true ); + } + + public function get recording():Boolean + { + return isRecording; + } + + public function get filename():String + { + return recordingName + '.flv'; + } + + override public function get height():Number + { + return cameraHeight; + } + + override public function get width():Number + { + return cameraWidth; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/component/video/YouTubePlayer.as b/com/firestartermedia/lib/as3/display/component/video/YouTubePlayer.as new file mode 100644 index 0000000..d218a85 --- /dev/null +++ b/com/firestartermedia/lib/as3/display/component/video/YouTubePlayer.as @@ -0,0 +1,174 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.display.component.video +{ + import com.firestartermedia.lib.as3.events.YouTubePlayerEvent; + import com.firestartermedia.lib.as3.utils.DisplayObjectUtil; + import com.gskinner.utils.SWFBridgeAS3; + + import flash.display.Loader; + import flash.display.Sprite; + import flash.errors.IllegalOperationError; + import flash.events.Event; + import flash.net.URLRequest; + import flash.system.ApplicationDomain; + import flash.system.Security; + import flash.utils.setTimeout; + + public class YouTubePlayer extends Sprite + { + public static const BRIDGE_NAME:String = 'YouTubePlayerBridge'; + + public var bridgeName:String = BRIDGE_NAME; + public var chromeless:Boolean = false; + public var playerHeight:Number = 240; + public var playerWidth:Number = 320; + public var wrapperURL:String = 'http://github.com/ahmednuaman/YouTube-Player-Wrapper/raw/master/YouTubePlayerWrapper.swf'; + + public var autoPlay:Boolean; + public var pars:String; + + private var isLoaded:Boolean = false; + + private var player:Loader; + private var bridge:SWFBridgeAS3; + private var videoId:String; + + public function YouTubePlayer():void + { + Security.allowDomain( '*' ); + Security.allowDomain( 'www.youtube.com' ); + Security.allowDomain( 'youtube.com' ); + Security.allowDomain( 's.ytimg.com' ); + Security.allowDomain( 'i.ytimg.com' ); + } + + public function init(videoId:String):void + { + trace( '*** This function is depreciated, please use play() ***' ); + + play( videoId ); + } + + public function play(videoId:String):void + { + var request:URLRequest; + + this.videoId = videoId; + + if ( !isLoaded ) + { + if ( wrapperURL ) + { + player = DisplayObjectUtil.loadMovie( wrapperURL + ( BRIDGE_NAME !== bridgeName ? '?bridgeName=' + bridgeName : '' ), this, handlePlayerLoadComplete, new ApplicationDomain() ); + } + else + { + throw new IllegalOperationError( 'You need to specify the wrapper url' ); + } + } + else + { + handlePlayerLoadComplete(); + } + } + + private function handlePlayerLoadComplete(e:Event=null):void + { + if ( bridge ) + { + handleBridgeConnect(); + } + else + { + bridge = new SWFBridgeAS3( bridgeName, this ); + + bridge.addEventListener( Event.CONNECT, handleBridgeConnect ); + } + } + + private function handleBridgeConnect(e:Event=null):void + { + isLoaded = true; + + dispatchEvent( new YouTubePlayerEvent( YouTubePlayerEvent.CONNECTED ) ); + + playVideo( videoId ); + } + + private function playVideo(videoId:String):void + { + sendCommand( 'playVideo', videoId, playerWidth, playerHeight, autoPlay, pars, chromeless ); + } + + private function sendCommand(...args):* + { + if ( isLoaded ) + { + return bridge.send.apply( null, args); + } + else + { + setTimeout( stop, 250 ); + } + } + + public function stop():void + { + sendCommand( 'stopVideo' ); + } + + public function pause():void + { + sendCommand( 'pauseVideo' ); + } + + public function resume():void + { + sendCommand( 'resumeVideo' ); + } + + public function resize(width:Number, height:Number):void + { + sendCommand( 'resizePlayer', width, height ); + } + + public function getCurrentTime():Number + { + return sendCommand( 'getCurrentTime' ); + } + + public function getDuration():Number + { + return sendCommand( 'getDuration' ); + } + + public function getVideoUrl():String + { + return sendCommand( 'getVideoUrl' ); + } + + public function getPlaybackQuality():String + { + return sendCommand( 'getPlaybackQuality' ); + } + + public function setPlaybackQuality(suggestedQuality:String):void + { + sendCommand( 'setPlaybackQuality', suggestedQuality ); + } + + public function sendEvent(e:String):void + { + var event:String = YouTubePlayerEvent.NAME + e.replace( /on|player/ , '' ); + + dispatchEvent( new YouTubePlayerEvent( event ) ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/component/video/YouTubePlayerAS3.as b/com/firestartermedia/lib/as3/display/component/video/YouTubePlayerAS3.as new file mode 100644 index 0000000..d047bcf --- /dev/null +++ b/com/firestartermedia/lib/as3/display/component/video/YouTubePlayerAS3.as @@ -0,0 +1,331 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.display.component.video +{ + import com.firestartermedia.lib.as3.events.YouTubePlayerEvent; + + import flash.display.DisplayObject; + import flash.display.Loader; + import flash.display.Sprite; + import flash.events.Event; + import flash.net.URLRequest; + import flash.system.Security; + + public class YouTubePlayerAS3 extends Sprite + { + public static const QUALITY_SMALL:String = 'small'; + public static const QUALITY_MEDIUM:String = 'medium'; + public static const QUALITY_LARGE:String = 'large'; + public static const QUALITY_HD:String = 'hd720'; + public static const QUALITY_DEFAULT:String = 'default'; + + public var autoplay:Boolean = false; + public var chromeless:Boolean = false; + public var loop:Boolean = false; + public var pars:String = ''; + public var playerHeight:Number = 300; + public var playerWidth:Number = 400; + public var quality:String = QUALITY_LARGE; + + private var isLoaded:Boolean = false; + private var isPlaying:Boolean = false; + private var requestURLChromed:String = 'http://www.youtube.com/v/ID?version=3'; + private var requestURLChromeless:String = 'http://www.youtube.com/apiplayer?version=3'; + + private var player:Object; + private var videoId:String; + + public function YouTubePlayerAS3() + { + Security.allowDomain( '*' ); + Security.allowDomain( 'www.youtube.com' ); + Security.allowDomain( 'youtube.com' ); + Security.allowDomain( 's.ytimg.com' ); + Security.allowDomain( 'i.ytimg.com' ); + } + + public function play(videoId:String):void + { + this.videoId = videoId; + + if ( !isLoaded ) + { + loadPlayer(); + } + else + { + playVideo(); + } + } + + private function loadPlayer():void + { + var request:URLRequest = new URLRequest( ( chromeless ? requestURLChromeless : requestURLChromed.replace( 'ID', videoId ) ) + ( pars.indexOf( '&' ) !== 0 ? '&' : '' ) + pars ); + var loader:Loader = new Loader(); + + loader.contentLoaderInfo.addEventListener( Event.INIT, handleLoaderInit ); + + loader.load( request ); + } + + private function handleLoaderInit(e:Event):void + { + var player:Object = e.target.content; + + player.addEventListener( 'onReady', handlePlayerReady ); + player.addEventListener( 'onStateChange', handlePlayerStateChange ); + player.addEventListener( 'onPlaybackQualityChange', handlePlayerQualityChange ); + player.addEventListener( 'onError', handlePlayerError ); + + addChild( player as DisplayObject ); + } + + private function handlePlayerReady(e:Event):void + { + player = e.target; + + isLoaded = true; + + dispatchEvent( new YouTubePlayerEvent( YouTubePlayerEvent.READY ) ); + + player.setSize( playerWidth, playerHeight ); + + playVideo(); + } + + private function handlePlayerStateChange(e:Object):void + { + var state:Number = player.getPlayerState(); + + switch ( state ) + { + case 0: + dispatchEvent( new YouTubePlayerEvent( YouTubePlayerEvent.ENDED ) ); + + isPlaying = false; + + if ( loop ) + { + playVideo(); + } + + break; + + case 1: + dispatchEvent( new YouTubePlayerEvent( YouTubePlayerEvent.PLAYING ) ); + + isPlaying = true; + + break; + + case 2: + dispatchEvent( new YouTubePlayerEvent( YouTubePlayerEvent.PAUSED ) ); + + isPlaying = false; + + break; + + case 3: + dispatchEvent( new YouTubePlayerEvent( YouTubePlayerEvent.BUFFERING ) ); + + isPlaying = false; + + if ( getPlaybackQuality() != quality ) + { + setPlaybackQuality( quality ); + } + + break; + + case 4: + // hmmm? + + break; + + case 5: + dispatchEvent( new YouTubePlayerEvent( YouTubePlayerEvent.QUEUED ) ); + + isPlaying = false; + + if ( getPlaybackQuality() != quality ) + { + setPlaybackQuality( quality ); + } + + break; + + default: + dispatchEvent( new YouTubePlayerEvent( YouTubePlayerEvent.NOT_STARTED ) ); + + isPlaying = false; + + break; + } + } + + private function handlePlayerQualityChange(e:Object):void + { + dispatchEvent( new YouTubePlayerEvent( YouTubePlayerEvent.QUALITY_CHANGED, getPlaybackQuality() ) ); + } + + private function handlePlayerError(e:Object):void + { + dispatchEvent( new YouTubePlayerEvent( YouTubePlayerEvent.ERROR, e ) ); + } + + private function playVideo():void + { + if ( isLoaded ) + { + if ( !autoplay ) + { + player.cueVideoById( videoId ); + } + else + { + player.loadVideoById( videoId ); + } + } + } + + public function stop():void + { + if ( isLoaded ) + { + player.stopVideo(); + } + } + + public function pause():void + { + if ( isLoaded ) + { + player.pauseVideo(); + } + } + + public function resume():void + { + if ( isLoaded ) + { + player.playVideo(); + } + } + + public function getCurrentTime():Number + { + return ( isLoaded ? player.getCurrentTime() : 0 ); + } + + public function getDuration():Number + { + return ( isLoaded ? player.getDuration() : 0 ); + } + + public function getVideoUrl():String + { + return ( isLoaded ? player.getVideoUrl() : '' ); + } + + public function getPlaybackQuality():String + { + return ( isLoaded ? player.getPlaybackQuality() : '' ); + } + + public function getVideoBytesLoaded():Number + { + return ( isLoaded ? player.getVideoBytesLoaded() : 0 ); + } + + public function getVideoBytesTotal():Number + { + return ( isLoaded ? player.getVideoBytesTotal() : 0 ); + } + + public function setPlaybackQuality(suggestedQuality:String):void + { + if ( isLoaded ) + { + player.setPlaybackQuality( suggestedQuality ); + } + } + + public function mute():void + { + if ( isLoaded ) + { + player.mute(); + } + } + + public function unMute():void + { + if ( isLoaded ) + { + player.unMute(); + } + } + + public function isMuted():Boolean + { + return ( isLoaded ? player.isMuted() : false ); + } + + public function setVolume(value:Number):void + { + if ( isLoaded ) + { + player.setVolume( value ); + } + } + + public function getVolume():Number + { + return ( isLoaded ? player.getVolume() : 0 ); + } + + public function seekTo(seconds:Number, allowSeekAhead:Boolean=true):void + { + if ( isLoaded ) + { + player.seekTo( seconds, allowSeekAhead ); + } + } + + public function get ytPlayer():Object + { + return ( isLoaded ? player : null ); + } + + public function get playing():Boolean + { + return isPlaying; + } + + override public function set height(value:Number):void + { + playerHeight = value; + + if ( isLoaded ) + { + player.setSize( playerWidth, playerHeight ); + } + } + + override public function set width(value:Number):void + { + playerWidth = value; + + if ( isLoaded ) + { + player.setSize( playerWidth, playerHeight ); + } + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/shape/Hexagon.as b/com/firestartermedia/lib/as3/display/shape/Hexagon.as new file mode 100644 index 0000000..fc27c67 --- /dev/null +++ b/com/firestartermedia/lib/as3/display/shape/Hexagon.as @@ -0,0 +1,12 @@ +package com.firestartermedia.lib.as3.display.shape +{ + import flash.display.Shape; + + public class Hexagon extends Polygon + { + public function Hexagon(radius:Number=100, bgColour:uint=0xFF6600, borderColour:uint=0x000099, borderThickness:Number=1) + { + super( radius, 6, bgColour, borderColour, borderThickness ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/shape/Polygon.as b/com/firestartermedia/lib/as3/display/shape/Polygon.as new file mode 100644 index 0000000..89e4f54 --- /dev/null +++ b/com/firestartermedia/lib/as3/display/shape/Polygon.as @@ -0,0 +1,52 @@ +package com.firestartermedia.lib.as3.display.shape +{ + import com.firestartermedia.lib.as3.utils.NumberUtil; + + import flash.display.Shape; + + public class Polygon extends Shape + { + public function Polygon(radius:Number=100, segments:Number=5, bgColour:uint=0xFF6600, borderColour:uint=0x000099, borderThickness:Number=1) + { + super(); + + draw( radius, segments, bgColour, borderColour, borderThickness ); + } + + protected function draw(radius:Number, segments:Number, bgColour:uint, borderColour:uint, borderThickness:Number):void + { + var coords:Array = [ ]; + var ratio:Number = 360 / segments; + var vectorId:Number = 0; + var vectorRadians:Number; + var vectorX:Number; + var vectorY:Number; + + graphics.beginFill( bgColour ); + graphics.lineStyle( borderThickness, borderColour ); + + for ( var i:Number = 0; i <= 360; i += ratio ) + { + vectorRadians = NumberUtil.toRadians( i ); + + vectorX = Math.sin( vectorRadians ) * radius; + vectorY = ( Math.cos( vectorRadians ) * radius ); + + coords[ vectorId ] = [ vectorX, vectorY ]; + + if ( vectorId >= 1 ) + { + graphics.lineTo( vectorX, vectorY ); + } + else + { + graphics.moveTo( vectorX, vectorY ); + } + + vectorId++; + } + + graphics.endFill(); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/threedee/Sprite3D.as b/com/firestartermedia/lib/as3/display/threedee/Sprite3D.as new file mode 100644 index 0000000..b238b96 --- /dev/null +++ b/com/firestartermedia/lib/as3/display/threedee/Sprite3D.as @@ -0,0 +1,253 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.display.threedee +{ + import com.firestartermedia.lib.as3.utils.DisplayObjectUtil; + import com.firestartermedia.lib.as3.utils.NumberUtil; + + import flash.display.DisplayObject; + import flash.display.Sprite; + import flash.geom.Matrix3D; + import flash.geom.Vector3D; + + public class Sprite3D extends Sprite + { + public static const SHAPE_RECTANGLE:String = 'rectangle'; + public static const SHAPE_SPHERE:String = 'sphere'; + + protected var _container:Sprite = new Sprite(); + + private var _angleX:Number = 0; + private var _angleY:Number = 0; + private var _angleZ:Number = 0; + private var _depth:Number = 0; + private var _height:Number = 0; + private var _width:Number = 0; + private var _x:Number = 0; + private var _y:Number = 0; + private var _z:Number = 0; + + private var _depthInitial:Number; + private var _shape:String; + + public function Sprite3D(shape:String='rectangle') + { + super(); + + super.addChild( container ); + } + + public function rotate(rotX:Number, rotY:Number, rotZ:Number, p:Vector3D=null):void + { + var pivot:Vector3D = ( p ||= calculatePivotPoint() ); + var matrix:Matrix3D = container.transform.matrix3D; + + if ( matrix ) + { + matrix.identity(); + matrix.appendTranslation( -pivot.x, -pivot.y, -pivot.z ); + matrix.appendRotation( rotX, Vector3D.X_AXIS ); + matrix.appendRotation( rotY, Vector3D.Y_AXIS ); + matrix.appendRotation( rotZ, Vector3D.Z_AXIS ); + matrix.appendTranslation( pivot.x, pivot.y, pivot.z ); + } + } + + private function calculatePivotPoint():Vector3D + { + var pivot:Vector3D = new Vector3D( width / 2, height / 2, depth / 2 ); + + return pivot; + } + + private function calculatePosition():void + { + calculateHeight(); + calculateWidth(); + calculateDepth(); + + rotate( _angleX, _angleY, _angleZ ); + } + + private function calculateDepth():void + { + if ( shape === SHAPE_RECTANGLE ) + { + calculateDepthRectangle(); + } + else + { + calculateDepthSphere(); + } + } + + private function calculateDepthRectangle():void + { + var depthX:Number = NumberUtil.toScalar( NumberUtil.calculateOppposite( rotationX, _height, true ) + NumberUtil.calculateAdjacent( rotationX, _depthInitial, true ) ); + var depthY:Number = NumberUtil.toScalar( NumberUtil.calculateOppposite( rotationX, _width / 2, true ) + NumberUtil.calculateAdjacent( rotationX, _depthInitial, true ) ); + var depthZ:Number = NumberUtil.toScalar( NumberUtil.calculateOppposite( rotationX, _height / 2, true ) ); + var newDepth:Number = 0; + + if ( depthX > depthY && depthX > depthZ && depthX > newDepth ) + { + newDepth = depthX; + } + + if ( depthY > depthX && depthY > depthZ && depthY > newDepth ) + { + newDepth = depthY; + } + + if ( depthZ > depthX && depthZ > depthY && depthZ > newDepth ) + { + newDepth = depthZ; + } + + _depth = ( newDepth === 0 ? _depthInitial : newDepth ); + } + + private function calculateDepthSphere():void + { + _depth = _depthInitial; + } + + private function calculateHeight():void + { + var callback:Function; + var heights:Array; + + callback = function(target:DisplayObject):Number + { + return target.height; + } + + heights = DisplayObjectUtil.eachChild( container, callback ); + + heights.sort( Array.DESCENDING | Array.NUMERIC ); + + _height = heights[ 0 ]; + } + + private function calculateWidth():void + { + var callback:Function; + var widths:Array; + + callback = function(target:DisplayObject):Number + { + return target.width; + } + + widths = DisplayObjectUtil.eachChild( container, callback ); + + widths.sort( Array.DESCENDING | Array.NUMERIC ); + + _width = widths[ 0 ]; + } + + public function get container():Sprite + { + return _container; + } + + public function set depth(value:Number):void + { + if ( !_depthInitial ) + { + _depthInitial = value; + } + + _depth = value; + + calculatePosition(); + } + + public function get depth():Number + { + return _depth; + } + + public function get shape():String + { + return _shape; + } + + override public function addChild(child:DisplayObject):DisplayObject + { + var c:DisplayObject = container.addChild( child ); + + calculatePosition(); + + return c; + } + + override public function addChildAt(child:DisplayObject, index:int):DisplayObject + { + var c:DisplayObject = container.addChildAt( child, index ); + + calculatePosition(); + + return c; + } + + override public function removeChild(child:DisplayObject):DisplayObject + { + var c:DisplayObject = container.removeChild( child ); + + calculatePosition(); + + return c; + } + + override public function removeChildAt(index:int):DisplayObject + { + var c:DisplayObject = container.removeChildAt( index ); + + calculatePosition(); + + return c; + } + + override public function set rotationX(value:Number):void + { + _angleX = NumberUtil.actualDegrees( value ); + + calculatePosition(); + } + + override public function get rotationX():Number + { + return _angleX; + } + + override public function set rotationY(value:Number):void + { + _angleY = NumberUtil.actualDegrees( value ); + + calculatePosition(); + } + + override public function get rotationY():Number + { + return _angleY; + } + + override public function set rotationZ(value:Number):void + { + _angleZ = NumberUtil.actualDegrees( value ); + + calculatePosition(); + } + + override public function get rotationZ():Number + { + return _angleZ; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/threedee/shape/Cube3D.as b/com/firestartermedia/lib/as3/display/threedee/shape/Cube3D.as new file mode 100644 index 0000000..9b1bb61 --- /dev/null +++ b/com/firestartermedia/lib/as3/display/threedee/shape/Cube3D.as @@ -0,0 +1,25 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.display.threedee.shape +{ + import flash.display.DisplayObject; + + public class Cube3D extends Rectangle3D + { + public function Cube() + { + super(); + } + + override protected function render(width:Number, height:Number, depth:Number):void + { + + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/threedee/shape/Rectangle3D.as b/com/firestartermedia/lib/as3/display/threedee/shape/Rectangle3D.as new file mode 100644 index 0000000..86386a6 --- /dev/null +++ b/com/firestartermedia/lib/as3/display/threedee/shape/Rectangle3D.as @@ -0,0 +1,197 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.display.threedee.shape +{ + import com.firestartermedia.lib.as3.display.threedee.Sprite3D; + + import flash.display.DisplayObject; + + public class Rectangle3D extends Sprite3D + { + protected var faces:Object = { }; + + public function Rectangle3D() + { + super(); + } + + public function build():void + { + var depth:Number; + var height:Number; + var width:Number; + + if ( faces.hasOwnProperty( 'all' ) || + ( faces.hasOwnProperty( 'front' ) && faces.hasOwnProperty( 'back' ) && + faces.hasOwnProperty( 'left' ) && faces.hasOwnProperty( 'right' ) && + faces.hasOwnProperty( 'top' ) && faces.hasOwnProperty( 'bottom' ) ) ) + { + if ( faces.hasOwnProperty( 'all' ) ) + { + depth = faces.all.width; + height = faces.all.height; + width = faces.all.width; + } + else + { + depth = ( faces.left.width >= faces.right.width ? faces.left.width : faces.right.width ); + height = ( faces.front.height >= faces.back.height ? faces.front.height : faces.back.height ); + width = ( faces.front.width >= faces.back.width ? faces.front.width : faces.back.width ); + } + + render( width, height, depth ); + } + else + { + throw new Error( 'Sorry, you need to specify the faces, so either "all" (not working yet...) or "front, back, left, right, top and bottom"' ); + } + } + + protected function render(width:Number, height:Number, depth:Number):void + { + this.depth = depth; + + if ( faces.hasOwnProperty( 'all' ) ) + { + faces.front = faces.all; + faces.back = faces.all; + faces.left = faces.all; + faces.right = faces.all; + faces.top = faces.all; + faces.bottom = faces.all; + } + + addChild( faces.back ); + addChild( faces.left ); + addChild( faces.right ); + addChild( faces.top ); + addChild( faces.bottom ); + addChild( faces.front ); + + faces.back.rotationY = 180; + faces.back.x = width; + faces.back.z = depth; + + faces.right.rotationY = 90; + faces.right.x = width; + faces.right.z = depth; + + faces.left.rotationY = 270; + faces.left.x = 0; + + faces.top.rotationX = 270; + faces.top.z = depth; + + faces.bottom.rotationX = 90; + faces.bottom.y = height; + } + + private function orderFaces():void + { + } + + /* public function set faceAll(object:DisplayObject):void + { + faces.all = object; + } */ + + public function set faceFront(object:DisplayObject):void + { + faces.front = object; + } + + public function set faceBack(object:DisplayObject):void + { + faces.back = object; + } + + public function set faceLeft(object:DisplayObject):void + { + faces.left = object; + } + + public function set faceRight(object:DisplayObject):void + { + faces.right = object; + } + + public function set faceTop(object:DisplayObject):void + { + faces.top = object; + } + + public function set faceBottom(object:DisplayObject):void + { + faces.bottom = object; + } + + /* public function get faceAll():DisplayObject + { + return faces.all as DisplayObject; + } */ + + public function get faceFront():DisplayObject + { + return faces.front as DisplayObject; + } + + public function get faceBack():DisplayObject + { + return faces.back as DisplayObject; + } + + public function get faceTop():DisplayObject + { + return faces.top as DisplayObject; + } + + public function get faceBottom():DisplayObject + { + return faces.bottom as DisplayObject; + } + + public function get faceLeft():DisplayObject + { + return faces.left as DisplayObject; + } + + public function get faceRight():DisplayObject + { + return faces.right as DisplayObject; + } + + override public function set rotation(value:Number):void + { + super.rotation = value; + + orderFaces(); + } + + override public function set rotationX(value:Number):void + { + super.rotationX = value; + + orderFaces(); + } + + override public function set rotationY(value:Number):void + { + super.rotationY = value; + + orderFaces(); + } + + override public function set rotationZ(value:Number):void + { + super.rotationZ = value; + + orderFaces(); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/display/tools/ScaleObject.as b/com/firestartermedia/lib/as3/display/tools/ScaleObject.as new file mode 100644 index 0000000..813ddfd --- /dev/null +++ b/com/firestartermedia/lib/as3/display/tools/ScaleObject.as @@ -0,0 +1,139 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.display.tools +{ + import com.firestartermedia.lib.as3.utils.BitmapUtil; + + import flash.display.BitmapData; + import flash.display.Sprite; + import flash.geom.Rectangle; + + public class ScaleObject extends Sprite + { + public var bitmapTL:Sprite; + public var bitmapTC:Sprite; + public var bitmapTR:Sprite; + public var bitmapML:Sprite; + public var bitmapMC:Sprite; + public var bitmapMR:Sprite; + public var bitmapBL:Sprite; + public var bitmapBC:Sprite; + public var bitmapBR:Sprite; + + private var master:*; + private var scaleGrid:Rectangle; + + public function ScaleObject(master:*, scaleGrid:Rectangle) + { + this.master = master; + this.scaleGrid = scaleGrid; + + init(); + } + + private function init():void + { + var tlX:Number = 0; + var tlY:Number = 0; + var tlWidth:Number = scaleGrid.x; + var tlHeight:Number = scaleGrid.y; + var tcX:Number = tlWidth; + var tcY:Number = tlY; + var tcWidth:Number = scaleGrid.width; + var tcHeight:Number = tlHeight; + var trX:Number = tlWidth + tcWidth; + var trY:Number = tlY; + var trWidth:Number = master.width - trX; + var trHeight:Number = tlHeight; + + var mlX:Number = 0; + var mlY:Number = tlHeight; + var mlWidth:Number = tlWidth; + var mlHeight:Number = scaleGrid.height; + var mcX:Number = tlWidth; + var mcY:Number = mlY; + var mcWidth:Number = tcWidth; + var mcHeight:Number = mlHeight; + var mrX:Number = trX; + var mrY:Number = mlY; + var mrWidth:Number = trWidth; + var mrHeight:Number = mlHeight; + + var blX:Number = 0; + var blY:Number = tlHeight + mlHeight; + var blWidth:Number = tlWidth; + var blHeight:Number = master.height - blY; + var bcX:Number = tlWidth; + var bcY:Number = blY; + var bcWidth:Number = tcWidth; + var bcHeight:Number = blHeight; + var brX:Number = trX; + var brY:Number = blY; + var brWidth:Number = trWidth; + var brHeight:Number = blHeight; + + bitmapTL = slice( tlX, tlY, tlWidth, tlHeight ); + bitmapTC = slice( tcX, tcY, tcWidth, tcHeight ); + bitmapTR = slice( trX, trY, trWidth, trHeight ); + bitmapML = slice( mlX, mlY, mlWidth, mlHeight ); + bitmapMC = slice( mcX, mcY, mcWidth, mcHeight ); + bitmapMR = slice( mrX, mrY, mrWidth, mrHeight ); + bitmapBL = slice( blX, blY, blWidth, blHeight ); + bitmapBC = slice( bcX, bcY, bcWidth, bcHeight ); + bitmapBR = slice( brX, brY, brWidth, brHeight ); + } + + private function slice(x:Number, y:Number, width:Number, height:Number):Sprite + { + var rect:Rectangle = new Rectangle( x, y, width, height ); + var sliceData:BitmapData = BitmapUtil.grab( master, rect ); + var slice:Sprite; + + slice = new Sprite(); + + slice.graphics.beginBitmapFill( sliceData ); + slice.graphics.drawRect( 0, 0, width, height ); + slice.graphics.endFill(); + slice.x = x; + slice.y = y; + + addChild( slice ); + + return slice; + } + + override public function set height(value:Number):void + { + var targetHeight:Number = Math.floor( value - bitmapTL.height - bitmapBL.height ); + var targetY:Number = Math.floor( value - bitmapBL.height ); + + bitmapML.height = targetHeight; + bitmapMC.height = targetHeight; + bitmapMR.height = targetHeight; + + bitmapBL.y = targetY; + bitmapBC.y = targetY; + bitmapBR.y = targetY; + } + + override public function set width(value:Number):void + { + var targetWidth:Number = Math.floor( value - bitmapTL.width - bitmapTR.width ); + var targetX:Number = Math.floor( targetWidth + bitmapTL.width ); + + bitmapTC.width = targetWidth; + bitmapMC.width = targetWidth; + bitmapBC.width = targetWidth; + + bitmapTR.x = targetX; + bitmapMR.x = targetX; + bitmapBR.x = targetX; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/effects/Explode.as b/com/firestartermedia/lib/as3/effects/Explode.as new file mode 100644 index 0000000..f9bfb91 --- /dev/null +++ b/com/firestartermedia/lib/as3/effects/Explode.as @@ -0,0 +1,41 @@ +package com.firestartermedia.lib.as3.effects +{ + import flash.display.BitmapData; + import flash.display.DisplayObject; + import flash.display.Sprite; + import flash.geom.Matrix; + + import org.osflash.thunderbolt.Logger; + + public class Explode extends Sprite + { + public var target:DisplayObject; + + public function Explode(target:DisplayObject) + { + this.target = target; + } + + public function init():void + { + var targetBitmap:BitmapData = new BitmapData( target.width, target.height, true, 0x00FFFFFF ); + var explosion:Sprite = new Sprite(); + var explosionMatrix:Matrix = new Matrix(); + + explosionMatrix.scale( 1, 1 ); + + targetBitmap.draw( target, explosionMatrix ); + + explosion.graphics.beginBitmapFill( targetBitmap ); + explosion.graphics.drawRect( 0, 0, target.width, target.height ); + explosion.graphics.endFill(); + + explosion.cacheAsBitmap = true; + + addChild( explosion ); + + target.alpha = 0; + target.visible = false; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/events/CountdownEvent.as b/com/firestartermedia/lib/as3/events/CountdownEvent.as new file mode 100644 index 0000000..c9f0c2d --- /dev/null +++ b/com/firestartermedia/lib/as3/events/CountdownEvent.as @@ -0,0 +1,21 @@ +package com.firestartermedia.lib.as3.events +{ + import flash.events.Event; + + public class CountdownEvent extends Event + { + public static const NAME:String = 'CountdownEvent'; + + public static const TIME:String = NAME + 'Time'; + + public var data:Object; + + public function CountdownEvent(type:String, data:Object=null, bubbles:Boolean=false, cancelable:Boolean=false) + { + super( type, bubbles, cancelable ); + + this.data = data; + } + + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/events/DataServiceEvent.as b/com/firestartermedia/lib/as3/events/DataServiceEvent.as new file mode 100644 index 0000000..e3dae5d --- /dev/null +++ b/com/firestartermedia/lib/as3/events/DataServiceEvent.as @@ -0,0 +1,32 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.events +{ + import flash.events.Event; + + public class DataServiceEvent extends Event + { + public static const NAME:String = 'GDataServiceEvent'; + + public static const LOADING:String = NAME + 'Loading'; + public static const LOADED:String = NAME + 'Loaded'; + public static const READY:String = NAME + 'Ready'; + + public var data:Object; + public var rawData:Object; + + public function DataServiceEvent(type:String, data:Object=null, rawData:Object=null, bubbles:Boolean=false, cancelable:Boolean=false) + { + super( type, bubbles, cancelable ); + + this.data = data; + this.rawData = rawData; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/events/LoaderProgressEvent.as b/com/firestartermedia/lib/as3/events/LoaderProgressEvent.as new file mode 100644 index 0000000..0f99940 --- /dev/null +++ b/com/firestartermedia/lib/as3/events/LoaderProgressEvent.as @@ -0,0 +1,23 @@ +package com.firestartermedia.lib.as3.events +{ + import flash.events.Event; + + public class LoaderProgressEvent extends Event + { + public static const NAME:String = 'LoaderProgressEvent'; + + public static const SHOW:String = NAME + 'Show'; + public static const UPDATE:String = NAME + 'Update'; + public static const COMPLETE:String = NAME + 'Complete'; + public static const HIDE:String = NAME + 'Hide'; + + public var data:Object; + + public function LoaderProgressEvent(type:String, data:Object=null, bubbles:Boolean=false, cancelable:Boolean=false) + { + super( type, bubbles, cancelable ); + + this.data = data; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/events/RemoteConnectionServiceEvent.as b/com/firestartermedia/lib/as3/events/RemoteConnectionServiceEvent.as new file mode 100644 index 0000000..55cd5cb --- /dev/null +++ b/com/firestartermedia/lib/as3/events/RemoteConnectionServiceEvent.as @@ -0,0 +1,30 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.events +{ + import flash.events.Event; + + public class RemoteConnectionServiceEvent extends Event + { + public static const NAME:String = 'RemoteConnectionServiceEvent'; + + public static const LOADED:String = NAME + 'Loaded'; + public static const READY:String = NAME + 'Ready'; + public static const FAULT:String = NAME + 'Fault'; + + public var data:Object; + + public function RemoteConnectionServiceEvent(type:String, data:Object=null, bubbles:Boolean=false, cancelable:Boolean=false) + { + super( type, bubbles, cancelable ); + + this.data = data; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/events/SoundPlayerEvent.as b/com/firestartermedia/lib/as3/events/SoundPlayerEvent.as new file mode 100644 index 0000000..b518e3e --- /dev/null +++ b/com/firestartermedia/lib/as3/events/SoundPlayerEvent.as @@ -0,0 +1,40 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.events +{ + import flash.events.Event; + + public class SoundPlayerEvent extends Event + { + public static const NAME:String = 'SoundPlayerEvent'; + + public static const BUFFERING:String = NAME + 'Buffering'; + public static const LOADING:String = NAME + 'Loading'; + public static const LOADED:String = NAME + 'Loaded'; + public static const ID3_READY:String = NAME + 'ID3Ready'; + public static const STARTED:String = NAME + 'Started'; + public static const PLAYING:String = NAME + 'Playing'; + public static const PAUSED:String = NAME + 'Paused'; + public static const CUE_POINT:String = NAME + 'CuePoint'; + public static const HALF_WAY:String = NAME + 'HalfWay'; + public static const ENDED:String = NAME + 'Ended'; + public static const ERROR:String = NAME + 'Error'; + public static const SOUND_CHANGED:String = NAME + 'SoundChanged'; + public static const FAILED:String = NAME + 'Failed'; + + public var data:Object; + + public function SoundPlayerEvent(type:String, data:Object=null, bubbles:Boolean=true, cancelable:Boolean=false) + { + super( type, bubbles, cancelable ); + + this.data = data; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/events/VideoPlayerEvent.as b/com/firestartermedia/lib/as3/events/VideoPlayerEvent.as new file mode 100644 index 0000000..0fdc7c0 --- /dev/null +++ b/com/firestartermedia/lib/as3/events/VideoPlayerEvent.as @@ -0,0 +1,47 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.events +{ + import flash.events.Event; + + public class VideoPlayerEvent extends Event + { + public static const NAME:String = 'VideoPlayerEvent'; + + public static const BUFFERING:String = NAME + 'Buffering'; + public static const LOADING:String = NAME + 'Loading'; + public static const LOADED:String = NAME + 'Loaded'; + public static const STARTED:String = NAME + 'Started'; + public static const PLAYING:String = NAME + 'Playing'; + public static const PAUSED:String = NAME + 'Paused'; + public static const CUE_POINT:String = NAME + 'CuePoint'; + public static const HALF_WAY:String = NAME + 'HalfWay'; + public static const ENDED:String = NAME + 'Ended'; + public static const ERROR:String = NAME + 'Error'; + public static const SOUND_CHANGED:String = NAME + 'SoundChanged'; + public static const CLICKED:String = NAME + 'Clicked'; + public static const OVER:String = NAME + 'Over'; + public static const OUT:String = NAME + 'Out'; + public static const SHARE:String = NAME + 'Share'; + public static const FULL_SCREEN_ON:String = NAME + 'FullScreenOn'; + public static const FULL_SCREEN_OFF:String = NAME + 'FullScreenOff'; + public static const FAILED:String = NAME + 'Failed'; + public static const SHOWING_ADS:String = NAME + 'ShowingAds'; + public static const FINISHED_ADS:String = NAME + 'FinishedAds'; + + public var data:Object; + + public function VideoPlayerEvent(type:String, data:Object=null, bubbles:Boolean=true, cancelable:Boolean=false) + { + super( type, bubbles, cancelable ); + + this.data = data; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/events/WebCamEvent.as b/com/firestartermedia/lib/as3/events/WebCamEvent.as new file mode 100644 index 0000000..82631fb --- /dev/null +++ b/com/firestartermedia/lib/as3/events/WebCamEvent.as @@ -0,0 +1,22 @@ +package com.firestartermedia.lib.as3.events +{ + import flash.events.Event; + + public class WebCamEvent extends Event + { + public static const NAME:String = 'WebCamEvent'; + + public static const CONNECTING:String = NAME + 'Connecting'; + public static const CONNECTED:String = NAME + 'Connected'; + public static const CONNECTION_FAILED:String = NAME + 'ConnectionFailed'; + public static const NO_WEBCAM:String = NAME + 'NoWebcam'; + public static const RECORDING_STARTED:String = NAME + 'RecordingStarted'; + public static const RECORDING_STOPPED:String = NAME + 'RecordingStopped'; + public static const RECORDING_FINISHED:String = NAME + 'RecordingFinished'; + + public function WebCamEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false) + { + super( type, bubbles, cancelable ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/events/YouTubePlayerEvent.as b/com/firestartermedia/lib/as3/events/YouTubePlayerEvent.as new file mode 100644 index 0000000..040de6f --- /dev/null +++ b/com/firestartermedia/lib/as3/events/YouTubePlayerEvent.as @@ -0,0 +1,38 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.events +{ + import flash.events.Event; + + public class YouTubePlayerEvent extends Event + { + public static const NAME:String = 'YouTubePlayerEvent'; + + public static const CONNECTED:String = NAME + 'Connected'; + public static const READY:String = NAME + 'Ready'; + public static const STATE_CHANGED:String = NAME + 'StateChange'; + public static const ERROR:String = NAME + 'Error'; + public static const PLAYING:String = NAME + 'Playing'; + public static const ENDED:String = NAME + 'Ended'; + public static const PAUSED:String = NAME + 'Paused'; + public static const QUEUED:String = NAME + 'Queued'; + public static const BUFFERING:String = NAME + 'Buffering'; + public static const NOT_STARTED:String = NAME + 'NotStarted'; + public static const QUALITY_CHANGED:String = NAME + 'QualityChanged'; + + public var data:Object; + + public function YouTubePlayerEvent(type:String, data:Object=null, bubbles:Boolean=false, cancelable:Boolean=false) + { + super( type, bubbles, cancelable ); + + this.data = data; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/sound/component/SoundPlayer.as b/com/firestartermedia/lib/as3/sound/component/SoundPlayer.as new file mode 100644 index 0000000..993f09a --- /dev/null +++ b/com/firestartermedia/lib/as3/sound/component/SoundPlayer.as @@ -0,0 +1,143 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.sound.component +{ + import com.firestartermedia.lib.as3.events.SoundPlayerEvent; + + import flash.events.Event; + import flash.events.EventDispatcher; + import flash.events.IEventDispatcher; + import flash.events.IOErrorEvent; + import flash.events.ProgressEvent; + import flash.media.Sound; + import flash.media.SoundChannel; + import flash.media.SoundLoaderContext; + import flash.net.URLRequest; + + public class SoundPlayer extends EventDispatcher implements IEventDispatcher + { + public var autoPlay:Boolean = true; + public var bufferTime:Number = 2; + + private var context:SoundLoaderContext = new SoundLoaderContext(); + private var currentPosition:Number = 0; + private var cuePoints:Array = [ ]; + private var isPlaying:Boolean = false; + private var lastFiredCuePoint:Number = 0; + + private var channel:SoundChannel; + private var sound:Sound; + + public function SoundPlayer() + { + super( this ); + + sound.addEventListener( ProgressEvent.PROGRESS, handleSoundProgress ); + sound.addEventListener( IOErrorEvent.IO_ERROR, handleSoundFault ); + sound.addEventListener( Event.ID3, handleSoundDataReady ); + sound.addEventListener( Event.COMPLETE, handleSoundComplete ); + } + + private function handleSoundProgress(e:ProgressEvent):void + { + dispatchEvent( new SoundPlayerEvent( SoundPlayerEvent.LOADING, loadingProgress ) ); + } + + private function handleSoundFault(e:*):void + { + dispatchEvent( new SoundPlayerEvent( SoundPlayerEvent.FAILED ) ); + } + + private function handleSoundDataReady(e:Event):void + { + dispatchEvent( new SoundPlayerEvent( SoundPlayerEvent.ID3_READY, sound.id3 ) ); + } + + private function handleSoundComplete(e:Event):void + { + if ( autoPlay ) + { + resume(); + } + } + + public function play(url:String):void + { + var request:URLRequest = new URLRequest( url ); + + context.bufferTime = 2; + + currentPosition = 0; + + if ( channel ) + { + channel = null; + } + + if ( sound ) + { + sound.close(); + } + + sound = new Sound(); + + sound.load( request, context ); + } + + public function resume():void + { + if ( !channel ) + { + channel = sound.play(); + } + + sound.play( currentPosition ); + + isPlaying = true; + } + + public function pause():void + { + if ( channel ) + { + currentPosition = channel.position; + + channel.stop(); + + isPlaying = false; + } + else + { + throw new Error( 'There\'s nothing to pause!' ); + } + } + + public function get loadingProgress():Object + { + var progress:Object = { }; + + progress.total = sound.bytesLoaded / sound.bytesTotal; + progress.bytesLoaded = sound.bytesLoaded; + progress.bytesTotal = sound.bytesTotal; + + return progress; + } + + public function get playingTime():Object + { + var time:Object = { }; + + /*time.current = stream.time; + time.total = metaData.duration; + time.formatted = NumberUtil.toTimeString( Math.round( stream.time ) ) + ' / ' + NumberUtil.toTimeString( Math.round( metaData.duration ) ); */ + + return time; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/utils/ArrayUtil.as b/com/firestartermedia/lib/as3/utils/ArrayUtil.as new file mode 100644 index 0000000..4dc679a --- /dev/null +++ b/com/firestartermedia/lib/as3/utils/ArrayUtil.as @@ -0,0 +1,70 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.utils +{ + public class ArrayUtil + { + public static function shuffle(array:Array):Array + { + var i:Number = array.length; + var j:Number; + var t1:*; + var t2:*; + + if ( i == 0 ) + { + return [ ]; + } + else + { + while ( --i ) + { + j = Math.floor( Math.random() * ( i + 1 ) ); + + t1 = array[ i ]; + t2 = array[ j ]; + + array[ i ] = t2; + array[ j ] = t1; + } + + return array; + } + } + + public static function search(array:Array, value:Object):Number + { + var found:Boolean = false; + + for ( var i:Number = 0; i < array.length; i++) + { + if ( array[ i ] == value ) + { + found = true; + + break; + } + } + + return ( found ? i : -1 ); + } + + public static function toArray(data:Object):Array + { + var array:Array = [ ]; + + for each ( var item:Object in data ) + { + array.push( item ); + } + + return array; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/utils/BitmapUtil.as b/com/firestartermedia/lib/as3/utils/BitmapUtil.as new file mode 100644 index 0000000..66ed64c --- /dev/null +++ b/com/firestartermedia/lib/as3/utils/BitmapUtil.as @@ -0,0 +1,43 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.utils +{ + import flash.display.Bitmap; + import flash.display.BitmapData; + import flash.display.DisplayObject; + import flash.display.PixelSnapping; + import flash.geom.Point; + import flash.geom.Rectangle; + + public class BitmapUtil + { + public static function flatten(source:*):BitmapData + { + return grab( source, new Rectangle( 0, 0, source.width, source.height ) ); + } + + public static function grab(source:*, rect:Rectangle, smoothing:Boolean=true):BitmapData + { + var draw:BitmapData = new BitmapData( source.width, source.height, true, 0 ); + var copy:BitmapData = new BitmapData( rect.width, rect.height, true, 0 ); + + draw.draw( source, null, null, null, null, smoothing ); + copy.copyPixels( draw, rect, new Point( 0, 0 ) ); + + draw.dispose(); + + return copy; + } + + public static function clone(source:*):Bitmap + { + return new Bitmap( grab( source, new Rectangle( 0, 0, source.width, source.height ) ), PixelSnapping.AUTO, true ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/utils/DateUtil.as b/com/firestartermedia/lib/as3/utils/DateUtil.as new file mode 100644 index 0000000..121fa67 --- /dev/null +++ b/com/firestartermedia/lib/as3/utils/DateUtil.as @@ -0,0 +1,128 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.utils +{ + public class DateUtil + { + /** + * This is taken from Adobe's CoreLib. Unfortunatly their DateUtil class doesn't seem to work + * as it can't find mx.formatters.DateBase and nor can I! + * + * @param str + * @return + * + */ + public static function parseW3CDTF(str:String):Date + { + var finalDate:Date; + try + { + var dateStr:String = str.substring(0, str.indexOf("T")); + var timeStr:String = str.substring(str.indexOf("T")+1, str.length); + var dateArr:Array = dateStr.split("-"); + var year:Number = Number(dateArr.shift()); + var month:Number = Number(dateArr.shift()); + var date:Number = Number(dateArr.shift()); + + var multiplier:Number; + var offsetHours:Number; + var offsetMinutes:Number; + var offsetStr:String; + + if (timeStr.indexOf("Z") != -1) + { + multiplier = 1; + offsetHours = 0; + offsetMinutes = 0; + timeStr = timeStr.replace("Z", ""); + } + else if (timeStr.indexOf("+") != -1) + { + multiplier = 1; + offsetStr = timeStr.substring(timeStr.indexOf("+")+1, timeStr.length); + offsetHours = Number(offsetStr.substring(0, offsetStr.indexOf(":"))); + offsetMinutes = Number(offsetStr.substring(offsetStr.indexOf(":")+1, offsetStr.length)); + timeStr = timeStr.substring(0, timeStr.indexOf("+")); + } + else // offset is - + { + multiplier = -1; + offsetStr = timeStr.substring(timeStr.indexOf("-")+1, timeStr.length); + offsetHours = Number(offsetStr.substring(0, offsetStr.indexOf(":"))); + offsetMinutes = Number(offsetStr.substring(offsetStr.indexOf(":")+1, offsetStr.length)); + timeStr = timeStr.substring(0, timeStr.indexOf("-")); + } + var timeArr:Array = timeStr.split(":"); + var hour:Number = Number(timeArr.shift()); + var minutes:Number = Number(timeArr.shift()); + var secondsArr:Array = (timeArr.length > 0) ? String(timeArr.shift()).split(".") : null; + var seconds:Number = (secondsArr != null && secondsArr.length > 0) ? Number(secondsArr.shift()) : 0; + var milliseconds:Number = (secondsArr != null && secondsArr.length > 0) ? Number(secondsArr.shift()) : 0; + var utc:Number = Date.UTC(year, month-1, date, hour, minutes, seconds, milliseconds); + var offset:Number = (((offsetHours * 3600000) + (offsetMinutes * 60000)) * multiplier); + finalDate = new Date(utc - offset); + + if (finalDate.toString() == "Invalid Date") + { + throw new Error("This date does not conform to W3CDTF."); + } + } + catch (e:Error) + { + var eStr:String = "Unable to parse the string [" +str+ "] into a date. "; + eStr += "The internal error was: " + e.toString(); + throw new Error(eStr); + } + return finalDate; + } + + public static function toTimestamp(date:Date):String + { + var timestamp:String = ''; + + timestamp += date.getFullYear() + '-' + NumberUtil.prependZero( date.getMonth() + 1 ) + '-' + NumberUtil.prependZero( date.getDate() ) + ' '; + timestamp += NumberUtil.prependZero( date.getHours() ) + ':' + NumberUtil.prependZero( date.getMinutes() ) + ':' + NumberUtil.prependZero( date.getSeconds() ); + + return timestamp; + } + + public static function toNumericalTimestamp(date:Date):String + { + var timestamp:String = ''; + + timestamp += date.getFullYear() + NumberUtil.prependZero( date.getMonth() + 1 ) + NumberUtil.prependZero( date.getDate() ); + timestamp += NumberUtil.prependZero( date.getHours() ) + NumberUtil.prependZero( date.getMinutes() ) + NumberUtil.prependZero( date.getSeconds() ); + + return timestamp; + } + + /* "stolen" from http://stackoverflow.com/questions/3163/actionscript-3-fastest-way-to-parse-yyyy-mm-dd-hhmmss-to-a-date-object */ + public static function parseUTCDate(str:String):Date + { + var matches : Array = str.match(/(\d\d\d\d)-(\d\d)-(\d\d)[\s|T]?(\d\d):(\d\d):(\d\d)/); + var d : Date = new Date(); + + d.setUTCFullYear(int(matches[1]), int(matches[2]) - 1, int(matches[3])); + d.setUTCHours(int(matches[4]), int(matches[5]), int(matches[6]), 0); + + return d; + } + + /* "stolen" from http://stackoverflow.com/questions/3163/actionscript-3-fastest-way-to-parse-yyyy-mm-dd-hhmmss-to-a-date-object */ + public static function parseDate(str:String):Date + { + var matches : Array = str.match(/(\d\d\d\d)-(\d\d)-(\d\d)/); + var d : Date = new Date(); + + d.setUTCFullYear(int(matches[1]), int(matches[2]) - 1, int(matches[3])); + + return d; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/utils/DisplayObject3DUtil.as b/com/firestartermedia/lib/as3/utils/DisplayObject3DUtil.as new file mode 100644 index 0000000..694bbfc --- /dev/null +++ b/com/firestartermedia/lib/as3/utils/DisplayObject3DUtil.as @@ -0,0 +1,30 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.utils +{ + import flash.display.DisplayObject; + import flash.geom.Matrix3D; + import flash.geom.Vector3D; + + public class DisplayObject3DUtil + { + public static function centerRotate(target:DisplayObject, center:Vector3D, degreesX:Number, degreesY:Number, degreesZ:Number):void + { + var m:Matrix3D = target.transform.matrix3D; + + m.appendTranslation( -center.x, -center.y, -center.z ); + m.appendRotation( degreesX, Vector3D.X_AXIS ); + m.appendRotation( degreesY, Vector3D.Y_AXIS ); + m.appendRotation( degreesZ, Vector3D.Z_AXIS ); + m.appendTranslation( center.x, center.y, center.z ); + + target.transform.matrix3D = m; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/utils/DisplayObjectUtil.as b/com/firestartermedia/lib/as3/utils/DisplayObjectUtil.as new file mode 100644 index 0000000..f0562e3 --- /dev/null +++ b/com/firestartermedia/lib/as3/utils/DisplayObjectUtil.as @@ -0,0 +1,135 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.utils +{ + import flash.display.DisplayObject; + import flash.display.DisplayObjectContainer; + import flash.display.Loader; + import flash.events.Event; + import flash.geom.ColorTransform; + import flash.geom.Matrix; + import flash.geom.Point; + import flash.net.URLRequest; + import flash.system.ApplicationDomain; + import flash.system.LoaderContext; + + public class DisplayObjectUtil + { + public static function removeChildren(target:DisplayObjectContainer):void + { + while ( target.numChildren ) + { + target.removeChildAt( target.numChildren - 1 ); + } + } + + public static function addChildren(target:DisplayObjectContainer, ...children):void + { + for each ( var child:DisplayObject in children ) + { + target.addChild( child ); + } + } + + public static function getChildren(target:DisplayObjectContainer):Array + { + var children:Array = [ ]; + + for ( var i:Number; target.numChildren < i; i++ ) + { + children.push( target.getChildAt( i ) ); + } + + return children; + } + + public static function loadMovie(url:String, parent:DisplayObjectContainer=null, completeFunction:Function=null, applicationDomain:ApplicationDomain=null, checkPolicyFile:Boolean=false):Loader + { + var request:URLRequest = new URLRequest( url ); + var context:LoaderContext = new LoaderContext( checkPolicyFile, ( applicationDomain ||= ApplicationDomain.currentDomain ) ); + var loader:Loader = new Loader(); + + if ( parent != null ) + { + parent.addChild( loader ); + } + + if ( completeFunction != null ) + { + loader.contentLoaderInfo.addEventListener( Event.COMPLETE, completeFunction ); + } + + try + { + loader.load( request, context ); + } + catch (e:*) + { } + + return loader; + } + + public static function scale(target:DisplayObject, width:Number=0, height:Number=0):void + { + var targetHeight:Number = ( height > 0 ? height : target.height ); + var targetWidth:Number = targetHeight * ( target.width / target.height ); + + if ( targetWidth > target.width ) + { + targetWidth = ( width > 0 ? width : target.width ); + targetHeight = targetWidth * ( target.height / target.width ); + } + + target.height = targetHeight; + target.width = targetWidth; + } + + public static function eachChild(target:DisplayObjectContainer, func:Function):Array + { + var funcReturn:Array = [ ]; + + for ( var i:Number = 0; i < target.numChildren; i++ ) + { + funcReturn.push( func.apply( null, [ target.getChildAt( i ) ] ) ); + } + + return funcReturn; + } + + public static function centerRotate(target:DisplayObject, center:Point, degrees:Number):void + { + var m:Matrix = target.transform.matrix; + + m.tx -= center.x; + m.ty -= center.y; + + m.rotate( NumberUtil.toRadians( degrees ) ); + + m.tx += center.x; + m.ty += center.y; + + target.transform.matrix = m; + } + + public static function changeColour(target:DisplayObject, colour:*):void + { + var trans:ColorTransform = target.transform.colorTransform; + var c:uint = ( colour is uint ? colour : NumberUtil.toUint( colour ) ); + + trans.color = c; + + target.transform.colorTransform = trans; + } + + public static function revertColour(target:DisplayObject):void + { + target.transform.colorTransform = new ColorTransform(); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/utils/GoogleUtil.as b/com/firestartermedia/lib/as3/utils/GoogleUtil.as new file mode 100644 index 0000000..d8ed197 --- /dev/null +++ b/com/firestartermedia/lib/as3/utils/GoogleUtil.as @@ -0,0 +1,23 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.utils +{ + import flash.external.ExternalInterface; + + public class GoogleUtil + { + public static function trackClick(page:String):void + { + try + { + ExternalInterface.call( 'pageTracker._trackPageview', page ); + } catch (e:*) { } + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/utils/NumberUtil.as b/com/firestartermedia/lib/as3/utils/NumberUtil.as new file mode 100644 index 0000000..274df72 --- /dev/null +++ b/com/firestartermedia/lib/as3/utils/NumberUtil.as @@ -0,0 +1,124 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.utils +{ + public class NumberUtil + { + public static function format(number:Number):String + { + var numString:String = number.toString() + var result:String = '' + var chunk:String; + + while ( numString.length > 3 ) + { + chunk = numString.substr( -3 ); + numString = numString.substr( 0, numString.length - 3 ); + result = ',' + chunk + result; + } + + if ( numString.length > 0 ) + { + result = numString + result; + } + + return result + } + + public static function toTimeString(number:Number, seperator:String=':'):String + { + var hours:Number = Math.floor( number / 3600 ); + var minutes:Number = Math.floor( ( number % 3600 ) / 60 ); + var seconds:Number = Math.floor( ( number % 3600 ) % 60 ); + var times:Array = [ likeTime( hours ), likeTime( minutes, true ), likeTime( seconds, true ) ]; + var test:Function = function(item:String, index:Number, array:Array):Boolean + { + return ObjectUtil.isValid( item ); + } + + return times.filter( test ).join( seperator ); + } + + public static function likeTime(number:Number, forceZero:Boolean=false):String + { + return ( number > 0 || ( number == 0 && forceZero ) ? prependZero( number ) : '' ); + } + + public static function prependZero(number:Number):String + { + return ( number < 10 ? '0' + number.toString() : number.toString() ); + } + + public static function toUint(string:Object):uint + { + return uint( string.toString().replace( '#', '0x' ) ); + } + + public static function toScalar(value:Number):Number + { + return value * ( value < 0 ? -1 : 1 ); + } + + public static function denominate(value:Number, denominator:Number):Number + { + var actual:Number = value; + + while ( actual >= denominator ) + { + actual -= denominator; + } + + while ( actual < -denominator ) + { + actual += denominator; + } + + return actual; + } + + public static function actualDegrees(degrees:Number):Number + { + return denominate( degrees, 360 ); + } + + public static function actualRadians(radians:Number):Number + { + return denominate( radians, Math.PI * 2 ); + } + + public static function toDegrees(radians:Number):Number + { + return actualRadians( radians ) * ( 180 / Math.PI ); + } + + public static function toRadians(degrees:Number):Number + { + return actualDegrees( degrees ) * ( Math.PI / 180 ); + } + + public static function calculateAdjacent(value:Number, hypotenuse:Number, isAngle:Boolean=false):Number + { + var radians:Number = ( isAngle ? toRadians( value ) : actualRadians( value ) ); + + return Math.cos( radians ) * hypotenuse; + } + + public static function calculateOppposite(value:Number, hypotenuse:Number, isAngle:Boolean=false):Number + { + var radians:Number = ( isAngle ? toRadians( value ) : actualRadians( value ) ); + + return Math.sin( radians ) * hypotenuse; + } + + public static function calculatePartPercentage(current:Number, total:Number, loaded:Number):Number + { + return ( loaded * ( 1 / total ) * 100 ) + ( current / total ) * 100; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/utils/ObjectUtil.as b/com/firestartermedia/lib/as3/utils/ObjectUtil.as new file mode 100644 index 0000000..092d4a0 --- /dev/null +++ b/com/firestartermedia/lib/as3/utils/ObjectUtil.as @@ -0,0 +1,18 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.utils +{ + public class ObjectUtil + { + public static function isValid(obj:*):Boolean + { + return ( obj ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/utils/StringUtil.as b/com/firestartermedia/lib/as3/utils/StringUtil.as new file mode 100644 index 0000000..6911055 --- /dev/null +++ b/com/firestartermedia/lib/as3/utils/StringUtil.as @@ -0,0 +1,44 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.utils +{ + public class StringUtil + { + public static function removeSpaces(string:String):String + { + return string.replace( /\s*/gim, '' ); + } + + public static function multiply(string:String, times:Number):String + { + var result:String = ''; + + for ( var i:Number = 0; i < times; i++ ) + { + result += string; + } + + return result; + } + + public static function print(obj:*, level:Number=0):void + { + var tabs:String = ''; + + StringUtil.multiply( "\t", level ); + + for ( var prop:String in obj ) + { + trace( tabs + '[' + prop + '] -> ' + obj[ prop ] ); +             + print( obj[ prop ], level + 1 ); + } + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/utils/URLUtil.as b/com/firestartermedia/lib/as3/utils/URLUtil.as new file mode 100644 index 0000000..13eff92 --- /dev/null +++ b/com/firestartermedia/lib/as3/utils/URLUtil.as @@ -0,0 +1,35 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.utils +{ + import flash.net.URLRequest; + import flash.net.navigateToURL; + + public class URLUtil + { + public static function goToURL(url:String, target:String='_blank'):void + { + var request:URLRequest = new URLRequest( url ); + + navigateToURL( request, target ); + } + + public static function parseURL(url:String):Object + { + var result:Object = { }; + + result.protocol = url.split( '://' )[ 0 ] + '://'; + result.hostAndPort = url.split( '/' )[ 2 ]; + result.host = result.hostAndPort.toString().split( ':' )[ 0 ]; + result.port = result.hostAndPort.toString().split( ':' )[ 1 ]; + + return result; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/utils/UintUtil.as b/com/firestartermedia/lib/as3/utils/UintUtil.as new file mode 100644 index 0000000..5726de2 --- /dev/null +++ b/com/firestartermedia/lib/as3/utils/UintUtil.as @@ -0,0 +1,20 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.utils +{ + public class UintUtil + { + public static function toUint(string:String):uint + { + trace( '*** This class is depreciated, please use NumberUtil instead ***' ); + + return uint( string.toString().replace('#','0x') ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/utils/YAMLUtil.as b/com/firestartermedia/lib/as3/utils/YAMLUtil.as new file mode 100644 index 0000000..8d9adfc --- /dev/null +++ b/com/firestartermedia/lib/as3/utils/YAMLUtil.as @@ -0,0 +1,63 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.utils +{ + import flash.utils.describeType; + + public class YAMLUtil + { + public static function formatArray(array:Array, tab:String):String + { + var result:String = ''; + + for each ( var item:Object in array ) + { + result += '\n' + tab + '- "' + item.toString() + '"'; + } + + return result; + } + + public static function formatHash(hash:Object, tab:String, depth:Number=1):String + { + var hashInfo:XML = describeType( hash ); + var result:String = ''; + var item:*; + var itemInfo:XML; + + if ( hashInfo.@name == 'Object' ) + { + for ( var key:String in hash ) + { + item = hash[ key ]; + + itemInfo = describeType( item ); + + result += '\n' + StringUtil.multiply( tab, depth ) + key +': ' + ( itemInfo.@name == 'String' ? item : '' ) + ''; + + if ( itemInfo.@name != 'String' ) + { + result += formatHash( item, tab, depth + 1 ); + } + } + } + else + { + for each ( var v:XML in hashInfo..*.( name() == 'variable' || name() == 'accessor' ) ) + { + item = hash[ v.@name ]; + + result += '\n' + StringUtil.multiply( tab, depth ) + v.@name +': ' + item + ''; + } + } + + return result; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/as3/utils/YouTubeUtil.as b/com/firestartermedia/lib/as3/utils/YouTubeUtil.as new file mode 100644 index 0000000..ac3198f --- /dev/null +++ b/com/firestartermedia/lib/as3/utils/YouTubeUtil.as @@ -0,0 +1,42 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.as3.utils +{ + //import com.adobe.utils.DateUtil; + + import mx.utils.StringUtil; + + public class YouTubeUtil + { + public static function cleanGDataFeed(data:XML):Array + { + var cleanData:Array = [ ]; + + for each ( var entry:XML in data..*::entry ) + { + if ( mx.utils.StringUtil.trim( entry..*::videoid ) != '' ) + { + cleanData.push({ + title: entry.*::title, + description: entry..*::description, + keywords: entry..*::keywords, + author: entry.*::author.name, + username: entry..*::credit.toString(), + videoId: entry..*::videoid.toString(), + rating: entry.*::rating.@average, + views: NumberUtil.format( entry.*::statistics.@viewCount ), + uploaded: DateUtil.parseW3CDTF( entry..*::uploaded.toString() ).valueOf() + }); + } + } + + return cleanData; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/puremvc/display/Canvas.as b/com/firestartermedia/lib/puremvc/display/Canvas.as new file mode 100644 index 0000000..29b85c7 --- /dev/null +++ b/com/firestartermedia/lib/puremvc/display/Canvas.as @@ -0,0 +1,32 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.puremvc.display +{ + import com.firestartermedia.lib.puremvc.events.CanvasEvent; + + import mx.containers.Canvas; + + public class Canvas extends mx.containers.Canvas + { + public var registered:Boolean = false; + public var ready:Boolean = false; + + public function sendEvent(eventName:String, body:Object=null):void + { + dispatchEvent( new CanvasEvent( eventName, body, true ) ); + } + + public function sendReady(eventName:String):void + { + ready = true; + + sendEvent( eventName ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/puremvc/display/Sprite.as b/com/firestartermedia/lib/puremvc/display/Sprite.as new file mode 100644 index 0000000..cef87bc --- /dev/null +++ b/com/firestartermedia/lib/puremvc/display/Sprite.as @@ -0,0 +1,125 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.puremvc.display +{ + import com.firestartermedia.lib.puremvc.events.SpriteEvent; + + import flash.display.DisplayObject; + import flash.display.Sprite; + + public class Sprite extends flash.display.Sprite + { + public static const NAME:String = 'Sprite'; + + public var display:Boolean = true; + public var registered:Boolean = false; + public var ready:Boolean = false; + public var tweenResize:Boolean = false; + + protected var tweenTime:Number = 1; + + protected var readyEvent:String; + protected var resetEvent:String; + protected var stageHeight:Number; + protected var stageWidth:Number; + + public function Sprite(readyEvent:String='SpriteReady', resetEvent:String='SpriteReset') + { + this.readyEvent = readyEvent; + this.resetEvent = resetEvent; + + registered = true; + } + + public function addChildren(...children):void + { + for each ( var child:DisplayObject in children ) + { + addChild( child ); + } + } + + public function removeChildren(...children):void + { + if ( children ) + { + for each ( var child:DisplayObject in children ) + { + removeChild( child ); + } + } + else + { + for ( var i:Number = 0; i < numChildren; i++ ) + { + removeChildAt( i ); + } + } + } + + override public function addChild(child:DisplayObject):DisplayObject + { + super.addChild( child ); + + handleResize(); + + return child; + } + + override public function addChildAt(child:DisplayObject, index:int):DisplayObject + { + super.addChildAt( child, index ); + + handleResize(); + + return child; + } + + protected function sendEvent(eventName:String, body:Object=null):void + { + dispatchEvent( new SpriteEvent( eventName, body, true ) ); + } + + protected function sendReady(eventName:String=null):void + { + if ( !ready ) + { + ready = true; + + sendEvent( ( eventName ? eventName : readyEvent ) ); + } + } + + protected function sendReset(eventName:String=null):void + { + if ( !ready ) + { + ready = false; + + sendEvent( ( eventName ? eventName : resetEvent ) ); + } + } + + public function handleReset():void + { + ready = false; + + sendReset(); + } + + public function handleResize(e:Object=null):void + { + if ( e ) + { + stageHeight = e.height; + stageWidth = e.width; + } + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/puremvc/events/CanvasEvent.as b/com/firestartermedia/lib/puremvc/events/CanvasEvent.as new file mode 100644 index 0000000..386c41d --- /dev/null +++ b/com/firestartermedia/lib/puremvc/events/CanvasEvent.as @@ -0,0 +1,24 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.puremvc.events +{ + import flash.events.Event; + + public class CanvasEvent extends Event + { + public var data:Object; + + public function CanvasEvent(type:String, data:Object=null, bubbles:Boolean=false, cancelable:Boolean=false) + { + super( type, bubbles, cancelable ); + + this.data = data; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/puremvc/events/SpriteEvent.as b/com/firestartermedia/lib/puremvc/events/SpriteEvent.as new file mode 100644 index 0000000..baf8ffb --- /dev/null +++ b/com/firestartermedia/lib/puremvc/events/SpriteEvent.as @@ -0,0 +1,24 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.puremvc.events +{ + import flash.events.Event; + + public class SpriteEvent extends Event + { + public var data:Object; + + public function SpriteEvent(type:String, data:Object=null, bubbles:Boolean=false, cancelable:Boolean=false) + { + super( type, bubbles, cancelable ); + + this.data = data; + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/puremvc/patterns/ApplicationMediator.as b/com/firestartermedia/lib/puremvc/patterns/ApplicationMediator.as new file mode 100644 index 0000000..3749af3 --- /dev/null +++ b/com/firestartermedia/lib/puremvc/patterns/ApplicationMediator.as @@ -0,0 +1,88 @@ +package com.firestartermedia.lib.puremvc.patterns +{ + import com.firestartermedia.lib.as3.utils.ArrayUtil; + + import flash.utils.getDefinitionByName; + + import org.puremvc.as3.interfaces.IMediator; + + public class ApplicationMediator extends Mediator implements IMediator + { + protected var excludedMediators:Array = [ ]; + protected var tabbedMediators:Array = [ ]; + + protected var classPath:String; + protected var currentMediator:String; + + public function ApplicationMediator(name:String=null, viewComponent:Object=null) + { + super( name, viewComponent ); + } + + protected function addMediator(mediator:Object, data:Object=null):void + { + var m:Object; + + if ( !mediator.hasOwnProperty( 'NAME' ) ) + { + mediator = getDefinitionByName( classPath + mediator.toString().split( '-' )[ 0 ] ) as Class + } + + if ( !facade.hasMediator( mediator.NAME ) ) + { + removeOtherMediators( mediator.NAME ); + + facade.registerMediator( new mediator() ); + + m = facade.retrieveMediator( mediator.NAME ); + + view.addChild( m.getViewComponent() ); + + if ( m.hasOwnProperty( 'data' ) ) + { + m.data = data; + } + + currentMediator = mediator.NAME; + } + } + + protected function removeMediator(mediator:Object):void + { + var m:Object; + + if ( !mediator.hasOwnProperty( 'NAME' ) ) + { + mediator = getDefinitionByName( classPath + mediator.toString().split( '-' )[ 0 ] ) as Class + } + + if ( facade.hasMediator( mediator.NAME ) ) + { + m = facade.retrieveMediator( mediator.NAME ); + + view.removeChild( m.getViewComponent() ); + + facade.removeMediator( mediator.NAME ); + } + } + + protected function removeOtherMediators(mediator:String=''):void + { + if ( ( ArrayUtil.search( excludedMediators, mediator ) === -1 && ArrayUtil.search( tabbedMediators, mediator ) !== -1 ) || mediator === '' ) + { + for each ( var m:String in tabbedMediators ) + { + if ( m !== mediator ) + { + removeMediator( getDefinitionByName( classPath + m ) as Class ); + } + } + } + } + + protected function mediator(name:String):* + { + return facade.retrieveMediator( name ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/puremvc/patterns/Facade.as b/com/firestartermedia/lib/puremvc/patterns/Facade.as new file mode 100644 index 0000000..049a08b --- /dev/null +++ b/com/firestartermedia/lib/puremvc/patterns/Facade.as @@ -0,0 +1,57 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.puremvc.patterns +{ + import org.puremvc.as3.patterns.facade.Facade; + import org.puremvc.as3.patterns.observer.Notification; + + public class Facade extends org.puremvc.as3.patterns.facade.Facade + { + protected var faultEvent:String; + protected var resizeEvent:String; + protected var startupEvent:String; + protected var trackEvent:String; + + public function Facade(startupEvent:String, faultEvent:String, resizeEvent:String, trackEvent:String) + { + this.faultEvent = faultEvent; + this.resizeEvent = resizeEvent; + this.startupEvent = startupEvent; + this.trackEvent = trackEvent; + } + + public function startup(stage:Object):void + { + sendNotification( startupEvent, stage ); + } + + public function sendResize(height:Number, width:Number):void + { + sendNotification( resizeEvent, { width: width, height: height } ); + } + + public function registerCommands(commands:Array, target:Class):void + { + for each ( var command:String in commands ) + { + registerCommand( command, target ); + } + } + + override public function sendNotification(notificationName:String, body:Object=null, type:String=null):void + { + if ( notificationName !== faultEvent && notificationName !== resizeEvent && notificationName !== trackEvent ) + { + sendNotification( trackEvent, { name: notificationName, body: body } ); + } + + notifyObservers( new Notification( notificationName, body, type ) ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/puremvc/patterns/Mediator.as b/com/firestartermedia/lib/puremvc/patterns/Mediator.as new file mode 100644 index 0000000..557ea14 --- /dev/null +++ b/com/firestartermedia/lib/puremvc/patterns/Mediator.as @@ -0,0 +1,100 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.puremvc.patterns +{ + import com.adobe.utils.ArrayUtil; + + import flash.utils.Dictionary; + + import org.puremvc.as3.interfaces.INotification; + import org.puremvc.as3.patterns.mediator.Mediator; + + public class Mediator extends org.puremvc.as3.patterns.mediator.Mediator + { + protected var notificationInterests:Array = [ ]; + protected var notificationHandlers:Dictionary = new Dictionary(); + + protected var view:Object; + + public function Mediator(name:String=null, viewComponent:Object=null) + { + super( name, viewComponent ); + + view = viewComponent; + + declareNotificationInterest( 'ApplicationFacadeResize', handleResize ); + + trackEvent( 'Created ' + mediatorName ); + } + + override public function onRegister():void + { + trackEvent( 'Registered ' + mediatorName ); + } + + override public function onRemove():void + { + trackEvent( 'Removed ' + mediatorName ); + + onReset(); + } + + private function onReset():void + { + if ( view.hasOwnProperty( 'handleReset' ) ) + { + trackEvent( 'Reset ' + mediatorName ); + + view.handleReset(); + } + } + + public function trackEvent(event:String):void + { + sendNotification( 'ApplicationFacadeTrack', event ); + } + + public function sendEvent(event:*):void + { + sendNotification( event.type, event.data ); + } + + public function declareNotificationInterest(notificationName:String, func:Function):void + { + notificationInterests.push( notificationName ); + + notificationInterests = ArrayUtil.createUniqueCopy( notificationInterests ); + + notificationHandlers[ notificationName ] = func; + } + + override public function listNotificationInterests():Array + { + return notificationInterests; + } + + override public function handleNotification(notification:INotification):void + { + notificationHandlers[ notification.getName() ].apply( null, [ notification ] ); + } + + public function handleReset(n:INotification):void + { + onReset(); + } + + public function handleResize(n:INotification):void + { + if ( view.hasOwnProperty( 'handleResize' ) ) + { + view.handleResize( n.getBody() ); + } + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/puremvc/patterns/MediatorMulticore.as b/com/firestartermedia/lib/puremvc/patterns/MediatorMulticore.as new file mode 100644 index 0000000..5fb67e8 --- /dev/null +++ b/com/firestartermedia/lib/puremvc/patterns/MediatorMulticore.as @@ -0,0 +1,80 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.puremvc.patterns +{ + import com.adobe.utils.ArrayUtil; + + import flash.utils.Dictionary; + + import org.puremvc.as3.multicore.interfaces.INotification; + import org.puremvc.as3.multicore.patterns.mediator.Mediator; + + public class MediatorMulticore extends Mediator + { + protected var notificationInterests:Array = [ ]; + protected var notificationHandlers:Dictionary = new Dictionary(); + + protected var view:Object; + + private var name:String; + + public function MediatorMulticore(name:String=null, viewComponent:Object=null) + { + super( name, viewComponent ); + + this.name = name; + } + + public function trackEvent(event:String):void + { + sendNotification( 'ApplicationFacadeTrack', event ); + } + + public function sendEvent(event:*):void + { + sendNotification( event.type, event.data ); + } + + public function declareNotificationInterest(notificationName:String, func:Function):void + { + notificationInterests.push( notificationName ); + + notificationInterests = ArrayUtil.createUniqueCopy( notificationInterests ); + + notificationHandlers[ notificationName ] = func; + } + + override public function listNotificationInterests():Array + { + return notificationInterests; + } + + override public function handleNotification(notification:INotification):void + { + notificationHandlers[ notification.getName() ].apply( null, [ notification ] ); + } + + override public function initializeNotifier(key:String):void + { + super.initializeNotifier( key ); + + trackEvent( 'Registered ' + name ); + } + + public function handleReset(n:INotification):void + { + view.handleReset(); + } + + public function handleResize(n:INotification):void + { + view.handleResize( n.getBody() ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/puremvc/patterns/Proxy.as b/com/firestartermedia/lib/puremvc/patterns/Proxy.as new file mode 100644 index 0000000..246c5ca --- /dev/null +++ b/com/firestartermedia/lib/puremvc/patterns/Proxy.as @@ -0,0 +1,29 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.puremvc.patterns +{ + import org.puremvc.as3.patterns.proxy.Proxy; + + public class Proxy extends org.puremvc.as3.patterns.proxy.Proxy + { + public static const NAME:String = 'Proxy'; + + public function Proxy(name:String=null, data:Object=null) + { + super( name, data ); + + trackEvent( 'Registered ' + name ); + } + + public function trackEvent(event:String):void + { + sendNotification( 'ApplicationFacadeTrack', event ); + } + } +} \ No newline at end of file diff --git a/com/firestartermedia/lib/puremvc/patterns/ProxyMulticore.as b/com/firestartermedia/lib/puremvc/patterns/ProxyMulticore.as new file mode 100644 index 0000000..d21de20 --- /dev/null +++ b/com/firestartermedia/lib/puremvc/patterns/ProxyMulticore.as @@ -0,0 +1,41 @@ +/** + * @author Ahmed Nuaman (http://www.ahmednuaman.com) + * @langversion 3 + * + * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License. + * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter + * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. +*/ +package com.firestartermedia.lib.puremvc.patterns +{ + import org.puremvc.as3.multicore.patterns.proxy.Proxy; + + public class ProxyMulticore extends Proxy + { + protected var declare:Boolean = true; + + private var name:String; + + public function ProxyMulticore(name:String=null, data:Object=null) + { + super( name, data ); + + this.name = name; + } + + public function trackEvent(event:String):void + { + sendNotification( 'ApplicationFacadeTrack', event ); + } + + override public function initializeNotifier(key:String):void + { + super.initializeNotifier( key ); + + if ( declare ) + { + trackEvent( 'Registered ' + name ); + } + } + } +} \ No newline at end of file
flare/app
e0520a999417c7c17a4ce0ff4e41771199e0d444
a lot of stuff
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 22a7940..f6979f4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,3 +1,12 @@ # Methods added to this helper will be available to all templates in the application. module ApplicationHelper + + def title + base_title = "Rails" + if @title.nil? + base_title + else + "#{base_title} | #{@title}" + end + end end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 3a313a9..e087f93 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -1,6 +1,13 @@ !!! %html{:lang => "en", "xml:lang" => "en", :xmlns => "http://www.w3.org/1999/xhtml"} - %head - %title Rails | #{@title} - %body= yield + %head + %title= title + = render 'layouts/stylesheets' + %body + .container + #header + = render 'layouts/header' + #content.round + = yield + = render 'layouts/footer' diff --git a/app/views/pages/about.html.haml b/app/views/pages/about.html.haml index 78d06ed..dc82041 100644 --- a/app/views/pages/about.html.haml +++ b/app/views/pages/about.html.haml @@ -1,6 +1,7 @@ %h1 About Us %p %a{:href => "http://www.railstutorial.org/"}Ruby on Rails Tutorial is a project to make a book and screencasts to teach web development - with %a{:href => "http://rubyonrails.org/"}Ruby on Rails. This + with + %a{:href => "http://rubyonrails.org/"}Ruby on Rails. This is the sample application for the tutorial. diff --git a/app/views/pages/contact.html.haml b/app/views/pages/contact.html.haml index 22c9aab..aee5292 100644 --- a/app/views/pages/contact.html.haml +++ b/app/views/pages/contact.html.haml @@ -1,4 +1,4 @@ -%hi Contact +%h1 Contact %p Contact Ruby on Rails Tutorial about the sample app at the %a{:href => "http://www.railstutorial.org/feedback"} feedback page diff --git a/app/views/pages/home.html.haml b/app/views/pages/home.html.haml index ebd1a21..a358730 100644 --- a/app/views/pages/home.html.haml +++ b/app/views/pages/home.html.haml @@ -1,5 +1,6 @@ -%hi Sample App Home +%h1 Sample App Home %p This is the home page for the %a{:href => "http://www.railstutorial.org/"}Ruby on Rails Tutorial sample application. += link_to "Sign up now!", '#', :class => "signup_button round" diff --git a/config/routes.rb b/config/routes.rb index ea14ce1..4a016a7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,43 +1,49 @@ ActionController::Routing::Routes.draw do |map| # The priority is based upon order of creation: first created -> highest priority. + map.contact '/contact', :controller => 'pages', :action => 'contact' + map.about '/about', :controller => 'pages', :action => 'about' + map.help '/help', :controller => 'pages', :action => 'help' + + map.root :controller => 'pages', :action => 'home' + # Sample of regular route: # map.connect 'products/:id', :controller => 'catalog', :action => 'view' # Keep in mind you can assign values other than :controller and :action # Sample of named route: # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase' # This route can be invoked with purchase_url(:id => product.id) # Sample resource route (maps HTTP verbs to controller actions automatically): # map.resources :products # Sample resource route with options: # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get } # Sample resource route with sub-resources: # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller # Sample resource route with more complex sub-resources # map.resources :products do |products| # products.resources :comments # products.resources :sales, :collection => { :recent => :get } # end # Sample resource route within a namespace: # map.namespace :admin do |admin| # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb) # admin.resources :products # end # You can have the root of your site routed with map.root -- just remember to delete public/index.html. # map.root :controller => "welcome" # See how all your routes lay out with "rake routes" # Install the default routes as the lowest priority. # Note: These default routes make all actions in every controller accessible via GET requests. You should # consider removing or commenting them out if you're using named routes and resources. map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' end diff --git a/public/index.html b/public/index.html deleted file mode 100644 index 0dd5189..0000000 --- a/public/index.html +++ /dev/null @@ -1,275 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html> - <head> - <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> - <title>Ruby on Rails: Welcome aboard</title> - <style type="text/css" media="screen"> - body { - margin: 0; - margin-bottom: 25px; - padding: 0; - background-color: #f0f0f0; - font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana"; - font-size: 13px; - color: #333; - } - - h1 { - font-size: 28px; - color: #000; - } - - a {color: #03c} - a:hover { - background-color: #03c; - color: white; - text-decoration: none; - } - - - #page { - background-color: #f0f0f0; - width: 750px; - margin: 0; - margin-left: auto; - margin-right: auto; - } - - #content { - float: left; - background-color: white; - border: 3px solid #aaa; - border-top: none; - padding: 25px; - width: 500px; - } - - #sidebar { - float: right; - width: 175px; - } - - #footer { - clear: both; - } - - - #header, #about, #getting-started { - padding-left: 75px; - padding-right: 30px; - } - - - #header { - background-image: url("images/rails.png"); - background-repeat: no-repeat; - background-position: top left; - height: 64px; - } - #header h1, #header h2 {margin: 0} - #header h2 { - color: #888; - font-weight: normal; - font-size: 16px; - } - - - #about h3 { - margin: 0; - margin-bottom: 10px; - font-size: 14px; - } - - #about-content { - background-color: #ffd; - border: 1px solid #fc0; - margin-left: -11px; - } - #about-content table { - margin-top: 10px; - margin-bottom: 10px; - font-size: 11px; - border-collapse: collapse; - } - #about-content td { - padding: 10px; - padding-top: 3px; - padding-bottom: 3px; - } - #about-content td.name {color: #555} - #about-content td.value {color: #000} - - #about-content.failure { - background-color: #fcc; - border: 1px solid #f00; - } - #about-content.failure p { - margin: 0; - padding: 10px; - } - - - #getting-started { - border-top: 1px solid #ccc; - margin-top: 25px; - padding-top: 15px; - } - #getting-started h1 { - margin: 0; - font-size: 20px; - } - #getting-started h2 { - margin: 0; - font-size: 14px; - font-weight: normal; - color: #333; - margin-bottom: 25px; - } - #getting-started ol { - margin-left: 0; - padding-left: 0; - } - #getting-started li { - font-size: 18px; - color: #888; - margin-bottom: 25px; - } - #getting-started li h2 { - margin: 0; - font-weight: normal; - font-size: 18px; - color: #333; - } - #getting-started li p { - color: #555; - font-size: 13px; - } - - - #search { - margin: 0; - padding-top: 10px; - padding-bottom: 10px; - font-size: 11px; - } - #search input { - font-size: 11px; - margin: 2px; - } - #search-text {width: 170px} - - - #sidebar ul { - margin-left: 0; - padding-left: 0; - } - #sidebar ul h3 { - margin-top: 25px; - font-size: 16px; - padding-bottom: 10px; - border-bottom: 1px solid #ccc; - } - #sidebar li { - list-style-type: none; - } - #sidebar ul.links li { - margin-bottom: 5px; - } - - </style> - <script type="text/javascript" src="javascripts/prototype.js"></script> - <script type="text/javascript" src="javascripts/effects.js"></script> - <script type="text/javascript"> - function about() { - if (Element.empty('about-content')) { - new Ajax.Updater('about-content', 'rails/info/properties', { - method: 'get', - onFailure: function() {Element.classNames('about-content').add('failure')}, - onComplete: function() {new Effect.BlindDown('about-content', {duration: 0.25})} - }); - } else { - new Effect[Element.visible('about-content') ? - 'BlindUp' : 'BlindDown']('about-content', {duration: 0.25}); - } - } - - window.onload = function() { - $('search-text').value = ''; - $('search').onsubmit = function() { - $('search-text').value = 'site:rubyonrails.org ' + $F('search-text'); - } - } - </script> - </head> - <body> - <div id="page"> - <div id="sidebar"> - <ul id="sidebar-items"> - <li> - <form id="search" action="http://www.google.com/search" method="get"> - <input type="hidden" name="hl" value="en" /> - <input type="text" id="search-text" name="q" value="site:rubyonrails.org " /> - <input type="submit" value="Search" /> the Rails site - </form> - </li> - - <li> - <h3>Join the community</h3> - <ul class="links"> - <li><a href="http://www.rubyonrails.org/">Ruby on Rails</a></li> - <li><a href="http://weblog.rubyonrails.org/">Official weblog</a></li> - <li><a href="http://wiki.rubyonrails.org/">Wiki</a></li> - </ul> - </li> - - <li> - <h3>Browse the documentation</h3> - <ul class="links"> - <li><a href="http://api.rubyonrails.org/">Rails API</a></li> - <li><a href="http://stdlib.rubyonrails.org/">Ruby standard library</a></li> - <li><a href="http://corelib.rubyonrails.org/">Ruby core</a></li> - <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li> - </ul> - </li> - </ul> - </div> - - <div id="content"> - <div id="header"> - <h1>Welcome aboard</h1> - <h2>You&rsquo;re riding Ruby on Rails!</h2> - </div> - - <div id="about"> - <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3> - <div id="about-content" style="display: none"></div> - </div> - - <div id="getting-started"> - <h1>Getting started</h1> - <h2>Here&rsquo;s how to get rolling:</h2> - - <ol> - <li> - <h2>Use <tt>script/generate</tt> to create your models and controllers</h2> - <p>To see all available options, run it without parameters.</p> - </li> - - <li> - <h2>Set up a default route and remove or rename this file</h2> - <p>Routes are set up in config/routes.rb.</p> - </li> - - <li> - <h2>Create your database</h2> - <p>Run <tt>rake db:migrate</tt> to create your database. If you're not using SQLite (the default), edit <tt>config/database.yml</tt> with your username and password.</p> - </li> - </ol> - </div> - </div> - - <div id="footer">&nbsp;</div> - </div> - </body> -</html> \ No newline at end of file
flare/app
7af2f23ec569e59efed67e62d3d36c8a7a30904b
done with statics
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 5635120..e052555 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -1,8 +1,15 @@ class PagesController < ApplicationController + def home + @title = "Home" end def contact + @title = "Contact" end + def about + @title = "About" + end end + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000..7aaeb12 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,11 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title>Ruby on Rails Tutorial Sample App | <%= @title %></title> + </head> + <body> + <%= yield %> + </body> +</html> + diff --git a/app/views/pages/about.html.erb b/app/views/pages/about.html.erb new file mode 100644 index 0000000..4e9030f --- /dev/null +++ b/app/views/pages/about.html.erb @@ -0,0 +1,8 @@ +<h1>About Us</h1> +<p> + <a href="http://www.railstutorial.org/">Ruby on Rails Tutorial</a> + is a project to make a book and screencasts to teach web development + with <a href="http://rubyonrails.org/">Ruby on Rails</a>. This + is the sample application for the tutorial. +</p> + diff --git a/app/views/pages/contact.html.erb b/app/views/pages/contact.html.erb index 6c6359a..4c445fe 100644 --- a/app/views/pages/contact.html.erb +++ b/app/views/pages/contact.html.erb @@ -1,2 +1,6 @@ -<h1>Pages#contact</h1> -<p>Find me in app/views/pages/contact.html.erb</p> +<h1>Contact</h1> +<p> + Contact Ruby on Rails Tutorial about the sample app at the + <a href="http://www.railstutorial.org/feedback">feedback page</a>. +</p> + diff --git a/app/views/pages/home.html.erb b/app/views/pages/home.html.erb index 3453cf2..465f3a9 100644 --- a/app/views/pages/home.html.erb +++ b/app/views/pages/home.html.erb @@ -1,2 +1,7 @@ -<h1>Pages#home</h1> -<p>Find me in app/views/pages/home.html.erb</p> +<h1>Sample App Home</h1> +<p> + This is the home page for the + <a href="http://www.railstutorial.org/">Ruby on Rails Tutorial</a> + sample application. +</p> + diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..b81ae5a --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,14 @@ +# This file is auto-generated from the current state of the database. Instead of editing this file, +# please use the migrations feature of Active Record to incrementally modify your database, and +# then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your database schema. If you need +# to create the application database on another system, you should be using db:schema:load, not running +# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended to check this file into your version control system. + +ActiveRecord::Schema.define(:version => 0) do + +end diff --git a/spec/controllers/pages_controller_spec.rb b/spec/controllers/pages_controller_spec.rb new file mode 100644 index 0000000..41da81e --- /dev/null +++ b/spec/controllers/pages_controller_spec.rb @@ -0,0 +1,44 @@ +require 'spec_helper' + +describe PagesController do + integrate_views + + describe "GET 'home'" do + it "should be successful" do + get 'home' + response.should be_success + end + + it "should have the right title" do + get 'home' + response.should have_tag("title", + "Ruby on Rails Tutorial Sample App | Home") + end + end + + describe "GET 'contact'" do + it "should be successful" do + get 'contact' + response.should be_success + end + + it "should have the right title" do + get 'contact' + response.should have_tag("title", + "Ruby on Rails Tutorial Sample App | Contact") + end + end + + describe "GET 'about'" do + it "should be successful" do + get 'about' + response.should be_success + end + + it "should have the right title" do + get 'about' + response.should have_tag("title", + "Ruby on Rails Tutorial Sample App | About") + end + end +end diff --git a/test/functional/pages_controller_test.rb b/test/functional/pages_controller_test.rb deleted file mode 100644 index 5ad8c34..0000000 --- a/test/functional/pages_controller_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'test_helper' - -class PagesControllerTest < ActionController::TestCase - # Replace this with your real tests. - test "the truth" do - assert true - end -end diff --git a/test/performance/browsing_test.rb b/test/performance/browsing_test.rb deleted file mode 100644 index 4b60558..0000000 --- a/test/performance/browsing_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'test_helper' -require 'performance_test_help' - -# Profiling results for each test method are written to tmp/performance. -class BrowsingTest < ActionController::PerformanceTest - def test_homepage - get '/' - end -end diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index b9fe251..0000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,38 +0,0 @@ -ENV["RAILS_ENV"] = "test" -require File.expand_path(File.dirname(__FILE__) + "/../config/environment") -require 'test_help' - -class ActiveSupport::TestCase - # Transactional fixtures accelerate your tests by wrapping each test method - # in a transaction that's rolled back on completion. This ensures that the - # test database remains unchanged so your fixtures don't have to be reloaded - # between every test method. Fewer database queries means faster tests. - # - # Read Mike Clark's excellent walkthrough at - # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting - # - # Every Active Record database supports transactions except MyISAM tables - # in MySQL. Turn off transactional fixtures in this case; however, if you - # don't care one way or the other, switching from MyISAM to InnoDB tables - # is recommended. - # - # The only drawback to using transactional fixtures is when you actually - # need to test transactions. Since your test is bracketed by a transaction, - # any transactions started in your code will be automatically rolled back. - self.use_transactional_fixtures = true - - # Instantiated fixtures are slow, but give you @david where otherwise you - # would need people(:david). If you don't want to migrate your existing - # test cases which use the @david style and don't mind the speed hit (each - # instantiated fixtures translates to a database query per test method), - # then set this back to true. - self.use_instantiated_fixtures = false - - # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. - # - # Note: You'll currently still have to declare fixtures explicitly in integration tests - # -- they do not yet inherit this setting - fixtures :all - - # Add more helper methods to be used by all tests here... -end diff --git a/test/unit/helpers/pages_helper_test.rb b/test/unit/helpers/pages_helper_test.rb deleted file mode 100644 index 535dfe1..0000000 --- a/test/unit/helpers/pages_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class PagesHelperTest < ActionView::TestCase -end
flare/app
691ff1f9ae43511764905b1d10840176b12fea4f
controller
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb new file mode 100644 index 0000000..5635120 --- /dev/null +++ b/app/controllers/pages_controller.rb @@ -0,0 +1,8 @@ +class PagesController < ApplicationController + def home + end + + def contact + end + +end diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb new file mode 100644 index 0000000..2c057fd --- /dev/null +++ b/app/helpers/pages_helper.rb @@ -0,0 +1,2 @@ +module PagesHelper +end diff --git a/app/views/pages/contact.html.erb b/app/views/pages/contact.html.erb new file mode 100644 index 0000000..6c6359a --- /dev/null +++ b/app/views/pages/contact.html.erb @@ -0,0 +1,2 @@ +<h1>Pages#contact</h1> +<p>Find me in app/views/pages/contact.html.erb</p> diff --git a/app/views/pages/home.html.erb b/app/views/pages/home.html.erb new file mode 100644 index 0000000..3453cf2 --- /dev/null +++ b/app/views/pages/home.html.erb @@ -0,0 +1,2 @@ +<h1>Pages#home</h1> +<p>Find me in app/views/pages/home.html.erb</p> diff --git a/test/functional/pages_controller_test.rb b/test/functional/pages_controller_test.rb new file mode 100644 index 0000000..5ad8c34 --- /dev/null +++ b/test/functional/pages_controller_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class PagesControllerTest < ActionController::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/test/unit/helpers/pages_helper_test.rb b/test/unit/helpers/pages_helper_test.rb new file mode 100644 index 0000000..535dfe1 --- /dev/null +++ b/test/unit/helpers/pages_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class PagesHelperTest < ActionView::TestCase +end
gisanfu/fast-change-dir
67ff9a240df3016ee8991c938ede2c4de5289384
add can use comment
diff --git a/vimlist.sh b/vimlist.sh index 23a0874..9cf667b 100755 --- a/vimlist.sh +++ b/vimlist.sh @@ -1,90 +1,91 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" program=$1 if [ "$groupname" != "" ]; then if [ "$program" == "" ]; then program2="vim -p $fast_change_dir_project_config/vimlist-$groupname.txt" else program2=$program fi cmdlist="cat $fast_change_dir_project_config/vimlist-$groupname.txt" # 正規的外面要用雙引包起來 regex="^vim" # 如果program這個變數是空白,就代表會使用vim-p的指令 # 使用vim,當然不會去開一些binary的檔案 if [[ "$program" == '' || "$program" =~ $regex ]]; then # 先把一些己知的東西先ignore掉,例如壓縮檔 cmdlist="$cmdlist | grep -v .tar.gz | grep -v .zip | grep -v .png | grep -v .gif | grep -v .jpeg | grep -v .jpg" # 這行是判斷是不是文字檔,但是遇到css的檔案,會誤判,所以暫時先mark起來,或許以後用得到 # cmdlist="$cmdlist | xargs -n 1 $fast_change_dir_bin/only-text-filecontent.sh" fi # 這是多行文字檔內容,變成以空格分格成字串的步驟 cmdlist2='| tr "\n" " "' cmdlist="$cmdlist $cmdlist2" cmdlist_result=`eval $cmdlist` cmd="$program2 $cmdlist_result" # 檢查一下數量,如果是一筆的話,那就自動跳到那一筆 # 這樣子只有一筆的時候,會比較方便 # 會這樣子寫,是因為不要去影響其它程式的相依性 if [ "$program" == "" ]; then count=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$count" == 1 ]; then cmd="$cmd +tabnext" fi # 如果大於1筆,就用選擇的方式,選擇第一次要看到的檔案 if [ "$count" -gt 1 ]; then vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) tmpfile="$fast_change_dir_tmp/`whoami`-vimlist-dialogselect-$( date +%Y%m%d-%H%M ).txt" dialogitems='' start=1 for echothem in ${vimlist_array[@]} do dialogitems=" $dialogitems '$start' $echothem " start=$(expr $start + 1) done cmd2=$( func_dialog_menu '你想從哪一個位置開始編輯 ' 100 "$dialogitems" $tmpfile ) eval $cmd2 result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then if [ "$result" -lt 10 ]; then # 為了加快速度而這麼寫的 tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') + #tabennn=('' '+tabn2' '+tabn3' '+tabn4' '+tabn5' '+tabn6' '+tabn7' '+tabn8' '+tabn9' '+tabn10' '+tabn11' '+tabn12') cmd="$cmd ${tabennn[$result]}" else echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' fi else # 如果使用者選擇取消,那就取消整個vff cmd="" fi fi fi if [ "$cmd" != '' ]; then eval $cmd fi func_checkfilecount else echo '[ERROR] groupname is empty, please use GA cmd' fi unset vimlist_array unset cmd
gisanfu/fast-change-dir
e779d81587c36d8accf9aae12920e2498cf98eff
add switch vimrc section
diff --git a/vimlist-many-open.sh b/vimlist-many-open.sh index a1209ef..d1c3cb3 100755 --- a/vimlist-many-open.sh +++ b/vimlist-many-open.sh @@ -1,23 +1,25 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" program2="vim -p $fast_change_dir_project_config/vimlist-$groupname.txt" cmdlist="cat $fast_change_dir_project_config/vimlist-$groupname.txt" # 先把一些己知的東西先ignore掉,例如壓縮檔 cmdlist="$cmdlist | grep -v .tar.gz | grep -v .zip | grep -v .png | grep -v .gif | grep -v .jpeg | grep -v .jpg" # 這是多行文字檔內容,變成以空格分格成字串的步驟 cmdlist2='| tr "\n" " "' cmdlist="$cmdlist $cmdlist2" cmdlist_result=`eval $cmdlist` cmd="$program2 $cmdlist_result" +cmd="$cmd -u ~/.vimrc_30" + if [ "$cmd" != '' ]; then eval $cmd fi func_checkfilecount unset cmd
gisanfu/fast-change-dir
fca095e414c9a753be614581ac8a35dc16bf40f5
add new func
diff --git a/abc-4.sh b/abc-4.sh index 1e14d82..d5a66f8 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,505 +1,509 @@ #!/bin/bash source "$fast_change_dir/config/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color fast_change_dir_switch_list='1' while [ 1 ]; do clear fast_change_dir_auto_list_file_enable='0' if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' if [ "$fast_change_dir_switch_list" == '1' ]; then ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd elif [ "$fast_change_dir_switch_list" == '2' ]; then tree -L 1 elif [ "$fast_change_dir_switch_list" == '3' ]; then tree -L 1 -d elif [ "$fast_change_dir_switch_list" == '4' ]; then tree -L 2 elif [ "$fast_change_dir_switch_list" == '5' ]; then tree -L 2 -d elif [ "$fast_change_dir_switch_list" == '6' ]; then ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=never" eval $cmd else ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd fi if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 將單檔案列入暫存,並使用vim編輯它們 (;) 分號' echo ' 只將單檔案列入暫存 (;) 分號' echo ' 將多個檔案列入暫存,並使用vim編輯它們 (*)' echo ' 只將多個檔案列入暫存 (&)' echo ' 切換檔案列表的方式 (T)' echo ' 上一層 (,) 逗點' echo ' 上一個資料夾 (<) 小於,跟上一層是同一個按鍵' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" - echo ' Do It! (I)' + echo ' 一次10個 (I)' + echo ' 每次20個 (U)' echo ' 利用檔案做索引,進入該檔案所在的資料夾 (O)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' - echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' elif [ "$inputvar" == '*' ]; then inputvar='FF' elif [ "$inputvar" == '&' ]; then inputvar='FFF' elif [ "$inputvar" == ':' ]; then inputvar='FFFF' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear fast_change_dir_auto_list_file_enable='1' unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue elif [ "$inputvar" == '<' ]; then cd - clear_var_all='1' continue # 想拉一個檔案進來,接下來會做vff的動作 elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue # 想拉一個檔案進來,但是不啟用vff的狀況 elif [ "$inputvar" == 'FFFF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 0" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 0" fi eval $run clear_var_all='1' continue # 多選功能在使用的,只支援本層 elif [ "$inputvar" == 'FF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" fi eval $run clear_var_all='1' continue # 多選功能在使用的,只支援本層(不啟動vff) elif [ "$inputvar" == 'FFF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 3" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 3" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue + elif [ "$inputvar" == 'U' ]; then + vfffff + clear_var_all='1' + continue elif [ "$inputvar" == 'O' ]; then d2ff clear_var_all='1' continue elif [ "$inputvar" == 'T' ]; then array=(ls Tree顯示全部 Tree只顯示資料夾 Tree顯示全部2層 Tree只顯示資料夾2層 ls無顏色) dialogitems='' start=1 for echothem in ${array[@]} do dialogitems=" $dialogitems '$start' $echothem " start=$(expr $start + 1) done tmpfile="$fast_change_dir_tmp/`whoami`-abc4T-dialogselect-$( date +%Y%m%d-%H%M ).txt" cmd2=$( func_dialog_menu '選擇檔案列表的方式 ' 100 "$dialogitems" $tmpfile ) eval $cmd2 result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then fast_change_dir_switch_list=$result fi clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd diff --git a/config/bashrc.txt b/config/bashrc.txt index 1104806..e4cf9d5 100644 --- a/config/bashrc.txt +++ b/config/bashrc.txt @@ -1,107 +1,108 @@ # fast-change-dir fast_change_dir_pwd=$HOME fast_change_dir="$fast_change_dir_pwd/gisanfu/fast-change-dir" fast_change_dir_bin="$fast_change_dir/bin" fast_change_dir_lib="$fast_change_dir/lib" fast_change_dir_func="$fast_change_dir_lib/func" fast_change_dir_project_config="" # # 這裡區塊,可以依照你的使用環境去修改 # fast_change_dir_tmp='/tmp' fast_change_dir_config="$fast_change_dir_pwd" # fast-change-dir: use relative keyword alias ll="ls -la" # main function alias ide=". $fast_change_dir/abc-4.sh" # number function alias gre=". $fast_change_dir/grep.sh" alias sear=". $fast_change_dir/search.sh" alias abc=". $fast_change_dir/abc-4.sh" alias 123=". $fast_change_dir/123.sh" alias abc123=". $fast_change_dir/123-2.sh" # Version Controll alias svnn=". $fast_change_dir/svn-3.sh" alias gitt=". $fast_change_dir/git-2.sh" alias hgg=". $fast_change_dir/hg.sh" # # GroupName # # select or switch GroupName alias ga=". $fast_change_dir/groupname.sh select" # append GroupName alias gaa=". $fast_change_dir/groupname.sh append" # edit GroupName alias gaaa=". $fast_change_dir/groupname.sh edit" # # cd # alias d=". $fast_change_dir/cddir.sh" alias d2=". $fast_change_dir/cddir2.sh" alias d2ff=". $fast_change_dir/cddir2-ui.sh" # cd point alias dv=". $fast_change_dir/dirpoint.sh" # append point alias dvv=". $fast_change_dir/dirpoint-append.sh" # edit point alias dvvv=". $fast_change_dir/dirpoint-edit.sh" # nopath, nolimit to change directory by keyword alias wv=". $fast_change_dir/nopath.sh" # vim alias v=". $fast_change_dir/editfile.sh" alias vf=". $fast_change_dir/vimlist-append.sh" alias vff=". $fast_change_dir/vimlist.sh" alias vfff=". $fast_change_dir/vimlist-edit.sh" alias vffff=". $fast_change_dir/vimlist-clear.sh" +alias vfffff=". $fast_change_dir/vimlist-many-open.sh" alias vfe=". $fast_change_dir/pos-vimlist-append.sh 1" alias vfee=". $fast_change_dir/pos-vimlist-append.sh 2" alias vfeee=". $fast_change_dir/pos-vimlist-append.sh 3" alias vfeeee=". $fast_change_dir/pos-vimlist-append.sh 4" alias vfeeeee=". $fast_change_dir/pos-vimlist-append.sh 5" alias vfeeeeee=". $fast_change_dir/pos-vimlist-append.sh 6" # # back, and cd dir # alias g=". $fast_change_dir/backdir.sh" # back back... layer dir alias ge=". $fast_change_dir/back-backdir.sh 1" alias gee=". $fast_change_dir/back-backdir.sh 2" alias geee=". $fast_change_dir/back-backdir.sh 3" alias geeee=". $fast_change_dir/back-backdir.sh 4" alias geeeee=". $fast_change_dir/back-backdir.sh 5" alias geeeeee=". $fast_change_dir/back-backdir.sh 6" # back and cd dir, use position alias gde=". $fast_change_dir/pos-backdir.sh 1" alias gdee=". $fast_change_dir/pos-backdir.sh 2" alias gdeee=". $fast_change_dir/pos-backdir.sh 3" alias gdeeee=". $fast_change_dir/pos-backdir.sh 4" alias gdeeeee=". $fast_change_dir/pos-backdir.sh 5" alias gdeeeeee=". $fast_change_dir/pos-backdir.sh 6" # fast-change-dir: cd dir, use position alias de=". $fast_change_dir/pos-cddir.sh 1" alias dee=". $fast_change_dir/pos-cddir.sh 2" alias deee=". $fast_change_dir/pos-cddir.sh 3" alias deeee=". $fast_change_dir/pos-cddir.sh 4" alias deeeee=". $fast_change_dir/pos-cddir.sh 5" alias deeeeee=". $fast_change_dir/pos-cddir.sh 6" # fast-change-dir: vim file, use position alias ve=". $fast_change_dir/pos-editfile.sh 1" alias vee=". $fast_change_dir/pos-editfile.sh 2" alias veee=". $fast_change_dir/pos-editfile.sh 3" alias veeee=". $fast_change_dir/pos-editfile.sh 4" alias veeeee=". $fast_change_dir/pos-editfile.sh 5" alias veeeeee=". $fast_change_dir/pos-editfile.sh 6" # 最後,啟動ide ide diff --git a/vimlist-many-open.sh b/vimlist-many-open.sh new file mode 100755 index 0000000..a1209ef --- /dev/null +++ b/vimlist-many-open.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +source "$fast_change_dir_func/normal.sh" + +program2="vim -p $fast_change_dir_project_config/vimlist-$groupname.txt" + +cmdlist="cat $fast_change_dir_project_config/vimlist-$groupname.txt" + +# 先把一些己知的東西先ignore掉,例如壓縮檔 +cmdlist="$cmdlist | grep -v .tar.gz | grep -v .zip | grep -v .png | grep -v .gif | grep -v .jpeg | grep -v .jpg" + +# 這是多行文字檔內容,變成以空格分格成字串的步驟 +cmdlist2='| tr "\n" " "' +cmdlist="$cmdlist $cmdlist2" +cmdlist_result=`eval $cmdlist` +cmd="$program2 $cmdlist_result" + +if [ "$cmd" != '' ]; then + eval $cmd +fi +func_checkfilecount + +unset cmd
gisanfu/fast-change-dir
24ddd75e3d189eb57d9d0a94368ada6a1bc18259
fix bug
diff --git a/vimlist-append.sh b/vimlist-append.sh index 6734243..6578411 100755 --- a/vimlist-append.sh +++ b/vimlist-append.sh @@ -1,187 +1,190 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 # 是否要vff,如果沒有指定,就是會詢問使用者 # 不詢問,不要vff的話,就放0 # 不詢問,要vff的話,就放1 # 想要vff,然後又要多選的狀況,那就放2,也會自動做vff的動作 # 同2,但不要vff的狀況 isVFF=$4 if [ "$isVFF" == '' ]; then isVFF=1 fi item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' if [ ${#item_array[@]} -eq 1 ]; then relativeitem=${item_array[0]} elif [[ ${#item_array[@]} -gt 1 && "$isVFF" == '2' || "$isVFF" == '3' ]]; then for file in ${item_array[@]} do selectitem='' selectitem=`pwd`/$file checkline=`grep $selectitem $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt fi done relativeitem='__empty' elif [ ${#item_array[@]} -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems="" for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem=$result else relativeitem='' fi else relativeitem='' fi if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then if [ "$isVFF" == '0' ]; then inputchar='n' elif [ "$isVFF" == '1' ]; then inputchar='y' elif [ "$isVFF" == '2' ]; then inputchar='y' elif [ "$isVFF" == '3' ]; then inputchar='n' else isVFF='' fi # 這裡可以考慮在加上一項,就是不要append這一個檔案 if [ "$isVFF" == '' ]; then # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' echo '[WAIT] 或是編輯列表 [j]' echo '[WAIT] 還是清空它 [k]' read -n 1 inputchar fi # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append if [ "$relativeitem" != '__empty' ]; then selectitem='' selectitem=`pwd`/$relativeitem checkline=`grep "$selectitem" $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt else echo '[NOTICE] File is exist' fi fi if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... checklinenumber=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` - cmd='vff "vim' + #cmd='vff "vim' + cmd='vim' # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 # 查詢更多資訊請執行: "vim -h" # 為了加快速度而這麼寫的 - tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') + tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') + vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) if [ "$checklinenumber" -lt 10 ]; then - cmd="$cmd ${tabennn[$checklinenumber]}" + cmd2="${vimlist_array[@]} ${tabennn[$checklinenumber]}" elif [[ "$checklinenumber" -ge 10 && "$checklinenumber" -lt 18 ]]; then # 先把編輯清單陣列1~8(從0開始)清掉,把10到19補進來 # 位置0是所開始的檔案列表 for i in {0..7} do - unset item_array[$i] + unset vimlist_array[$i] done # 在這裡,只是準備好tabenext的數量,剩下的工作會交給vimlist2.sh - cmd="$cmd ${tabennn[$(expr $checklinenumber - 8)]}" + cmd2="${vimlist_array[@]} ${tabennn[$(expr $checklinenumber - 8)]}" elif [[ "$checklinenumber" -ge 18 && "$checklinenumber" -lt 27 ]]; then for i in {0..16} do - unset item_array[$i] + unset vimlist_array[$i] done # 在這裡,只是準備好tabenext的數量,剩下的工作會交給vimlist2.sh - cmd="$cmd ${tabennn[$(expr $checklinenumber - 17)]}" + cmd2="${vimlist_array[@]} ${tabennn[$(expr $checklinenumber - 17)]}" elif [[ "$checklinenumber" -ge 27 && "$checklinenumber" -lt 36 ]]; then for i in {0..25} do - unset item_array[$i] + unset vimlist_array[$i] done # 在這裡,只是準備好tabenext的數量,剩下的工作會交給vimlist2.sh - cmd="$cmd ${tabennn[$(expr $checklinenumber - 26)]}" + cmd2="${vimlist_array[@]} ${tabennn[$(expr $checklinenumber - 26)]}" else echo '[NOTICE] 不要超過35個以上(不含35)的編輯檔案' echo '[NOTICE] 純編輯這個檔案,以及叫出列表,看你要砍掉哪一個' vim "$selectitem" unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem vfff cmd='' fi if [ "$cmd" != '' ]; then - cmd="$cmd -p $fast_change_dir_project_config/vimlist-$groupname.txt\"" + #cmd="$cmd -p $fast_change_dir_project_config/vimlist-$groupname.txt\"" + cmd="$cmd -p $fast_change_dir_project_config/vimlist-$groupname.txt $cmd2" eval $cmd fi elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then echo "Your want append other file" elif [ "$inputchar" == 'j' ]; then vfff elif [ "$inputchar" == 'k' ]; then vffff else echo "Your want append other file" fi # 最後,顯示目前目錄的檔案 func_checkfilecount elif [ "$groupname" == "" ]; then echo '[ERROR] Argument or $groupname is empty' fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem
gisanfu/fast-change-dir
db7377ca09ffa7efd87e8e53a23f8003e7f00ec0
modify
diff --git a/IDEA b/IDEA index 0402709..88c1001 100644 --- a/IDEA +++ b/IDEA @@ -1,512 +1,516 @@ +# 2013-01-13 + +vimlist-append.sh到第18個,會異常,17還是正常的,要找一下問題 + # 2013-01-12 dialog,想要加上-----分隔項目,當vim筆數很多的時候 前面想要加上分區ax,bx,cx...分區後面才跟著流水號 vim想找一下看有沒有能開很多tab的東西 # 2012-02-18 這個pushd和popd的概念可以參考一下,雖然不是很好用 http://usagiblog.wordpress.com/2006/02/18/pushd-%E5%92%8C-popd/ 想要在vim的地方加一個東西 當超過10個檔案,就編輯下10個檔案,有點像是分頁 雖然vim可以設定開幾個檔案,可是vim的引數+是有限制的,剛剛好就是10個 # 2011-10-30 在command-line下看圖片的軟體,或許可以結合看看 http://inouire.net/archives/image-couleur_source.tar.gz # 2011-06-19 想要加上以下的範例指定進來 echo "hello" | xclip 可以把hello貼到clipboard裡面,然後回到vim貼上, 在ubuntu是按mouse的中鍵, windows裡面使用putty可能要測試一下。 # 2011-05-15 想要加上"cd -"的指令進來 # 2011-04-17 想要寫abc第4個版本 這個版本的特色為: - 不會即時搜尋各功能 - 當然也不會顯示搜尋後的結果 - 點確認以後,才會開始搜尋,以及各功能所會做的動作 - 為了要增加執行的效率,才會做這一個版本 - 先做基本的功能(本層、上層的檔案和資料夾處理),如果效率沒有問題,在加寫其它的功能 - 如果有重覆的,就用dialog menu - relativeitem或許可以取消cache功能 - 使用各快速鍵來啟動該功能,例如我輸入了eeee,然後按大寫F,來搜尋本層的檔案,如果只有一筆,那就加入暫存列表,並直接編輯它 # 2011-04-16 想用python重寫relativeitem 當有人在問它的時候,就會同時找以下的東西: 1. 本層的檔案和資料夾 2. 上一層的檔案和資料夾 找到了以後,第一次會將列表寫入檔案, 可能會給檔案一個編號當檔名,這個編號也會回傳給bash abc-v3主程式 當下一個relative開始,就會帶著這個編號去問新的程式, 這時新的程式,可以用這個編號去找檔案,而不用重新取得列表。 # 2011-04-15 1. 在vff的前面,加一個flow,選擇你要編輯的檔案 2. 正在想,要不要加入其它的語言,為了增加效率 # 2011-04-14 可以把各專案的設定檔,放到各專案的資料夾裡面, 不過關於這一點,可能要改很多地方。 # 2011-04-12 想要把資料夾和檔案的檔名,寫到一支文字檔裡面, 然後增加一個功能,對那個文字檔做控制 # 2011-03-22 可以把Groupname,在abc version3裡面,加上dialog的選擇功能 # 2011-03-01 在ide階段,想要不輸入東西,就可以使用F和D以及上一層的功能, 使用的方式為dialog。 增加這個功能了以後,感覺更好用了。 想要在vf詢問的地方,加上"是否使用純vim編輯,而不列入暫存"的選項 詢問過後,程式才會決定要不要寫入暫存 # 2011-02-21 看能不能在啟動ide之前,先去update(應該是說git pull)最新的資料, 這樣子就可以做最快速的同步, 希望目前原有的fast-change-dir-config的目標,能夠改成自己的git repo,比較安全, 不過這裡是點奇怪的,又想要private repo,但又想要密碼驗證,然後又想要安全性, 最好的方式,應該是每一個target或者說是End端,都要有一個類似驗證碼的東西, 送上去的時候,不是我的人就不能送上去, 目前還沒有想到一個比較好的方式。 應該是說,可以抓下去,要透過驗證碼 (每一台,或是每一個權限,使用的驗證碼都不一樣), 要送上去的時候,是需要密碼的,這樣子的方式應該是比較好的方式。 送上去的時候,可能是送到我自己的svn repo, 送上去以後,會export到某一個http的路徑, 然後我透過http simple auth,讓該權限來下載東西,或是更新東西下去, 但如果是這種作法的話,要怎麼樣上傳呢? 好像想的太複雜了@@。 # 2011-02-18 有想到一個功能, 如果我想要去一個資料夾, 它是在某一個資料下底下, 這種狀況常常會發生,就是進去上一個資料夾以後,就忘了下一個資料夾要去哪裡了。 所以想做一個功能,就是先輸入下一個條件,在然在進去第一個資料夾, 當第一個資料夾進去了以後,就會自動處理在暫存的指令, 不過後來想一想,其實如果是在本機操作,也可以進去第一層,然後按"R",啟動nautilus, 用GUI去操作。 # 2011-02-16 想要加上git的路徑(我指的是1.7的git) 不然又需要root權限了 想要多錯字處理的功能, 例如我輸入了misc, 打錯成為mics, 這時是可以判斷的,不過細節的部份要在思考一下, 而且這個功能,可能也會造成速度變慢,或許是不需要做的 # 2011-02-14 想要做一個功能,是不受groupname限制的, 很像是ssh txtfile的功能, 就是輸入一個關鍵字,可能就會跳到那一個資料夾裡面, 因為有時候很累的時候,跟本就沒有辦法輸入快速鍵。 # 2011-02-10 想要寫一支script,針對Zend Framework的架構, 匯出dirpoint的檔案出來, 可能可以針對root、module name等變數來做組合,以及匯出。 # 2011-02-01 想要把function放到lib/func資料夾裡面。 想要把片段程式碼放到lib/某一個資料夾裡面,可能是several, 想在abc-v3的第二個引數,加上@小老鼠,使用在position 還想要更改所有的文字檔到指定的某個位置, 除了路徑以外,檔名都要是變數,都是可以被修改的。 例如是放在~/git/公司名稱_某分類名稱/, 然後如果在公司做到一個地方,可以把裡面的東西,先存起來, 將整個設定和環境一起帶到另外一台電腦上面。 暫存的路徑是需要的,但是檔名應該先不需要, 其它的應該都是需要的。 # 2011-01-31 目前己經有一個輸入@小老鼠,可以為grep加上^的指令, 我想加一個#井字號,告訴程式我想要使用dialog menu的方式來選擇我要的東西, 經測試了以後,發現不能夠在bash function裡面,下dialog的指令, 所以這個功能必需要在函式以外的地方先處理, 感覺很麻煩,不過也蠻實用的。 # 2011-01-30 能不能讓每一個group,都有自己的設定檔, 例如home的group,可能就會啟動parent-item的功能, 而某程式設計的專案,可能就會因為感覺良好,而關閉它。 # 2011-01-29 能不能在同一個func_relative裡面, 同時做同個資料夾的item處理,以及上一層資料夾內的item處理呢? 能否使用C語言來改寫func_relative的函式, 然後讓bash來呼叫,看能不能改善效率, 讓反應速度能夠跟上我的操作速度, 在呈現的部份。 # 2011-01-28 有機會想要做web的部份。 關於資料夾、或是檔案碰到多筆的狀況, 可以多一個使用dialog menu的選擇來協助, 關於資料夾的部份,可以使用.(點)的快速鍵。 不過好像太麻煩了,可以試著按斜線清掉執行鍵, 然後想想如何使用更好的關鍵字來對它選取, 然後將它記錄在腦海裡面,下次就使用新的或是更好的方式來選擇該項目。 # 2011-01-27 對於vf按y和n,有想到一個方式 就是先把.(點)改回來, 可能把點使用在append-vff, 而;(分號),就是append+vff, 這樣子keyin的數量應該會少很多, 效率應該會比較快。 不過這個idea可能不會用在數字模式上,因為狀況不同 另外,如果輸入錯了快速鍵,或是打錯關鍵字, 想要暫停2秒鐘,然後自動清除關鍵字,並重來, 這樣子可能也多多少少增加一些速度, 不然打錯了還要手動去按一下/(斜線) 有時候按斜線還會按錯 分號,在切換資料夾的時候,可以想看看有沒有什麼其它的應用。 關鍵字的部份好像有點問題, 如果某一個物件名稱是aaabbb, 我輸入aa bb是可以找得到的, 但是如果我輸入bb aa好像是找不到的。 # 2011-01-26 想要把abc v3的第一次顯示help的部份拿掉 想加上更多操作檔案的功能 例如之前idea前寫過的: 執行檔案(依照副檔名) 刪除檔案(當然要可以刪除單檔、多檔,或是針對資料夾,或是混合) 更改名稱 移動路徑 想要在touch檔案以後,順便去編輯它 如果是在有啟動groupname的時候,步驟就會走到詢問你要不要vff的階段 touch檔案,應該是使用dialog的方式才對 刪除的功能,在C的快速鍵中,感覺不是很實用 目前是用C來當做Create,感覺還不錯 看要不要在建立另外一個關鍵字,來做刪除的動作 刪除的動作,也可以考慮不要做,改用cli, or nautilus來做會比較保險。 # 2011-01-25 想要在每一個版本控制功能中, 都加上R功能,也就是切換到Browser。 # 2011-01-22 想要在按分號的時候,就直接編輯檔案(如果是選檔案是在第一項) 就不要在按Y的,很麻煩,也為了可以簡化。 但是,如果我只是想append,但還沒有要edit,那這時怎麼辦呢? 是不是也是要維持現在的使用方式就可以了呢? 可以在append,詢問Y和N的地方,加上分號,或是F當做Y, 但這樣子不知道會不會換右手酸了。 目的還是要簡少按鍵數量。 或是在多一個快速鍵,跟F結合在一起,可能是寫在F,裡面在多一個判斷, 目的是要把append檔案的部份,分一個Y的,和一個N的。 另外,想加一個C快速鍵,就是選到項目的時候所使用的, 裡面可以刪除檔案、等其它額外擴充的功能 還有,別忘了還有一個IDEA需要被完成,就是判斷副檔名的部份。 就是在vim -p files...的時候,如果副檔名是.tar.gz、zip、image file等東西, 在vim的部份,就是會ignore它們。 # 2011-01-18 想要把原先放在/bin下的執行檔,都改放在自己的家目錄, 這樣子在有些沒有root的環境下,才可以使用, 而且這樣子也比較合理 不過有些檔案的目標路徑,是寫死的, 利用這個idea把它們都做個修正。 # 2011-01-17 想要在vimlist的功能,加上判斷副檔名的功能, 如果是使用vim編輯的話,就會乎略掉某些副檔名, 例如tar.gz, zip, images, videos, music # 2011-01-13 想要在vf的地方,加上以下的功能項目: 1. execute 2. delete execute的部份,可能就會判斷副檔名, 刪除的部份,可能會用D的關鍵字來做。 # 2011-01-11 想要在/斜線的地方,加上重新去include檔案的程式碼, 這樣子如果修改了searchfile, or searchdir,把它設定為啟動, 這時只要按一下斜線,就可以生效了 設定檔的地方,想要在加上bash history, 以及google search function 另外,以現在的使用方式,是增加判斷式和google groupname, 這樣子的使用方式,跟我新增設定檔的目標是很像的, 打算選擇設定檔的方式,在加上面的idea,可能會比較好使用。 # 2011-01-09 想要在各version control裡面的push之前, 加上"處理中..."的字眼,或者是顯示執行的指令。 在要增加一些功能的開關設定, 因為不管是在比較慢的電腦,或是比較快的,上執行這套程式,會很慢, 例如搜尋檔案的功能,或者是搜尋bash history的功能, 或許我可以把這些開關的設定,寫在某一支bash file裡面, 要使用的時候,才去修改它, 然後abc-v3就去include它。 # 2011-01-07 想要加一個快速鍵,來show/hide Help,應該就是大寫的H了 想要加上一個功能,就是按下vim的F8,就會離開vim,以及重新啟動vimlist的功能, 當然這個功能要先選擇groupname,這個功能是可以做的, 可能就離開前先寫入文字檔,然後abc-v3去判斷文字檔內是否有內容, 有的話在重新啟動vimlist的功能,因為不是很重要,所以暫時先不用寫 有沒有可能在vim裡面,按某一個快速鍵,然後就會把menu列出來讓你選擇, 或是可以讓你用快速鍵去選擇裡面的項目。 # 2011-01-03 想要加上切換到firefox的快速鍵 以及想要把切換的程式,加上引數,可以選擇切換後,要不要按下重整的按鈕。 另外,想要在啟動ide and abc-v3的時候,如果groupname是空白,就自動補上home, 關於這個idea在想想看,因為空groupname也是有我設計的理念在裡面,先不要拿掉好了。 # 2011-01-01 在abc-v3的V快速鍵中, 想要check current dir是否有.svn or .hg or .git的資料夾, 如果有的話,就直接啟用該版本控制, 還有,這個功能選擇版本控制的快速鍵,想要大小寫都可以使用。 我想在各版本控制的介面中,加上抓repo的功能下來,但這個IDEA好像不是很實用。 # 2010-12-31 想要將版本控制都放在一起, 例如按V(Version),就代表版本控制, 然後就會出現H(hg), G(git), S(Svn), C(cvs這個應該不會做) 一樣也是按快速鍵去執行它 在要加上第2層的判斷, 可能試著執行status,例如git status, 如果有正常的反應,我指的是在正確的repo裡面, 那這時我就會判斷正常,來執行指定的版本控制的指令。 # 2010-12-26 想要思考一下,怎麼樣在commander與cli之間做快速的切換, 有想到幾種方式: 1. 輸入一個快速鍵,然後會顯示讓你輸入指令的地方,只執行一次就會回到commander 2. 離開commander以後,可以任意的輸入指令,然後透過輸入某個指令,就會回到commander 3. 利用Ctrl+Z,把現在執行的東西放到background,透過fg把commander叫起來 4. 把MC啟動很慢的問題解決掉 5. 開2個視窗,用alt + tab切換 6. 開2個電腦,分別用不同的鍵盤 目前有加上nautilus,在abc裡面,所以未來我可以直接離開,或是不使用ide的指令, 如果要執行指令的時候,直接離開abc,如果指令打完,在輸入abc啟動ide就可以了。 # 2010-12-16 想要更改現在目前爛爛的svnn功能, 以及想要新增hg進來,不然就叫做hgg。 另外,svnn和hg,想要加上一個功能, commit cache的功能, 就是送出指定的檔案, 會想加上這個功能, 是因為有些檔案是我不想要送的檔案, 或是說,有些檔案己經完成了,但其它的檔案還在修改當中。 這個cache,想要寫在一個文字檔裡面,類似vimlist, 以svn來說,只要commit,就會送出了,這是與hg不同的地方, 我打算在送出了之後,就清空這個cache, 這個cache,我想取名為svnlist(svn commit list) 關於cache的功能,有一些想法: 1. 全部列入(或取消)cache 2. 關鍵字選擇單項(或多項)項目列入(或取消)cache 3. 觀看修改的內容,使用svn diff的指令,跟最後一個版本做比較 4. svn add的功能 5. 可以選擇清除cache, and uncache file 6. 可以選擇重新建立uncache file 這個會比較複雜,會有4種模式(gitv2只有2種) 每一個模式都可以下commit的指令 1. svn status, filter by untracked, or new file, 其它都沒有哦 2. svn status, filter by added, or deleted, modify一定會在裡面的(我想取commit list) 3. uncache list(這個還是要有,會比較方便) 4. cache list 在模式1的時候,可以使用關鍵字來對沒有被svn add的檔案操作, 然後會忽略掉modify或是己被svn add的檔案, commit list反之。 關於模式3,只要模式1有動作,就會重新輸出uncache file,也會清空cache file, 會這樣子做,是因為沒有svn-add的檔案(狀態為問號),是沒有辦法被commit的,請注意! 還是把模式1,變成狀態只能是問號的 另外,我想把寫入檔案這個動作,寫成bash function, 因為這個動作看起來還蠻常用的。 # 2010-12-15 搜尋google的功能, 除了想獨立一個功能來做以外, 還想要在abc3也想加上這一個功能, 不過可能只會搜尋一筆, 因為如果很多筆的話,abc3會變的很亂。 # 2010-12-14 想要加上搜尋google的功能, 請參考study/google-search.pl檔案, 當輸入關鍵字的時候,就會順便去搜尋Google, 然後我可以去選擇我想要的項目編號, 選了之後,就會用firefox指令去開啟該網址, 並且切換到firefox的視窗。 可能會新增一個項目,來放這個新功能, 然後英文模式在透過某一個快速鍵來連到這一個功能 另外,我在想要不要使用firefox, 理論上來說,我應該選擇的是links或是其它文字型的瀏覽器。 我看,還是做一個選項之類的東西,來切換瀏覽器。 後來找到了w3m,打算使用這一個。 如果要使用這個功能,請建立google這一個groupname。 使用text browser有一個好處,因為很多主機是沒有圖型介面的, 而且都是放在機房,如果沒有帶自己筆記型電腦過去,是上不了Google查資料的。 # 2010-12-10 想要加一個功能,是在輸入關鍵字的時候, 也順便去搜尋底下的資料夾, 當選擇的時候,當然是進去那一個資料夾裡面。 不過這個功能我不打算加入groupname功能內。 # 2010-12-03 在想要不要把MC加進來, 在create, delete資料夾或是文字檔的時候, 或是在copy, move, rename的時候, 轉使用MC工具,不過MC啟動的時候有點慢,大約要10秒鐘, 而且使用-s or -b的引數都還是很慢, 我在找找看有沒有其它的使用選擇。 # 2010-11-30 在想要不要增加一些系統的元素進來, 例如: sudo or leave sudo edit hosts edit php.ini edit apache conf(s) edit or tail message, dmesg start restart service search bash history(只是有些指令在cli下執行會卡住) ssh remote server 以上這個話題,可以分一些思考點出來 1. 編輯檔案的部份,可以參考dirpoint的作法 2. 搜尋檔案內容的部份,就比較單純 3. sudo 可能就要在想一下了,可能就下sudo的指令,然後我可能不要打密碼, 接下來會切換到root,這時會自動用root來執行ide或是abc。 4. start restart service, 可能需要搭配dialog來做。 5. ssh remote server, 這可能會蠻實用的,我可能會先寫入一個文字檔列表, 這個功能應該很單純,然後是全域的,不會被groupname所區分。 關於上述第1點, 可以設定檔案的virtual徑捷,例如我輸入config,這時可能會出現aaa.xml出來, 可能要想一下,這一點是否真的實用才做。 後來想一想,可能不太實用,因為我還有搜尋的功能,假設在任何地方輸入aaa, 還是會出現aaa.xml 有些功能,我在想,可能不需要,或是不能用.(點)來做選擇, 一定要用所指定的快速鍵來選擇該功能,這樣可能比較不會有誤動作。 # 2010-11-24 我新增了一個study,是可以自動切換到指定的視窗,然後送指令.
gisanfu/fast-change-dir
2faf2bebe066741fedd014a79517326dee344561
fix bug
diff --git a/lib/func/relativeitem.sh b/lib/func/relativeitem.sh index e7d7c13..7b5f839 100644 --- a/lib/func/relativeitem.sh +++ b/lib/func/relativeitem.sh @@ -1,165 +1,166 @@ #!/bin/bash source "$fast_change_dir_func/md5.sh" func_relative() { nextRelativeItem=$1 secondCondition=$2 # 檔案的位置 fileposition=$3 # 要搜尋哪裡的路徑,空白代表現行目錄 lspath=$4 # dir or file filetype=$5 # get all item flag # 0 or empty: do not get all # 1: Get All isgetall=$6 declare -a itemList declare -a itemListTmp declare -a relativeitem if [ "$lspath" == "" ]; then lspath=`pwd` elif [ "$lspath" == ".." ]; then lspath="`pwd`/../" fi if [ "$nextRelativeItem" == '' ]; then isgetall='1' fi tmpfile="$fast_change_dir_tmp/`whoami`-function-relativeitem-$( date +%Y%m%d-%H%M ).txt" # ignore file or dir # ignorelist=$(func_getlsignore) ignorelist='' Success="0" # 試著使用@來決定第一個grep,從最開啟來找字串 firstchar=${nextRelativeItem:0:1} isHeadSearch='' # 這裡要注意,不能夠使用井字號(#)來當做控制字元,會有問題 if [ "$firstchar" == '@' ]; then isHeadSearch='^' nextRelativeItem=${nextRelativeItem:1} #elif [ "$firstchar" == '*' ]; then # nextRelativeItem=${nextRelativeItem:1} else firstchar='' fi # 試著使用第二個引數的第一個字元,來判斷是不是position firstchar2=${secondCondition:0:1} if [[ "$firstchar2" == '@' && "$fileposition" == '' ]]; then fileposition=${secondCondition:1} secondCondition='' fi # 先把英文轉成數字,如果這個欄位有資料的話 fileposition=( `func_entonum "$fileposition"` ) if [ "$fileposition" != '' ]; then newposition=$(($fileposition - 1)) fi lucky='' if [ "$filetype" == "dir" ]; then filetype_ls_arg='' filetype_grep_arg='' if [[ -d "$lspath$nextRelativeItem" && "$isgetall" != '1' ]]; then echo "$nextRelativeItem" exit fi else filetype_ls_arg='--file-type' filetype_grep_arg='-v' if [[ -f "$lspath$nextRelativeItem" && "$isgetall" != '1' ]]; then echo "$nextRelativeItem" exit fi fi # default ifs value default_ifs=$' \t\n' - IFS=$'\n' + # 把空格也加進去,因為在用vf的指令的時候,沒有加的話,abc和abc-2這兩個檔案(例),會在vim中當做一個檔名 + IFS=$' \n' #cmd="ls -AFL $ignorelist $filetype_ls_arg $lspath | grep $filetype_grep_arg \"/$\"" cmd="ls -AFL $ignorelist --file-type $lspath" # 先去cache找看看,有沒有暫存的路徑檔案 #md5key=(`func_md5 $cmd`) #cachefile="$fast_change_dir_tmp/`whoami`-relativeitem-cache-$md5key.txt" # 如果該cache有存在,就改寫指令 # 如果不存在,那在處理之前,先寫入cache #if [ ! -f "$cachefile" ]; then # cmd="$cmd > $cachefile" # eval $cmd #fi #cmd="cat $cachefile " cmd="$cmd | grep $filetype_grep_arg \"/$\"" if [ "$isgetall" != '1' ]; then cmd="$cmd | grep -ir $isHeadSearch$nextRelativeItem" fi if [ "$secondCondition" != '' ]; then cmd="$cmd | grep -ir $secondCondition" fi # 取得項目列表,存到陣列裡面,當然也會做空白的處理 declare -i num itemListTmp=(`eval $cmd`) for i in ${itemListTmp[@]} do # 為了要解決空白檔名的問題 itemList[$num]=`echo $i|sed 's/ /___/g'` num=$num+1 done IFS=$default_ifs num=0 if [ "$nextRelativeItem" != "" ]; then if [ "${#itemList[@]}" == "1" ]; then relativeitem=${itemList[0]} #func_statusbar 'USE-ITEM' elif [ "${#itemList[@]}" -gt "1" ]; then relativeitem=${itemList[@]} fi fi if [ "$isgetall" == '1' ]; then if [ "${#itemList[@]}" == "1" ]; then relativeitem=${itemList[0]} #func_statusbar 'USE-ITEM' elif [ "${#itemList[@]}" -gt "1" ]; then relativeitem=${itemList[@]} fi fi # return array的標準用法 if [ "$relativeitem" != '' ]; then if [ "$newposition" == '' ]; then echo ${relativeitem[@]} else # 先把含空格的文字,轉成陣列 aaa=(${relativeitem[@]}) # 然後在指定位置輸出 echo ${aaa[$newposition]} fi else echo '' fi }
gisanfu/fast-change-dir
e8a851e86e1f80ecb22cede7956c739051d28cdc
add idea
diff --git a/IDEA b/IDEA index 78be29d..0402709 100644 --- a/IDEA +++ b/IDEA @@ -1,516 +1,518 @@ # 2013-01-12 dialog,想要加上-----分隔項目,當vim筆數很多的時候 -前面想要加上分區ax,bx,cx... +前面想要加上分區ax,bx,cx...分區後面才跟著流水號 + +vim想找一下看有沒有能開很多tab的東西 # 2012-02-18 這個pushd和popd的概念可以參考一下,雖然不是很好用 http://usagiblog.wordpress.com/2006/02/18/pushd-%E5%92%8C-popd/ 想要在vim的地方加一個東西 當超過10個檔案,就編輯下10個檔案,有點像是分頁 雖然vim可以設定開幾個檔案,可是vim的引數+是有限制的,剛剛好就是10個 # 2011-10-30 在command-line下看圖片的軟體,或許可以結合看看 http://inouire.net/archives/image-couleur_source.tar.gz # 2011-06-19 想要加上以下的範例指定進來 echo "hello" | xclip 可以把hello貼到clipboard裡面,然後回到vim貼上, 在ubuntu是按mouse的中鍵, windows裡面使用putty可能要測試一下。 # 2011-05-15 想要加上"cd -"的指令進來 # 2011-04-17 想要寫abc第4個版本 這個版本的特色為: - 不會即時搜尋各功能 - 當然也不會顯示搜尋後的結果 - 點確認以後,才會開始搜尋,以及各功能所會做的動作 - 為了要增加執行的效率,才會做這一個版本 - 先做基本的功能(本層、上層的檔案和資料夾處理),如果效率沒有問題,在加寫其它的功能 - 如果有重覆的,就用dialog menu - relativeitem或許可以取消cache功能 - 使用各快速鍵來啟動該功能,例如我輸入了eeee,然後按大寫F,來搜尋本層的檔案,如果只有一筆,那就加入暫存列表,並直接編輯它 # 2011-04-16 想用python重寫relativeitem 當有人在問它的時候,就會同時找以下的東西: 1. 本層的檔案和資料夾 2. 上一層的檔案和資料夾 找到了以後,第一次會將列表寫入檔案, 可能會給檔案一個編號當檔名,這個編號也會回傳給bash abc-v3主程式 當下一個relative開始,就會帶著這個編號去問新的程式, 這時新的程式,可以用這個編號去找檔案,而不用重新取得列表。 # 2011-04-15 1. 在vff的前面,加一個flow,選擇你要編輯的檔案 2. 正在想,要不要加入其它的語言,為了增加效率 # 2011-04-14 可以把各專案的設定檔,放到各專案的資料夾裡面, 不過關於這一點,可能要改很多地方。 # 2011-04-12 想要把資料夾和檔案的檔名,寫到一支文字檔裡面, 然後增加一個功能,對那個文字檔做控制 # 2011-03-22 可以把Groupname,在abc version3裡面,加上dialog的選擇功能 # 2011-03-01 在ide階段,想要不輸入東西,就可以使用F和D以及上一層的功能, 使用的方式為dialog。 增加這個功能了以後,感覺更好用了。 想要在vf詢問的地方,加上"是否使用純vim編輯,而不列入暫存"的選項 詢問過後,程式才會決定要不要寫入暫存 # 2011-02-21 看能不能在啟動ide之前,先去update(應該是說git pull)最新的資料, 這樣子就可以做最快速的同步, 希望目前原有的fast-change-dir-config的目標,能夠改成自己的git repo,比較安全, 不過這裡是點奇怪的,又想要private repo,但又想要密碼驗證,然後又想要安全性, 最好的方式,應該是每一個target或者說是End端,都要有一個類似驗證碼的東西, 送上去的時候,不是我的人就不能送上去, 目前還沒有想到一個比較好的方式。 應該是說,可以抓下去,要透過驗證碼 (每一台,或是每一個權限,使用的驗證碼都不一樣), 要送上去的時候,是需要密碼的,這樣子的方式應該是比較好的方式。 送上去的時候,可能是送到我自己的svn repo, 送上去以後,會export到某一個http的路徑, 然後我透過http simple auth,讓該權限來下載東西,或是更新東西下去, 但如果是這種作法的話,要怎麼樣上傳呢? 好像想的太複雜了@@。 # 2011-02-18 有想到一個功能, 如果我想要去一個資料夾, 它是在某一個資料下底下, 這種狀況常常會發生,就是進去上一個資料夾以後,就忘了下一個資料夾要去哪裡了。 所以想做一個功能,就是先輸入下一個條件,在然在進去第一個資料夾, 當第一個資料夾進去了以後,就會自動處理在暫存的指令, 不過後來想一想,其實如果是在本機操作,也可以進去第一層,然後按"R",啟動nautilus, 用GUI去操作。 # 2011-02-16 想要加上git的路徑(我指的是1.7的git) 不然又需要root權限了 想要多錯字處理的功能, 例如我輸入了misc, 打錯成為mics, 這時是可以判斷的,不過細節的部份要在思考一下, 而且這個功能,可能也會造成速度變慢,或許是不需要做的 # 2011-02-14 想要做一個功能,是不受groupname限制的, 很像是ssh txtfile的功能, 就是輸入一個關鍵字,可能就會跳到那一個資料夾裡面, 因為有時候很累的時候,跟本就沒有辦法輸入快速鍵。 # 2011-02-10 想要寫一支script,針對Zend Framework的架構, 匯出dirpoint的檔案出來, 可能可以針對root、module name等變數來做組合,以及匯出。 # 2011-02-01 想要把function放到lib/func資料夾裡面。 想要把片段程式碼放到lib/某一個資料夾裡面,可能是several, 想在abc-v3的第二個引數,加上@小老鼠,使用在position 還想要更改所有的文字檔到指定的某個位置, 除了路徑以外,檔名都要是變數,都是可以被修改的。 例如是放在~/git/公司名稱_某分類名稱/, 然後如果在公司做到一個地方,可以把裡面的東西,先存起來, 將整個設定和環境一起帶到另外一台電腦上面。 暫存的路徑是需要的,但是檔名應該先不需要, 其它的應該都是需要的。 # 2011-01-31 目前己經有一個輸入@小老鼠,可以為grep加上^的指令, 我想加一個#井字號,告訴程式我想要使用dialog menu的方式來選擇我要的東西, 經測試了以後,發現不能夠在bash function裡面,下dialog的指令, 所以這個功能必需要在函式以外的地方先處理, 感覺很麻煩,不過也蠻實用的。 # 2011-01-30 能不能讓每一個group,都有自己的設定檔, 例如home的group,可能就會啟動parent-item的功能, 而某程式設計的專案,可能就會因為感覺良好,而關閉它。 # 2011-01-29 能不能在同一個func_relative裡面, 同時做同個資料夾的item處理,以及上一層資料夾內的item處理呢? 能否使用C語言來改寫func_relative的函式, 然後讓bash來呼叫,看能不能改善效率, 讓反應速度能夠跟上我的操作速度, 在呈現的部份。 # 2011-01-28 有機會想要做web的部份。 關於資料夾、或是檔案碰到多筆的狀況, 可以多一個使用dialog menu的選擇來協助, 關於資料夾的部份,可以使用.(點)的快速鍵。 不過好像太麻煩了,可以試著按斜線清掉執行鍵, 然後想想如何使用更好的關鍵字來對它選取, 然後將它記錄在腦海裡面,下次就使用新的或是更好的方式來選擇該項目。 # 2011-01-27 對於vf按y和n,有想到一個方式 就是先把.(點)改回來, 可能把點使用在append-vff, 而;(分號),就是append+vff, 這樣子keyin的數量應該會少很多, 效率應該會比較快。 不過這個idea可能不會用在數字模式上,因為狀況不同 另外,如果輸入錯了快速鍵,或是打錯關鍵字, 想要暫停2秒鐘,然後自動清除關鍵字,並重來, 這樣子可能也多多少少增加一些速度, 不然打錯了還要手動去按一下/(斜線) 有時候按斜線還會按錯 分號,在切換資料夾的時候,可以想看看有沒有什麼其它的應用。 關鍵字的部份好像有點問題, 如果某一個物件名稱是aaabbb, 我輸入aa bb是可以找得到的, 但是如果我輸入bb aa好像是找不到的。 # 2011-01-26 想要把abc v3的第一次顯示help的部份拿掉 想加上更多操作檔案的功能 例如之前idea前寫過的: 執行檔案(依照副檔名) 刪除檔案(當然要可以刪除單檔、多檔,或是針對資料夾,或是混合) 更改名稱 移動路徑 想要在touch檔案以後,順便去編輯它 如果是在有啟動groupname的時候,步驟就會走到詢問你要不要vff的階段 touch檔案,應該是使用dialog的方式才對 刪除的功能,在C的快速鍵中,感覺不是很實用 目前是用C來當做Create,感覺還不錯 看要不要在建立另外一個關鍵字,來做刪除的動作 刪除的動作,也可以考慮不要做,改用cli, or nautilus來做會比較保險。 # 2011-01-25 想要在每一個版本控制功能中, 都加上R功能,也就是切換到Browser。 # 2011-01-22 想要在按分號的時候,就直接編輯檔案(如果是選檔案是在第一項) 就不要在按Y的,很麻煩,也為了可以簡化。 但是,如果我只是想append,但還沒有要edit,那這時怎麼辦呢? 是不是也是要維持現在的使用方式就可以了呢? 可以在append,詢問Y和N的地方,加上分號,或是F當做Y, 但這樣子不知道會不會換右手酸了。 目的還是要簡少按鍵數量。 或是在多一個快速鍵,跟F結合在一起,可能是寫在F,裡面在多一個判斷, 目的是要把append檔案的部份,分一個Y的,和一個N的。 另外,想加一個C快速鍵,就是選到項目的時候所使用的, 裡面可以刪除檔案、等其它額外擴充的功能 還有,別忘了還有一個IDEA需要被完成,就是判斷副檔名的部份。 就是在vim -p files...的時候,如果副檔名是.tar.gz、zip、image file等東西, 在vim的部份,就是會ignore它們。 # 2011-01-18 想要把原先放在/bin下的執行檔,都改放在自己的家目錄, 這樣子在有些沒有root的環境下,才可以使用, 而且這樣子也比較合理 不過有些檔案的目標路徑,是寫死的, 利用這個idea把它們都做個修正。 # 2011-01-17 想要在vimlist的功能,加上判斷副檔名的功能, 如果是使用vim編輯的話,就會乎略掉某些副檔名, 例如tar.gz, zip, images, videos, music # 2011-01-13 想要在vf的地方,加上以下的功能項目: 1. execute 2. delete execute的部份,可能就會判斷副檔名, 刪除的部份,可能會用D的關鍵字來做。 # 2011-01-11 想要在/斜線的地方,加上重新去include檔案的程式碼, 這樣子如果修改了searchfile, or searchdir,把它設定為啟動, 這時只要按一下斜線,就可以生效了 設定檔的地方,想要在加上bash history, 以及google search function 另外,以現在的使用方式,是增加判斷式和google groupname, 這樣子的使用方式,跟我新增設定檔的目標是很像的, 打算選擇設定檔的方式,在加上面的idea,可能會比較好使用。 # 2011-01-09 想要在各version control裡面的push之前, 加上"處理中..."的字眼,或者是顯示執行的指令。 在要增加一些功能的開關設定, 因為不管是在比較慢的電腦,或是比較快的,上執行這套程式,會很慢, 例如搜尋檔案的功能,或者是搜尋bash history的功能, 或許我可以把這些開關的設定,寫在某一支bash file裡面, 要使用的時候,才去修改它, 然後abc-v3就去include它。 # 2011-01-07 想要加一個快速鍵,來show/hide Help,應該就是大寫的H了 想要加上一個功能,就是按下vim的F8,就會離開vim,以及重新啟動vimlist的功能, 當然這個功能要先選擇groupname,這個功能是可以做的, 可能就離開前先寫入文字檔,然後abc-v3去判斷文字檔內是否有內容, 有的話在重新啟動vimlist的功能,因為不是很重要,所以暫時先不用寫 有沒有可能在vim裡面,按某一個快速鍵,然後就會把menu列出來讓你選擇, 或是可以讓你用快速鍵去選擇裡面的項目。 # 2011-01-03 想要加上切換到firefox的快速鍵 以及想要把切換的程式,加上引數,可以選擇切換後,要不要按下重整的按鈕。 另外,想要在啟動ide and abc-v3的時候,如果groupname是空白,就自動補上home, 關於這個idea在想想看,因為空groupname也是有我設計的理念在裡面,先不要拿掉好了。 # 2011-01-01 在abc-v3的V快速鍵中, 想要check current dir是否有.svn or .hg or .git的資料夾, 如果有的話,就直接啟用該版本控制, 還有,這個功能選擇版本控制的快速鍵,想要大小寫都可以使用。 我想在各版本控制的介面中,加上抓repo的功能下來,但這個IDEA好像不是很實用。 # 2010-12-31 想要將版本控制都放在一起, 例如按V(Version),就代表版本控制, 然後就會出現H(hg), G(git), S(Svn), C(cvs這個應該不會做) 一樣也是按快速鍵去執行它 在要加上第2層的判斷, 可能試著執行status,例如git status, 如果有正常的反應,我指的是在正確的repo裡面, 那這時我就會判斷正常,來執行指定的版本控制的指令。 # 2010-12-26 想要思考一下,怎麼樣在commander與cli之間做快速的切換, 有想到幾種方式: 1. 輸入一個快速鍵,然後會顯示讓你輸入指令的地方,只執行一次就會回到commander 2. 離開commander以後,可以任意的輸入指令,然後透過輸入某個指令,就會回到commander 3. 利用Ctrl+Z,把現在執行的東西放到background,透過fg把commander叫起來 4. 把MC啟動很慢的問題解決掉 5. 開2個視窗,用alt + tab切換 6. 開2個電腦,分別用不同的鍵盤 目前有加上nautilus,在abc裡面,所以未來我可以直接離開,或是不使用ide的指令, 如果要執行指令的時候,直接離開abc,如果指令打完,在輸入abc啟動ide就可以了。 # 2010-12-16 想要更改現在目前爛爛的svnn功能, 以及想要新增hg進來,不然就叫做hgg。 另外,svnn和hg,想要加上一個功能, commit cache的功能, 就是送出指定的檔案, 會想加上這個功能, 是因為有些檔案是我不想要送的檔案, 或是說,有些檔案己經完成了,但其它的檔案還在修改當中。 這個cache,想要寫在一個文字檔裡面,類似vimlist, 以svn來說,只要commit,就會送出了,這是與hg不同的地方, 我打算在送出了之後,就清空這個cache, 這個cache,我想取名為svnlist(svn commit list) 關於cache的功能,有一些想法: 1. 全部列入(或取消)cache 2. 關鍵字選擇單項(或多項)項目列入(或取消)cache 3. 觀看修改的內容,使用svn diff的指令,跟最後一個版本做比較 4. svn add的功能 5. 可以選擇清除cache, and uncache file 6. 可以選擇重新建立uncache file 這個會比較複雜,會有4種模式(gitv2只有2種) 每一個模式都可以下commit的指令 1. svn status, filter by untracked, or new file, 其它都沒有哦 2. svn status, filter by added, or deleted, modify一定會在裡面的(我想取commit list) 3. uncache list(這個還是要有,會比較方便) 4. cache list 在模式1的時候,可以使用關鍵字來對沒有被svn add的檔案操作, 然後會忽略掉modify或是己被svn add的檔案, commit list反之。 關於模式3,只要模式1有動作,就會重新輸出uncache file,也會清空cache file, 會這樣子做,是因為沒有svn-add的檔案(狀態為問號),是沒有辦法被commit的,請注意! 還是把模式1,變成狀態只能是問號的 另外,我想把寫入檔案這個動作,寫成bash function, 因為這個動作看起來還蠻常用的。 # 2010-12-15 搜尋google的功能, 除了想獨立一個功能來做以外, 還想要在abc3也想加上這一個功能, 不過可能只會搜尋一筆, 因為如果很多筆的話,abc3會變的很亂。 # 2010-12-14 想要加上搜尋google的功能, 請參考study/google-search.pl檔案, 當輸入關鍵字的時候,就會順便去搜尋Google, 然後我可以去選擇我想要的項目編號, 選了之後,就會用firefox指令去開啟該網址, 並且切換到firefox的視窗。 可能會新增一個項目,來放這個新功能, 然後英文模式在透過某一個快速鍵來連到這一個功能 另外,我在想要不要使用firefox, 理論上來說,我應該選擇的是links或是其它文字型的瀏覽器。 我看,還是做一個選項之類的東西,來切換瀏覽器。 後來找到了w3m,打算使用這一個。 如果要使用這個功能,請建立google這一個groupname。 使用text browser有一個好處,因為很多主機是沒有圖型介面的, 而且都是放在機房,如果沒有帶自己筆記型電腦過去,是上不了Google查資料的。 # 2010-12-10 想要加一個功能,是在輸入關鍵字的時候, 也順便去搜尋底下的資料夾, 當選擇的時候,當然是進去那一個資料夾裡面。 不過這個功能我不打算加入groupname功能內。 # 2010-12-03 在想要不要把MC加進來, 在create, delete資料夾或是文字檔的時候, 或是在copy, move, rename的時候, 轉使用MC工具,不過MC啟動的時候有點慢,大約要10秒鐘, 而且使用-s or -b的引數都還是很慢, 我在找找看有沒有其它的使用選擇。 # 2010-11-30 在想要不要增加一些系統的元素進來, 例如: sudo or leave sudo edit hosts edit php.ini edit apache conf(s) edit or tail message, dmesg start restart service search bash history(只是有些指令在cli下執行會卡住) ssh remote server 以上這個話題,可以分一些思考點出來 1. 編輯檔案的部份,可以參考dirpoint的作法 2. 搜尋檔案內容的部份,就比較單純 3. sudo 可能就要在想一下了,可能就下sudo的指令,然後我可能不要打密碼, 接下來會切換到root,這時會自動用root來執行ide或是abc。 4. start restart service, 可能需要搭配dialog來做。 5. ssh remote server, 這可能會蠻實用的,我可能會先寫入一個文字檔列表, 這個功能應該很單純,然後是全域的,不會被groupname所區分。 關於上述第1點, 可以設定檔案的virtual徑捷,例如我輸入config,這時可能會出現aaa.xml出來, 可能要想一下,這一點是否真的實用才做。 後來想一想,可能不太實用,因為我還有搜尋的功能,假設在任何地方輸入aaa, 還是會出現aaa.xml 有些功能,我在想,可能不需要,或是不能用.(點)來做選擇, 一定要用所指定的快速鍵來選擇該功能,這樣可能比較不會有誤動作。 # 2010-11-24 我新增了一個study,是可以自動切換到指定的視窗,然後送指令. 我想利用這個study,做以下的動作: 1. In Gnome-terminal vim edit file 2. 離開vim,然後執行某一個快速鍵,這時會切到firefox,然後重新整理頁面 3. 也會在回到vim 這個動作可能可以想一下應用
gisanfu/fast-change-dir
c9b2d7f30649067958912bd04ecdb255a025eaf0
add idea
diff --git a/IDEA b/IDEA index 13dcb84..78be29d 100644 --- a/IDEA +++ b/IDEA @@ -1,512 +1,517 @@ +# 2013-01-12 + +dialog,想要加上-----分隔項目,當vim筆數很多的時候 +前面想要加上分區ax,bx,cx... + # 2012-02-18 這個pushd和popd的概念可以參考一下,雖然不是很好用 http://usagiblog.wordpress.com/2006/02/18/pushd-%E5%92%8C-popd/ 想要在vim的地方加一個東西 當超過10個檔案,就編輯下10個檔案,有點像是分頁 雖然vim可以設定開幾個檔案,可是vim的引數+是有限制的,剛剛好就是10個 # 2011-10-30 在command-line下看圖片的軟體,或許可以結合看看 http://inouire.net/archives/image-couleur_source.tar.gz # 2011-06-19 想要加上以下的範例指定進來 echo "hello" | xclip 可以把hello貼到clipboard裡面,然後回到vim貼上, 在ubuntu是按mouse的中鍵, windows裡面使用putty可能要測試一下。 # 2011-05-15 想要加上"cd -"的指令進來 # 2011-04-17 想要寫abc第4個版本 這個版本的特色為: - 不會即時搜尋各功能 - 當然也不會顯示搜尋後的結果 - 點確認以後,才會開始搜尋,以及各功能所會做的動作 - 為了要增加執行的效率,才會做這一個版本 - 先做基本的功能(本層、上層的檔案和資料夾處理),如果效率沒有問題,在加寫其它的功能 - 如果有重覆的,就用dialog menu - relativeitem或許可以取消cache功能 - 使用各快速鍵來啟動該功能,例如我輸入了eeee,然後按大寫F,來搜尋本層的檔案,如果只有一筆,那就加入暫存列表,並直接編輯它 # 2011-04-16 想用python重寫relativeitem 當有人在問它的時候,就會同時找以下的東西: 1. 本層的檔案和資料夾 2. 上一層的檔案和資料夾 找到了以後,第一次會將列表寫入檔案, 可能會給檔案一個編號當檔名,這個編號也會回傳給bash abc-v3主程式 當下一個relative開始,就會帶著這個編號去問新的程式, 這時新的程式,可以用這個編號去找檔案,而不用重新取得列表。 # 2011-04-15 1. 在vff的前面,加一個flow,選擇你要編輯的檔案 2. 正在想,要不要加入其它的語言,為了增加效率 # 2011-04-14 可以把各專案的設定檔,放到各專案的資料夾裡面, 不過關於這一點,可能要改很多地方。 # 2011-04-12 想要把資料夾和檔案的檔名,寫到一支文字檔裡面, 然後增加一個功能,對那個文字檔做控制 # 2011-03-22 可以把Groupname,在abc version3裡面,加上dialog的選擇功能 # 2011-03-01 在ide階段,想要不輸入東西,就可以使用F和D以及上一層的功能, 使用的方式為dialog。 增加這個功能了以後,感覺更好用了。 想要在vf詢問的地方,加上"是否使用純vim編輯,而不列入暫存"的選項 詢問過後,程式才會決定要不要寫入暫存 # 2011-02-21 看能不能在啟動ide之前,先去update(應該是說git pull)最新的資料, 這樣子就可以做最快速的同步, 希望目前原有的fast-change-dir-config的目標,能夠改成自己的git repo,比較安全, 不過這裡是點奇怪的,又想要private repo,但又想要密碼驗證,然後又想要安全性, 最好的方式,應該是每一個target或者說是End端,都要有一個類似驗證碼的東西, 送上去的時候,不是我的人就不能送上去, 目前還沒有想到一個比較好的方式。 應該是說,可以抓下去,要透過驗證碼 (每一台,或是每一個權限,使用的驗證碼都不一樣), 要送上去的時候,是需要密碼的,這樣子的方式應該是比較好的方式。 送上去的時候,可能是送到我自己的svn repo, 送上去以後,會export到某一個http的路徑, 然後我透過http simple auth,讓該權限來下載東西,或是更新東西下去, 但如果是這種作法的話,要怎麼樣上傳呢? 好像想的太複雜了@@。 # 2011-02-18 有想到一個功能, 如果我想要去一個資料夾, 它是在某一個資料下底下, 這種狀況常常會發生,就是進去上一個資料夾以後,就忘了下一個資料夾要去哪裡了。 所以想做一個功能,就是先輸入下一個條件,在然在進去第一個資料夾, 當第一個資料夾進去了以後,就會自動處理在暫存的指令, 不過後來想一想,其實如果是在本機操作,也可以進去第一層,然後按"R",啟動nautilus, 用GUI去操作。 # 2011-02-16 想要加上git的路徑(我指的是1.7的git) 不然又需要root權限了 想要多錯字處理的功能, 例如我輸入了misc, 打錯成為mics, 這時是可以判斷的,不過細節的部份要在思考一下, 而且這個功能,可能也會造成速度變慢,或許是不需要做的 # 2011-02-14 想要做一個功能,是不受groupname限制的, 很像是ssh txtfile的功能, 就是輸入一個關鍵字,可能就會跳到那一個資料夾裡面, 因為有時候很累的時候,跟本就沒有辦法輸入快速鍵。 # 2011-02-10 想要寫一支script,針對Zend Framework的架構, 匯出dirpoint的檔案出來, 可能可以針對root、module name等變數來做組合,以及匯出。 # 2011-02-01 想要把function放到lib/func資料夾裡面。 想要把片段程式碼放到lib/某一個資料夾裡面,可能是several, 想在abc-v3的第二個引數,加上@小老鼠,使用在position 還想要更改所有的文字檔到指定的某個位置, 除了路徑以外,檔名都要是變數,都是可以被修改的。 例如是放在~/git/公司名稱_某分類名稱/, 然後如果在公司做到一個地方,可以把裡面的東西,先存起來, 將整個設定和環境一起帶到另外一台電腦上面。 暫存的路徑是需要的,但是檔名應該先不需要, 其它的應該都是需要的。 # 2011-01-31 目前己經有一個輸入@小老鼠,可以為grep加上^的指令, 我想加一個#井字號,告訴程式我想要使用dialog menu的方式來選擇我要的東西, 經測試了以後,發現不能夠在bash function裡面,下dialog的指令, 所以這個功能必需要在函式以外的地方先處理, 感覺很麻煩,不過也蠻實用的。 # 2011-01-30 能不能讓每一個group,都有自己的設定檔, 例如home的group,可能就會啟動parent-item的功能, 而某程式設計的專案,可能就會因為感覺良好,而關閉它。 # 2011-01-29 能不能在同一個func_relative裡面, 同時做同個資料夾的item處理,以及上一層資料夾內的item處理呢? 能否使用C語言來改寫func_relative的函式, 然後讓bash來呼叫,看能不能改善效率, 讓反應速度能夠跟上我的操作速度, 在呈現的部份。 # 2011-01-28 有機會想要做web的部份。 關於資料夾、或是檔案碰到多筆的狀況, 可以多一個使用dialog menu的選擇來協助, 關於資料夾的部份,可以使用.(點)的快速鍵。 不過好像太麻煩了,可以試著按斜線清掉執行鍵, 然後想想如何使用更好的關鍵字來對它選取, 然後將它記錄在腦海裡面,下次就使用新的或是更好的方式來選擇該項目。 # 2011-01-27 對於vf按y和n,有想到一個方式 就是先把.(點)改回來, 可能把點使用在append-vff, 而;(分號),就是append+vff, 這樣子keyin的數量應該會少很多, 效率應該會比較快。 不過這個idea可能不會用在數字模式上,因為狀況不同 另外,如果輸入錯了快速鍵,或是打錯關鍵字, 想要暫停2秒鐘,然後自動清除關鍵字,並重來, 這樣子可能也多多少少增加一些速度, 不然打錯了還要手動去按一下/(斜線) 有時候按斜線還會按錯 分號,在切換資料夾的時候,可以想看看有沒有什麼其它的應用。 關鍵字的部份好像有點問題, 如果某一個物件名稱是aaabbb, 我輸入aa bb是可以找得到的, 但是如果我輸入bb aa好像是找不到的。 # 2011-01-26 想要把abc v3的第一次顯示help的部份拿掉 想加上更多操作檔案的功能 例如之前idea前寫過的: 執行檔案(依照副檔名) 刪除檔案(當然要可以刪除單檔、多檔,或是針對資料夾,或是混合) 更改名稱 移動路徑 想要在touch檔案以後,順便去編輯它 如果是在有啟動groupname的時候,步驟就會走到詢問你要不要vff的階段 touch檔案,應該是使用dialog的方式才對 刪除的功能,在C的快速鍵中,感覺不是很實用 目前是用C來當做Create,感覺還不錯 看要不要在建立另外一個關鍵字,來做刪除的動作 刪除的動作,也可以考慮不要做,改用cli, or nautilus來做會比較保險。 # 2011-01-25 想要在每一個版本控制功能中, 都加上R功能,也就是切換到Browser。 # 2011-01-22 想要在按分號的時候,就直接編輯檔案(如果是選檔案是在第一項) 就不要在按Y的,很麻煩,也為了可以簡化。 但是,如果我只是想append,但還沒有要edit,那這時怎麼辦呢? 是不是也是要維持現在的使用方式就可以了呢? 可以在append,詢問Y和N的地方,加上分號,或是F當做Y, 但這樣子不知道會不會換右手酸了。 目的還是要簡少按鍵數量。 或是在多一個快速鍵,跟F結合在一起,可能是寫在F,裡面在多一個判斷, 目的是要把append檔案的部份,分一個Y的,和一個N的。 另外,想加一個C快速鍵,就是選到項目的時候所使用的, 裡面可以刪除檔案、等其它額外擴充的功能 還有,別忘了還有一個IDEA需要被完成,就是判斷副檔名的部份。 就是在vim -p files...的時候,如果副檔名是.tar.gz、zip、image file等東西, 在vim的部份,就是會ignore它們。 # 2011-01-18 想要把原先放在/bin下的執行檔,都改放在自己的家目錄, 這樣子在有些沒有root的環境下,才可以使用, 而且這樣子也比較合理 不過有些檔案的目標路徑,是寫死的, 利用這個idea把它們都做個修正。 # 2011-01-17 想要在vimlist的功能,加上判斷副檔名的功能, 如果是使用vim編輯的話,就會乎略掉某些副檔名, 例如tar.gz, zip, images, videos, music # 2011-01-13 想要在vf的地方,加上以下的功能項目: 1. execute 2. delete execute的部份,可能就會判斷副檔名, 刪除的部份,可能會用D的關鍵字來做。 # 2011-01-11 想要在/斜線的地方,加上重新去include檔案的程式碼, 這樣子如果修改了searchfile, or searchdir,把它設定為啟動, 這時只要按一下斜線,就可以生效了 設定檔的地方,想要在加上bash history, 以及google search function 另外,以現在的使用方式,是增加判斷式和google groupname, 這樣子的使用方式,跟我新增設定檔的目標是很像的, 打算選擇設定檔的方式,在加上面的idea,可能會比較好使用。 # 2011-01-09 想要在各version control裡面的push之前, 加上"處理中..."的字眼,或者是顯示執行的指令。 在要增加一些功能的開關設定, 因為不管是在比較慢的電腦,或是比較快的,上執行這套程式,會很慢, 例如搜尋檔案的功能,或者是搜尋bash history的功能, 或許我可以把這些開關的設定,寫在某一支bash file裡面, 要使用的時候,才去修改它, 然後abc-v3就去include它。 # 2011-01-07 想要加一個快速鍵,來show/hide Help,應該就是大寫的H了 想要加上一個功能,就是按下vim的F8,就會離開vim,以及重新啟動vimlist的功能, 當然這個功能要先選擇groupname,這個功能是可以做的, 可能就離開前先寫入文字檔,然後abc-v3去判斷文字檔內是否有內容, 有的話在重新啟動vimlist的功能,因為不是很重要,所以暫時先不用寫 有沒有可能在vim裡面,按某一個快速鍵,然後就會把menu列出來讓你選擇, 或是可以讓你用快速鍵去選擇裡面的項目。 # 2011-01-03 想要加上切換到firefox的快速鍵 以及想要把切換的程式,加上引數,可以選擇切換後,要不要按下重整的按鈕。 另外,想要在啟動ide and abc-v3的時候,如果groupname是空白,就自動補上home, 關於這個idea在想想看,因為空groupname也是有我設計的理念在裡面,先不要拿掉好了。 # 2011-01-01 在abc-v3的V快速鍵中, 想要check current dir是否有.svn or .hg or .git的資料夾, 如果有的話,就直接啟用該版本控制, 還有,這個功能選擇版本控制的快速鍵,想要大小寫都可以使用。 我想在各版本控制的介面中,加上抓repo的功能下來,但這個IDEA好像不是很實用。 # 2010-12-31 想要將版本控制都放在一起, 例如按V(Version),就代表版本控制, 然後就會出現H(hg), G(git), S(Svn), C(cvs這個應該不會做) 一樣也是按快速鍵去執行它 在要加上第2層的判斷, 可能試著執行status,例如git status, 如果有正常的反應,我指的是在正確的repo裡面, 那這時我就會判斷正常,來執行指定的版本控制的指令。 # 2010-12-26 想要思考一下,怎麼樣在commander與cli之間做快速的切換, 有想到幾種方式: 1. 輸入一個快速鍵,然後會顯示讓你輸入指令的地方,只執行一次就會回到commander 2. 離開commander以後,可以任意的輸入指令,然後透過輸入某個指令,就會回到commander 3. 利用Ctrl+Z,把現在執行的東西放到background,透過fg把commander叫起來 4. 把MC啟動很慢的問題解決掉 5. 開2個視窗,用alt + tab切換 6. 開2個電腦,分別用不同的鍵盤 目前有加上nautilus,在abc裡面,所以未來我可以直接離開,或是不使用ide的指令, 如果要執行指令的時候,直接離開abc,如果指令打完,在輸入abc啟動ide就可以了。 # 2010-12-16 想要更改現在目前爛爛的svnn功能, 以及想要新增hg進來,不然就叫做hgg。 另外,svnn和hg,想要加上一個功能, commit cache的功能, 就是送出指定的檔案, 會想加上這個功能, 是因為有些檔案是我不想要送的檔案, 或是說,有些檔案己經完成了,但其它的檔案還在修改當中。 這個cache,想要寫在一個文字檔裡面,類似vimlist, 以svn來說,只要commit,就會送出了,這是與hg不同的地方, 我打算在送出了之後,就清空這個cache, 這個cache,我想取名為svnlist(svn commit list) 關於cache的功能,有一些想法: 1. 全部列入(或取消)cache 2. 關鍵字選擇單項(或多項)項目列入(或取消)cache 3. 觀看修改的內容,使用svn diff的指令,跟最後一個版本做比較 4. svn add的功能 5. 可以選擇清除cache, and uncache file 6. 可以選擇重新建立uncache file 這個會比較複雜,會有4種模式(gitv2只有2種) 每一個模式都可以下commit的指令 1. svn status, filter by untracked, or new file, 其它都沒有哦 2. svn status, filter by added, or deleted, modify一定會在裡面的(我想取commit list) 3. uncache list(這個還是要有,會比較方便) 4. cache list 在模式1的時候,可以使用關鍵字來對沒有被svn add的檔案操作, 然後會忽略掉modify或是己被svn add的檔案, commit list反之。 關於模式3,只要模式1有動作,就會重新輸出uncache file,也會清空cache file, 會這樣子做,是因為沒有svn-add的檔案(狀態為問號),是沒有辦法被commit的,請注意! 還是把模式1,變成狀態只能是問號的 另外,我想把寫入檔案這個動作,寫成bash function, 因為這個動作看起來還蠻常用的。 # 2010-12-15 搜尋google的功能, 除了想獨立一個功能來做以外, 還想要在abc3也想加上這一個功能, 不過可能只會搜尋一筆, 因為如果很多筆的話,abc3會變的很亂。 # 2010-12-14 想要加上搜尋google的功能, 請參考study/google-search.pl檔案, 當輸入關鍵字的時候,就會順便去搜尋Google, 然後我可以去選擇我想要的項目編號, 選了之後,就會用firefox指令去開啟該網址, 並且切換到firefox的視窗。 可能會新增一個項目,來放這個新功能, 然後英文模式在透過某一個快速鍵來連到這一個功能 另外,我在想要不要使用firefox, 理論上來說,我應該選擇的是links或是其它文字型的瀏覽器。 我看,還是做一個選項之類的東西,來切換瀏覽器。 後來找到了w3m,打算使用這一個。 如果要使用這個功能,請建立google這一個groupname。 使用text browser有一個好處,因為很多主機是沒有圖型介面的, 而且都是放在機房,如果沒有帶自己筆記型電腦過去,是上不了Google查資料的。 # 2010-12-10 想要加一個功能,是在輸入關鍵字的時候, 也順便去搜尋底下的資料夾, 當選擇的時候,當然是進去那一個資料夾裡面。 不過這個功能我不打算加入groupname功能內。 # 2010-12-03 在想要不要把MC加進來, 在create, delete資料夾或是文字檔的時候, 或是在copy, move, rename的時候, 轉使用MC工具,不過MC啟動的時候有點慢,大約要10秒鐘, 而且使用-s or -b的引數都還是很慢, 我在找找看有沒有其它的使用選擇。 # 2010-11-30 在想要不要增加一些系統的元素進來, 例如: sudo or leave sudo edit hosts edit php.ini edit apache conf(s) edit or tail message, dmesg start restart service search bash history(只是有些指令在cli下執行會卡住) ssh remote server 以上這個話題,可以分一些思考點出來 1. 編輯檔案的部份,可以參考dirpoint的作法 2. 搜尋檔案內容的部份,就比較單純 3. sudo 可能就要在想一下了,可能就下sudo的指令,然後我可能不要打密碼, 接下來會切換到root,這時會自動用root來執行ide或是abc。 4. start restart service, 可能需要搭配dialog來做。 5. ssh remote server, 這可能會蠻實用的,我可能會先寫入一個文字檔列表, 這個功能應該很單純,然後是全域的,不會被groupname所區分。 關於上述第1點, 可以設定檔案的virtual徑捷,例如我輸入config,這時可能會出現aaa.xml出來, 可能要想一下,這一點是否真的實用才做。 後來想一想,可能不太實用,因為我還有搜尋的功能,假設在任何地方輸入aaa, 還是會出現aaa.xml 有些功能,我在想,可能不需要,或是不能用.(點)來做選擇, 一定要用所指定的快速鍵來選擇該功能,這樣可能比較不會有誤動作。 # 2010-11-24 我新增了一個study,是可以自動切換到指定的視窗,然後送指令. 我想利用這個study,做以下的動作: 1. In Gnome-terminal vim edit file 2. 離開vim,然後執行某一個快速鍵,這時會切到firefox,然後重新整理頁面 3. 也會在回到vim 這個動作可能可以想一下應用
gisanfu/fast-change-dir
a32fb94c68a84651ce34366e8ab9fabb63a82a5a
add new option
diff --git a/abc-4.sh b/abc-4.sh index 1a71d61..1e14d82 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,497 +1,505 @@ #!/bin/bash source "$fast_change_dir/config/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color fast_change_dir_switch_list='1' while [ 1 ]; do clear fast_change_dir_auto_list_file_enable='0' if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' - if [ "$fast_change_dir_switch_list" == '2' ]; then + if [ "$fast_change_dir_switch_list" == '1' ]; then + ignorelist=$(func_getlsignore) + cmd="ls -AF $ignorelist --color=auto" + eval $cmd + elif [ "$fast_change_dir_switch_list" == '2' ]; then tree -L 1 elif [ "$fast_change_dir_switch_list" == '3' ]; then tree -L 1 -d elif [ "$fast_change_dir_switch_list" == '4' ]; then tree -L 2 elif [ "$fast_change_dir_switch_list" == '5' ]; then tree -L 2 -d + elif [ "$fast_change_dir_switch_list" == '6' ]; then + ignorelist=$(func_getlsignore) + cmd="ls -AF $ignorelist --color=never" + eval $cmd else ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd fi if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 將單檔案列入暫存,並使用vim編輯它們 (;) 分號' echo ' 只將單檔案列入暫存 (;) 分號' echo ' 將多個檔案列入暫存,並使用vim編輯它們 (*)' echo ' 只將多個檔案列入暫存 (&)' echo ' 切換檔案列表的方式 (T)' echo ' 上一層 (,) 逗點' echo ' 上一個資料夾 (<) 小於,跟上一層是同一個按鍵' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' 利用檔案做索引,進入該檔案所在的資料夾 (O)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' elif [ "$inputvar" == '*' ]; then inputvar='FF' elif [ "$inputvar" == '&' ]; then inputvar='FFF' elif [ "$inputvar" == ':' ]; then inputvar='FFFF' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear fast_change_dir_auto_list_file_enable='1' unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue elif [ "$inputvar" == '<' ]; then cd - clear_var_all='1' continue # 想拉一個檔案進來,接下來會做vff的動作 elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue # 想拉一個檔案進來,但是不啟用vff的狀況 elif [ "$inputvar" == 'FFFF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 0" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 0" fi eval $run clear_var_all='1' continue # 多選功能在使用的,只支援本層 elif [ "$inputvar" == 'FF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" fi eval $run clear_var_all='1' continue # 多選功能在使用的,只支援本層(不啟動vff) elif [ "$inputvar" == 'FFF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 3" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 3" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'O' ]; then d2ff clear_var_all='1' continue elif [ "$inputvar" == 'T' ]; then - array=(ls Tree顯示全部 Tree只顯示資料夾 Tree顯示全部2層 Tree只顯示資料夾2層) + array=(ls Tree顯示全部 Tree只顯示資料夾 Tree顯示全部2層 Tree只顯示資料夾2層 ls無顏色) dialogitems='' start=1 for echothem in ${array[@]} do dialogitems=" $dialogitems '$start' $echothem " start=$(expr $start + 1) done tmpfile="$fast_change_dir_tmp/`whoami`-abc4T-dialogselect-$( date +%Y%m%d-%H%M ).txt" cmd2=$( func_dialog_menu '選擇檔案列表的方式 ' 100 "$dialogitems" $tmpfile ) eval $cmd2 result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then fast_change_dir_switch_list=$result fi clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd
gisanfu/fast-change-dir
0335aa35f3123fa35b45db7eb5d4593ddf33c6fc
+ ‘test/aaa.txt’
diff --git a/test/aaa.txt b/test/aaa.txt new file mode 100644 index 0000000..c3828f7 --- /dev/null +++ b/test/aaa.txt @@ -0,0 +1,558 @@ +<?PHP + +/** + * Project: Absynthe sql4array + * File: sql4array.class.php5 + * Author: Absynthe <[email protected]> + * Webste: http://absynthe.is.free.fr/sql4array/ + * Version: alpha 1 + * Date: 30/04/2007 + * License: LGPL + */ + +/** + * Parameters available : + * SELECT, DISTINCT, FROM, WHERE, ORDER BY, LIMIT, OFFSET + * + * Operators available : + * =, <, >, <=, >=, <>, !=, IS, IS IN, IS NOT, IS NOT IN, LIKE, ILIKE, NOT LIKE, NOT ILIKE + * + * Functions available in WHERE parameters : + * LOWER(var), UPPER(var), TRIM(var) + */ + +class sql4array +{ + /** + * Init + */ + protected $query = FALSE; + protected $parse_query = FALSE; + protected $parse_query_lower = FALSE; + protected $parse_select = FALSE; + protected $parse_select_as = FALSE; + protected $parse_from = FALSE; + protected $parse_from_as = FALSE; + protected $parse_where = FALSE; + protected $distinct_query = FALSE; + protected $tables = array(); + protected $response = array(); + + protected static $cache_patterns = array(); + protected static $cache_replacements = array(); + + /** + * sql4array setting + */ + protected $attr = array(); + + /** + * sql4array tables map + */ + protected $globals = array(); + + protected $cache_query = array(); + + public function __construct() + { + $this + ->destroy() + ->createFromGlobals(false) + ->cacheQuery(true) + ; + } + + /** + * set tables get from where + * and this func will reset $this->globals + * + * @return sql4array + */ + public function createFromGlobals($enabled = true) + { + $this->attr['createFromGlobals'] = $enabled; + + // reset $this->globals + $this->globals = array(); + + return $this; + } + + /** + * @return array + */ + function table($table) + { + if ($this->attr['createFromGlobals']) + { + return $GLOBALS[$table]; + } + else + { + return $this->globals[$table]; + } + } + + /** + * set tables map + * + * @return sql4array + */ + function asset($key, $value) { + $this->globals[$key] = $value; + + return $this; + } + + /** + * Query function + * + * @return array - return $this->return_response(); + */ + public function query($query) + { + $this->destroy(); + $this->query = $query; + + if (!$this->cacheQueryGet($this->query)) + { + + $this + ->parse_query() + ->parse_select() + ->parse_select_as() + ->parse_from() + ->parse_from_as() + ->parse_where() + ; + + $this->cacheQuerySet($this->query); + + } + + $this + ->exec_query() + ->parse_order() + ; + + return $this->return_response(); + } + + public function cacheQuery($val = true, $clear = false) + { + $this->attr['cacheQuery'] = $val; + + if ($clear) $this->cache_query = array(); + + return $this; + } + + /** + * @return bool + */ + protected function cacheQueryGet($query) + { + $key = md5($query); + + if ( + $this->attr['cacheQuery'] + && + array_key_exists($key, $this->cache_query) + && $data = &$this->cache_query[$key] + ) + { + $this->query = $data['query']; + $this->parse_query = $data['parse_query']; + $this->parse_query_lower = $data['parse_query_lower']; + $this->parse_select = $data['parse_select']; + $this->parse_select_as = $data['parse_select_as']; + $this->parse_from = $data['parse_from']; + $this->parse_from_as = $data['parse_from_as']; + $this->parse_where = $data['parse_where']; + $this->distinct_query = $data['distinct_query']; + + $data['count_used'] += 1; + + return true; + } + + return false; + } + + protected function cacheQuerySet($query) + { + $key = md5($query); + + $data = array(); + + $data['query'] = $this->query; + $data['parse_query'] = $this->parse_query; + $data['parse_query_lower'] = $this->parse_query_lower; + $data['parse_select'] = $this->parse_select; + $data['parse_select_as'] = $this->parse_select_as; + $data['parse_from'] = $this->parse_from; + $data['parse_from_as'] = $this->parse_from_as; + $data['parse_where'] = $this->parse_where; + $data['distinct_query'] = $this->distinct_query; + + $this->cache_query[$key] = $data; + + return $this; + } + + /** + * Destroy current values + */ + protected function destroy() + { + $this->query = FALSE; + $this->parse_query = FALSE; + $this->parse_query_lower = FALSE; + $this->parse_select = FALSE; + $this->parse_select_as = FALSE; + $this->parse_from = FALSE; + $this->parse_from_as = FALSE; + $this->parse_where = FALSE; + $this->distinct_query = FALSE; + $this->tables = array(); + $this->response = array(); + + return $this; + } + + /** + * Parse SQL query + */ + protected function parse_query() + { + $this->parse_query = preg_replace('#ORDER(\s){2,}BY(\s+)(.*)(\s+)(ASC|DESC)#i', 'ORDER BY \\3 \\5', $this->query); + $this->parse_query = preg_split('#(SELECT|DISTINCT|FROM|JOIN|WHERE|ORDER(\s+)BY|LIMIT|OFFSET)+#i', $this->parse_query, -1, PREG_SPLIT_DELIM_CAPTURE); + $this->parse_query = array_map('trim', $this->parse_query); + $this->parse_query_lower = array_map('strtolower', $this->parse_query); + + return $this; + } + + /** + * Parse SQL select parameters + */ + protected function parse_select() + { + $key = array_search('distinct', $this->parse_query_lower); + + if ($key === FALSE) $key = array_search("select", $this->parse_query_lower); + else $this->distinct_query = TRUE; + + $string = $this->parse_query[$key + 1]; + $arrays = preg_split('#((\s)*,(\s)*)#i', $string, -1, PREG_SPLIT_NO_EMPTY); + + foreach ($arrays as $array) $this->parse_select[] = $array; + + return $this; + } + + /** + * Parse again SQL select parameters with as keyword + */ + protected function parse_select_as() + { + foreach ($this->parse_select as $select) + { + if (preg_match('#as#i', $select)) + { + $arrays = preg_split('#((\s)+AS(\s)+)#i', $select, -1, PREG_SPLIT_NO_EMPTY); + $this->parse_select_as[$arrays[1]] = $arrays[0]; + } + else + { + $this->parse_select_as[$select] = $select; + } + } + + return $this; + } + + /** + * Parse SQL from parameters + */ + protected function parse_from() + { + $key = array_search('from', $this->parse_query_lower); + $string = $this->parse_query[$key + 1]; + $arrays = preg_split('#((\s)*,(\s)*)#i', $string, -1, PREG_SPLIT_NO_EMPTY); + + foreach ($arrays as $array) $this->parse_from[] = $array; + + return $this; + } + + /** + * Parse again SQL from parameters with as keyword + */ + protected function parse_from_as() + { + foreach ($this->parse_from as $from) + { + if (preg_match('#as#i', $from)) + { + $arrays = preg_split('#((\s)+AS(\s)+)#i', $from, -1, PREG_SPLIT_NO_EMPTY); + + $table = $arrays[0]; + $from = $arrays[1]; + } + else + { + $table = $from; + } + + $this->parse_from_as[$from] = $table; + /* + $this->tables[$from] = $this->table($table); + */ + } + + return $this; + } + + /** + * Parse SQL where parameters + */ + protected function parse_where() + { + $key = array_search('where', $this->parse_query_lower); + + if ($key == FALSE) + { + $this->parse_where = 'return TRUE;'; + + return $this; + } + + $string = $this->parse_query[$key + 1]; + + if (trim($string) == '') return $this->parse_where = 'return TRUE;'; + + if (self::$cache_patterns && self::$cache_replacements) + { + $patterns = self::$cache_patterns; + $replacements = self::$cache_replacements; + } + else + { + + /** + * SQL Functions + */ + $patterns[] = '#LOWER\((.*)\)#ie'; + $patterns[] = '#UPPER\((.*)\)#ie'; + $patterns[] = '#TRIM\((.*)\)#ie'; + + $replacements[] = "'strtolower(\\1)'"; + $replacements[] = "'strtoupper(\\1)'"; + $replacements[] = "'trim(\\1)'"; + + /** + * Basics SQL operators + */ + $patterns[] = '#(([a-zA-Z0-9\._]+)(\())?([a-zA-Z0-9\.]+)(\))?(\s)+(=|IS)(\s)+([[:digit:]]+)(\s)*#ie'; + $patterns[] = '#(([a-zA-Z0-9\._]+)(\())?([a-zA-Z0-9\.]+)(\))?(\s)+(=|IS)(\s)+(\'|\")(.*)(\'|\")(\s)*#ie'; + $patterns[] = '#(([a-zA-Z0-9\._]+)(\())?([a-zA-Z0-9\.]+)(\))?(\s)+(>|<)(\s)+([[:digit:]]+)(\s)*#ie'; + $patterns[] = '#(([a-zA-Z0-9\._]+)(\())?([a-zA-Z0-9\.]+)(\))?(\s)+(<=|>=)(\s)+([[:digit:]]+)(\s)*#ie'; + $patterns[] = '#(([a-zA-Z0-9\._]+)(\())?([a-zA-Z0-9\.]+)(\))?(\s)+(<>|IS NOT|!=)(\s)+([[:digit:]]+)(\s)*#ie'; + $patterns[] = '#(([a-zA-Z0-9\._]+)(\())?([a-zA-Z0-9\.]+)(\))?(\s)+(<>|IS NOT|!=)(\s)+(\'|\")(.*)(\'|\")(\s)*#ie'; + $patterns[] = '#(([a-zA-Z0-9\._]+)(\())?([a-zA-Z0-9\.]+)(\))?(\s)+(IS)?(NOT IN)(\s)+\((.*)\)#ie'; + $patterns[] = '#(([a-zA-Z0-9\._]+)(\())?([a-zA-Z0-9\.]+)(\))?(\s)+(IS)?(IN)(\s)+\((.*)\)#ie'; + + $replacements[] = "'\\1'.\$this->parse_where_key(\"\\4\").'\\5 == \\9 '"; + $replacements[] = "'\\1'.\$this->parse_where_key(\"\\4\").'\\5 == \"\\10\" '"; + $replacements[] = "'\\1'.\$this->parse_where_key(\"\\4\").'\\5 \\7 \\9 '"; + $replacements[] = "'\\1'.\$this->parse_where_key(\"\\4\").'\\5 \\7 \\9 '"; + $replacements[] = "'\\1'.\$this->parse_where_key(\"\\4\").'\\5 != \\9 '"; + $replacements[] = "'\\1'.\$this->parse_where_key(\"\\4\").'\\5 != \"\\10\" '"; + $replacements[] = "'\\1'.\$this->parse_where_key(\"\\4\").'\\5 != ('.\$this->parse_in(\"\\10\").') '"; + $replacements[] = "'\\1'.\$this->parse_where_key(\"\\4\").'\\5 == ('.\$this->parse_in(\"\\10\").') '"; + + self::$cache_patterns = $patterns; + self::$cache_replacements = $replacements; + + } + + /** + * match SQL operators + */ + $ereg = array('%' => '(.*)', '_' => '(.)'); + + $patterns[] = '#([a-zA-Z0-9\.]+)(\s)+LIKE(\s)*(\'|\")(.*)(\'|\")#ie'; + $patterns[] = '#([a-zA-Z0-9\.]+)(\s)+ILIKE(\s)*(\'|\")(.*)(\'|\")#ie'; + $patterns[] = '#([a-zA-Z0-9\.]+)(\s)+NOT LIKE(\s)*(\'|\")(.*)(\'|\")#ie'; + $patterns[] = '#([a-zA-Z0-9\.]+)(\s)+NOT ILIKE(\s)*(\'|\")(.*)(\'|\")#ie'; + + // TODO: use preg to replace ereg + + $replacements[] = "'ereg(\"'.strtr(\"\\5\", \$ereg).'\", '.\$this->parse_where_key(\"\\1\").')'"; + $replacements[] = "'eregi(\"'.strtr(\"\\5\", \$ereg).'\", '.\$this->parse_where_key(\"\\1\").')'"; + $replacements[] = "'!ereg(\"'.strtr(\"\\5\", \$ereg).'\", '.\$this->parse_where_key(\"\\1\").')'"; + $replacements[] = "'!eregi(\"'.strtr(\"\\5\", \$ereg).'\", '.\$this->parse_where_key(\"\\1\").')'"; + + $this->parse_where = "return " . stripslashes(trim(preg_replace($patterns, $replacements, $string))) . ";"; + + return $this; + } + + /** + * return '$row[$this->parse_select_as[' . $key . ']]'; + * + * @return string + */ + protected function parse_where_key($key) + { + if (preg_match('#\.#', $key)) + { + list($table, $col) = explode('.', $key); + + $key = $col; + } + + return '$row[$this->parse_select_as[' . $key . ']]'; + } + + /** + * Format IN parameters for PHP + * + * @return string + */ + protected function parse_in($string) + { + $array = explode(',', $string); + $array = array_map('trim', $array); + + return implode(' || ', $array); + } + + /** + * Execute query + */ + protected function exec_query() + { + $klimit = array_search('limit', $this->parse_query_lower); + $koffset = array_search('offset', $this->parse_query_lower); + + if ($klimit !== FALSE) $limit = (int)$this->parse_query[$klimit + 1]; + + if ($koffset !== FALSE) $offset = (int)$this->parse_query[$koffset + 1]; + + $irow = 0; + $distinct = array(); + + foreach ($this->parse_from_as as $from_name => $table_name) + { + + $this->tables[$from_name] = $this->table($table_name); + + foreach ($this->tables[$from_name] as $row) + { + // Offset + if ($koffset !== FALSE && $irow < $offset) + { + $irow++; + continue; + } + + if (eval($this->parse_where)) + { + if ($this->parse_select_as[0] == '*') + { + foreach (array_keys($row) as $key) $temp[$key] = $row[$key]; + + if ($this->distinct_query && in_array($temp, $distinct)) continue; + else $this->response[] = $temp; + + $distinct[] = $response; + } + else + { + foreach ($this->parse_select_as as $key => $value) $temp[$key] = $row[$value]; + + if ($this->distinct_query && in_array($temp, $distinct)) continue; + else $this->response[] = $temp; + + $distinct[] = $temp; + } + + // Limit + if ($klimit !== FALSE && count($this->response) == $limit) break; + } + + $irow++; + } + } + + return $this; + } + + /** + * Parse SQL order by parameters + */ + protected function parse_order() + { + $key = array_search('order by', $this->parse_query_lower); + + if ($key === FALSE) return; + + $string = $this->parse_query[$key + 2]; + $arrays = explode(',', $string); + + if (!is_array($arrays)) $arrays[] = $string; + + $arrays = array_map('trim', $arrays); + + $multisort = 'array_multisort('; + + foreach ($arrays as $array) + { + list($col, $sort) = preg_split('#((\s)+)#', $array, -1, PREG_SPLIT_NO_EMPTY); + $multisort .= "\$this->split_array(\$this->response, '$col'), SORT_" . strtoupper($sort) . ', SORT_STRING, '; + } + + $multisort .= '$this->response);'; + + eval($multisort); + + return $this; + } + + /** + * Return response + */ + protected function return_response() + { + return $this->response; + } + + /** + * Return a column of an array + */ + protected function split_array($input_array, $column) + { + $output_array = array(); + + foreach ($input_array as $key => $value) $output_array[] = $value[$column]; + + return $output_array; + } + + /** + * Entire array search + */ + protected function entire_array_search($needle, $array) + { + foreach ($array as $key => $value) + if ($value === $needle) $return[] = $key; + + if (!is_array($return)) $return = FALSE; + + return $return; + } +} + +?>
gisanfu/fast-change-dir
39e2a4202fb633bb31993d01c6ff24760a85a0ea
+ ‘lib/.empty’
diff --git a/lib/.empty b/lib/.empty new file mode 100644 index 0000000..e69de29
gisanfu/fast-change-dir
46538ace74f43295082a850895cbc2571c1af691
remove debug
diff --git a/vimlist-append.sh b/vimlist-append.sh index 1046738..6734243 100755 --- a/vimlist-append.sh +++ b/vimlist-append.sh @@ -1,188 +1,187 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 # 是否要vff,如果沒有指定,就是會詢問使用者 # 不詢問,不要vff的話,就放0 # 不詢問,要vff的話,就放1 # 想要vff,然後又要多選的狀況,那就放2,也會自動做vff的動作 # 同2,但不要vff的狀況 isVFF=$4 if [ "$isVFF" == '' ]; then isVFF=1 fi item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' if [ ${#item_array[@]} -eq 1 ]; then relativeitem=${item_array[0]} elif [[ ${#item_array[@]} -gt 1 && "$isVFF" == '2' || "$isVFF" == '3' ]]; then for file in ${item_array[@]} do selectitem='' selectitem=`pwd`/$file checkline=`grep $selectitem $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt fi done relativeitem='__empty' elif [ ${#item_array[@]} -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems="" for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem=$result else relativeitem='' fi else relativeitem='' fi if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then if [ "$isVFF" == '0' ]; then inputchar='n' elif [ "$isVFF" == '1' ]; then inputchar='y' elif [ "$isVFF" == '2' ]; then inputchar='y' elif [ "$isVFF" == '3' ]; then inputchar='n' else isVFF='' fi # 這裡可以考慮在加上一項,就是不要append這一個檔案 if [ "$isVFF" == '' ]; then # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' echo '[WAIT] 或是編輯列表 [j]' echo '[WAIT] 還是清空它 [k]' read -n 1 inputchar fi # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append if [ "$relativeitem" != '__empty' ]; then selectitem='' selectitem=`pwd`/$relativeitem checkline=`grep "$selectitem" $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt else echo '[NOTICE] File is exist' fi fi if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... checklinenumber=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` cmd='vff "vim' # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 # 查詢更多資訊請執行: "vim -h" # 為了加快速度而這麼寫的 tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') if [ "$checklinenumber" -lt 10 ]; then cmd="$cmd ${tabennn[$checklinenumber]}" - echo $cmd elif [[ "$checklinenumber" -ge 10 && "$checklinenumber" -lt 18 ]]; then # 先把編輯清單陣列1~8(從0開始)清掉,把10到19補進來 # 位置0是所開始的檔案列表 for i in {0..7} do unset item_array[$i] done # 在這裡,只是準備好tabenext的數量,剩下的工作會交給vimlist2.sh cmd="$cmd ${tabennn[$(expr $checklinenumber - 8)]}" elif [[ "$checklinenumber" -ge 18 && "$checklinenumber" -lt 27 ]]; then for i in {0..16} do unset item_array[$i] done # 在這裡,只是準備好tabenext的數量,剩下的工作會交給vimlist2.sh cmd="$cmd ${tabennn[$(expr $checklinenumber - 17)]}" elif [[ "$checklinenumber" -ge 27 && "$checklinenumber" -lt 36 ]]; then for i in {0..25} do unset item_array[$i] done # 在這裡,只是準備好tabenext的數量,剩下的工作會交給vimlist2.sh cmd="$cmd ${tabennn[$(expr $checklinenumber - 26)]}" else echo '[NOTICE] 不要超過35個以上(不含35)的編輯檔案' echo '[NOTICE] 純編輯這個檔案,以及叫出列表,看你要砍掉哪一個' vim "$selectitem" unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem vfff cmd='' fi if [ "$cmd" != '' ]; then cmd="$cmd -p $fast_change_dir_project_config/vimlist-$groupname.txt\"" eval $cmd fi elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then echo "Your want append other file" elif [ "$inputchar" == 'j' ]; then vfff elif [ "$inputchar" == 'k' ]; then vffff else echo "Your want append other file" fi # 最後,顯示目前目錄的檔案 func_checkfilecount elif [ "$groupname" == "" ]; then echo '[ERROR] Argument or $groupname is empty' fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem
gisanfu/fast-change-dir
38d43032460dc2206bceef6524598fe1ec1bf696
fix bug
diff --git a/vimlist-append.sh b/vimlist-append.sh index 62731fb..1046738 100755 --- a/vimlist-append.sh +++ b/vimlist-append.sh @@ -1,188 +1,188 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 # 是否要vff,如果沒有指定,就是會詢問使用者 # 不詢問,不要vff的話,就放0 # 不詢問,要vff的話,就放1 # 想要vff,然後又要多選的狀況,那就放2,也會自動做vff的動作 # 同2,但不要vff的狀況 isVFF=$4 if [ "$isVFF" == '' ]; then isVFF=1 fi item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' if [ ${#item_array[@]} -eq 1 ]; then relativeitem=${item_array[0]} elif [[ ${#item_array[@]} -gt 1 && "$isVFF" == '2' || "$isVFF" == '3' ]]; then for file in ${item_array[@]} do selectitem='' selectitem=`pwd`/$file checkline=`grep $selectitem $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt fi done relativeitem='__empty' elif [ ${#item_array[@]} -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems="" for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem=$result else relativeitem='' fi else relativeitem='' fi if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then if [ "$isVFF" == '0' ]; then inputchar='n' elif [ "$isVFF" == '1' ]; then inputchar='y' elif [ "$isVFF" == '2' ]; then inputchar='y' elif [ "$isVFF" == '3' ]; then inputchar='n' else isVFF='' fi # 這裡可以考慮在加上一項,就是不要append這一個檔案 if [ "$isVFF" == '' ]; then # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' echo '[WAIT] 或是編輯列表 [j]' echo '[WAIT] 還是清空它 [k]' read -n 1 inputchar fi # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append if [ "$relativeitem" != '__empty' ]; then selectitem='' selectitem=`pwd`/$relativeitem checkline=`grep "$selectitem" $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt else echo '[NOTICE] File is exist' fi fi if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... checklinenumber=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` cmd='vff "vim' # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 # 查詢更多資訊請執行: "vim -h" # 為了加快速度而這麼寫的 tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') if [ "$checklinenumber" -lt 10 ]; then cmd="$cmd ${tabennn[$checklinenumber]}" echo $cmd elif [[ "$checklinenumber" -ge 10 && "$checklinenumber" -lt 18 ]]; then # 先把編輯清單陣列1~8(從0開始)清掉,把10到19補進來 # 位置0是所開始的檔案列表 for i in {0..7} do unset item_array[$i] done # 在這裡,只是準備好tabenext的數量,剩下的工作會交給vimlist2.sh - cmd="$cmd ${tabennn[$(expr $checklinenumber - 7)]}" + cmd="$cmd ${tabennn[$(expr $checklinenumber - 8)]}" elif [[ "$checklinenumber" -ge 18 && "$checklinenumber" -lt 27 ]]; then for i in {0..16} do unset item_array[$i] done # 在這裡,只是準備好tabenext的數量,剩下的工作會交給vimlist2.sh cmd="$cmd ${tabennn[$(expr $checklinenumber - 17)]}" elif [[ "$checklinenumber" -ge 27 && "$checklinenumber" -lt 36 ]]; then for i in {0..25} do unset item_array[$i] done # 在這裡,只是準備好tabenext的數量,剩下的工作會交給vimlist2.sh cmd="$cmd ${tabennn[$(expr $checklinenumber - 26)]}" else echo '[NOTICE] 不要超過35個以上(不含35)的編輯檔案' echo '[NOTICE] 純編輯這個檔案,以及叫出列表,看你要砍掉哪一個' vim "$selectitem" unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem vfff cmd='' fi if [ "$cmd" != '' ]; then cmd="$cmd -p $fast_change_dir_project_config/vimlist-$groupname.txt\"" eval $cmd fi elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then echo "Your want append other file" elif [ "$inputchar" == 'j' ]; then vfff elif [ "$inputchar" == 'k' ]; then vffff else echo "Your want append other file" fi # 最後,顯示目前目錄的檔案 func_checkfilecount elif [ "$groupname" == "" ]; then echo '[ERROR] Argument or $groupname is empty' fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem
gisanfu/fast-change-dir
03e607a22596d30028bb37f87a33f02b107e6ee0
add comment
diff --git a/vimlist-append.sh b/vimlist-append.sh index 60aa04f..62731fb 100755 --- a/vimlist-append.sh +++ b/vimlist-append.sh @@ -1,188 +1,188 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 # 是否要vff,如果沒有指定,就是會詢問使用者 # 不詢問,不要vff的話,就放0 # 不詢問,要vff的話,就放1 # 想要vff,然後又要多選的狀況,那就放2,也會自動做vff的動作 # 同2,但不要vff的狀況 isVFF=$4 if [ "$isVFF" == '' ]; then isVFF=1 fi item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' if [ ${#item_array[@]} -eq 1 ]; then relativeitem=${item_array[0]} elif [[ ${#item_array[@]} -gt 1 && "$isVFF" == '2' || "$isVFF" == '3' ]]; then for file in ${item_array[@]} do selectitem='' selectitem=`pwd`/$file checkline=`grep $selectitem $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt fi done relativeitem='__empty' elif [ ${#item_array[@]} -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems="" for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem=$result else relativeitem='' fi else relativeitem='' fi if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then if [ "$isVFF" == '0' ]; then inputchar='n' elif [ "$isVFF" == '1' ]; then inputchar='y' elif [ "$isVFF" == '2' ]; then inputchar='y' elif [ "$isVFF" == '3' ]; then inputchar='n' else isVFF='' fi # 這裡可以考慮在加上一項,就是不要append這一個檔案 if [ "$isVFF" == '' ]; then # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' echo '[WAIT] 或是編輯列表 [j]' echo '[WAIT] 還是清空它 [k]' read -n 1 inputchar fi # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append if [ "$relativeitem" != '__empty' ]; then selectitem='' selectitem=`pwd`/$relativeitem checkline=`grep "$selectitem" $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt else echo '[NOTICE] File is exist' fi fi if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... checklinenumber=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` cmd='vff "vim' # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 # 查詢更多資訊請執行: "vim -h" # 為了加快速度而這麼寫的 tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') if [ "$checklinenumber" -lt 10 ]; then cmd="$cmd ${tabennn[$checklinenumber]}" echo $cmd elif [[ "$checklinenumber" -ge 10 && "$checklinenumber" -lt 18 ]]; then # 先把編輯清單陣列1~8(從0開始)清掉,把10到19補進來 # 位置0是所開始的檔案列表 for i in {0..7} do unset item_array[$i] done # 在這裡,只是準備好tabenext的數量,剩下的工作會交給vimlist2.sh cmd="$cmd ${tabennn[$(expr $checklinenumber - 7)]}" elif [[ "$checklinenumber" -ge 18 && "$checklinenumber" -lt 27 ]]; then for i in {0..16} do unset item_array[$i] done # 在這裡,只是準備好tabenext的數量,剩下的工作會交給vimlist2.sh cmd="$cmd ${tabennn[$(expr $checklinenumber - 17)]}" elif [[ "$checklinenumber" -ge 27 && "$checklinenumber" -lt 36 ]]; then for i in {0..25} do unset item_array[$i] done # 在這裡,只是準備好tabenext的數量,剩下的工作會交給vimlist2.sh cmd="$cmd ${tabennn[$(expr $checklinenumber - 26)]}" else - echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' + echo '[NOTICE] 不要超過35個以上(不含35)的編輯檔案' echo '[NOTICE] 純編輯這個檔案,以及叫出列表,看你要砍掉哪一個' vim "$selectitem" unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem vfff cmd='' fi if [ "$cmd" != '' ]; then cmd="$cmd -p $fast_change_dir_project_config/vimlist-$groupname.txt\"" eval $cmd fi elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then echo "Your want append other file" elif [ "$inputchar" == 'j' ]; then vfff elif [ "$inputchar" == 'k' ]; then vffff else echo "Your want append other file" fi # 最後,顯示目前目錄的檔案 func_checkfilecount elif [ "$groupname" == "" ]; then echo '[ERROR] Argument or $groupname is empty' fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem diff --git a/vimlist2.sh b/vimlist2.sh index 1185ffa..26cedfa 100755 --- a/vimlist2.sh +++ b/vimlist2.sh @@ -1,138 +1,138 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" program=$1 if [ "$groupname" != "" ]; then # 在還沒有處理到vim清單的時候,就己經先將固定的清單處理好了(1項) if [ "$program" == "" ]; then program2="vim -p $fast_change_dir_project_config/vimlist-$groupname.txt" else program2=$program fi cmdlist="cat $fast_change_dir_project_config/vimlist-$groupname.txt" # 正規的外面要用雙引包起來 regex="^vim" # 如果program這個變數是空白,就代表會使用vim-p的指令 # 使用vim,當然不會去開一些binary的檔案 if [[ "$program" == '' || "$program" =~ $regex ]]; then # 先把一些己知的東西先ignore掉,例如壓縮檔 cmdlist="$cmdlist | grep -v .tar.gz | grep -v .zip | grep -v .png | grep -v .gif | grep -v .jpeg | grep -v .jpg" # 這行是判斷是不是文字檔,但是遇到css的檔案,會誤判,所以暫時先mark起來,或許以後用得到 # cmdlist="$cmdlist | xargs -n 1 $fast_change_dir_bin/only-text-filecontent.sh" fi # 這是多行文字檔內容,變成以空格分格成字串的步驟 cmdlist2='| tr "\n" " "' cmdlist="$cmdlist $cmdlist2" cmdlist_result=`eval $cmdlist` cmd="$program2 $cmdlist_result" # 檢查一下數量,如果是一筆的話,那就自動跳到那一筆 # 這樣子只有一筆的時候,會比較方便 # 會這樣子寫,是因為不要去影響其它程式的相依性 if [ "$program" == "" ]; then count=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$count" == 1 ]; then cmd="$cmd +tabnext" fi # 如果大於1筆,就用選擇的方式,選擇第一次要看到的檔案 if [ "$count" -gt 1 ]; then vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) tmpfile="$fast_change_dir_tmp/`whoami`-vimlist2-dialogselect-$( date +%Y%m%d-%H%M ).txt" dialogitems='' start=1 for echothem in ${vimlist_array[@]} do dialogitems=" $dialogitems '$start' $echothem " start=$(expr $start + 1) done cmd2=$( func_dialog_menu '你想從哪一個位置開始編輯 ' 100 "$dialogitems" $tmpfile ) eval $cmd2 result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') if [ "$result" -lt 10 ]; then # 為了加快速度而這麼寫的 cmd="$cmd ${tabennn[$result]}" # 底下是一次9個累加 elif [[ "$result" -ge 10 && "$result" -lt 18 ]]; then # 先把編輯清單陣列1~8(從0開始)清掉,把10到19補進來 # 位置0是所開始的檔案列表 for i in {0..7} do unset vimlist_array[$i] done cmd="$program2 ${vimlist_array[@]}" cmd="$cmd ${tabennn[$(expr $result - 8)]}" elif [[ "$result" -ge 18 && "$result" -lt 27 ]]; then for i in {0..16} do unset vimlist_array[$i] done cmd="$program2 ${vimlist_array[@]}" cmd="$cmd ${tabennn[$(expr $result - 17)]}" elif [[ "$result" -ge 27 && "$result" -lt 36 ]]; then for i in {0..25} do unset vimlist_array[$i] done cmd="$program2 ${vimlist_array[@]}" cmd="$cmd ${tabennn[$(expr $result - 26)]}" else - echo '[NOTICE] 10個以上的tabnext會有問題,所以我略過了:p' + #echo '[NOTICE] 10個以上的tabnext會有問題,所以我略過了:p' + echo '[NOTICE] 不要超過35個以上(不含35)的編輯檔案' fi else # 如果使用者選擇取消,那就取消整個vff cmd="" fi fi else # 如果選擇某一個檔案,這時就會跑以下這個判斷式 count=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) if [[ "$count" -ge 10 && "$count" -lt 20 ]]; then # 先把編輯清單陣列1~8(從0開始)清掉,把10到19補進來 # 位置0是所開始的檔案列表 for i in {1..8} do unset vimlist_array[$i] done elif [[ "$count" -ge 20 && "$count" -lt 30 ]]; then for i in {1..18} do unset vimlist_array[$i] done fi cmd="$program2 ${vimlist_array[@]}" fi if [ "$cmd" != '' ]; then - echo $cmd eval $cmd fi func_checkfilecount else echo '[ERROR] groupname is empty, please use GA cmd' fi unset vimlist_array unset cmd
gisanfu/fast-change-dir
92fa22c46d40471fc1444dcc42a3fb0efbef42f5
fix bug
diff --git a/vimlist-append.sh b/vimlist-append.sh index 1b7c370..60aa04f 100755 --- a/vimlist-append.sh +++ b/vimlist-append.sh @@ -1,172 +1,188 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 # 是否要vff,如果沒有指定,就是會詢問使用者 # 不詢問,不要vff的話,就放0 # 不詢問,要vff的話,就放1 # 想要vff,然後又要多選的狀況,那就放2,也會自動做vff的動作 # 同2,但不要vff的狀況 isVFF=$4 if [ "$isVFF" == '' ]; then isVFF=1 fi item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' if [ ${#item_array[@]} -eq 1 ]; then relativeitem=${item_array[0]} elif [[ ${#item_array[@]} -gt 1 && "$isVFF" == '2' || "$isVFF" == '3' ]]; then for file in ${item_array[@]} do selectitem='' selectitem=`pwd`/$file checkline=`grep $selectitem $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt fi done relativeitem='__empty' elif [ ${#item_array[@]} -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems="" for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem=$result else relativeitem='' fi else relativeitem='' fi if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then if [ "$isVFF" == '0' ]; then inputchar='n' elif [ "$isVFF" == '1' ]; then inputchar='y' elif [ "$isVFF" == '2' ]; then inputchar='y' elif [ "$isVFF" == '3' ]; then inputchar='n' else isVFF='' fi # 這裡可以考慮在加上一項,就是不要append這一個檔案 if [ "$isVFF" == '' ]; then # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' echo '[WAIT] 或是編輯列表 [j]' echo '[WAIT] 還是清空它 [k]' read -n 1 inputchar fi # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append if [ "$relativeitem" != '__empty' ]; then selectitem='' selectitem=`pwd`/$relativeitem checkline=`grep "$selectitem" $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt else echo '[NOTICE] File is exist' fi fi if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... checklinenumber=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` cmd='vff "vim' # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 # 查詢更多資訊請執行: "vim -h" # 為了加快速度而這麼寫的 tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') if [ "$checklinenumber" -lt 10 ]; then cmd="$cmd ${tabennn[$checklinenumber]}" echo $cmd - elif [[ "$checklinenumber" -ge 10 && "$checklinenumber" -lt 20 ]]; then + elif [[ "$checklinenumber" -ge 10 && "$checklinenumber" -lt 18 ]]; then # 先把編輯清單陣列1~8(從0開始)清掉,把10到19補進來 # 位置0是所開始的檔案列表 - for i in {1..8} + for i in {0..7} do unset item_array[$i] done # 在這裡,只是準備好tabenext的數量,剩下的工作會交給vimlist2.sh - cmd="$cmd ${tabennn[$(expr $checklinenumber - 8)]}" + cmd="$cmd ${tabennn[$(expr $checklinenumber - 7)]}" + elif [[ "$checklinenumber" -ge 18 && "$checklinenumber" -lt 27 ]]; then + for i in {0..16} + do + unset item_array[$i] + done + + # 在這裡,只是準備好tabenext的數量,剩下的工作會交給vimlist2.sh + cmd="$cmd ${tabennn[$(expr $checklinenumber - 17)]}" + elif [[ "$checklinenumber" -ge 27 && "$checklinenumber" -lt 36 ]]; then + for i in {0..25} + do + unset item_array[$i] + done + + # 在這裡,只是準備好tabenext的數量,剩下的工作會交給vimlist2.sh + cmd="$cmd ${tabennn[$(expr $checklinenumber - 26)]}" else echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' echo '[NOTICE] 純編輯這個檔案,以及叫出列表,看你要砍掉哪一個' vim "$selectitem" unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem vfff cmd='' fi if [ "$cmd" != '' ]; then cmd="$cmd -p $fast_change_dir_project_config/vimlist-$groupname.txt\"" eval $cmd fi elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then echo "Your want append other file" elif [ "$inputchar" == 'j' ]; then vfff elif [ "$inputchar" == 'k' ]; then vffff else echo "Your want append other file" fi # 最後,顯示目前目錄的檔案 func_checkfilecount elif [ "$groupname" == "" ]; then echo '[ERROR] Argument or $groupname is empty' fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem diff --git a/vimlist2.sh b/vimlist2.sh index e323a49..1185ffa 100755 --- a/vimlist2.sh +++ b/vimlist2.sh @@ -1,116 +1,138 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" program=$1 if [ "$groupname" != "" ]; then # 在還沒有處理到vim清單的時候,就己經先將固定的清單處理好了(1項) if [ "$program" == "" ]; then program2="vim -p $fast_change_dir_project_config/vimlist-$groupname.txt" else program2=$program fi cmdlist="cat $fast_change_dir_project_config/vimlist-$groupname.txt" # 正規的外面要用雙引包起來 regex="^vim" # 如果program這個變數是空白,就代表會使用vim-p的指令 # 使用vim,當然不會去開一些binary的檔案 if [[ "$program" == '' || "$program" =~ $regex ]]; then # 先把一些己知的東西先ignore掉,例如壓縮檔 cmdlist="$cmdlist | grep -v .tar.gz | grep -v .zip | grep -v .png | grep -v .gif | grep -v .jpeg | grep -v .jpg" # 這行是判斷是不是文字檔,但是遇到css的檔案,會誤判,所以暫時先mark起來,或許以後用得到 # cmdlist="$cmdlist | xargs -n 1 $fast_change_dir_bin/only-text-filecontent.sh" fi # 這是多行文字檔內容,變成以空格分格成字串的步驟 cmdlist2='| tr "\n" " "' cmdlist="$cmdlist $cmdlist2" cmdlist_result=`eval $cmdlist` cmd="$program2 $cmdlist_result" # 檢查一下數量,如果是一筆的話,那就自動跳到那一筆 # 這樣子只有一筆的時候,會比較方便 # 會這樣子寫,是因為不要去影響其它程式的相依性 if [ "$program" == "" ]; then count=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$count" == 1 ]; then cmd="$cmd +tabnext" fi # 如果大於1筆,就用選擇的方式,選擇第一次要看到的檔案 if [ "$count" -gt 1 ]; then vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) tmpfile="$fast_change_dir_tmp/`whoami`-vimlist2-dialogselect-$( date +%Y%m%d-%H%M ).txt" dialogitems='' start=1 for echothem in ${vimlist_array[@]} do dialogitems=" $dialogitems '$start' $echothem " start=$(expr $start + 1) done cmd2=$( func_dialog_menu '你想從哪一個位置開始編輯 ' 100 "$dialogitems" $tmpfile ) eval $cmd2 result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then - tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') + tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') if [ "$result" -lt 10 ]; then # 為了加快速度而這麼寫的 cmd="$cmd ${tabennn[$result]}" - elif [[ "$result" -ge 10 && "$result" -lt 20 ]]; then + # 底下是一次9個累加 + elif [[ "$result" -ge 10 && "$result" -lt 18 ]]; then # 先把編輯清單陣列1~8(從0開始)清掉,把10到19補進來 # 位置0是所開始的檔案列表 - for i in {1..8} + for i in {0..7} do unset vimlist_array[$i] done cmd="$program2 ${vimlist_array[@]}" cmd="$cmd ${tabennn[$(expr $result - 8)]}" + elif [[ "$result" -ge 18 && "$result" -lt 27 ]]; then + for i in {0..16} + do + unset vimlist_array[$i] + done + + cmd="$program2 ${vimlist_array[@]}" + cmd="$cmd ${tabennn[$(expr $result - 17)]}" + elif [[ "$result" -ge 27 && "$result" -lt 36 ]]; then + for i in {0..25} + do + unset vimlist_array[$i] + done + + cmd="$program2 ${vimlist_array[@]}" + cmd="$cmd ${tabennn[$(expr $result - 26)]}" else - echo '[NOTICE] 19個以上的tabnext會有問題,所以我略過了:p' + echo '[NOTICE] 10個以上的tabnext會有問題,所以我略過了:p' fi else # 如果使用者選擇取消,那就取消整個vff cmd="" fi fi else # 如果選擇某一個檔案,這時就會跑以下這個判斷式 count=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) if [[ "$count" -ge 10 && "$count" -lt 20 ]]; then - vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) # 先把編輯清單陣列1~8(從0開始)清掉,把10到19補進來 # 位置0是所開始的檔案列表 for i in {1..8} do unset vimlist_array[$i] done + elif [[ "$count" -ge 20 && "$count" -lt 30 ]]; then + for i in {1..18} + do + unset vimlist_array[$i] + done fi cmd="$program2 ${vimlist_array[@]}" fi if [ "$cmd" != '' ]; then + echo $cmd eval $cmd fi func_checkfilecount else echo '[ERROR] groupname is empty, please use GA cmd' fi unset vimlist_array unset cmd
gisanfu/fast-change-dir
542c36612fce2cdbeef05368c82c264d050fb20d
fix bug
diff --git a/vimlist2.sh b/vimlist2.sh index 4c909e1..e323a49 100755 --- a/vimlist2.sh +++ b/vimlist2.sh @@ -1,115 +1,116 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" program=$1 if [ "$groupname" != "" ]; then # 在還沒有處理到vim清單的時候,就己經先將固定的清單處理好了(1項) if [ "$program" == "" ]; then program2="vim -p $fast_change_dir_project_config/vimlist-$groupname.txt" else program2=$program fi cmdlist="cat $fast_change_dir_project_config/vimlist-$groupname.txt" # 正規的外面要用雙引包起來 regex="^vim" # 如果program這個變數是空白,就代表會使用vim-p的指令 # 使用vim,當然不會去開一些binary的檔案 if [[ "$program" == '' || "$program" =~ $regex ]]; then # 先把一些己知的東西先ignore掉,例如壓縮檔 cmdlist="$cmdlist | grep -v .tar.gz | grep -v .zip | grep -v .png | grep -v .gif | grep -v .jpeg | grep -v .jpg" # 這行是判斷是不是文字檔,但是遇到css的檔案,會誤判,所以暫時先mark起來,或許以後用得到 # cmdlist="$cmdlist | xargs -n 1 $fast_change_dir_bin/only-text-filecontent.sh" fi # 這是多行文字檔內容,變成以空格分格成字串的步驟 cmdlist2='| tr "\n" " "' cmdlist="$cmdlist $cmdlist2" cmdlist_result=`eval $cmdlist` cmd="$program2 $cmdlist_result" # 檢查一下數量,如果是一筆的話,那就自動跳到那一筆 # 這樣子只有一筆的時候,會比較方便 # 會這樣子寫,是因為不要去影響其它程式的相依性 if [ "$program" == "" ]; then count=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$count" == 1 ]; then cmd="$cmd +tabnext" fi # 如果大於1筆,就用選擇的方式,選擇第一次要看到的檔案 if [ "$count" -gt 1 ]; then vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) tmpfile="$fast_change_dir_tmp/`whoami`-vimlist2-dialogselect-$( date +%Y%m%d-%H%M ).txt" dialogitems='' start=1 for echothem in ${vimlist_array[@]} do dialogitems=" $dialogitems '$start' $echothem " start=$(expr $start + 1) done cmd2=$( func_dialog_menu '你想從哪一個位置開始編輯 ' 100 "$dialogitems" $tmpfile ) eval $cmd2 result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') if [ "$result" -lt 10 ]; then # 為了加快速度而這麼寫的 cmd="$cmd ${tabennn[$result]}" elif [[ "$result" -ge 10 && "$result" -lt 20 ]]; then # 先把編輯清單陣列1~8(從0開始)清掉,把10到19補進來 # 位置0是所開始的檔案列表 for i in {1..8} do unset vimlist_array[$i] done cmd="$program2 ${vimlist_array[@]}" cmd="$cmd ${tabennn[$(expr $result - 8)]}" else echo '[NOTICE] 19個以上的tabnext會有問題,所以我略過了:p' fi else # 如果使用者選擇取消,那就取消整個vff cmd="" fi fi else # 如果選擇某一個檔案,這時就會跑以下這個判斷式 count=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` + vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) if [[ "$count" -ge 10 && "$count" -lt 20 ]]; then vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) + # 先把編輯清單陣列1~8(從0開始)清掉,把10到19補進來 + # 位置0是所開始的檔案列表 + for i in {1..8} + do + unset vimlist_array[$i] + done fi - # 先把編輯清單陣列1~8(從0開始)清掉,把10到19補進來 - # 位置0是所開始的檔案列表 - for i in {1..8} - do - unset vimlist_array[$i] - done cmd="$program2 ${vimlist_array[@]}" fi if [ "$cmd" != '' ]; then eval $cmd fi func_checkfilecount else echo '[ERROR] groupname is empty, please use GA cmd' fi unset vimlist_array unset cmd
gisanfu/fast-change-dir
332b66425626d20f0092d9e96b8f39324a2bede0
add new feature
diff --git a/IDEA b/IDEA index af21a0b..13dcb84 100644 --- a/IDEA +++ b/IDEA @@ -1,512 +1,521 @@ +# 2012-02-18 + +這個pushd和popd的概念可以參考一下,雖然不是很好用 +http://usagiblog.wordpress.com/2006/02/18/pushd-%E5%92%8C-popd/ + +想要在vim的地方加一個東西 +當超過10個檔案,就編輯下10個檔案,有點像是分頁 +雖然vim可以設定開幾個檔案,可是vim的引數+是有限制的,剛剛好就是10個 + # 2011-10-30 在command-line下看圖片的軟體,或許可以結合看看 http://inouire.net/archives/image-couleur_source.tar.gz # 2011-06-19 想要加上以下的範例指定進來 echo "hello" | xclip 可以把hello貼到clipboard裡面,然後回到vim貼上, 在ubuntu是按mouse的中鍵, windows裡面使用putty可能要測試一下。 # 2011-05-15 想要加上"cd -"的指令進來 # 2011-04-17 想要寫abc第4個版本 這個版本的特色為: - 不會即時搜尋各功能 - 當然也不會顯示搜尋後的結果 - 點確認以後,才會開始搜尋,以及各功能所會做的動作 - 為了要增加執行的效率,才會做這一個版本 - 先做基本的功能(本層、上層的檔案和資料夾處理),如果效率沒有問題,在加寫其它的功能 - 如果有重覆的,就用dialog menu - relativeitem或許可以取消cache功能 - 使用各快速鍵來啟動該功能,例如我輸入了eeee,然後按大寫F,來搜尋本層的檔案,如果只有一筆,那就加入暫存列表,並直接編輯它 # 2011-04-16 想用python重寫relativeitem 當有人在問它的時候,就會同時找以下的東西: 1. 本層的檔案和資料夾 2. 上一層的檔案和資料夾 找到了以後,第一次會將列表寫入檔案, 可能會給檔案一個編號當檔名,這個編號也會回傳給bash abc-v3主程式 當下一個relative開始,就會帶著這個編號去問新的程式, 這時新的程式,可以用這個編號去找檔案,而不用重新取得列表。 # 2011-04-15 1. 在vff的前面,加一個flow,選擇你要編輯的檔案 2. 正在想,要不要加入其它的語言,為了增加效率 # 2011-04-14 可以把各專案的設定檔,放到各專案的資料夾裡面, 不過關於這一點,可能要改很多地方。 # 2011-04-12 想要把資料夾和檔案的檔名,寫到一支文字檔裡面, 然後增加一個功能,對那個文字檔做控制 # 2011-03-22 可以把Groupname,在abc version3裡面,加上dialog的選擇功能 # 2011-03-01 在ide階段,想要不輸入東西,就可以使用F和D以及上一層的功能, 使用的方式為dialog。 增加這個功能了以後,感覺更好用了。 想要在vf詢問的地方,加上"是否使用純vim編輯,而不列入暫存"的選項 詢問過後,程式才會決定要不要寫入暫存 # 2011-02-21 看能不能在啟動ide之前,先去update(應該是說git pull)最新的資料, 這樣子就可以做最快速的同步, 希望目前原有的fast-change-dir-config的目標,能夠改成自己的git repo,比較安全, 不過這裡是點奇怪的,又想要private repo,但又想要密碼驗證,然後又想要安全性, 最好的方式,應該是每一個target或者說是End端,都要有一個類似驗證碼的東西, 送上去的時候,不是我的人就不能送上去, 目前還沒有想到一個比較好的方式。 應該是說,可以抓下去,要透過驗證碼 (每一台,或是每一個權限,使用的驗證碼都不一樣), 要送上去的時候,是需要密碼的,這樣子的方式應該是比較好的方式。 送上去的時候,可能是送到我自己的svn repo, 送上去以後,會export到某一個http的路徑, 然後我透過http simple auth,讓該權限來下載東西,或是更新東西下去, 但如果是這種作法的話,要怎麼樣上傳呢? 好像想的太複雜了@@。 # 2011-02-18 有想到一個功能, 如果我想要去一個資料夾, 它是在某一個資料下底下, 這種狀況常常會發生,就是進去上一個資料夾以後,就忘了下一個資料夾要去哪裡了。 所以想做一個功能,就是先輸入下一個條件,在然在進去第一個資料夾, 當第一個資料夾進去了以後,就會自動處理在暫存的指令, 不過後來想一想,其實如果是在本機操作,也可以進去第一層,然後按"R",啟動nautilus, 用GUI去操作。 # 2011-02-16 想要加上git的路徑(我指的是1.7的git) 不然又需要root權限了 想要多錯字處理的功能, 例如我輸入了misc, 打錯成為mics, 這時是可以判斷的,不過細節的部份要在思考一下, 而且這個功能,可能也會造成速度變慢,或許是不需要做的 # 2011-02-14 想要做一個功能,是不受groupname限制的, 很像是ssh txtfile的功能, 就是輸入一個關鍵字,可能就會跳到那一個資料夾裡面, 因為有時候很累的時候,跟本就沒有辦法輸入快速鍵。 # 2011-02-10 想要寫一支script,針對Zend Framework的架構, 匯出dirpoint的檔案出來, 可能可以針對root、module name等變數來做組合,以及匯出。 # 2011-02-01 想要把function放到lib/func資料夾裡面。 想要把片段程式碼放到lib/某一個資料夾裡面,可能是several, 想在abc-v3的第二個引數,加上@小老鼠,使用在position 還想要更改所有的文字檔到指定的某個位置, 除了路徑以外,檔名都要是變數,都是可以被修改的。 例如是放在~/git/公司名稱_某分類名稱/, 然後如果在公司做到一個地方,可以把裡面的東西,先存起來, 將整個設定和環境一起帶到另外一台電腦上面。 暫存的路徑是需要的,但是檔名應該先不需要, 其它的應該都是需要的。 # 2011-01-31 目前己經有一個輸入@小老鼠,可以為grep加上^的指令, 我想加一個#井字號,告訴程式我想要使用dialog menu的方式來選擇我要的東西, 經測試了以後,發現不能夠在bash function裡面,下dialog的指令, 所以這個功能必需要在函式以外的地方先處理, 感覺很麻煩,不過也蠻實用的。 # 2011-01-30 能不能讓每一個group,都有自己的設定檔, 例如home的group,可能就會啟動parent-item的功能, 而某程式設計的專案,可能就會因為感覺良好,而關閉它。 # 2011-01-29 能不能在同一個func_relative裡面, 同時做同個資料夾的item處理,以及上一層資料夾內的item處理呢? 能否使用C語言來改寫func_relative的函式, 然後讓bash來呼叫,看能不能改善效率, 讓反應速度能夠跟上我的操作速度, 在呈現的部份。 # 2011-01-28 有機會想要做web的部份。 關於資料夾、或是檔案碰到多筆的狀況, 可以多一個使用dialog menu的選擇來協助, 關於資料夾的部份,可以使用.(點)的快速鍵。 不過好像太麻煩了,可以試著按斜線清掉執行鍵, 然後想想如何使用更好的關鍵字來對它選取, 然後將它記錄在腦海裡面,下次就使用新的或是更好的方式來選擇該項目。 # 2011-01-27 對於vf按y和n,有想到一個方式 就是先把.(點)改回來, 可能把點使用在append-vff, 而;(分號),就是append+vff, 這樣子keyin的數量應該會少很多, 效率應該會比較快。 不過這個idea可能不會用在數字模式上,因為狀況不同 另外,如果輸入錯了快速鍵,或是打錯關鍵字, 想要暫停2秒鐘,然後自動清除關鍵字,並重來, 這樣子可能也多多少少增加一些速度, 不然打錯了還要手動去按一下/(斜線) 有時候按斜線還會按錯 分號,在切換資料夾的時候,可以想看看有沒有什麼其它的應用。 關鍵字的部份好像有點問題, 如果某一個物件名稱是aaabbb, 我輸入aa bb是可以找得到的, 但是如果我輸入bb aa好像是找不到的。 # 2011-01-26 想要把abc v3的第一次顯示help的部份拿掉 想加上更多操作檔案的功能 例如之前idea前寫過的: 執行檔案(依照副檔名) 刪除檔案(當然要可以刪除單檔、多檔,或是針對資料夾,或是混合) 更改名稱 移動路徑 想要在touch檔案以後,順便去編輯它 如果是在有啟動groupname的時候,步驟就會走到詢問你要不要vff的階段 touch檔案,應該是使用dialog的方式才對 刪除的功能,在C的快速鍵中,感覺不是很實用 目前是用C來當做Create,感覺還不錯 看要不要在建立另外一個關鍵字,來做刪除的動作 刪除的動作,也可以考慮不要做,改用cli, or nautilus來做會比較保險。 # 2011-01-25 想要在每一個版本控制功能中, 都加上R功能,也就是切換到Browser。 # 2011-01-22 想要在按分號的時候,就直接編輯檔案(如果是選檔案是在第一項) 就不要在按Y的,很麻煩,也為了可以簡化。 但是,如果我只是想append,但還沒有要edit,那這時怎麼辦呢? 是不是也是要維持現在的使用方式就可以了呢? 可以在append,詢問Y和N的地方,加上分號,或是F當做Y, 但這樣子不知道會不會換右手酸了。 目的還是要簡少按鍵數量。 或是在多一個快速鍵,跟F結合在一起,可能是寫在F,裡面在多一個判斷, 目的是要把append檔案的部份,分一個Y的,和一個N的。 另外,想加一個C快速鍵,就是選到項目的時候所使用的, 裡面可以刪除檔案、等其它額外擴充的功能 還有,別忘了還有一個IDEA需要被完成,就是判斷副檔名的部份。 就是在vim -p files...的時候,如果副檔名是.tar.gz、zip、image file等東西, 在vim的部份,就是會ignore它們。 # 2011-01-18 想要把原先放在/bin下的執行檔,都改放在自己的家目錄, 這樣子在有些沒有root的環境下,才可以使用, 而且這樣子也比較合理 不過有些檔案的目標路徑,是寫死的, 利用這個idea把它們都做個修正。 # 2011-01-17 想要在vimlist的功能,加上判斷副檔名的功能, 如果是使用vim編輯的話,就會乎略掉某些副檔名, 例如tar.gz, zip, images, videos, music # 2011-01-13 想要在vf的地方,加上以下的功能項目: 1. execute 2. delete execute的部份,可能就會判斷副檔名, 刪除的部份,可能會用D的關鍵字來做。 # 2011-01-11 想要在/斜線的地方,加上重新去include檔案的程式碼, 這樣子如果修改了searchfile, or searchdir,把它設定為啟動, 這時只要按一下斜線,就可以生效了 設定檔的地方,想要在加上bash history, 以及google search function 另外,以現在的使用方式,是增加判斷式和google groupname, 這樣子的使用方式,跟我新增設定檔的目標是很像的, 打算選擇設定檔的方式,在加上面的idea,可能會比較好使用。 # 2011-01-09 想要在各version control裡面的push之前, 加上"處理中..."的字眼,或者是顯示執行的指令。 在要增加一些功能的開關設定, 因為不管是在比較慢的電腦,或是比較快的,上執行這套程式,會很慢, 例如搜尋檔案的功能,或者是搜尋bash history的功能, 或許我可以把這些開關的設定,寫在某一支bash file裡面, 要使用的時候,才去修改它, 然後abc-v3就去include它。 # 2011-01-07 想要加一個快速鍵,來show/hide Help,應該就是大寫的H了 想要加上一個功能,就是按下vim的F8,就會離開vim,以及重新啟動vimlist的功能, 當然這個功能要先選擇groupname,這個功能是可以做的, 可能就離開前先寫入文字檔,然後abc-v3去判斷文字檔內是否有內容, 有的話在重新啟動vimlist的功能,因為不是很重要,所以暫時先不用寫 有沒有可能在vim裡面,按某一個快速鍵,然後就會把menu列出來讓你選擇, 或是可以讓你用快速鍵去選擇裡面的項目。 # 2011-01-03 想要加上切換到firefox的快速鍵 以及想要把切換的程式,加上引數,可以選擇切換後,要不要按下重整的按鈕。 另外,想要在啟動ide and abc-v3的時候,如果groupname是空白,就自動補上home, 關於這個idea在想想看,因為空groupname也是有我設計的理念在裡面,先不要拿掉好了。 # 2011-01-01 在abc-v3的V快速鍵中, 想要check current dir是否有.svn or .hg or .git的資料夾, 如果有的話,就直接啟用該版本控制, 還有,這個功能選擇版本控制的快速鍵,想要大小寫都可以使用。 我想在各版本控制的介面中,加上抓repo的功能下來,但這個IDEA好像不是很實用。 # 2010-12-31 想要將版本控制都放在一起, 例如按V(Version),就代表版本控制, 然後就會出現H(hg), G(git), S(Svn), C(cvs這個應該不會做) 一樣也是按快速鍵去執行它 在要加上第2層的判斷, 可能試著執行status,例如git status, 如果有正常的反應,我指的是在正確的repo裡面, 那這時我就會判斷正常,來執行指定的版本控制的指令。 # 2010-12-26 想要思考一下,怎麼樣在commander與cli之間做快速的切換, 有想到幾種方式: 1. 輸入一個快速鍵,然後會顯示讓你輸入指令的地方,只執行一次就會回到commander 2. 離開commander以後,可以任意的輸入指令,然後透過輸入某個指令,就會回到commander 3. 利用Ctrl+Z,把現在執行的東西放到background,透過fg把commander叫起來 4. 把MC啟動很慢的問題解決掉 5. 開2個視窗,用alt + tab切換 6. 開2個電腦,分別用不同的鍵盤 目前有加上nautilus,在abc裡面,所以未來我可以直接離開,或是不使用ide的指令, 如果要執行指令的時候,直接離開abc,如果指令打完,在輸入abc啟動ide就可以了。 # 2010-12-16 想要更改現在目前爛爛的svnn功能, 以及想要新增hg進來,不然就叫做hgg。 另外,svnn和hg,想要加上一個功能, commit cache的功能, 就是送出指定的檔案, 會想加上這個功能, 是因為有些檔案是我不想要送的檔案, 或是說,有些檔案己經完成了,但其它的檔案還在修改當中。 這個cache,想要寫在一個文字檔裡面,類似vimlist, 以svn來說,只要commit,就會送出了,這是與hg不同的地方, 我打算在送出了之後,就清空這個cache, 這個cache,我想取名為svnlist(svn commit list) 關於cache的功能,有一些想法: 1. 全部列入(或取消)cache 2. 關鍵字選擇單項(或多項)項目列入(或取消)cache 3. 觀看修改的內容,使用svn diff的指令,跟最後一個版本做比較 4. svn add的功能 5. 可以選擇清除cache, and uncache file 6. 可以選擇重新建立uncache file 這個會比較複雜,會有4種模式(gitv2只有2種) 每一個模式都可以下commit的指令 1. svn status, filter by untracked, or new file, 其它都沒有哦 2. svn status, filter by added, or deleted, modify一定會在裡面的(我想取commit list) 3. uncache list(這個還是要有,會比較方便) 4. cache list 在模式1的時候,可以使用關鍵字來對沒有被svn add的檔案操作, 然後會忽略掉modify或是己被svn add的檔案, commit list反之。 關於模式3,只要模式1有動作,就會重新輸出uncache file,也會清空cache file, 會這樣子做,是因為沒有svn-add的檔案(狀態為問號),是沒有辦法被commit的,請注意! 還是把模式1,變成狀態只能是問號的 另外,我想把寫入檔案這個動作,寫成bash function, 因為這個動作看起來還蠻常用的。 # 2010-12-15 搜尋google的功能, 除了想獨立一個功能來做以外, 還想要在abc3也想加上這一個功能, 不過可能只會搜尋一筆, 因為如果很多筆的話,abc3會變的很亂。 # 2010-12-14 想要加上搜尋google的功能, 請參考study/google-search.pl檔案, 當輸入關鍵字的時候,就會順便去搜尋Google, 然後我可以去選擇我想要的項目編號, 選了之後,就會用firefox指令去開啟該網址, 並且切換到firefox的視窗。 可能會新增一個項目,來放這個新功能, 然後英文模式在透過某一個快速鍵來連到這一個功能 另外,我在想要不要使用firefox, 理論上來說,我應該選擇的是links或是其它文字型的瀏覽器。 我看,還是做一個選項之類的東西,來切換瀏覽器。 後來找到了w3m,打算使用這一個。 如果要使用這個功能,請建立google這一個groupname。 使用text browser有一個好處,因為很多主機是沒有圖型介面的, 而且都是放在機房,如果沒有帶自己筆記型電腦過去,是上不了Google查資料的。 # 2010-12-10 想要加一個功能,是在輸入關鍵字的時候, 也順便去搜尋底下的資料夾, 當選擇的時候,當然是進去那一個資料夾裡面。 不過這個功能我不打算加入groupname功能內。 # 2010-12-03 在想要不要把MC加進來, 在create, delete資料夾或是文字檔的時候, 或是在copy, move, rename的時候, 轉使用MC工具,不過MC啟動的時候有點慢,大約要10秒鐘, 而且使用-s or -b的引數都還是很慢, 我在找找看有沒有其它的使用選擇。 # 2010-11-30 在想要不要增加一些系統的元素進來, 例如: sudo or leave sudo edit hosts edit php.ini edit apache conf(s) edit or tail message, dmesg start restart service search bash history(只是有些指令在cli下執行會卡住) ssh remote server 以上這個話題,可以分一些思考點出來 1. 編輯檔案的部份,可以參考dirpoint的作法 2. 搜尋檔案內容的部份,就比較單純 3. sudo 可能就要在想一下了,可能就下sudo的指令,然後我可能不要打密碼, 接下來會切換到root,這時會自動用root來執行ide或是abc。 4. start restart service, 可能需要搭配dialog來做。 5. ssh remote server, 這可能會蠻實用的,我可能會先寫入一個文字檔列表, 這個功能應該很單純,然後是全域的,不會被groupname所區分。 關於上述第1點, 可以設定檔案的virtual徑捷,例如我輸入config,這時可能會出現aaa.xml出來, 可能要想一下,這一點是否真的實用才做。 後來想一想,可能不太實用,因為我還有搜尋的功能,假設在任何地方輸入aaa, 還是會出現aaa.xml 有些功能,我在想,可能不需要,或是不能用.(點)來做選擇, 一定要用所指定的快速鍵來選擇該功能,這樣可能比較不會有誤動作。 # 2010-11-24 我新增了一個study,是可以自動切換到指定的視窗,然後送指令. 我想利用這個study,做以下的動作: 1. In Gnome-terminal vim edit file 2. 離開vim,然後執行某一個快速鍵,這時會切到firefox,然後重新整理頁面 3. 也會在回到vim 這個動作可能可以想一下應用 # 2010-11-18 想把abc裡面的重覆項目, 做一些功能選擇, 1. 將這些項目,append到vimlist 2. 在這些項目中做多項的選擇,一樣會把所選擇的結果append到vimlist中 應該除了ga和dvv功能以外,其它功能都想要套用以上的功能 diff --git a/vimlist-append-files.sh b/vimlist-append-files.sh index 93a08bd..e4e4925 100755 --- a/vimlist-append-files.sh +++ b/vimlist-append-files.sh @@ -1,66 +1,65 @@ #!/bin/bash # 這支程式是設計給搜尋功能,用來append多個檔案所使用 files=($@) if [ "$groupname" != '' ]; then for file in ${files[@]} do # 取得實際的路徑 # 這裡可能有以下幾種狀況: # ../aaa.txt # ./aaa.txt # aaa.txt # /home/user/aaa.txt absoluteitem_path=`readlink -m $file` checkline=`grep "$absoluteitem_path" $fast_change_dir_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$absoluteitem_path\"" >> $fast_change_dir_config/vimlist-$groupname.txt fi done # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' echo '[WAIT] 或是編輯列表 [j]' echo '[WAIT] 還是清空它 [k]' read -n 1 inputchar if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... checklinenumber=`cat $fast_change_dir_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$absoluteitem_path" | head -n 1 | awk -F: '{print $1}'` cmd='vff "vim' - # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 - # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 + # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數,因為vim只能接受10個+ # 查詢更多資訊請執行: "vim -h" if [ "$checklinenumber" -lt 10 ]; then for i in `seq 1 $checklinenumber` do cmd="$cmd +tabnext" done else echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' fi cmd="$cmd -p $fast_change_dir_config/vimlist-$groupname.txt\"" eval $cmd elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then echo "Your want append other file" elif [ "$inputchar" == 'j' ]; then vfff elif [ "$inputchar" == 'k' ]; then vffff else echo "Your want append other file" fi else vim -p ${files[@]} fi # 結束前,把這裡所用到的變數給清空 files='' file='' inputvar='' checkline='' cmd='' checklinenumber='' diff --git a/vimlist-append.sh b/vimlist-append.sh index 36caffb..1b7c370 100755 --- a/vimlist-append.sh +++ b/vimlist-append.sh @@ -1,160 +1,172 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 # 是否要vff,如果沒有指定,就是會詢問使用者 # 不詢問,不要vff的話,就放0 # 不詢問,要vff的話,就放1 # 想要vff,然後又要多選的狀況,那就放2,也會自動做vff的動作 # 同2,但不要vff的狀況 isVFF=$4 if [ "$isVFF" == '' ]; then isVFF=1 fi item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' if [ ${#item_array[@]} -eq 1 ]; then relativeitem=${item_array[0]} elif [[ ${#item_array[@]} -gt 1 && "$isVFF" == '2' || "$isVFF" == '3' ]]; then for file in ${item_array[@]} do selectitem='' selectitem=`pwd`/$file checkline=`grep $selectitem $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt fi done relativeitem='__empty' elif [ ${#item_array[@]} -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems="" for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem=$result else relativeitem='' fi else relativeitem='' fi if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then if [ "$isVFF" == '0' ]; then inputchar='n' elif [ "$isVFF" == '1' ]; then inputchar='y' elif [ "$isVFF" == '2' ]; then inputchar='y' elif [ "$isVFF" == '3' ]; then inputchar='n' else isVFF='' fi # 這裡可以考慮在加上一項,就是不要append這一個檔案 if [ "$isVFF" == '' ]; then # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' echo '[WAIT] 或是編輯列表 [j]' echo '[WAIT] 還是清空它 [k]' read -n 1 inputchar fi # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append if [ "$relativeitem" != '__empty' ]; then selectitem='' selectitem=`pwd`/$relativeitem checkline=`grep "$selectitem" $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt else echo '[NOTICE] File is exist' fi fi if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... checklinenumber=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` cmd='vff "vim' # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 # 查詢更多資訊請執行: "vim -h" + + # 為了加快速度而這麼寫的 + tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') if [ "$checklinenumber" -lt 10 ]; then - # 為了加快速度而這麼寫的 - tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') cmd="$cmd ${tabennn[$checklinenumber]}" + echo $cmd + elif [[ "$checklinenumber" -ge 10 && "$checklinenumber" -lt 20 ]]; then + # 先把編輯清單陣列1~8(從0開始)清掉,把10到19補進來 + # 位置0是所開始的檔案列表 + for i in {1..8} + do + unset item_array[$i] + done + + # 在這裡,只是準備好tabenext的數量,剩下的工作會交給vimlist2.sh + cmd="$cmd ${tabennn[$(expr $checklinenumber - 8)]}" else echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' echo '[NOTICE] 純編輯這個檔案,以及叫出列表,看你要砍掉哪一個' vim "$selectitem" unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem vfff cmd='' fi if [ "$cmd" != '' ]; then cmd="$cmd -p $fast_change_dir_project_config/vimlist-$groupname.txt\"" eval $cmd fi elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then echo "Your want append other file" elif [ "$inputchar" == 'j' ]; then vfff elif [ "$inputchar" == 'k' ]; then vffff else echo "Your want append other file" fi # 最後,顯示目前目錄的檔案 func_checkfilecount elif [ "$groupname" == "" ]; then echo '[ERROR] Argument or $groupname is empty' fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem diff --git a/vimlist2.sh b/vimlist2.sh new file mode 100755 index 0000000..4c909e1 --- /dev/null +++ b/vimlist2.sh @@ -0,0 +1,115 @@ +#!/bin/bash + +source "$fast_change_dir_func/normal.sh" +source "$fast_change_dir_func/dialog.sh" + +program=$1 + +if [ "$groupname" != "" ]; then + # 在還沒有處理到vim清單的時候,就己經先將固定的清單處理好了(1項) + if [ "$program" == "" ]; then + program2="vim -p $fast_change_dir_project_config/vimlist-$groupname.txt" + else + program2=$program + fi + + cmdlist="cat $fast_change_dir_project_config/vimlist-$groupname.txt" + + # 正規的外面要用雙引包起來 + regex="^vim" + + # 如果program這個變數是空白,就代表會使用vim-p的指令 + # 使用vim,當然不會去開一些binary的檔案 + if [[ "$program" == '' || "$program" =~ $regex ]]; then + # 先把一些己知的東西先ignore掉,例如壓縮檔 + cmdlist="$cmdlist | grep -v .tar.gz | grep -v .zip | grep -v .png | grep -v .gif | grep -v .jpeg | grep -v .jpg" + + # 這行是判斷是不是文字檔,但是遇到css的檔案,會誤判,所以暫時先mark起來,或許以後用得到 + # cmdlist="$cmdlist | xargs -n 1 $fast_change_dir_bin/only-text-filecontent.sh" + fi + + # 這是多行文字檔內容,變成以空格分格成字串的步驟 + cmdlist2='| tr "\n" " "' + cmdlist="$cmdlist $cmdlist2" + cmdlist_result=`eval $cmdlist` + cmd="$program2 $cmdlist_result" + + # 檢查一下數量,如果是一筆的話,那就自動跳到那一筆 + # 這樣子只有一筆的時候,會比較方便 + # 會這樣子寫,是因為不要去影響其它程式的相依性 + if [ "$program" == "" ]; then + count=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` + + if [ "$count" == 1 ]; then + cmd="$cmd +tabnext" + fi + + # 如果大於1筆,就用選擇的方式,選擇第一次要看到的檔案 + if [ "$count" -gt 1 ]; then + vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) + tmpfile="$fast_change_dir_tmp/`whoami`-vimlist2-dialogselect-$( date +%Y%m%d-%H%M ).txt" + dialogitems='' + start=1 + for echothem in ${vimlist_array[@]} + do + dialogitems=" $dialogitems '$start' $echothem " + start=$(expr $start + 1) + done + cmd2=$( func_dialog_menu '你想從哪一個位置開始編輯 ' 100 "$dialogitems" $tmpfile ) + + eval $cmd2 + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" != "" ]; then + tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') + if [ "$result" -lt 10 ]; then + # 為了加快速度而這麼寫的 + cmd="$cmd ${tabennn[$result]}" + elif [[ "$result" -ge 10 && "$result" -lt 20 ]]; then + # 先把編輯清單陣列1~8(從0開始)清掉,把10到19補進來 + # 位置0是所開始的檔案列表 + for i in {1..8} + do + unset vimlist_array[$i] + done + + cmd="$program2 ${vimlist_array[@]}" + cmd="$cmd ${tabennn[$(expr $result - 8)]}" + else + echo '[NOTICE] 19個以上的tabnext會有問題,所以我略過了:p' + fi + else + # 如果使用者選擇取消,那就取消整個vff + cmd="" + fi + fi + else + # 如果選擇某一個檔案,這時就會跑以下這個判斷式 + count=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` + if [[ "$count" -ge 10 && "$count" -lt 20 ]]; then + vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) + fi + # 先把編輯清單陣列1~8(從0開始)清掉,把10到19補進來 + # 位置0是所開始的檔案列表 + for i in {1..8} + do + unset vimlist_array[$i] + done + + cmd="$program2 ${vimlist_array[@]}" + fi + + if [ "$cmd" != '' ]; then + eval $cmd + fi + func_checkfilecount +else + echo '[ERROR] groupname is empty, please use GA cmd' +fi + +unset vimlist_array +unset cmd
gisanfu/fast-change-dir
69d2a6fde96b5b3e55711e42ab8f69041b02fb35
add tree function
diff --git a/abc-4.sh b/abc-4.sh index 100d7e5..1a71d61 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,457 +1,497 @@ #!/bin/bash source "$fast_change_dir/config/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color +fast_change_dir_switch_list='1' + while [ 1 ]; do clear fast_change_dir_auto_list_file_enable='0' if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' - ignorelist=$(func_getlsignore) - cmd="ls -AF $ignorelist --color=auto" - eval $cmd + if [ "$fast_change_dir_switch_list" == '2' ]; then + tree -L 1 + elif [ "$fast_change_dir_switch_list" == '3' ]; then + tree -L 1 -d + elif [ "$fast_change_dir_switch_list" == '4' ]; then + tree -L 2 + elif [ "$fast_change_dir_switch_list" == '5' ]; then + tree -L 2 -d + else + ignorelist=$(func_getlsignore) + cmd="ls -AF $ignorelist --color=auto" + eval $cmd + fi + if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 將單檔案列入暫存,並使用vim編輯它們 (;) 分號' echo ' 只將單檔案列入暫存 (;) 分號' echo ' 將多個檔案列入暫存,並使用vim編輯它們 (*)' echo ' 只將多個檔案列入暫存 (&)' + echo ' 切換檔案列表的方式 (T)' echo ' 上一層 (,) 逗點' echo ' 上一個資料夾 (<) 小於,跟上一層是同一個按鍵' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' 利用檔案做索引,進入該檔案所在的資料夾 (O)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' elif [ "$inputvar" == '*' ]; then inputvar='FF' elif [ "$inputvar" == '&' ]; then inputvar='FFF' elif [ "$inputvar" == ':' ]; then inputvar='FFFF' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear fast_change_dir_auto_list_file_enable='1' unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue elif [ "$inputvar" == '<' ]; then cd - clear_var_all='1' continue # 想拉一個檔案進來,接下來會做vff的動作 elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue # 想拉一個檔案進來,但是不啟用vff的狀況 elif [ "$inputvar" == 'FFFF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 0" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 0" fi eval $run clear_var_all='1' continue # 多選功能在使用的,只支援本層 elif [ "$inputvar" == 'FF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" fi eval $run clear_var_all='1' continue # 多選功能在使用的,只支援本層(不啟動vff) elif [ "$inputvar" == 'FFF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 3" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 3" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'O' ]; then d2ff clear_var_all='1' continue + elif [ "$inputvar" == 'T' ]; then + array=(ls Tree顯示全部 Tree只顯示資料夾 Tree顯示全部2層 Tree只顯示資料夾2層) + dialogitems='' + start=1 + for echothem in ${array[@]} + do + dialogitems=" $dialogitems '$start' $echothem " + start=$(expr $start + 1) + done + tmpfile="$fast_change_dir_tmp/`whoami`-abc4T-dialogselect-$( date +%Y%m%d-%H%M ).txt" + cmd2=$( func_dialog_menu '選擇檔案列表的方式 ' 100 "$dialogitems" $tmpfile ) + + eval $cmd2 + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" != "" ]; then + fast_change_dir_switch_list=$result + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd
gisanfu/fast-change-dir
a5060ac806786fc4b79c1b057fb3bdf8b0a183b8
fix bug
diff --git a/cddir2-ui.sh b/cddir2-ui.sh index 8d28ffd..2524baa 100755 --- a/cddir2-ui.sh +++ b/cddir2-ui.sh @@ -1,72 +1,73 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" if [ "$groupname" != "" ]; then cmdlist="cat $fast_change_dir_project_config/vimlist-$groupname.txt" # 這是多行文字檔內容,變成以空格分格成字串的步驟 cmdlist2='| tr "\n" " "' cmdlist="$cmdlist $cmdlist2" cmdlist_result=`eval $cmdlist` cmd="d2 " # 檢查一下數量,如果是一筆的話,那就自動跳到那一筆 # 這樣子只有一筆的時候,會比較方便 # 會這樣子寫,是因為不要去影響其它程式的相依性 count=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` #if [ "$count" == 1 ]; then # cmd="$cmd +tabnext" #fi # 如果大於1筆,就用選擇的方式,選擇第一次要看到的檔案 if [ "$count" -gt 1 ]; then vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) tmpfile="$fast_change_dir_tmp/`whoami`-cddir2-ui-dialogselect-$( date +%Y%m%d-%H%M ).txt" dialogitems='' start=1 for echothem in ${vimlist_array[@]} do dialogitems=" $dialogitems '$start' $echothem " start=$(expr $start + 1) done cmd2=$( func_dialog_menu '選擇一個檔案位置進入該資料夾 ' 100 "$dialogitems" $tmpfile ) eval $cmd2 result=`cat $tmpfile` - echo $result if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then if [ "$result" -lt 10 ]; then # 為了加快速度而這麼寫的 #tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') #cmd="$cmd ${tabennn[$result]}" #echo ${vimlist_array[$(expr $result + 1)]} cmd="$cmd ${vimlist_array[$(expr $result - 1)]}" else echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' fi else # 如果使用者選擇取消,那就取消整個vff cmd="" fi + elif [ "$count" -eq 1 ]; then + vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) + cmd="$cmd ${vimlist_array[0]}" fi if [ "$cmd" != '' ]; then - echo $cmd eval $cmd fi func_checkfilecount else echo '[ERROR] groupname is empty, please use GA cmd' fi unset vimlist_array unset cmd
gisanfu/fast-change-dir
ad1fd89369e50edf83a9f8a606eb647bb525b922
add comment
diff --git a/abc-4.sh b/abc-4.sh index ffdbc06..100d7e5 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,456 +1,457 @@ #!/bin/bash source "$fast_change_dir/config/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color while [ 1 ]; do clear fast_change_dir_auto_list_file_enable='0' if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 將單檔案列入暫存,並使用vim編輯它們 (;) 分號' echo ' 只將單檔案列入暫存 (;) 分號' echo ' 將多個檔案列入暫存,並使用vim編輯它們 (*)' echo ' 只將多個檔案列入暫存 (&)' echo ' 上一層 (,) 逗點' echo ' 上一個資料夾 (<) 小於,跟上一層是同一個按鍵' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' + echo ' 利用檔案做索引,進入該檔案所在的資料夾 (O)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' elif [ "$inputvar" == '*' ]; then inputvar='FF' elif [ "$inputvar" == '&' ]; then inputvar='FFF' elif [ "$inputvar" == ':' ]; then inputvar='FFFF' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear fast_change_dir_auto_list_file_enable='1' unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue elif [ "$inputvar" == '<' ]; then cd - clear_var_all='1' continue # 想拉一個檔案進來,接下來會做vff的動作 elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue # 想拉一個檔案進來,但是不啟用vff的狀況 elif [ "$inputvar" == 'FFFF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 0" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 0" fi eval $run clear_var_all='1' continue # 多選功能在使用的,只支援本層 elif [ "$inputvar" == 'FF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" fi eval $run clear_var_all='1' continue # 多選功能在使用的,只支援本層(不啟動vff) elif [ "$inputvar" == 'FFF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 3" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 3" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'O' ]; then d2ff clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd
gisanfu/fast-change-dir
f9aca7f860a52f0aefd60d55a7068a8dfbc21805
makd filename index to switch directory
diff --git a/abc-4.sh b/abc-4.sh index cc8b309..ffdbc06 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,452 +1,456 @@ #!/bin/bash source "$fast_change_dir/config/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color while [ 1 ]; do clear fast_change_dir_auto_list_file_enable='0' if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 將單檔案列入暫存,並使用vim編輯它們 (;) 分號' echo ' 只將單檔案列入暫存 (;) 分號' echo ' 將多個檔案列入暫存,並使用vim編輯它們 (*)' echo ' 只將多個檔案列入暫存 (&)' echo ' 上一層 (,) 逗點' echo ' 上一個資料夾 (<) 小於,跟上一層是同一個按鍵' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' elif [ "$inputvar" == '*' ]; then inputvar='FF' elif [ "$inputvar" == '&' ]; then inputvar='FFF' elif [ "$inputvar" == ':' ]; then inputvar='FFFF' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear fast_change_dir_auto_list_file_enable='1' unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue elif [ "$inputvar" == '<' ]; then cd - clear_var_all='1' continue # 想拉一個檔案進來,接下來會做vff的動作 elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue # 想拉一個檔案進來,但是不啟用vff的狀況 elif [ "$inputvar" == 'FFFF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 0" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 0" fi eval $run clear_var_all='1' continue # 多選功能在使用的,只支援本層 elif [ "$inputvar" == 'FF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" fi eval $run clear_var_all='1' continue # 多選功能在使用的,只支援本層(不啟動vff) elif [ "$inputvar" == 'FFF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 3" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 3" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue + elif [ "$inputvar" == 'O' ]; then + d2ff + clear_var_all='1' + continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd diff --git a/cddir2-ui.sh b/cddir2-ui.sh new file mode 100755 index 0000000..8d28ffd --- /dev/null +++ b/cddir2-ui.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +source "$fast_change_dir_func/normal.sh" +source "$fast_change_dir_func/dialog.sh" + +if [ "$groupname" != "" ]; then + + cmdlist="cat $fast_change_dir_project_config/vimlist-$groupname.txt" + + # 這是多行文字檔內容,變成以空格分格成字串的步驟 + cmdlist2='| tr "\n" " "' + cmdlist="$cmdlist $cmdlist2" + cmdlist_result=`eval $cmdlist` + cmd="d2 " + + # 檢查一下數量,如果是一筆的話,那就自動跳到那一筆 + # 這樣子只有一筆的時候,會比較方便 + # 會這樣子寫,是因為不要去影響其它程式的相依性 + count=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` + + #if [ "$count" == 1 ]; then + # cmd="$cmd +tabnext" + #fi + + # 如果大於1筆,就用選擇的方式,選擇第一次要看到的檔案 + if [ "$count" -gt 1 ]; then + vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) + tmpfile="$fast_change_dir_tmp/`whoami`-cddir2-ui-dialogselect-$( date +%Y%m%d-%H%M ).txt" + dialogitems='' + start=1 + for echothem in ${vimlist_array[@]} + do + dialogitems=" $dialogitems '$start' $echothem " + start=$(expr $start + 1) + done + cmd2=$( func_dialog_menu '選擇一個檔案位置進入該資料夾 ' 100 "$dialogitems" $tmpfile ) + + eval $cmd2 + result=`cat $tmpfile` + echo $result + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" != "" ]; then + if [ "$result" -lt 10 ]; then + # 為了加快速度而這麼寫的 + #tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') + #cmd="$cmd ${tabennn[$result]}" + #echo ${vimlist_array[$(expr $result + 1)]} + cmd="$cmd ${vimlist_array[$(expr $result - 1)]}" + else + echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' + fi + else + # 如果使用者選擇取消,那就取消整個vff + cmd="" + fi + fi + + if [ "$cmd" != '' ]; then + echo $cmd + eval $cmd + fi + func_checkfilecount +else + echo '[ERROR] groupname is empty, please use GA cmd' +fi + +unset vimlist_array +unset cmd diff --git a/cddir2.sh b/cddir2.sh index cd25769..9357db4 100644 --- a/cddir2.sh +++ b/cddir2.sh @@ -1,5 +1,57 @@ #!/bin/bash # 跟一般的cd很像 # 只是會自動的把最右邊的檔名去除掉(如果有的話),然後在進去該資料夾 # 而且不管是絕對路徑,或是相對路徑 + +# http://bashscripts.org/forum/viewtopic.php?f=16&t=365 +#test script for file/path manipulation + +# First, we'll need a path, so let's make one up + +#fullpath="/mnt/test/this/is/a/ridiculously/long/path/to/test.file" + +fullpathg=$1 + +if [ "$fullpathg" != "" ]; then + + # Now we'll chop the filename off of the end. In awk, NF + # is the Number of Fields. If there are 10 fields, $NF is + # equal to $10, or whatever the last field is. We're using + # the slash (/) as a field seperator (escaped with a "\" + # filename="$(echo "$fullpath" |awk -F\/ '{ print $NF }')" + + # or using basename: + #filenameg="$(basename "$fullpathg")" + + + # Now I'm just being lazy and using sed to chop off the + # filename that we grabbed for our $filename variable + # (commenting this out, since finding 'dirname') + # use this if you still want the trailing slash :) + + #directory="$(echo "$fullpath"|sed s/"$filename"/""/g)" + + + # The dirname command! This works even if the file + # you give it doesn't actually exist. It does chop off + # the trailing slash though, so watch out for that. + # Also, if you don't give it a full path, it will return + # a relative path. + + directoryg="$(dirname "$fullpathg")" + + + # Now for the output, in case anybody + # wants to run this script as-is + + #echo "$fullpath" + #echo "$directory" + #echo "$filename" + + cd $directoryg + + unset directoryg + #unset filename + #unset fullpath +fi diff --git a/config/bashrc.txt b/config/bashrc.txt index 38a146b..1104806 100644 --- a/config/bashrc.txt +++ b/config/bashrc.txt @@ -1,105 +1,107 @@ # fast-change-dir fast_change_dir_pwd=$HOME fast_change_dir="$fast_change_dir_pwd/gisanfu/fast-change-dir" fast_change_dir_bin="$fast_change_dir/bin" fast_change_dir_lib="$fast_change_dir/lib" fast_change_dir_func="$fast_change_dir_lib/func" fast_change_dir_project_config="" # # 這裡區塊,可以依照你的使用環境去修改 # fast_change_dir_tmp='/tmp' fast_change_dir_config="$fast_change_dir_pwd" # fast-change-dir: use relative keyword alias ll="ls -la" # main function alias ide=". $fast_change_dir/abc-4.sh" # number function alias gre=". $fast_change_dir/grep.sh" alias sear=". $fast_change_dir/search.sh" alias abc=". $fast_change_dir/abc-4.sh" alias 123=". $fast_change_dir/123.sh" alias abc123=". $fast_change_dir/123-2.sh" # Version Controll alias svnn=". $fast_change_dir/svn-3.sh" alias gitt=". $fast_change_dir/git-2.sh" alias hgg=". $fast_change_dir/hg.sh" # # GroupName # # select or switch GroupName alias ga=". $fast_change_dir/groupname.sh select" # append GroupName alias gaa=". $fast_change_dir/groupname.sh append" # edit GroupName alias gaaa=". $fast_change_dir/groupname.sh edit" # # cd # alias d=". $fast_change_dir/cddir.sh" +alias d2=". $fast_change_dir/cddir2.sh" +alias d2ff=". $fast_change_dir/cddir2-ui.sh" # cd point alias dv=". $fast_change_dir/dirpoint.sh" # append point alias dvv=". $fast_change_dir/dirpoint-append.sh" # edit point alias dvvv=". $fast_change_dir/dirpoint-edit.sh" # nopath, nolimit to change directory by keyword alias wv=". $fast_change_dir/nopath.sh" # vim alias v=". $fast_change_dir/editfile.sh" alias vf=". $fast_change_dir/vimlist-append.sh" alias vff=". $fast_change_dir/vimlist.sh" alias vfff=". $fast_change_dir/vimlist-edit.sh" alias vffff=". $fast_change_dir/vimlist-clear.sh" alias vfe=". $fast_change_dir/pos-vimlist-append.sh 1" alias vfee=". $fast_change_dir/pos-vimlist-append.sh 2" alias vfeee=". $fast_change_dir/pos-vimlist-append.sh 3" alias vfeeee=". $fast_change_dir/pos-vimlist-append.sh 4" alias vfeeeee=". $fast_change_dir/pos-vimlist-append.sh 5" alias vfeeeeee=". $fast_change_dir/pos-vimlist-append.sh 6" # # back, and cd dir # alias g=". $fast_change_dir/backdir.sh" # back back... layer dir alias ge=". $fast_change_dir/back-backdir.sh 1" alias gee=". $fast_change_dir/back-backdir.sh 2" alias geee=". $fast_change_dir/back-backdir.sh 3" alias geeee=". $fast_change_dir/back-backdir.sh 4" alias geeeee=". $fast_change_dir/back-backdir.sh 5" alias geeeeee=". $fast_change_dir/back-backdir.sh 6" # back and cd dir, use position alias gde=". $fast_change_dir/pos-backdir.sh 1" alias gdee=". $fast_change_dir/pos-backdir.sh 2" alias gdeee=". $fast_change_dir/pos-backdir.sh 3" alias gdeeee=". $fast_change_dir/pos-backdir.sh 4" alias gdeeeee=". $fast_change_dir/pos-backdir.sh 5" alias gdeeeeee=". $fast_change_dir/pos-backdir.sh 6" # fast-change-dir: cd dir, use position alias de=". $fast_change_dir/pos-cddir.sh 1" alias dee=". $fast_change_dir/pos-cddir.sh 2" alias deee=". $fast_change_dir/pos-cddir.sh 3" alias deeee=". $fast_change_dir/pos-cddir.sh 4" alias deeeee=". $fast_change_dir/pos-cddir.sh 5" alias deeeeee=". $fast_change_dir/pos-cddir.sh 6" # fast-change-dir: vim file, use position alias ve=". $fast_change_dir/pos-editfile.sh 1" alias vee=". $fast_change_dir/pos-editfile.sh 2" alias veee=". $fast_change_dir/pos-editfile.sh 3" alias veeee=". $fast_change_dir/pos-editfile.sh 4" alias veeeee=". $fast_change_dir/pos-editfile.sh 5" alias veeeeee=". $fast_change_dir/pos-editfile.sh 6" # 最後,啟動ide ide
gisanfu/fast-change-dir
87b11b0e651b37ef2bf493d0dc52648610426781
add file, but not complete
diff --git a/cddir2.sh b/cddir2.sh new file mode 100644 index 0000000..cd25769 --- /dev/null +++ b/cddir2.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# 跟一般的cd很像 +# 只是會自動的把最右邊的檔名去除掉(如果有的話),然後在進去該資料夾 +# 而且不管是絕對路徑,或是相對路徑
gisanfu/fast-change-dir
89bedbe12b0928d234bd02eb7e174abc9a3a8549
add idea
diff --git a/IDEA b/IDEA index 1c5fb5c..af21a0b 100644 --- a/IDEA +++ b/IDEA @@ -1,512 +1,518 @@ +# 2011-10-30 + +在command-line下看圖片的軟體,或許可以結合看看 + +http://inouire.net/archives/image-couleur_source.tar.gz + # 2011-06-19 想要加上以下的範例指定進來 echo "hello" | xclip 可以把hello貼到clipboard裡面,然後回到vim貼上, 在ubuntu是按mouse的中鍵, windows裡面使用putty可能要測試一下。 # 2011-05-15 想要加上"cd -"的指令進來 # 2011-04-17 想要寫abc第4個版本 這個版本的特色為: - 不會即時搜尋各功能 - 當然也不會顯示搜尋後的結果 - 點確認以後,才會開始搜尋,以及各功能所會做的動作 - 為了要增加執行的效率,才會做這一個版本 - 先做基本的功能(本層、上層的檔案和資料夾處理),如果效率沒有問題,在加寫其它的功能 - 如果有重覆的,就用dialog menu - relativeitem或許可以取消cache功能 - 使用各快速鍵來啟動該功能,例如我輸入了eeee,然後按大寫F,來搜尋本層的檔案,如果只有一筆,那就加入暫存列表,並直接編輯它 # 2011-04-16 想用python重寫relativeitem 當有人在問它的時候,就會同時找以下的東西: 1. 本層的檔案和資料夾 2. 上一層的檔案和資料夾 找到了以後,第一次會將列表寫入檔案, 可能會給檔案一個編號當檔名,這個編號也會回傳給bash abc-v3主程式 當下一個relative開始,就會帶著這個編號去問新的程式, 這時新的程式,可以用這個編號去找檔案,而不用重新取得列表。 # 2011-04-15 1. 在vff的前面,加一個flow,選擇你要編輯的檔案 2. 正在想,要不要加入其它的語言,為了增加效率 # 2011-04-14 可以把各專案的設定檔,放到各專案的資料夾裡面, 不過關於這一點,可能要改很多地方。 # 2011-04-12 想要把資料夾和檔案的檔名,寫到一支文字檔裡面, 然後增加一個功能,對那個文字檔做控制 # 2011-03-22 可以把Groupname,在abc version3裡面,加上dialog的選擇功能 # 2011-03-01 在ide階段,想要不輸入東西,就可以使用F和D以及上一層的功能, 使用的方式為dialog。 增加這個功能了以後,感覺更好用了。 想要在vf詢問的地方,加上"是否使用純vim編輯,而不列入暫存"的選項 詢問過後,程式才會決定要不要寫入暫存 # 2011-02-21 看能不能在啟動ide之前,先去update(應該是說git pull)最新的資料, 這樣子就可以做最快速的同步, 希望目前原有的fast-change-dir-config的目標,能夠改成自己的git repo,比較安全, 不過這裡是點奇怪的,又想要private repo,但又想要密碼驗證,然後又想要安全性, 最好的方式,應該是每一個target或者說是End端,都要有一個類似驗證碼的東西, 送上去的時候,不是我的人就不能送上去, 目前還沒有想到一個比較好的方式。 應該是說,可以抓下去,要透過驗證碼 (每一台,或是每一個權限,使用的驗證碼都不一樣), 要送上去的時候,是需要密碼的,這樣子的方式應該是比較好的方式。 送上去的時候,可能是送到我自己的svn repo, 送上去以後,會export到某一個http的路徑, 然後我透過http simple auth,讓該權限來下載東西,或是更新東西下去, 但如果是這種作法的話,要怎麼樣上傳呢? 好像想的太複雜了@@。 # 2011-02-18 有想到一個功能, 如果我想要去一個資料夾, 它是在某一個資料下底下, 這種狀況常常會發生,就是進去上一個資料夾以後,就忘了下一個資料夾要去哪裡了。 所以想做一個功能,就是先輸入下一個條件,在然在進去第一個資料夾, 當第一個資料夾進去了以後,就會自動處理在暫存的指令, 不過後來想一想,其實如果是在本機操作,也可以進去第一層,然後按"R",啟動nautilus, 用GUI去操作。 # 2011-02-16 想要加上git的路徑(我指的是1.7的git) 不然又需要root權限了 想要多錯字處理的功能, 例如我輸入了misc, 打錯成為mics, 這時是可以判斷的,不過細節的部份要在思考一下, 而且這個功能,可能也會造成速度變慢,或許是不需要做的 # 2011-02-14 想要做一個功能,是不受groupname限制的, 很像是ssh txtfile的功能, 就是輸入一個關鍵字,可能就會跳到那一個資料夾裡面, 因為有時候很累的時候,跟本就沒有辦法輸入快速鍵。 # 2011-02-10 想要寫一支script,針對Zend Framework的架構, 匯出dirpoint的檔案出來, 可能可以針對root、module name等變數來做組合,以及匯出。 # 2011-02-01 想要把function放到lib/func資料夾裡面。 想要把片段程式碼放到lib/某一個資料夾裡面,可能是several, 想在abc-v3的第二個引數,加上@小老鼠,使用在position 還想要更改所有的文字檔到指定的某個位置, 除了路徑以外,檔名都要是變數,都是可以被修改的。 例如是放在~/git/公司名稱_某分類名稱/, 然後如果在公司做到一個地方,可以把裡面的東西,先存起來, 將整個設定和環境一起帶到另外一台電腦上面。 暫存的路徑是需要的,但是檔名應該先不需要, 其它的應該都是需要的。 # 2011-01-31 目前己經有一個輸入@小老鼠,可以為grep加上^的指令, 我想加一個#井字號,告訴程式我想要使用dialog menu的方式來選擇我要的東西, 經測試了以後,發現不能夠在bash function裡面,下dialog的指令, 所以這個功能必需要在函式以外的地方先處理, 感覺很麻煩,不過也蠻實用的。 # 2011-01-30 能不能讓每一個group,都有自己的設定檔, 例如home的group,可能就會啟動parent-item的功能, 而某程式設計的專案,可能就會因為感覺良好,而關閉它。 # 2011-01-29 能不能在同一個func_relative裡面, 同時做同個資料夾的item處理,以及上一層資料夾內的item處理呢? 能否使用C語言來改寫func_relative的函式, 然後讓bash來呼叫,看能不能改善效率, 讓反應速度能夠跟上我的操作速度, 在呈現的部份。 # 2011-01-28 有機會想要做web的部份。 關於資料夾、或是檔案碰到多筆的狀況, 可以多一個使用dialog menu的選擇來協助, 關於資料夾的部份,可以使用.(點)的快速鍵。 不過好像太麻煩了,可以試著按斜線清掉執行鍵, 然後想想如何使用更好的關鍵字來對它選取, 然後將它記錄在腦海裡面,下次就使用新的或是更好的方式來選擇該項目。 # 2011-01-27 對於vf按y和n,有想到一個方式 就是先把.(點)改回來, 可能把點使用在append-vff, 而;(分號),就是append+vff, 這樣子keyin的數量應該會少很多, 效率應該會比較快。 不過這個idea可能不會用在數字模式上,因為狀況不同 另外,如果輸入錯了快速鍵,或是打錯關鍵字, 想要暫停2秒鐘,然後自動清除關鍵字,並重來, 這樣子可能也多多少少增加一些速度, 不然打錯了還要手動去按一下/(斜線) 有時候按斜線還會按錯 分號,在切換資料夾的時候,可以想看看有沒有什麼其它的應用。 關鍵字的部份好像有點問題, 如果某一個物件名稱是aaabbb, 我輸入aa bb是可以找得到的, 但是如果我輸入bb aa好像是找不到的。 # 2011-01-26 想要把abc v3的第一次顯示help的部份拿掉 想加上更多操作檔案的功能 例如之前idea前寫過的: 執行檔案(依照副檔名) 刪除檔案(當然要可以刪除單檔、多檔,或是針對資料夾,或是混合) 更改名稱 移動路徑 想要在touch檔案以後,順便去編輯它 如果是在有啟動groupname的時候,步驟就會走到詢問你要不要vff的階段 touch檔案,應該是使用dialog的方式才對 刪除的功能,在C的快速鍵中,感覺不是很實用 目前是用C來當做Create,感覺還不錯 看要不要在建立另外一個關鍵字,來做刪除的動作 刪除的動作,也可以考慮不要做,改用cli, or nautilus來做會比較保險。 # 2011-01-25 想要在每一個版本控制功能中, 都加上R功能,也就是切換到Browser。 # 2011-01-22 想要在按分號的時候,就直接編輯檔案(如果是選檔案是在第一項) 就不要在按Y的,很麻煩,也為了可以簡化。 但是,如果我只是想append,但還沒有要edit,那這時怎麼辦呢? 是不是也是要維持現在的使用方式就可以了呢? 可以在append,詢問Y和N的地方,加上分號,或是F當做Y, 但這樣子不知道會不會換右手酸了。 目的還是要簡少按鍵數量。 或是在多一個快速鍵,跟F結合在一起,可能是寫在F,裡面在多一個判斷, 目的是要把append檔案的部份,分一個Y的,和一個N的。 另外,想加一個C快速鍵,就是選到項目的時候所使用的, 裡面可以刪除檔案、等其它額外擴充的功能 還有,別忘了還有一個IDEA需要被完成,就是判斷副檔名的部份。 就是在vim -p files...的時候,如果副檔名是.tar.gz、zip、image file等東西, 在vim的部份,就是會ignore它們。 # 2011-01-18 想要把原先放在/bin下的執行檔,都改放在自己的家目錄, 這樣子在有些沒有root的環境下,才可以使用, 而且這樣子也比較合理 不過有些檔案的目標路徑,是寫死的, 利用這個idea把它們都做個修正。 # 2011-01-17 想要在vimlist的功能,加上判斷副檔名的功能, 如果是使用vim編輯的話,就會乎略掉某些副檔名, 例如tar.gz, zip, images, videos, music # 2011-01-13 想要在vf的地方,加上以下的功能項目: 1. execute 2. delete execute的部份,可能就會判斷副檔名, 刪除的部份,可能會用D的關鍵字來做。 # 2011-01-11 想要在/斜線的地方,加上重新去include檔案的程式碼, 這樣子如果修改了searchfile, or searchdir,把它設定為啟動, 這時只要按一下斜線,就可以生效了 設定檔的地方,想要在加上bash history, 以及google search function 另外,以現在的使用方式,是增加判斷式和google groupname, 這樣子的使用方式,跟我新增設定檔的目標是很像的, 打算選擇設定檔的方式,在加上面的idea,可能會比較好使用。 # 2011-01-09 想要在各version control裡面的push之前, 加上"處理中..."的字眼,或者是顯示執行的指令。 在要增加一些功能的開關設定, 因為不管是在比較慢的電腦,或是比較快的,上執行這套程式,會很慢, 例如搜尋檔案的功能,或者是搜尋bash history的功能, 或許我可以把這些開關的設定,寫在某一支bash file裡面, 要使用的時候,才去修改它, 然後abc-v3就去include它。 # 2011-01-07 想要加一個快速鍵,來show/hide Help,應該就是大寫的H了 想要加上一個功能,就是按下vim的F8,就會離開vim,以及重新啟動vimlist的功能, 當然這個功能要先選擇groupname,這個功能是可以做的, 可能就離開前先寫入文字檔,然後abc-v3去判斷文字檔內是否有內容, 有的話在重新啟動vimlist的功能,因為不是很重要,所以暫時先不用寫 有沒有可能在vim裡面,按某一個快速鍵,然後就會把menu列出來讓你選擇, 或是可以讓你用快速鍵去選擇裡面的項目。 # 2011-01-03 想要加上切換到firefox的快速鍵 以及想要把切換的程式,加上引數,可以選擇切換後,要不要按下重整的按鈕。 另外,想要在啟動ide and abc-v3的時候,如果groupname是空白,就自動補上home, 關於這個idea在想想看,因為空groupname也是有我設計的理念在裡面,先不要拿掉好了。 # 2011-01-01 在abc-v3的V快速鍵中, 想要check current dir是否有.svn or .hg or .git的資料夾, 如果有的話,就直接啟用該版本控制, 還有,這個功能選擇版本控制的快速鍵,想要大小寫都可以使用。 我想在各版本控制的介面中,加上抓repo的功能下來,但這個IDEA好像不是很實用。 # 2010-12-31 想要將版本控制都放在一起, 例如按V(Version),就代表版本控制, 然後就會出現H(hg), G(git), S(Svn), C(cvs這個應該不會做) 一樣也是按快速鍵去執行它 在要加上第2層的判斷, 可能試著執行status,例如git status, 如果有正常的反應,我指的是在正確的repo裡面, 那這時我就會判斷正常,來執行指定的版本控制的指令。 # 2010-12-26 想要思考一下,怎麼樣在commander與cli之間做快速的切換, 有想到幾種方式: 1. 輸入一個快速鍵,然後會顯示讓你輸入指令的地方,只執行一次就會回到commander 2. 離開commander以後,可以任意的輸入指令,然後透過輸入某個指令,就會回到commander 3. 利用Ctrl+Z,把現在執行的東西放到background,透過fg把commander叫起來 4. 把MC啟動很慢的問題解決掉 5. 開2個視窗,用alt + tab切換 6. 開2個電腦,分別用不同的鍵盤 目前有加上nautilus,在abc裡面,所以未來我可以直接離開,或是不使用ide的指令, 如果要執行指令的時候,直接離開abc,如果指令打完,在輸入abc啟動ide就可以了。 # 2010-12-16 想要更改現在目前爛爛的svnn功能, 以及想要新增hg進來,不然就叫做hgg。 另外,svnn和hg,想要加上一個功能, commit cache的功能, 就是送出指定的檔案, 會想加上這個功能, 是因為有些檔案是我不想要送的檔案, 或是說,有些檔案己經完成了,但其它的檔案還在修改當中。 這個cache,想要寫在一個文字檔裡面,類似vimlist, 以svn來說,只要commit,就會送出了,這是與hg不同的地方, 我打算在送出了之後,就清空這個cache, 這個cache,我想取名為svnlist(svn commit list) 關於cache的功能,有一些想法: 1. 全部列入(或取消)cache 2. 關鍵字選擇單項(或多項)項目列入(或取消)cache 3. 觀看修改的內容,使用svn diff的指令,跟最後一個版本做比較 4. svn add的功能 5. 可以選擇清除cache, and uncache file 6. 可以選擇重新建立uncache file 這個會比較複雜,會有4種模式(gitv2只有2種) 每一個模式都可以下commit的指令 1. svn status, filter by untracked, or new file, 其它都沒有哦 2. svn status, filter by added, or deleted, modify一定會在裡面的(我想取commit list) 3. uncache list(這個還是要有,會比較方便) 4. cache list 在模式1的時候,可以使用關鍵字來對沒有被svn add的檔案操作, 然後會忽略掉modify或是己被svn add的檔案, commit list反之。 關於模式3,只要模式1有動作,就會重新輸出uncache file,也會清空cache file, 會這樣子做,是因為沒有svn-add的檔案(狀態為問號),是沒有辦法被commit的,請注意! 還是把模式1,變成狀態只能是問號的 另外,我想把寫入檔案這個動作,寫成bash function, 因為這個動作看起來還蠻常用的。 # 2010-12-15 搜尋google的功能, 除了想獨立一個功能來做以外, 還想要在abc3也想加上這一個功能, 不過可能只會搜尋一筆, 因為如果很多筆的話,abc3會變的很亂。 # 2010-12-14 想要加上搜尋google的功能, 請參考study/google-search.pl檔案, 當輸入關鍵字的時候,就會順便去搜尋Google, 然後我可以去選擇我想要的項目編號, 選了之後,就會用firefox指令去開啟該網址, 並且切換到firefox的視窗。 可能會新增一個項目,來放這個新功能, 然後英文模式在透過某一個快速鍵來連到這一個功能 另外,我在想要不要使用firefox, 理論上來說,我應該選擇的是links或是其它文字型的瀏覽器。 我看,還是做一個選項之類的東西,來切換瀏覽器。 後來找到了w3m,打算使用這一個。 如果要使用這個功能,請建立google這一個groupname。 使用text browser有一個好處,因為很多主機是沒有圖型介面的, 而且都是放在機房,如果沒有帶自己筆記型電腦過去,是上不了Google查資料的。 # 2010-12-10 想要加一個功能,是在輸入關鍵字的時候, 也順便去搜尋底下的資料夾, 當選擇的時候,當然是進去那一個資料夾裡面。 不過這個功能我不打算加入groupname功能內。 # 2010-12-03 在想要不要把MC加進來, 在create, delete資料夾或是文字檔的時候, 或是在copy, move, rename的時候, 轉使用MC工具,不過MC啟動的時候有點慢,大約要10秒鐘, 而且使用-s or -b的引數都還是很慢, 我在找找看有沒有其它的使用選擇。 # 2010-11-30 在想要不要增加一些系統的元素進來, 例如: sudo or leave sudo edit hosts edit php.ini edit apache conf(s) edit or tail message, dmesg start restart service search bash history(只是有些指令在cli下執行會卡住) ssh remote server 以上這個話題,可以分一些思考點出來 1. 編輯檔案的部份,可以參考dirpoint的作法 2. 搜尋檔案內容的部份,就比較單純 3. sudo 可能就要在想一下了,可能就下sudo的指令,然後我可能不要打密碼, 接下來會切換到root,這時會自動用root來執行ide或是abc。 4. start restart service, 可能需要搭配dialog來做。 5. ssh remote server, 這可能會蠻實用的,我可能會先寫入一個文字檔列表, 這個功能應該很單純,然後是全域的,不會被groupname所區分。 關於上述第1點, 可以設定檔案的virtual徑捷,例如我輸入config,這時可能會出現aaa.xml出來, 可能要想一下,這一點是否真的實用才做。 後來想一想,可能不太實用,因為我還有搜尋的功能,假設在任何地方輸入aaa, 還是會出現aaa.xml 有些功能,我在想,可能不需要,或是不能用.(點)來做選擇, 一定要用所指定的快速鍵來選擇該功能,這樣可能比較不會有誤動作。 # 2010-11-24 我新增了一個study,是可以自動切換到指定的視窗,然後送指令. 我想利用這個study,做以下的動作: 1. In Gnome-terminal vim edit file 2. 離開vim,然後執行某一個快速鍵,這時會切到firefox,然後重新整理頁面 3. 也會在回到vim 這個動作可能可以想一下應用 # 2010-11-18 想把abc裡面的重覆項目, 做一些功能選擇, 1. 將這些項目,append到vimlist 2. 在這些項目中做多項的選擇,一樣會把所選擇的結果append到vimlist中 應該除了ga和dvv功能以外,其它功能都想要套用以上的功能 另外,gitt也想要加這個功能,就可能輸入關鍵字,然後如果是多項的話, 就一次把他們加入。 多項的選擇,本來是用ers(123)的方式,只要加上星號,就可以選多項了, 或是輸入e|r|s之類的,來選其它的多項。
gisanfu/fast-change-dir
15b8909f3645271dc4d8af700d0942babc85dd3a
mark check text process by vimlist shell script
diff --git a/vimlist.sh b/vimlist.sh index ea90605..23a0874 100755 --- a/vimlist.sh +++ b/vimlist.sh @@ -1,88 +1,90 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" program=$1 if [ "$groupname" != "" ]; then if [ "$program" == "" ]; then program2="vim -p $fast_change_dir_project_config/vimlist-$groupname.txt" else program2=$program fi cmdlist="cat $fast_change_dir_project_config/vimlist-$groupname.txt" # 正規的外面要用雙引包起來 regex="^vim" # 如果program這個變數是空白,就代表會使用vim-p的指令 # 使用vim,當然不會去開一些binary的檔案 if [[ "$program" == '' || "$program" =~ $regex ]]; then # 先把一些己知的東西先ignore掉,例如壓縮檔 cmdlist="$cmdlist | grep -v .tar.gz | grep -v .zip | grep -v .png | grep -v .gif | grep -v .jpeg | grep -v .jpg" - cmdlist="$cmdlist | xargs -n 1 $fast_change_dir_bin/only-text-filecontent.sh" + + # 這行是判斷是不是文字檔,但是遇到css的檔案,會誤判,所以暫時先mark起來,或許以後用得到 + # cmdlist="$cmdlist | xargs -n 1 $fast_change_dir_bin/only-text-filecontent.sh" fi # 這是多行文字檔內容,變成以空格分格成字串的步驟 cmdlist2='| tr "\n" " "' cmdlist="$cmdlist $cmdlist2" cmdlist_result=`eval $cmdlist` cmd="$program2 $cmdlist_result" # 檢查一下數量,如果是一筆的話,那就自動跳到那一筆 # 這樣子只有一筆的時候,會比較方便 # 會這樣子寫,是因為不要去影響其它程式的相依性 if [ "$program" == "" ]; then count=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$count" == 1 ]; then cmd="$cmd +tabnext" fi # 如果大於1筆,就用選擇的方式,選擇第一次要看到的檔案 if [ "$count" -gt 1 ]; then vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) tmpfile="$fast_change_dir_tmp/`whoami`-vimlist-dialogselect-$( date +%Y%m%d-%H%M ).txt" dialogitems='' start=1 for echothem in ${vimlist_array[@]} do dialogitems=" $dialogitems '$start' $echothem " start=$(expr $start + 1) done cmd2=$( func_dialog_menu '你想從哪一個位置開始編輯 ' 100 "$dialogitems" $tmpfile ) eval $cmd2 result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then if [ "$result" -lt 10 ]; then # 為了加快速度而這麼寫的 tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') cmd="$cmd ${tabennn[$result]}" else echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' fi else # 如果使用者選擇取消,那就取消整個vff cmd="" fi fi fi if [ "$cmd" != '' ]; then eval $cmd fi func_checkfilecount else echo '[ERROR] groupname is empty, please use GA cmd' fi unset vimlist_array unset cmd
gisanfu/fast-change-dir
153cfa9527276dc24f5d910b5d7e1289c25d16f2
add help
diff --git a/abc-4.sh b/abc-4.sh index 0c61f76..cc8b309 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,449 +1,452 @@ #!/bin/bash source "$fast_change_dir/config/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color while [ 1 ]; do clear fast_change_dir_auto_list_file_enable='0' if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' - echo ' 智慧選取單項 (;) 分號' + echo ' 將單檔案列入暫存,並使用vim編輯它們 (;) 分號' + echo ' 只將單檔案列入暫存 (;) 分號' + echo ' 將多個檔案列入暫存,並使用vim編輯它們 (*)' + echo ' 只將多個檔案列入暫存 (&)' echo ' 上一層 (,) 逗點' echo ' 上一個資料夾 (<) 小於,跟上一層是同一個按鍵' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' elif [ "$inputvar" == '*' ]; then inputvar='FF' elif [ "$inputvar" == '&' ]; then inputvar='FFF' elif [ "$inputvar" == ':' ]; then inputvar='FFFF' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear fast_change_dir_auto_list_file_enable='1' unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue elif [ "$inputvar" == '<' ]; then cd - clear_var_all='1' continue # 想拉一個檔案進來,接下來會做vff的動作 elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue # 想拉一個檔案進來,但是不啟用vff的狀況 elif [ "$inputvar" == 'FFFF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 0" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 0" fi eval $run clear_var_all='1' continue # 多選功能在使用的,只支援本層 elif [ "$inputvar" == 'FF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" fi eval $run clear_var_all='1' continue # 多選功能在使用的,只支援本層(不啟動vff) elif [ "$inputvar" == 'FFF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 3" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 3" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd
gisanfu/fast-change-dir
adad986d5d55ef35a6546ae15e3c693976a64b53
add vf method
diff --git a/abc-4.sh b/abc-4.sh index 4ea0ef0..0c61f76 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,449 +1,449 @@ #!/bin/bash source "$fast_change_dir/config/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color while [ 1 ]; do clear fast_change_dir_auto_list_file_enable='0' if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 智慧選取單項 (;) 分號' echo ' 上一層 (,) 逗點' echo ' 上一個資料夾 (<) 小於,跟上一層是同一個按鍵' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' elif [ "$inputvar" == '*' ]; then inputvar='FF' elif [ "$inputvar" == '&' ]; then inputvar='FFF' - if [ "$inputvar" == ':' ]; then + elif [ "$inputvar" == ':' ]; then inputvar='FFFF' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear fast_change_dir_auto_list_file_enable='1' unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue elif [ "$inputvar" == '<' ]; then cd - clear_var_all='1' continue # 想拉一個檔案進來,接下來會做vff的動作 elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue # 想拉一個檔案進來,但是不啟用vff的狀況 elif [ "$inputvar" == 'FFFF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 0" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 0" fi eval $run clear_var_all='1' continue # 多選功能在使用的,只支援本層 elif [ "$inputvar" == 'FF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" fi eval $run clear_var_all='1' continue # 多選功能在使用的,只支援本層(不啟動vff) elif [ "$inputvar" == 'FFF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 3" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 3" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd
gisanfu/fast-change-dir
bab65b8ac3d89620669bb2fd792d265d4a5df8fa
modify
diff --git a/abc-4.sh b/abc-4.sh index e4c0bbb..4ea0ef0 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,420 +1,449 @@ #!/bin/bash source "$fast_change_dir/config/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color while [ 1 ]; do clear fast_change_dir_auto_list_file_enable='0' if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 智慧選取單項 (;) 分號' echo ' 上一層 (,) 逗點' echo ' 上一個資料夾 (<) 小於,跟上一層是同一個按鍵' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' elif [ "$inputvar" == '*' ]; then inputvar='FF' + elif [ "$inputvar" == '&' ]; then + inputvar='FFF' + if [ "$inputvar" == ':' ]; then + inputvar='FFFF' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear fast_change_dir_auto_list_file_enable='1' unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue elif [ "$inputvar" == '<' ]; then cd - clear_var_all='1' continue + # 想拉一個檔案進來,接下來會做vff的動作 elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run + clear_var_all='1' + continue + # 想拉一個檔案進來,但是不啟用vff的狀況 + elif [ "$inputvar" == 'FFFF' ]; then + if [ "$groupname" != '' ]; then + run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 0" + else + run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 0" + fi + + eval $run + clear_var_all='1' continue # 多選功能在使用的,只支援本層 elif [ "$inputvar" == 'FF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" fi eval $run + clear_var_all='1' + continue + # 多選功能在使用的,只支援本層(不啟動vff) + elif [ "$inputvar" == 'FFF' ]; then + if [ "$groupname" != '' ]; then + run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 3" + else + run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 3" + fi + + eval $run + clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd diff --git a/vimlist-append.sh b/vimlist-append.sh index 49a1e8b..36caffb 100755 --- a/vimlist-append.sh +++ b/vimlist-append.sh @@ -1,157 +1,160 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 # 是否要vff,如果沒有指定,就是會詢問使用者 # 不詢問,不要vff的話,就放0 # 不詢問,要vff的話,就放1 # 想要vff,然後又要多選的狀況,那就放2,也會自動做vff的動作 +# 同2,但不要vff的狀況 isVFF=$4 if [ "$isVFF" == '' ]; then isVFF=1 fi item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' if [ ${#item_array[@]} -eq 1 ]; then relativeitem=${item_array[0]} -elif [[ ${#item_array[@]} -gt 1 && "$isVFF" == '2' ]]; then +elif [[ ${#item_array[@]} -gt 1 && "$isVFF" == '2' || "$isVFF" == '3' ]]; then for file in ${item_array[@]} do selectitem='' selectitem=`pwd`/$file checkline=`grep $selectitem $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt fi done relativeitem='__empty' elif [ ${#item_array[@]} -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems="" for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem=$result else relativeitem='' fi else relativeitem='' fi if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then if [ "$isVFF" == '0' ]; then inputchar='n' elif [ "$isVFF" == '1' ]; then inputchar='y' elif [ "$isVFF" == '2' ]; then inputchar='y' + elif [ "$isVFF" == '3' ]; then + inputchar='n' else isVFF='' fi # 這裡可以考慮在加上一項,就是不要append這一個檔案 if [ "$isVFF" == '' ]; then # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' echo '[WAIT] 或是編輯列表 [j]' echo '[WAIT] 還是清空它 [k]' read -n 1 inputchar fi # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append if [ "$relativeitem" != '__empty' ]; then selectitem='' selectitem=`pwd`/$relativeitem checkline=`grep "$selectitem" $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt else echo '[NOTICE] File is exist' fi fi if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... checklinenumber=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` cmd='vff "vim' # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 # 查詢更多資訊請執行: "vim -h" if [ "$checklinenumber" -lt 10 ]; then # 為了加快速度而這麼寫的 tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') cmd="$cmd ${tabennn[$checklinenumber]}" else echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' echo '[NOTICE] 純編輯這個檔案,以及叫出列表,看你要砍掉哪一個' vim "$selectitem" unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem vfff cmd='' fi if [ "$cmd" != '' ]; then cmd="$cmd -p $fast_change_dir_project_config/vimlist-$groupname.txt\"" eval $cmd fi elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then echo "Your want append other file" elif [ "$inputchar" == 'j' ]; then vfff elif [ "$inputchar" == 'k' ]; then vffff else echo "Your want append other file" fi # 最後,顯示目前目錄的檔案 func_checkfilecount elif [ "$groupname" == "" ]; then echo '[ERROR] Argument or $groupname is empty' fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem
gisanfu/fast-change-dir
780661940d94795a45b41ddac38ec70345bb3dec
fix bug
diff --git a/abc-4.sh b/abc-4.sh index 4bb2af7..e4c0bbb 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,406 +1,420 @@ #!/bin/bash source "$fast_change_dir/config/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color while [ 1 ]; do clear fast_change_dir_auto_list_file_enable='0' if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 智慧選取單項 (;) 分號' echo ' 上一層 (,) 逗點' echo ' 上一個資料夾 (<) 小於,跟上一層是同一個按鍵' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' elif [ "$inputvar" == '*' ]; then inputvar='FF' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear fast_change_dir_auto_list_file_enable='1' + + unset condition + unset inputvar + unset item_file_array + unset item_dir_array + unset item_parent_file_array + unset item_parent_dir_array + unset item_dirpoint_array + unset item_groupname_array + unset cmd1 + unset cmd2 + unset cmd3 + clear_var_all='' + break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue elif [ "$inputvar" == '<' ]; then cd - clear_var_all='1' continue elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue # 多選功能在使用的,只支援本層 elif [ "$inputvar" == 'FF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd
gisanfu/fast-change-dir
b6c9682121f3b7367e485f7ed68d46b0d19974ec
add feature
diff --git a/README.markdown b/README.markdown index dfba1f5..611b99f 100644 --- a/README.markdown +++ b/README.markdown @@ -1,299 +1,301 @@ # Fast Change Dir # author: gisanfu ## 這是什麼東西? 算是以下幾種東西的結合: - Command-Line Helper - Simple File Manager - Simple Version Control UI ## 什麼人適合用? - MIS 網管 - 程式設計師 ## 主要特色 - 平行切換資料夾 - 捷徑切換資料夾 +- 快速回上N層資料夾 - 2層式關鍵字定位 - 相對名稱定位 - 絕對位置定位 -- 多檔名暫存以及執行 - 進入資料夾自動顯示檔案列表 -- 快速回上N層資料夾 - 操作物件(含資料夾與檔案),目前有定位以及模糊方式 +- 資料夾與檔案,當有一筆以上的狀況,會詢問與選單 +- 檔案複選以及編輯 +- 多檔名暫存以及執行 - 即時搜尋檔案名稱 - 即時搜尋關鍵字 - 即時搜尋SSH目標主機列表 - 即時搜尋bash history - 即時關鍵字操作物件 - 即時數字鍵操作物件 - 版本控制功能(Git, Subversion, Mercurial) - 主控台(整合快速鍵) ## 其它文件 ### 安裝文件 請參考`INSTALL.mkd`檔案 ### 操作文件 請參考`COMMAND.mkd`檔案 ## 簡易影片Demo <http://www.youtube.com/watch?v=t1zYZF0UzMw> 來看看我輸入了哪些指令 ide<cr> a git. fast. dirF gtgtgt <f4> homeG desktopL , git. fast. stu. find.y <f4> bash.y gt dd <f4> I gt <f4> , cdF gt dd <f4> I <f4> ? q 對照一般的CLI,我其實輸入以下的指令, 這還不包含給vim所使用的暫存指令 cd ~<cr> cd git<cr> ls<cr> cd fast-change-dir<cr> ls<cr> vim -p *dir*<cr> gtgtgt :qa<cr> cd ~<cr> ls<cr> cd 桌面<cr> ls<cr> cd ..<cr> ls<cr> cd git<cr> ls<cr> cd fast-change-dir<cr> ls<cr> cd study<cr> ls<cr> vim -p *find*<cr> :qa<cr> vim -p *bash*<cr> :qa<cr> ls<cr> cd ..<cr> ls<cr> vim -p *cd*<cr> :qa<cr> ## 比較 使用這種方式,來切換資料夾,以及寫程式, 跟一般使用GUI editor或是IDE的差別。 ### 缺點: - 功能可能沒有IDE來的完整 - 小電腦或是速度不快的電腦可能會有點慢 *由其是安裝了Ubuntu 10.04 or 10.10的小電腦* *或者是開啟了所有功能* ### 優點: - 在切換資料夾或是選取物件,如果熟悉的話,可以暫時讓眼睛休息,可以使用這個程式所提供的各種方式(請看上面的特色)來選擇項目 - 把CLI, Editor, Browser的距離拉近,而不是三個視窗 - 跨平台,免安裝(因為是在CLI的環境下,不同作業系統下,只要透過ssh protocol連進來就可以開始開發) - 跟CLI相比,可以不用常按Enter,或是Tab鍵,還有ls(顯示現在這一層的內容) ### 同時是優點也是缺點: - 滑鼠用的機率會少很多 - 鍵盤會很常用 - 有兩種主要的使用方式,CLI和IDE,可以依照狀況來選擇您要的方式,例如網管可以使用CLI方式,加速CLI的操作速度,如果是程式設計師,可以使用IDE的方式 ## CLI部份使用方式 ### if directory is aaa +-- dddd abc bbb +-- eeee ccc +-- ffff +-- ggggg +-- hhhhhh ### show list $ ls -la drwxr-xr-x 8 blha blha 4096 200X-XX-XX XX:XX aaa drwxr-xr-x 8 blha blha 4096 200X-XX-XX XX:XX abc drwxr-xr-x 8 blha blha 4096 200X-XX-XX XX:XX bbb drwxr-xr-x 8 blha blha 4096 200X-XX-XX XX:XX ccc drwxr-xr-x 8 blha blha 4096 200X-XX-XX XX:XX gggg drwxr-xr-x 8 blha blha 4096 200X-XX-XX XX:XX ggfff ### into bbb deee ### into aaa cd aaa (it's standard, you know) ### goto parent directory cd .. (you know) ### replace cd to d d aaa [PWD]=>/aaa ddd/ ### replace cd .. to g $ g (goto parent directory) [PWD]=>/ aaa/ bbb/ ccc/ abc/ ### input several `^`keyword, if duplicate, then show them d a aaa/ abc/ ### input no duplicate keyword d aa ### goto many directory $ d ccc $ d ffff $ d ggggg $ d hhhhhh ### return to parent dir for 4 layer $ geeee (maximum layer is 6) ### goto the last time directory(old command is => cd -) $ d ### goto directory by two condition $ d gg ff ### edit position 3 file use vim $ veee ### set groupname to environment variable $ export groupname=project01 ### add filename to vim argument list buffer $ vf ### vim argument list buffer (vim -p aaa.txt bbb.txt ....) $ vff ### vimdiff $ vff vimdiff ### rm buffer file $ vff "rm -rf" ### edit ~/gisanfu-vimlist-${groupname}.txt file $ vfff ### add dirpoint to buffer(library is point) $ dvv library /home/user01/zend/library ### switch to dirpoint $ dv library ### edit ~/gisanfu-dirpoint-${groupname}.txt file $ dvvv ## IDE部份使用方式 會有IDE的方式,剛開始的想法,主要是要擺脫CLI的一些先天的缺點, 例如我要進入一個資料夾,就必需要輸入`cd dir01` [Enter], 如果輸入錯誤,當下是不知道的,當你打錯成`cd dir02`,這時你是必需要重打指令的, 不然你就是要輸入cd di`<tab><tab>`r`<tab><tab>`0`<tab><tab>`, 如果使用IDE裡面的英文選擇功能的話(abc),就可以輸入dir02[.點], 當你在輸入的時候,程式就會告訴你是否能直接選擇這個項目、這個項目是dir or file、等等, 另外,IDE目前己經整合大部份CLI的指令,而且做了所多的改版。 ### 啟動IDE功能 *輸入以下指令,啟動IDE,不管輸入ide或是abc都是英文選擇模式 ide 或 abc ![abc](http://pic.pimg.tw/gisanfu/4569bf373a01ac17f245e9cf392035ae.png)
gisanfu/fast-change-dir
6c4ba14d71a9216b9ee1e5e257ecb2a67a3e8786
add no groupname editfile multi select function
diff --git a/abc-4.sh b/abc-4.sh index e11d353..4bb2af7 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,406 +1,406 @@ #!/bin/bash source "$fast_change_dir/config/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color while [ 1 ]; do clear fast_change_dir_auto_list_file_enable='0' if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 智慧選取單項 (;) 分號' echo ' 上一層 (,) 逗點' echo ' 上一個資料夾 (<) 小於,跟上一層是同一個按鍵' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' elif [ "$inputvar" == '*' ]; then inputvar='FF' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear fast_change_dir_auto_list_file_enable='1' break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue elif [ "$inputvar" == '<' ]; then cd - clear_var_all='1' continue elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue - # 多選所使用 + # 多選功能在使用的,只支援本層 elif [ "$inputvar" == 'FF' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd diff --git a/editfile.sh b/editfile.sh index e5f4e93..0472199 100755 --- a/editfile.sh +++ b/editfile.sh @@ -1,53 +1,64 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 +# 是否要vff +# 2代表要多選 +isVFF=$4 + item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' -if [ "${#item_array[@]}" -gt 1 ]; then +if [[ "${#item_array[@]}" -gt 1 && "$isVFF" == '2' ]]; then + vimpitems="" + for echothem in ${item_array[@]} + do + vimpitems=" $vimpitems $echothem " + done + relativeitem=" -p $vimpitems" +elif [ "${#item_array[@]}" -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems='' for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem="$result" fi elif [ "${#item_array[@]}" -eq 1 ]; then relativeitem="${item_array[0]}" #cmd="vim \"${item_array[0]}\"" #eval $cmd fi if [ "$relativeitem" != '' ]; then vim $relativeitem fi # check file count and ls action func_checkfilecount unset cmd unset cmd1 unset cmd2 unset cmd3 unset item_array
gisanfu/fast-change-dir
2f0354be085b96c1fae6f0ae69087756b282c3ad
add multi select file section
diff --git a/abc-4.sh b/abc-4.sh index 696d0b1..e11d353 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,392 +1,406 @@ #!/bin/bash source "$fast_change_dir/config/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color while [ 1 ]; do clear fast_change_dir_auto_list_file_enable='0' if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 智慧選取單項 (;) 分號' echo ' 上一層 (,) 逗點' echo ' 上一個資料夾 (<) 小於,跟上一層是同一個按鍵' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' + elif [ "$inputvar" == '*' ]; then + inputvar='FF' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear fast_change_dir_auto_list_file_enable='1' break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue elif [ "$inputvar" == '<' ]; then cd - clear_var_all='1' continue elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run + clear_var_all='1' + continue + # 多選所使用 + elif [ "$inputvar" == 'FF' ]; then + if [ "$groupname" != '' ]; then + run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" + else + run="v \"$cmd1\" \"$cmd2\" \"$cmd3\" 2" + fi + + eval $run + clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd diff --git a/vimlist-append.sh b/vimlist-append.sh index 51d8689..49a1e8b 100755 --- a/vimlist-append.sh +++ b/vimlist-append.sh @@ -1,141 +1,157 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 # 是否要vff,如果沒有指定,就是會詢問使用者 # 不詢問,不要vff的話,就放0 # 不詢問,要vff的話,就放1 +# 想要vff,然後又要多選的狀況,那就放2,也會自動做vff的動作 isVFF=$4 if [ "$isVFF" == '' ]; then isVFF=1 fi item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' if [ ${#item_array[@]} -eq 1 ]; then relativeitem=${item_array[0]} +elif [[ ${#item_array[@]} -gt 1 && "$isVFF" == '2' ]]; then + for file in ${item_array[@]} + do + selectitem='' + selectitem=`pwd`/$file + checkline=`grep $selectitem $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` + if [ "$checkline" -lt 1 ]; then + echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt + fi + done + relativeitem='__empty' elif [ ${#item_array[@]} -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" - dialogitems='' + dialogitems="" for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem=$result else relativeitem='' fi else relativeitem='' fi if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then if [ "$isVFF" == '0' ]; then inputchar='n' elif [ "$isVFF" == '1' ]; then inputchar='y' + elif [ "$isVFF" == '2' ]; then + inputchar='y' else isVFF='' fi # 這裡可以考慮在加上一項,就是不要append這一個檔案 if [ "$isVFF" == '' ]; then # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' echo '[WAIT] 或是編輯列表 [j]' echo '[WAIT] 還是清空它 [k]' read -n 1 inputchar fi # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append - selectitem='' - selectitem=`pwd`/$relativeitem - checkline=`grep "$selectitem" $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` - if [ "$checkline" -lt 1 ]; then - echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt - else - echo '[NOTICE] File is exist' + if [ "$relativeitem" != '__empty' ]; then + selectitem='' + selectitem=`pwd`/$relativeitem + checkline=`grep "$selectitem" $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` + if [ "$checkline" -lt 1 ]; then + echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt + else + echo '[NOTICE] File is exist' + fi fi if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... checklinenumber=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` cmd='vff "vim' # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 # 查詢更多資訊請執行: "vim -h" if [ "$checklinenumber" -lt 10 ]; then # 為了加快速度而這麼寫的 tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') cmd="$cmd ${tabennn[$checklinenumber]}" else echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' echo '[NOTICE] 純編輯這個檔案,以及叫出列表,看你要砍掉哪一個' vim "$selectitem" unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem vfff cmd='' fi if [ "$cmd" != '' ]; then cmd="$cmd -p $fast_change_dir_project_config/vimlist-$groupname.txt\"" eval $cmd fi elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then echo "Your want append other file" elif [ "$inputchar" == 'j' ]; then vfff elif [ "$inputchar" == 'k' ]; then vffff else echo "Your want append other file" fi # 最後,顯示目前目錄的檔案 func_checkfilecount elif [ "$groupname" == "" ]; then echo '[ERROR] Argument or $groupname is empty' fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem
gisanfu/fast-change-dir
9920ab56ec05bb284a37f19ec5364ea6004081bd
add idea
diff --git a/IDEA b/IDEA index c123c07..1c5fb5c 100644 --- a/IDEA +++ b/IDEA @@ -1,512 +1,524 @@ +# 2011-06-19 + +想要加上以下的範例指定進來 + +echo "hello" | xclip + +可以把hello貼到clipboard裡面,然後回到vim貼上, + +在ubuntu是按mouse的中鍵, + +windows裡面使用putty可能要測試一下。 + # 2011-05-15 想要加上"cd -"的指令進來 # 2011-04-17 想要寫abc第4個版本 這個版本的特色為: - 不會即時搜尋各功能 - 當然也不會顯示搜尋後的結果 - 點確認以後,才會開始搜尋,以及各功能所會做的動作 - 為了要增加執行的效率,才會做這一個版本 - 先做基本的功能(本層、上層的檔案和資料夾處理),如果效率沒有問題,在加寫其它的功能 - 如果有重覆的,就用dialog menu - relativeitem或許可以取消cache功能 - 使用各快速鍵來啟動該功能,例如我輸入了eeee,然後按大寫F,來搜尋本層的檔案,如果只有一筆,那就加入暫存列表,並直接編輯它 # 2011-04-16 想用python重寫relativeitem 當有人在問它的時候,就會同時找以下的東西: 1. 本層的檔案和資料夾 2. 上一層的檔案和資料夾 找到了以後,第一次會將列表寫入檔案, 可能會給檔案一個編號當檔名,這個編號也會回傳給bash abc-v3主程式 當下一個relative開始,就會帶著這個編號去問新的程式, 這時新的程式,可以用這個編號去找檔案,而不用重新取得列表。 # 2011-04-15 1. 在vff的前面,加一個flow,選擇你要編輯的檔案 2. 正在想,要不要加入其它的語言,為了增加效率 # 2011-04-14 可以把各專案的設定檔,放到各專案的資料夾裡面, 不過關於這一點,可能要改很多地方。 # 2011-04-12 想要把資料夾和檔案的檔名,寫到一支文字檔裡面, 然後增加一個功能,對那個文字檔做控制 # 2011-03-22 可以把Groupname,在abc version3裡面,加上dialog的選擇功能 # 2011-03-01 在ide階段,想要不輸入東西,就可以使用F和D以及上一層的功能, 使用的方式為dialog。 增加這個功能了以後,感覺更好用了。 想要在vf詢問的地方,加上"是否使用純vim編輯,而不列入暫存"的選項 詢問過後,程式才會決定要不要寫入暫存 # 2011-02-21 看能不能在啟動ide之前,先去update(應該是說git pull)最新的資料, 這樣子就可以做最快速的同步, 希望目前原有的fast-change-dir-config的目標,能夠改成自己的git repo,比較安全, 不過這裡是點奇怪的,又想要private repo,但又想要密碼驗證,然後又想要安全性, 最好的方式,應該是每一個target或者說是End端,都要有一個類似驗證碼的東西, 送上去的時候,不是我的人就不能送上去, 目前還沒有想到一個比較好的方式。 應該是說,可以抓下去,要透過驗證碼 (每一台,或是每一個權限,使用的驗證碼都不一樣), 要送上去的時候,是需要密碼的,這樣子的方式應該是比較好的方式。 送上去的時候,可能是送到我自己的svn repo, 送上去以後,會export到某一個http的路徑, 然後我透過http simple auth,讓該權限來下載東西,或是更新東西下去, 但如果是這種作法的話,要怎麼樣上傳呢? 好像想的太複雜了@@。 # 2011-02-18 有想到一個功能, 如果我想要去一個資料夾, 它是在某一個資料下底下, 這種狀況常常會發生,就是進去上一個資料夾以後,就忘了下一個資料夾要去哪裡了。 所以想做一個功能,就是先輸入下一個條件,在然在進去第一個資料夾, 當第一個資料夾進去了以後,就會自動處理在暫存的指令, 不過後來想一想,其實如果是在本機操作,也可以進去第一層,然後按"R",啟動nautilus, 用GUI去操作。 # 2011-02-16 想要加上git的路徑(我指的是1.7的git) 不然又需要root權限了 想要多錯字處理的功能, 例如我輸入了misc, 打錯成為mics, 這時是可以判斷的,不過細節的部份要在思考一下, 而且這個功能,可能也會造成速度變慢,或許是不需要做的 # 2011-02-14 想要做一個功能,是不受groupname限制的, 很像是ssh txtfile的功能, 就是輸入一個關鍵字,可能就會跳到那一個資料夾裡面, 因為有時候很累的時候,跟本就沒有辦法輸入快速鍵。 # 2011-02-10 想要寫一支script,針對Zend Framework的架構, 匯出dirpoint的檔案出來, 可能可以針對root、module name等變數來做組合,以及匯出。 # 2011-02-01 想要把function放到lib/func資料夾裡面。 想要把片段程式碼放到lib/某一個資料夾裡面,可能是several, 想在abc-v3的第二個引數,加上@小老鼠,使用在position 還想要更改所有的文字檔到指定的某個位置, 除了路徑以外,檔名都要是變數,都是可以被修改的。 例如是放在~/git/公司名稱_某分類名稱/, 然後如果在公司做到一個地方,可以把裡面的東西,先存起來, 將整個設定和環境一起帶到另外一台電腦上面。 暫存的路徑是需要的,但是檔名應該先不需要, 其它的應該都是需要的。 # 2011-01-31 目前己經有一個輸入@小老鼠,可以為grep加上^的指令, 我想加一個#井字號,告訴程式我想要使用dialog menu的方式來選擇我要的東西, 經測試了以後,發現不能夠在bash function裡面,下dialog的指令, 所以這個功能必需要在函式以外的地方先處理, 感覺很麻煩,不過也蠻實用的。 # 2011-01-30 能不能讓每一個group,都有自己的設定檔, 例如home的group,可能就會啟動parent-item的功能, 而某程式設計的專案,可能就會因為感覺良好,而關閉它。 # 2011-01-29 能不能在同一個func_relative裡面, 同時做同個資料夾的item處理,以及上一層資料夾內的item處理呢? 能否使用C語言來改寫func_relative的函式, 然後讓bash來呼叫,看能不能改善效率, 讓反應速度能夠跟上我的操作速度, 在呈現的部份。 # 2011-01-28 有機會想要做web的部份。 關於資料夾、或是檔案碰到多筆的狀況, 可以多一個使用dialog menu的選擇來協助, 關於資料夾的部份,可以使用.(點)的快速鍵。 不過好像太麻煩了,可以試著按斜線清掉執行鍵, 然後想想如何使用更好的關鍵字來對它選取, 然後將它記錄在腦海裡面,下次就使用新的或是更好的方式來選擇該項目。 # 2011-01-27 對於vf按y和n,有想到一個方式 就是先把.(點)改回來, 可能把點使用在append-vff, 而;(分號),就是append+vff, 這樣子keyin的數量應該會少很多, 效率應該會比較快。 不過這個idea可能不會用在數字模式上,因為狀況不同 另外,如果輸入錯了快速鍵,或是打錯關鍵字, 想要暫停2秒鐘,然後自動清除關鍵字,並重來, 這樣子可能也多多少少增加一些速度, 不然打錯了還要手動去按一下/(斜線) 有時候按斜線還會按錯 分號,在切換資料夾的時候,可以想看看有沒有什麼其它的應用。 關鍵字的部份好像有點問題, 如果某一個物件名稱是aaabbb, 我輸入aa bb是可以找得到的, 但是如果我輸入bb aa好像是找不到的。 # 2011-01-26 想要把abc v3的第一次顯示help的部份拿掉 想加上更多操作檔案的功能 例如之前idea前寫過的: 執行檔案(依照副檔名) 刪除檔案(當然要可以刪除單檔、多檔,或是針對資料夾,或是混合) 更改名稱 移動路徑 想要在touch檔案以後,順便去編輯它 如果是在有啟動groupname的時候,步驟就會走到詢問你要不要vff的階段 touch檔案,應該是使用dialog的方式才對 刪除的功能,在C的快速鍵中,感覺不是很實用 目前是用C來當做Create,感覺還不錯 看要不要在建立另外一個關鍵字,來做刪除的動作 刪除的動作,也可以考慮不要做,改用cli, or nautilus來做會比較保險。 # 2011-01-25 想要在每一個版本控制功能中, 都加上R功能,也就是切換到Browser。 # 2011-01-22 想要在按分號的時候,就直接編輯檔案(如果是選檔案是在第一項) 就不要在按Y的,很麻煩,也為了可以簡化。 但是,如果我只是想append,但還沒有要edit,那這時怎麼辦呢? 是不是也是要維持現在的使用方式就可以了呢? 可以在append,詢問Y和N的地方,加上分號,或是F當做Y, 但這樣子不知道會不會換右手酸了。 目的還是要簡少按鍵數量。 或是在多一個快速鍵,跟F結合在一起,可能是寫在F,裡面在多一個判斷, 目的是要把append檔案的部份,分一個Y的,和一個N的。 另外,想加一個C快速鍵,就是選到項目的時候所使用的, 裡面可以刪除檔案、等其它額外擴充的功能 還有,別忘了還有一個IDEA需要被完成,就是判斷副檔名的部份。 就是在vim -p files...的時候,如果副檔名是.tar.gz、zip、image file等東西, 在vim的部份,就是會ignore它們。 # 2011-01-18 想要把原先放在/bin下的執行檔,都改放在自己的家目錄, 這樣子在有些沒有root的環境下,才可以使用, 而且這樣子也比較合理 不過有些檔案的目標路徑,是寫死的, 利用這個idea把它們都做個修正。 # 2011-01-17 想要在vimlist的功能,加上判斷副檔名的功能, 如果是使用vim編輯的話,就會乎略掉某些副檔名, 例如tar.gz, zip, images, videos, music # 2011-01-13 想要在vf的地方,加上以下的功能項目: 1. execute 2. delete execute的部份,可能就會判斷副檔名, 刪除的部份,可能會用D的關鍵字來做。 # 2011-01-11 想要在/斜線的地方,加上重新去include檔案的程式碼, 這樣子如果修改了searchfile, or searchdir,把它設定為啟動, 這時只要按一下斜線,就可以生效了 設定檔的地方,想要在加上bash history, 以及google search function 另外,以現在的使用方式,是增加判斷式和google groupname, 這樣子的使用方式,跟我新增設定檔的目標是很像的, 打算選擇設定檔的方式,在加上面的idea,可能會比較好使用。 # 2011-01-09 想要在各version control裡面的push之前, 加上"處理中..."的字眼,或者是顯示執行的指令。 在要增加一些功能的開關設定, 因為不管是在比較慢的電腦,或是比較快的,上執行這套程式,會很慢, 例如搜尋檔案的功能,或者是搜尋bash history的功能, 或許我可以把這些開關的設定,寫在某一支bash file裡面, 要使用的時候,才去修改它, 然後abc-v3就去include它。 # 2011-01-07 想要加一個快速鍵,來show/hide Help,應該就是大寫的H了 想要加上一個功能,就是按下vim的F8,就會離開vim,以及重新啟動vimlist的功能, 當然這個功能要先選擇groupname,這個功能是可以做的, 可能就離開前先寫入文字檔,然後abc-v3去判斷文字檔內是否有內容, 有的話在重新啟動vimlist的功能,因為不是很重要,所以暫時先不用寫 有沒有可能在vim裡面,按某一個快速鍵,然後就會把menu列出來讓你選擇, 或是可以讓你用快速鍵去選擇裡面的項目。 # 2011-01-03 想要加上切換到firefox的快速鍵 以及想要把切換的程式,加上引數,可以選擇切換後,要不要按下重整的按鈕。 另外,想要在啟動ide and abc-v3的時候,如果groupname是空白,就自動補上home, 關於這個idea在想想看,因為空groupname也是有我設計的理念在裡面,先不要拿掉好了。 # 2011-01-01 在abc-v3的V快速鍵中, 想要check current dir是否有.svn or .hg or .git的資料夾, 如果有的話,就直接啟用該版本控制, 還有,這個功能選擇版本控制的快速鍵,想要大小寫都可以使用。 我想在各版本控制的介面中,加上抓repo的功能下來,但這個IDEA好像不是很實用。 # 2010-12-31 想要將版本控制都放在一起, 例如按V(Version),就代表版本控制, 然後就會出現H(hg), G(git), S(Svn), C(cvs這個應該不會做) 一樣也是按快速鍵去執行它 在要加上第2層的判斷, 可能試著執行status,例如git status, 如果有正常的反應,我指的是在正確的repo裡面, 那這時我就會判斷正常,來執行指定的版本控制的指令。 # 2010-12-26 想要思考一下,怎麼樣在commander與cli之間做快速的切換, 有想到幾種方式: 1. 輸入一個快速鍵,然後會顯示讓你輸入指令的地方,只執行一次就會回到commander 2. 離開commander以後,可以任意的輸入指令,然後透過輸入某個指令,就會回到commander 3. 利用Ctrl+Z,把現在執行的東西放到background,透過fg把commander叫起來 4. 把MC啟動很慢的問題解決掉 5. 開2個視窗,用alt + tab切換 6. 開2個電腦,分別用不同的鍵盤 目前有加上nautilus,在abc裡面,所以未來我可以直接離開,或是不使用ide的指令, 如果要執行指令的時候,直接離開abc,如果指令打完,在輸入abc啟動ide就可以了。 # 2010-12-16 想要更改現在目前爛爛的svnn功能, 以及想要新增hg進來,不然就叫做hgg。 另外,svnn和hg,想要加上一個功能, commit cache的功能, 就是送出指定的檔案, 會想加上這個功能, 是因為有些檔案是我不想要送的檔案, 或是說,有些檔案己經完成了,但其它的檔案還在修改當中。 這個cache,想要寫在一個文字檔裡面,類似vimlist, 以svn來說,只要commit,就會送出了,這是與hg不同的地方, 我打算在送出了之後,就清空這個cache, 這個cache,我想取名為svnlist(svn commit list) 關於cache的功能,有一些想法: 1. 全部列入(或取消)cache 2. 關鍵字選擇單項(或多項)項目列入(或取消)cache 3. 觀看修改的內容,使用svn diff的指令,跟最後一個版本做比較 4. svn add的功能 5. 可以選擇清除cache, and uncache file 6. 可以選擇重新建立uncache file 這個會比較複雜,會有4種模式(gitv2只有2種) 每一個模式都可以下commit的指令 1. svn status, filter by untracked, or new file, 其它都沒有哦 2. svn status, filter by added, or deleted, modify一定會在裡面的(我想取commit list) 3. uncache list(這個還是要有,會比較方便) 4. cache list 在模式1的時候,可以使用關鍵字來對沒有被svn add的檔案操作, 然後會忽略掉modify或是己被svn add的檔案, commit list反之。 關於模式3,只要模式1有動作,就會重新輸出uncache file,也會清空cache file, 會這樣子做,是因為沒有svn-add的檔案(狀態為問號),是沒有辦法被commit的,請注意! 還是把模式1,變成狀態只能是問號的 另外,我想把寫入檔案這個動作,寫成bash function, 因為這個動作看起來還蠻常用的。 # 2010-12-15 搜尋google的功能, 除了想獨立一個功能來做以外, 還想要在abc3也想加上這一個功能, 不過可能只會搜尋一筆, 因為如果很多筆的話,abc3會變的很亂。 # 2010-12-14 想要加上搜尋google的功能, 請參考study/google-search.pl檔案, 當輸入關鍵字的時候,就會順便去搜尋Google, 然後我可以去選擇我想要的項目編號, 選了之後,就會用firefox指令去開啟該網址, 並且切換到firefox的視窗。 可能會新增一個項目,來放這個新功能, 然後英文模式在透過某一個快速鍵來連到這一個功能 另外,我在想要不要使用firefox, 理論上來說,我應該選擇的是links或是其它文字型的瀏覽器。 我看,還是做一個選項之類的東西,來切換瀏覽器。 後來找到了w3m,打算使用這一個。 如果要使用這個功能,請建立google這一個groupname。 使用text browser有一個好處,因為很多主機是沒有圖型介面的, 而且都是放在機房,如果沒有帶自己筆記型電腦過去,是上不了Google查資料的。 # 2010-12-10 想要加一個功能,是在輸入關鍵字的時候, 也順便去搜尋底下的資料夾, 當選擇的時候,當然是進去那一個資料夾裡面。 不過這個功能我不打算加入groupname功能內。 # 2010-12-03 在想要不要把MC加進來, 在create, delete資料夾或是文字檔的時候, 或是在copy, move, rename的時候, 轉使用MC工具,不過MC啟動的時候有點慢,大約要10秒鐘, 而且使用-s or -b的引數都還是很慢, 我在找找看有沒有其它的使用選擇。 # 2010-11-30 在想要不要增加一些系統的元素進來, 例如: sudo or leave sudo edit hosts edit php.ini edit apache conf(s) edit or tail message, dmesg start restart service search bash history(只是有些指令在cli下執行會卡住) ssh remote server 以上這個話題,可以分一些思考點出來 1. 編輯檔案的部份,可以參考dirpoint的作法 2. 搜尋檔案內容的部份,就比較單純 3. sudo 可能就要在想一下了,可能就下sudo的指令,然後我可能不要打密碼, 接下來會切換到root,這時會自動用root來執行ide或是abc。 4. start restart service, 可能需要搭配dialog來做。 5. ssh remote server, 這可能會蠻實用的,我可能會先寫入一個文字檔列表, 這個功能應該很單純,然後是全域的,不會被groupname所區分。 關於上述第1點, 可以設定檔案的virtual徑捷,例如我輸入config,這時可能會出現aaa.xml出來, 可能要想一下,這一點是否真的實用才做。 後來想一想,可能不太實用,因為我還有搜尋的功能,假設在任何地方輸入aaa, 還是會出現aaa.xml 有些功能,我在想,可能不需要,或是不能用.(點)來做選擇, 一定要用所指定的快速鍵來選擇該功能,這樣可能比較不會有誤動作。 # 2010-11-24 我新增了一個study,是可以自動切換到指定的視窗,然後送指令. 我想利用這個study,做以下的動作: 1. In Gnome-terminal vim edit file 2. 離開vim,然後執行某一個快速鍵,這時會切到firefox,然後重新整理頁面 3. 也會在回到vim 這個動作可能可以想一下應用 # 2010-11-18 想把abc裡面的重覆項目, 做一些功能選擇, 1. 將這些項目,append到vimlist 2. 在這些項目中做多項的選擇,一樣會把所選擇的結果append到vimlist中 應該除了ga和dvv功能以外,其它功能都想要套用以上的功能 另外,gitt也想要加這個功能,就可能輸入關鍵字,然後如果是多項的話, 就一次把他們加入。 多項的選擇,本來是用ers(123)的方式,只要加上星號,就可以選多項了, 或是輸入e|r|s之類的,來選其它的多項。 然後找找看,如果以vim -p來開啟檔案,能不能指向要以哪一個先顯示, 結論是可以的,請參考vim.txt這個study檔案 # 2010-11-17 想要增加一個功能在abc裡面, 當我在輸入關鍵字的時候,會即時去搜尋資料夾的檔案。 另外,想要增加效率,這個要在看一下程式能不能在做修改。 想要在clear vimlist的時候,寫入history, 這個history是要查詢用的,這樣子如果剛才需修改的檔案,
gisanfu/fast-change-dir
addfb63feda50a08c757eac73913a989b4021921
fix bug
diff --git a/cddir.sh b/cddir.sh index 12325c3..f883359 100755 --- a/cddir.sh +++ b/cddir.sh @@ -1,55 +1,57 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "dir"` ) if [ "${#item_array[@]}" -gt 1 ]; then # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 tmpfile="$fast_change_dir_tmp/`whoami`-cddir-dialogselect-$( date +%Y%m%d-%H%M ).txt" dialogitems='' for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then match=`echo $result | sed 's/___/ /g'` run="cd \"$match\"" + else + run='' fi elif [ "${#item_array[@]}" -eq 1 ]; then run="cd \"${item_array[0]}\"" else run='' fi if [ "$run" != '' ]; then eval $run # check file count and ls action func_checkfilecount fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset run unset number unset item_array
gisanfu/fast-change-dir
98cbaa0a85d513c8b2082e0606b465b2c0c63adb
add cd - command
diff --git a/IDEA b/IDEA index 86074cc..c123c07 100644 --- a/IDEA +++ b/IDEA @@ -1,512 +1,516 @@ +# 2011-05-15 + +想要加上"cd -"的指令進來 + # 2011-04-17 想要寫abc第4個版本 這個版本的特色為: - 不會即時搜尋各功能 - 當然也不會顯示搜尋後的結果 - 點確認以後,才會開始搜尋,以及各功能所會做的動作 - 為了要增加執行的效率,才會做這一個版本 - 先做基本的功能(本層、上層的檔案和資料夾處理),如果效率沒有問題,在加寫其它的功能 - 如果有重覆的,就用dialog menu - relativeitem或許可以取消cache功能 - 使用各快速鍵來啟動該功能,例如我輸入了eeee,然後按大寫F,來搜尋本層的檔案,如果只有一筆,那就加入暫存列表,並直接編輯它 # 2011-04-16 想用python重寫relativeitem 當有人在問它的時候,就會同時找以下的東西: 1. 本層的檔案和資料夾 2. 上一層的檔案和資料夾 找到了以後,第一次會將列表寫入檔案, 可能會給檔案一個編號當檔名,這個編號也會回傳給bash abc-v3主程式 當下一個relative開始,就會帶著這個編號去問新的程式, 這時新的程式,可以用這個編號去找檔案,而不用重新取得列表。 # 2011-04-15 1. 在vff的前面,加一個flow,選擇你要編輯的檔案 2. 正在想,要不要加入其它的語言,為了增加效率 # 2011-04-14 可以把各專案的設定檔,放到各專案的資料夾裡面, 不過關於這一點,可能要改很多地方。 # 2011-04-12 想要把資料夾和檔案的檔名,寫到一支文字檔裡面, 然後增加一個功能,對那個文字檔做控制 # 2011-03-22 可以把Groupname,在abc version3裡面,加上dialog的選擇功能 # 2011-03-01 在ide階段,想要不輸入東西,就可以使用F和D以及上一層的功能, 使用的方式為dialog。 增加這個功能了以後,感覺更好用了。 想要在vf詢問的地方,加上"是否使用純vim編輯,而不列入暫存"的選項 詢問過後,程式才會決定要不要寫入暫存 # 2011-02-21 看能不能在啟動ide之前,先去update(應該是說git pull)最新的資料, 這樣子就可以做最快速的同步, 希望目前原有的fast-change-dir-config的目標,能夠改成自己的git repo,比較安全, 不過這裡是點奇怪的,又想要private repo,但又想要密碼驗證,然後又想要安全性, 最好的方式,應該是每一個target或者說是End端,都要有一個類似驗證碼的東西, 送上去的時候,不是我的人就不能送上去, 目前還沒有想到一個比較好的方式。 應該是說,可以抓下去,要透過驗證碼 (每一台,或是每一個權限,使用的驗證碼都不一樣), 要送上去的時候,是需要密碼的,這樣子的方式應該是比較好的方式。 送上去的時候,可能是送到我自己的svn repo, 送上去以後,會export到某一個http的路徑, 然後我透過http simple auth,讓該權限來下載東西,或是更新東西下去, 但如果是這種作法的話,要怎麼樣上傳呢? 好像想的太複雜了@@。 # 2011-02-18 有想到一個功能, 如果我想要去一個資料夾, 它是在某一個資料下底下, 這種狀況常常會發生,就是進去上一個資料夾以後,就忘了下一個資料夾要去哪裡了。 所以想做一個功能,就是先輸入下一個條件,在然在進去第一個資料夾, 當第一個資料夾進去了以後,就會自動處理在暫存的指令, 不過後來想一想,其實如果是在本機操作,也可以進去第一層,然後按"R",啟動nautilus, 用GUI去操作。 # 2011-02-16 想要加上git的路徑(我指的是1.7的git) 不然又需要root權限了 想要多錯字處理的功能, 例如我輸入了misc, 打錯成為mics, 這時是可以判斷的,不過細節的部份要在思考一下, 而且這個功能,可能也會造成速度變慢,或許是不需要做的 # 2011-02-14 想要做一個功能,是不受groupname限制的, 很像是ssh txtfile的功能, 就是輸入一個關鍵字,可能就會跳到那一個資料夾裡面, 因為有時候很累的時候,跟本就沒有辦法輸入快速鍵。 # 2011-02-10 想要寫一支script,針對Zend Framework的架構, 匯出dirpoint的檔案出來, 可能可以針對root、module name等變數來做組合,以及匯出。 # 2011-02-01 想要把function放到lib/func資料夾裡面。 想要把片段程式碼放到lib/某一個資料夾裡面,可能是several, 想在abc-v3的第二個引數,加上@小老鼠,使用在position 還想要更改所有的文字檔到指定的某個位置, 除了路徑以外,檔名都要是變數,都是可以被修改的。 例如是放在~/git/公司名稱_某分類名稱/, 然後如果在公司做到一個地方,可以把裡面的東西,先存起來, 將整個設定和環境一起帶到另外一台電腦上面。 暫存的路徑是需要的,但是檔名應該先不需要, 其它的應該都是需要的。 # 2011-01-31 目前己經有一個輸入@小老鼠,可以為grep加上^的指令, 我想加一個#井字號,告訴程式我想要使用dialog menu的方式來選擇我要的東西, 經測試了以後,發現不能夠在bash function裡面,下dialog的指令, 所以這個功能必需要在函式以外的地方先處理, 感覺很麻煩,不過也蠻實用的。 # 2011-01-30 能不能讓每一個group,都有自己的設定檔, 例如home的group,可能就會啟動parent-item的功能, 而某程式設計的專案,可能就會因為感覺良好,而關閉它。 # 2011-01-29 能不能在同一個func_relative裡面, 同時做同個資料夾的item處理,以及上一層資料夾內的item處理呢? 能否使用C語言來改寫func_relative的函式, 然後讓bash來呼叫,看能不能改善效率, 讓反應速度能夠跟上我的操作速度, 在呈現的部份。 # 2011-01-28 有機會想要做web的部份。 關於資料夾、或是檔案碰到多筆的狀況, 可以多一個使用dialog menu的選擇來協助, 關於資料夾的部份,可以使用.(點)的快速鍵。 不過好像太麻煩了,可以試著按斜線清掉執行鍵, 然後想想如何使用更好的關鍵字來對它選取, 然後將它記錄在腦海裡面,下次就使用新的或是更好的方式來選擇該項目。 # 2011-01-27 對於vf按y和n,有想到一個方式 就是先把.(點)改回來, 可能把點使用在append-vff, 而;(分號),就是append+vff, 這樣子keyin的數量應該會少很多, 效率應該會比較快。 不過這個idea可能不會用在數字模式上,因為狀況不同 另外,如果輸入錯了快速鍵,或是打錯關鍵字, 想要暫停2秒鐘,然後自動清除關鍵字,並重來, 這樣子可能也多多少少增加一些速度, 不然打錯了還要手動去按一下/(斜線) 有時候按斜線還會按錯 分號,在切換資料夾的時候,可以想看看有沒有什麼其它的應用。 關鍵字的部份好像有點問題, 如果某一個物件名稱是aaabbb, 我輸入aa bb是可以找得到的, 但是如果我輸入bb aa好像是找不到的。 # 2011-01-26 想要把abc v3的第一次顯示help的部份拿掉 想加上更多操作檔案的功能 例如之前idea前寫過的: 執行檔案(依照副檔名) 刪除檔案(當然要可以刪除單檔、多檔,或是針對資料夾,或是混合) 更改名稱 移動路徑 想要在touch檔案以後,順便去編輯它 如果是在有啟動groupname的時候,步驟就會走到詢問你要不要vff的階段 touch檔案,應該是使用dialog的方式才對 刪除的功能,在C的快速鍵中,感覺不是很實用 目前是用C來當做Create,感覺還不錯 看要不要在建立另外一個關鍵字,來做刪除的動作 刪除的動作,也可以考慮不要做,改用cli, or nautilus來做會比較保險。 # 2011-01-25 想要在每一個版本控制功能中, 都加上R功能,也就是切換到Browser。 # 2011-01-22 想要在按分號的時候,就直接編輯檔案(如果是選檔案是在第一項) 就不要在按Y的,很麻煩,也為了可以簡化。 但是,如果我只是想append,但還沒有要edit,那這時怎麼辦呢? 是不是也是要維持現在的使用方式就可以了呢? 可以在append,詢問Y和N的地方,加上分號,或是F當做Y, 但這樣子不知道會不會換右手酸了。 目的還是要簡少按鍵數量。 或是在多一個快速鍵,跟F結合在一起,可能是寫在F,裡面在多一個判斷, 目的是要把append檔案的部份,分一個Y的,和一個N的。 另外,想加一個C快速鍵,就是選到項目的時候所使用的, 裡面可以刪除檔案、等其它額外擴充的功能 還有,別忘了還有一個IDEA需要被完成,就是判斷副檔名的部份。 就是在vim -p files...的時候,如果副檔名是.tar.gz、zip、image file等東西, 在vim的部份,就是會ignore它們。 # 2011-01-18 想要把原先放在/bin下的執行檔,都改放在自己的家目錄, 這樣子在有些沒有root的環境下,才可以使用, 而且這樣子也比較合理 不過有些檔案的目標路徑,是寫死的, 利用這個idea把它們都做個修正。 # 2011-01-17 想要在vimlist的功能,加上判斷副檔名的功能, 如果是使用vim編輯的話,就會乎略掉某些副檔名, 例如tar.gz, zip, images, videos, music # 2011-01-13 想要在vf的地方,加上以下的功能項目: 1. execute 2. delete execute的部份,可能就會判斷副檔名, 刪除的部份,可能會用D的關鍵字來做。 # 2011-01-11 想要在/斜線的地方,加上重新去include檔案的程式碼, 這樣子如果修改了searchfile, or searchdir,把它設定為啟動, 這時只要按一下斜線,就可以生效了 設定檔的地方,想要在加上bash history, 以及google search function 另外,以現在的使用方式,是增加判斷式和google groupname, 這樣子的使用方式,跟我新增設定檔的目標是很像的, 打算選擇設定檔的方式,在加上面的idea,可能會比較好使用。 # 2011-01-09 想要在各version control裡面的push之前, 加上"處理中..."的字眼,或者是顯示執行的指令。 在要增加一些功能的開關設定, 因為不管是在比較慢的電腦,或是比較快的,上執行這套程式,會很慢, 例如搜尋檔案的功能,或者是搜尋bash history的功能, 或許我可以把這些開關的設定,寫在某一支bash file裡面, 要使用的時候,才去修改它, 然後abc-v3就去include它。 # 2011-01-07 想要加一個快速鍵,來show/hide Help,應該就是大寫的H了 想要加上一個功能,就是按下vim的F8,就會離開vim,以及重新啟動vimlist的功能, 當然這個功能要先選擇groupname,這個功能是可以做的, 可能就離開前先寫入文字檔,然後abc-v3去判斷文字檔內是否有內容, 有的話在重新啟動vimlist的功能,因為不是很重要,所以暫時先不用寫 有沒有可能在vim裡面,按某一個快速鍵,然後就會把menu列出來讓你選擇, 或是可以讓你用快速鍵去選擇裡面的項目。 # 2011-01-03 想要加上切換到firefox的快速鍵 以及想要把切換的程式,加上引數,可以選擇切換後,要不要按下重整的按鈕。 另外,想要在啟動ide and abc-v3的時候,如果groupname是空白,就自動補上home, 關於這個idea在想想看,因為空groupname也是有我設計的理念在裡面,先不要拿掉好了。 # 2011-01-01 在abc-v3的V快速鍵中, 想要check current dir是否有.svn or .hg or .git的資料夾, 如果有的話,就直接啟用該版本控制, 還有,這個功能選擇版本控制的快速鍵,想要大小寫都可以使用。 我想在各版本控制的介面中,加上抓repo的功能下來,但這個IDEA好像不是很實用。 # 2010-12-31 想要將版本控制都放在一起, 例如按V(Version),就代表版本控制, 然後就會出現H(hg), G(git), S(Svn), C(cvs這個應該不會做) 一樣也是按快速鍵去執行它 在要加上第2層的判斷, 可能試著執行status,例如git status, 如果有正常的反應,我指的是在正確的repo裡面, 那這時我就會判斷正常,來執行指定的版本控制的指令。 # 2010-12-26 想要思考一下,怎麼樣在commander與cli之間做快速的切換, 有想到幾種方式: 1. 輸入一個快速鍵,然後會顯示讓你輸入指令的地方,只執行一次就會回到commander 2. 離開commander以後,可以任意的輸入指令,然後透過輸入某個指令,就會回到commander 3. 利用Ctrl+Z,把現在執行的東西放到background,透過fg把commander叫起來 4. 把MC啟動很慢的問題解決掉 5. 開2個視窗,用alt + tab切換 6. 開2個電腦,分別用不同的鍵盤 目前有加上nautilus,在abc裡面,所以未來我可以直接離開,或是不使用ide的指令, 如果要執行指令的時候,直接離開abc,如果指令打完,在輸入abc啟動ide就可以了。 # 2010-12-16 想要更改現在目前爛爛的svnn功能, 以及想要新增hg進來,不然就叫做hgg。 另外,svnn和hg,想要加上一個功能, commit cache的功能, 就是送出指定的檔案, 會想加上這個功能, 是因為有些檔案是我不想要送的檔案, 或是說,有些檔案己經完成了,但其它的檔案還在修改當中。 這個cache,想要寫在一個文字檔裡面,類似vimlist, 以svn來說,只要commit,就會送出了,這是與hg不同的地方, 我打算在送出了之後,就清空這個cache, 這個cache,我想取名為svnlist(svn commit list) 關於cache的功能,有一些想法: 1. 全部列入(或取消)cache 2. 關鍵字選擇單項(或多項)項目列入(或取消)cache 3. 觀看修改的內容,使用svn diff的指令,跟最後一個版本做比較 4. svn add的功能 5. 可以選擇清除cache, and uncache file 6. 可以選擇重新建立uncache file 這個會比較複雜,會有4種模式(gitv2只有2種) 每一個模式都可以下commit的指令 1. svn status, filter by untracked, or new file, 其它都沒有哦 2. svn status, filter by added, or deleted, modify一定會在裡面的(我想取commit list) 3. uncache list(這個還是要有,會比較方便) 4. cache list 在模式1的時候,可以使用關鍵字來對沒有被svn add的檔案操作, 然後會忽略掉modify或是己被svn add的檔案, commit list反之。 關於模式3,只要模式1有動作,就會重新輸出uncache file,也會清空cache file, 會這樣子做,是因為沒有svn-add的檔案(狀態為問號),是沒有辦法被commit的,請注意! 還是把模式1,變成狀態只能是問號的 另外,我想把寫入檔案這個動作,寫成bash function, 因為這個動作看起來還蠻常用的。 # 2010-12-15 搜尋google的功能, 除了想獨立一個功能來做以外, 還想要在abc3也想加上這一個功能, 不過可能只會搜尋一筆, 因為如果很多筆的話,abc3會變的很亂。 # 2010-12-14 想要加上搜尋google的功能, 請參考study/google-search.pl檔案, 當輸入關鍵字的時候,就會順便去搜尋Google, 然後我可以去選擇我想要的項目編號, 選了之後,就會用firefox指令去開啟該網址, 並且切換到firefox的視窗。 可能會新增一個項目,來放這個新功能, 然後英文模式在透過某一個快速鍵來連到這一個功能 另外,我在想要不要使用firefox, 理論上來說,我應該選擇的是links或是其它文字型的瀏覽器。 我看,還是做一個選項之類的東西,來切換瀏覽器。 後來找到了w3m,打算使用這一個。 如果要使用這個功能,請建立google這一個groupname。 使用text browser有一個好處,因為很多主機是沒有圖型介面的, 而且都是放在機房,如果沒有帶自己筆記型電腦過去,是上不了Google查資料的。 # 2010-12-10 想要加一個功能,是在輸入關鍵字的時候, 也順便去搜尋底下的資料夾, 當選擇的時候,當然是進去那一個資料夾裡面。 不過這個功能我不打算加入groupname功能內。 # 2010-12-03 在想要不要把MC加進來, 在create, delete資料夾或是文字檔的時候, 或是在copy, move, rename的時候, 轉使用MC工具,不過MC啟動的時候有點慢,大約要10秒鐘, 而且使用-s or -b的引數都還是很慢, 我在找找看有沒有其它的使用選擇。 # 2010-11-30 在想要不要增加一些系統的元素進來, 例如: sudo or leave sudo edit hosts edit php.ini edit apache conf(s) edit or tail message, dmesg start restart service search bash history(只是有些指令在cli下執行會卡住) ssh remote server 以上這個話題,可以分一些思考點出來 1. 編輯檔案的部份,可以參考dirpoint的作法 2. 搜尋檔案內容的部份,就比較單純 3. sudo 可能就要在想一下了,可能就下sudo的指令,然後我可能不要打密碼, 接下來會切換到root,這時會自動用root來執行ide或是abc。 4. start restart service, 可能需要搭配dialog來做。 5. ssh remote server, 這可能會蠻實用的,我可能會先寫入一個文字檔列表, 這個功能應該很單純,然後是全域的,不會被groupname所區分。 關於上述第1點, 可以設定檔案的virtual徑捷,例如我輸入config,這時可能會出現aaa.xml出來, 可能要想一下,這一點是否真的實用才做。 後來想一想,可能不太實用,因為我還有搜尋的功能,假設在任何地方輸入aaa, 還是會出現aaa.xml 有些功能,我在想,可能不需要,或是不能用.(點)來做選擇, 一定要用所指定的快速鍵來選擇該功能,這樣可能比較不會有誤動作。 # 2010-11-24 我新增了一個study,是可以自動切換到指定的視窗,然後送指令. 我想利用這個study,做以下的動作: 1. In Gnome-terminal vim edit file 2. 離開vim,然後執行某一個快速鍵,這時會切到firefox,然後重新整理頁面 3. 也會在回到vim 這個動作可能可以想一下應用 # 2010-11-18 想把abc裡面的重覆項目, 做一些功能選擇, 1. 將這些項目,append到vimlist 2. 在這些項目中做多項的選擇,一樣會把所選擇的結果append到vimlist中 應該除了ga和dvv功能以外,其它功能都想要套用以上的功能 另外,gitt也想要加這個功能,就可能輸入關鍵字,然後如果是多項的話, 就一次把他們加入。 多項的選擇,本來是用ers(123)的方式,只要加上星號,就可以選多項了, 或是輸入e|r|s之類的,來選其它的多項。 然後找找看,如果以vim -p來開啟檔案,能不能指向要以哪一個先顯示, 結論是可以的,請參考vim.txt這個study檔案 # 2010-11-17 想要增加一個功能在abc裡面, 當我在輸入關鍵字的時候,會即時去搜尋資料夾的檔案。 另外,想要增加效率,這個要在看一下程式能不能在做修改。 想要在clear vimlist的時候,寫入history, 這個history是要查詢用的,這樣子如果剛才需修改的檔案, 可以在重新呈現在vimlist裡面。 # 2010-11-15 diff --git a/abc-4.sh b/abc-4.sh index 33ae2e0..696d0b1 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,390 +1,392 @@ #!/bin/bash source "$fast_change_dir/config/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color while [ 1 ]; do clear fast_change_dir_auto_list_file_enable='0' if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 智慧選取單項 (;) 分號' echo ' 上一層 (,) 逗點' + echo ' 上一個資料夾 (<) 小於,跟上一層是同一個按鍵' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear fast_change_dir_auto_list_file_enable='1' break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue - - #clear_var_all='1' + elif [ "$inputvar" == '<' ]; then + cd - + clear_var_all='1' continue elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd
gisanfu/fast-change-dir
dc05227f7c2ebe3078ae2f2b233578103719989e
add condition on dirpoint function
diff --git a/dirpoint.sh b/dirpoint.sh index a33d7ec..f7039b0 100755 --- a/dirpoint.sh +++ b/dirpoint.sh @@ -1,74 +1,97 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" # default ifs value default_ifs=$' \t\n' # fix space to effect array result IFS=$'\012' dirpoint=$1 tmpfile="$fast_change_dir_tmp/`whoami`-dirpoint-dialog-$( date +%Y%m%d-%H%M ).txt" if [ "$groupname" != "" ]; then if [ ! -f $fast_change_dir_project_config/dirpoint-$groupname.txt ]; then touch $fast_change_dir_project_config/dirpoint-$groupname.txt fi if [ "$dirpoint" != "" ]; then - result=`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f2` resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f2`) if [ "${#resultarray[@]}" -gt "1" ]; then - cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `grep $dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | tr "\n" " " | tr ',' ' '` $tmpfile ) + cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | tr "\n" " " | tr ',' ' '` $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" == "" ]; then echo '[ERROR] dirpoint is empty' else dv $result fi elif [ "${#resultarray[@]}" == "1" ]; then - cmd="cd $result" + cmd="cd ${resultarray[0]}" eval $cmd func_checkfilecount else - echo '[ERROR] dirpoint is not exist!!' + resultarray=(`grep $dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f2`) + if [ "${#resultarray[@]}" -gt "1" ]; then + cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `grep $dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | tr "\n" " " | tr ',' ' '` $tmpfile ) + + eval $cmd + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" == "" ]; then + echo '[ERROR] dirpoint is empty' + else + dv $result + fi + elif [ "${#resultarray[@]}" == "1" ]; then + cmd="cd ${resultarray[0]}" + eval $cmd + func_checkfilecount + else + echo '[ERROR] dirpoint is not exist!!' + fi fi else resultvalue=`cat $fast_change_dir_project_config/dirpoint-$groupname.txt | grep -v "^#" | wc -l` if [ "$resultvalue" -ge "1" ]; then cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `cat $fast_change_dir_project_config/dirpoint-$groupname.txt | grep -v "^#" | tr "\n" " " | tr ',' ' '` $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" == "" ]; then echo '[ERROR] dirpoint is empty' else dv $result fi else echo '[ERROR] Please use DVV cmd to create dirpoint' fi fi else echo '[ERROR] groupname is empty, please use GA cmd' fi +fetchone='' +result='' tmpfile='' IFS=$default_ifs
gisanfu/fast-change-dir
ee555acc7aa698ea373ddc36faf588a86544eac0
add list file enable variable
diff --git a/abc-4.sh b/abc-4.sh index a46f551..33ae2e0 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,387 +1,390 @@ #!/bin/bash source "$fast_change_dir/config/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color while [ 1 ]; do clear + fast_change_dir_auto_list_file_enable='0' + if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array unset cmd1 unset cmd2 unset cmd3 clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 智慧選取單項 (;) 分號' echo ' 上一層 (,) 逗點' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear + fast_change_dir_auto_list_file_enable='1' break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue #clear_var_all='1' continue elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd diff --git a/config/config.sh b/config/config.sh index 2bc6f79..f0a612d 100644 --- a/config/config.sh +++ b/config/config.sh @@ -1,20 +1,23 @@ #!/bin/bash # 這個是fast-change-dir專案的設定檔 # 預設值,應該是要設定成啟動 # 然後使用者可以在他自己的家目錄設定 # 檔名也是config.sh # 目前先加搜尋檔案/資料夾的功能啟用設定 # 因為這兩個影響速度最明顯 fast_change_dir_config_searchfile_enable='1' fast_change_dir_config_searchdir_enable='1' fast_change_dir_config_googlesearch_enable='1' fast_change_dir_config_bashhistorysearch_enable='1' # 上一層的兩個功能,合併在同一項控制 fast_change_dir_config_parent_enable='1' # 重覆項目的顯示開關 fast_change_dir_config_duplicate_enable='1' + +# 是否自動的在執行指令完後,顯示資料夾裡面的東西 +fast_change_dir_auto_list_file_enable='1' diff --git a/lib/func/normal.sh b/lib/func/normal.sh index 18019c1..0b29240 100644 --- a/lib/func/normal.sh +++ b/lib/func/normal.sh @@ -1,30 +1,32 @@ #!/bin/bash # +--------+----------------------+ # |FUNCTION| func_statusbar | # +--------+----------------------+ # |ARGUMENT| $1: Action Name | # +--------+----------------------+ func_statusbar() { echo "[ACT]=>$1" #echo "[PWD]=>`pwd`" } # +--------+----------------------+ # |FUNCTION| func_checkfilecount | # +--------+----------------------+ # |ARGUMENT| | # +--------+----------------------+ func_checkfilecount() { - echo "[PWD]=>`pwd`" - #filecount=`ls | wc -l` - #if [ "$filecount" == "0" ]; then - # echo "[EMPTY]" - #elif [ "$filecount" -le "6" ]; then - # ls -la - #else - # ls - #fi + if [ "$fast_change_dir_auto_list_file_enable" == '1' ]; then + echo "[PWD]=>`pwd`" + filecount=`ls | wc -l` + if [ "$filecount" == "0" ]; then + echo "[EMPTY]" + elif [ "$filecount" -le "6" ]; then + ls -la + else + ls + fi + fi }
gisanfu/fast-change-dir
17693180e5c7cdf6086d67520b044a4a9a3dad8a
fix speed, and add vimfile count > 10 action
diff --git a/lib/func/normal.sh b/lib/func/normal.sh index 8346e5b..18019c1 100644 --- a/lib/func/normal.sh +++ b/lib/func/normal.sh @@ -1,30 +1,30 @@ #!/bin/bash # +--------+----------------------+ # |FUNCTION| func_statusbar | # +--------+----------------------+ # |ARGUMENT| $1: Action Name | # +--------+----------------------+ func_statusbar() { echo "[ACT]=>$1" #echo "[PWD]=>`pwd`" } # +--------+----------------------+ # |FUNCTION| func_checkfilecount | # +--------+----------------------+ # |ARGUMENT| | # +--------+----------------------+ func_checkfilecount() { echo "[PWD]=>`pwd`" - filecount=`ls | wc -l` - if [ "$filecount" == "0" ]; then - echo "[EMPTY]" - elif [ "$filecount" -le "6" ]; then - ls -la - else - ls - fi + #filecount=`ls | wc -l` + #if [ "$filecount" == "0" ]; then + # echo "[EMPTY]" + #elif [ "$filecount" -le "6" ]; then + # ls -la + #else + # ls + #fi } diff --git a/vimlist-append.sh b/vimlist-append.sh index cae5a49..51d8689 100755 --- a/vimlist-append.sh +++ b/vimlist-append.sh @@ -1,124 +1,141 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 # 是否要vff,如果沒有指定,就是會詢問使用者 # 不詢問,不要vff的話,就放0 # 不詢問,要vff的話,就放1 isVFF=$4 if [ "$isVFF" == '' ]; then isVFF=1 fi item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' if [ ${#item_array[@]} -eq 1 ]; then relativeitem=${item_array[0]} elif [ ${#item_array[@]} -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems='' for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem=$result else relativeitem='' fi else relativeitem='' fi if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then if [ "$isVFF" == '0' ]; then inputchar='n' elif [ "$isVFF" == '1' ]; then inputchar='y' else isVFF='' fi # 這裡可以考慮在加上一項,就是不要append這一個檔案 if [ "$isVFF" == '' ]; then # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' echo '[WAIT] 或是編輯列表 [j]' echo '[WAIT] 還是清空它 [k]' read -n 1 inputchar fi # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append selectitem='' selectitem=`pwd`/$relativeitem checkline=`grep "$selectitem" $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt else echo '[NOTICE] File is exist' fi if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... checklinenumber=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` cmd='vff "vim' # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 # 查詢更多資訊請執行: "vim -h" if [ "$checklinenumber" -lt 10 ]; then # 為了加快速度而這麼寫的 - tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') + tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') cmd="$cmd ${tabennn[$checklinenumber]}" else echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' + echo '[NOTICE] 純編輯這個檔案,以及叫出列表,看你要砍掉哪一個' + vim "$selectitem" + + unset cmd + unset cmd1 + unset cmd2 + unset cmd3 + unset number + unset item_array + unset checklinenumber + unset relativeitem + unset selectitem + + vfff + cmd='' fi - cmd="$cmd -p $fast_change_dir_project_config/vimlist-$groupname.txt\"" - eval $cmd + if [ "$cmd" != '' ]; then + cmd="$cmd -p $fast_change_dir_project_config/vimlist-$groupname.txt\"" + eval $cmd + fi elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then echo "Your want append other file" elif [ "$inputchar" == 'j' ]; then vfff elif [ "$inputchar" == 'k' ]; then vffff else echo "Your want append other file" fi # 最後,顯示目前目錄的檔案 func_checkfilecount elif [ "$groupname" == "" ]; then echo '[ERROR] Argument or $groupname is empty' fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem diff --git a/vimlist-edit.sh b/vimlist-edit.sh index eeef7ce..a6b2518 100755 --- a/vimlist-edit.sh +++ b/vimlist-edit.sh @@ -1,14 +1,15 @@ #!/bin/bash if [ "$groupname" != "" ]; then vim $fast_change_dir_project_config/vimlist-$groupname.txt # 詢問使用者,看要不要編輯list - echo '[WAIT] 預設是編輯暫存檔案群,我指的是vff [Y1,n0]' + echo '[WAIT] 預設是編輯暫存檔案群,我指的是vff [y1,n0]' read -n 1 inputchar if [[ "$inputchar" == 'y' || "$inputchar" == '1' || "$inputchar" == '' ]]; then - vff + # 如果不加空白引數,會將外面那一層的引數帶進來,這時會造成程式錯誤 + vff '' fi else echo '[ERROR] groupname is empty' fi diff --git a/vimlist.sh b/vimlist.sh index 9b63c77..ea90605 100755 --- a/vimlist.sh +++ b/vimlist.sh @@ -1,85 +1,88 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" program=$1 if [ "$groupname" != "" ]; then if [ "$program" == "" ]; then program2="vim -p $fast_change_dir_project_config/vimlist-$groupname.txt" else program2=$program fi cmdlist="cat $fast_change_dir_project_config/vimlist-$groupname.txt" # 正規的外面要用雙引包起來 regex="^vim" # 如果program這個變數是空白,就代表會使用vim-p的指令 # 使用vim,當然不會去開一些binary的檔案 if [[ "$program" == '' || "$program" =~ $regex ]]; then # 先把一些己知的東西先ignore掉,例如壓縮檔 cmdlist="$cmdlist | grep -v .tar.gz | grep -v .zip | grep -v .png | grep -v .gif | grep -v .jpeg | grep -v .jpg" cmdlist="$cmdlist | xargs -n 1 $fast_change_dir_bin/only-text-filecontent.sh" fi # 這是多行文字檔內容,變成以空格分格成字串的步驟 cmdlist2='| tr "\n" " "' cmdlist="$cmdlist $cmdlist2" cmdlist_result=`eval $cmdlist` cmd="$program2 $cmdlist_result" # 檢查一下數量,如果是一筆的話,那就自動跳到那一筆 # 這樣子只有一筆的時候,會比較方便 # 會這樣子寫,是因為不要去影響其它程式的相依性 if [ "$program" == "" ]; then count=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$count" == 1 ]; then cmd="$cmd +tabnext" fi # 如果大於1筆,就用選擇的方式,選擇第一次要看到的檔案 if [ "$count" -gt 1 ]; then vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) tmpfile="$fast_change_dir_tmp/`whoami`-vimlist-dialogselect-$( date +%Y%m%d-%H%M ).txt" dialogitems='' start=1 for echothem in ${vimlist_array[@]} do dialogitems=" $dialogitems '$start' $echothem " start=$(expr $start + 1) done cmd2=$( func_dialog_menu '你想從哪一個位置開始編輯 ' 100 "$dialogitems" $tmpfile ) eval $cmd2 result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then - for (( b=1; b<=$result; b++ )) - do - cmd="$cmd +tabnext" - done + if [ "$result" -lt 10 ]; then + # 為了加快速度而這麼寫的 + tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') + cmd="$cmd ${tabennn[$result]}" + else + echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' + fi else # 如果使用者選擇取消,那就取消整個vff cmd="" fi fi fi if [ "$cmd" != '' ]; then eval $cmd fi func_checkfilecount else echo '[ERROR] groupname is empty, please use GA cmd' fi unset vimlist_array unset cmd
gisanfu/fast-change-dir
fd9a1469ba49363580d66750e9d750d7a62cfe50
add speed section by vim append function
diff --git a/vimlist-append.sh b/vimlist-append.sh index caf71e9..cae5a49 100755 --- a/vimlist-append.sh +++ b/vimlist-append.sh @@ -1,125 +1,124 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 # 是否要vff,如果沒有指定,就是會詢問使用者 # 不詢問,不要vff的話,就放0 # 不詢問,要vff的話,就放1 isVFF=$4 if [ "$isVFF" == '' ]; then isVFF=1 fi item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' if [ ${#item_array[@]} -eq 1 ]; then relativeitem=${item_array[0]} elif [ ${#item_array[@]} -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems='' for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem=$result else relativeitem='' fi else relativeitem='' fi if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then if [ "$isVFF" == '0' ]; then inputchar='n' elif [ "$isVFF" == '1' ]; then inputchar='y' else isVFF='' fi # 這裡可以考慮在加上一項,就是不要append這一個檔案 if [ "$isVFF" == '' ]; then # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' echo '[WAIT] 或是編輯列表 [j]' echo '[WAIT] 還是清空它 [k]' read -n 1 inputchar fi # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append selectitem='' selectitem=`pwd`/$relativeitem checkline=`grep "$selectitem" $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt else echo '[NOTICE] File is exist' fi if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... checklinenumber=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` cmd='vff "vim' # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 # 查詢更多資訊請執行: "vim -h" if [ "$checklinenumber" -lt 10 ]; then - for i in `seq 1 $checklinenumber` - do - cmd="$cmd +tabnext" - done + # 為了加快速度而這麼寫的 + tabennn=('' '+tabnext' '+tabnext +tabnext' '+tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext' '+tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext +tabnext') + cmd="$cmd ${tabennn[$checklinenumber]}" else echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' fi cmd="$cmd -p $fast_change_dir_project_config/vimlist-$groupname.txt\"" eval $cmd elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then echo "Your want append other file" elif [ "$inputchar" == 'j' ]; then vfff elif [ "$inputchar" == 'k' ]; then vffff else echo "Your want append other file" fi # 最後,顯示目前目錄的檔案 func_checkfilecount elif [ "$groupname" == "" ]; then echo '[ERROR] Argument or $groupname is empty' fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem
gisanfu/fast-change-dir
cd54cde53624573d992c807f409dc19e697fc903
fix bug
diff --git a/vimlist.sh b/vimlist.sh index f1cf4f4..9b63c77 100755 --- a/vimlist.sh +++ b/vimlist.sh @@ -1,81 +1,85 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" program=$1 if [ "$groupname" != "" ]; then if [ "$program" == "" ]; then program2="vim -p $fast_change_dir_project_config/vimlist-$groupname.txt" else program2=$program fi cmdlist="cat $fast_change_dir_project_config/vimlist-$groupname.txt" # 正規的外面要用雙引包起來 regex="^vim" # 如果program這個變數是空白,就代表會使用vim-p的指令 # 使用vim,當然不會去開一些binary的檔案 if [[ "$program" == '' || "$program" =~ $regex ]]; then # 先把一些己知的東西先ignore掉,例如壓縮檔 cmdlist="$cmdlist | grep -v .tar.gz | grep -v .zip | grep -v .png | grep -v .gif | grep -v .jpeg | grep -v .jpg" cmdlist="$cmdlist | xargs -n 1 $fast_change_dir_bin/only-text-filecontent.sh" fi # 這是多行文字檔內容,變成以空格分格成字串的步驟 cmdlist2='| tr "\n" " "' cmdlist="$cmdlist $cmdlist2" cmdlist_result=`eval $cmdlist` cmd="$program2 $cmdlist_result" # 檢查一下數量,如果是一筆的話,那就自動跳到那一筆 # 這樣子只有一筆的時候,會比較方便 # 會這樣子寫,是因為不要去影響其它程式的相依性 if [ "$program" == "" ]; then count=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$count" == 1 ]; then cmd="$cmd +tabnext" fi # 如果大於1筆,就用選擇的方式,選擇第一次要看到的檔案 if [ "$count" -gt 1 ]; then vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) tmpfile="$fast_change_dir_tmp/`whoami`-vimlist-dialogselect-$( date +%Y%m%d-%H%M ).txt" dialogitems='' start=1 for echothem in ${vimlist_array[@]} do dialogitems=" $dialogitems '$start' $echothem " start=$(expr $start + 1) done cmd2=$( func_dialog_menu '你想從哪一個位置開始編輯 ' 100 "$dialogitems" $tmpfile ) eval $cmd2 result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then for (( b=1; b<=$result; b++ )) do cmd="$cmd +tabnext" done else - cmd="$cmd +tabnext" + # 如果使用者選擇取消,那就取消整個vff + cmd="" fi fi fi - eval $cmd + if [ "$cmd" != '' ]; then + eval $cmd + fi func_checkfilecount else echo '[ERROR] groupname is empty, please use GA cmd' fi unset vimlist_array +unset cmd
gisanfu/fast-change-dir
271abe5bd249e3afc2290e362faf76f85e948cad
fix bug
diff --git a/backdir.sh b/backdir.sh index f6836c7..de398b2 100755 --- a/backdir.sh +++ b/backdir.sh @@ -1,52 +1,54 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 +unset run + item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" ".." "dir"` ) if [ "${#item_array[@]}" -gt 1 ]; then # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 tmpfile="$fast_change_dir_tmp/`whoami`-cddir-dialogselect-$( date +%Y%m%d-%H%M ).txt" dialogitems='' for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then match=`echo $result | sed 's/___/ /g'` run="cd ../\"$match\"" fi elif [ "${#item_array[@]}" -eq 1 ]; then run="cd ../\"${item_array[0]}\"" fi if [ "$run" != '' ]; then eval $run # check file count and ls action func_checkfilecount fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array
gisanfu/fast-change-dir
69ee09ff9257c3c6a3b8c79563d248528d4c0677
fix bug
diff --git a/editfile.sh b/editfile.sh index cf6fe71..e5f4e93 100755 --- a/editfile.sh +++ b/editfile.sh @@ -1,52 +1,53 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' if [ "${#item_array[@]}" -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems='' for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem="$result" fi elif [ "${#item_array[@]}" -eq 1 ]; then relativeitem="${item_array[0]}" #cmd="vim \"${item_array[0]}\"" #eval $cmd - # check file count and ls action - func_checkfilecount fi if [ "$relativeitem" != '' ]; then vim $relativeitem fi +# check file count and ls action +func_checkfilecount + unset cmd unset cmd1 unset cmd2 unset cmd3 unset item_array diff --git a/groupname.sh b/groupname.sh index d526e1d..5a45ab4 100755 --- a/groupname.sh +++ b/groupname.sh @@ -1,125 +1,101 @@ #!/bin/bash # # 這個檔案,是選擇、以及增加專案代碼 # source "$fast_change_dir_func/dialog.sh" -action=$1 -groupname=$2 -tmpfile="$fast_change_dir_tmp/`whoami`-dialog-$( date +%Y%m%d-%H%M ).txt" +action_arg=$1 +groupname_arg=$2 +#tmpfile="$fast_change_dir_tmp/`whoami`-dialog-$( date +%Y%m%d-%H%M ).txt" -if [ -f $fast_change_dir_config/groupname.txt ]; then - echo -else +if [ ! -f $fast_change_dir_config/groupname.txt ]; then # 如果檔案不存在,就建立文字檔案,以及建立一個預設空白的groupname touch $fast_change_dir_config/groupname.txt #echo '""' >> $fast_change_dir_config/groupname.txt fi -if [ "$action" == "select" ]; then - if [ "$groupname" != "" ]; then - # 這個變數是存放選擇後,或是match後的結果 - groupname_select='' - - resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) +if [ "$action_arg" == "select" ]; then + # 這個變數是存放選擇後,或是match後的結果 + groupname_select='' - # 先處理與判斷,將結果存起來,最後才去處理那個結果 - if [ "${#resultarray[@]}" -gt "1" ]; then - # 把陣列轉成dialog,以數字來選單 - dialogitems='' - start=1 - for echothem in ${resultarray[@]} - do - dialogitems=" $dialogitems '$start' $echothem " - start=$(expr $start + 1) - done - tmpfile="$fast_change_dir_tmp/`whoami`-groupname-dialogselect-$( date +%Y%m%d-%H%M ).txt" - cmd=$( func_dialog_menu 'Please select groupname' 100 "$dialogitems" $tmpfile ) + if [ "$groupname_arg" != "" ]; then + resultarray=(`grep $groupname_arg $fast_change_dir_config/groupname.txt`) + else + resultarray=(`cat $fast_change_dir_config/groupname.txt`) + fi - eval $cmd - result=`cat $tmpfile` + # 先處理與判斷,將結果存起來,最後才去處理那個結果 + if [ "${#resultarray[@]}" -gt "1" ]; then + # 把陣列轉成dialog,以數字來選單 + dialogitems='' + start=1 + for echothem in ${resultarray[@]} + do + dialogitems=" $dialogitems '$start' $echothem " + start=$(expr $start + 1) + done + tmpfile="$fast_change_dir_tmp/`whoami`-groupname-dialogselect-$( date +%Y%m%d-%H%M ).txt" + cmd=$( func_dialog_menu 'Please select groupname' 100 "$dialogitems" $tmpfile ) - if [ -f "$tmpfile" ]; then - rm -rf $tmpfile - fi + eval $cmd + result=`cat $tmpfile` - if [ "$result" != "" ]; then - groupname_select=${resultarray[$result - 1]} - echo $groupname_select - else - echo '[ERROR] groupname no match, or no select' - fi - elif [ "${#resultarray[@]}" == "1" ]; then - groupname_select=${resultarray[0]} - else - echo '[ERROR] groupname is not select or not exist!!' + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile fi - if [ "$groupname_select" != '' ]; then - export groupname=$groupname_select - - if [ -f $fast_change_dir_config/your-project-config-$groupname_select.sh ]; then - source $fast_change_dir_config/your-project-config-$groupname_select.sh - fast_change_dir_project_config=$fast_change_dir_your_project_config - else - fast_change_dir_project_config=$fast_change_dir_config - fi - - echo '[OK] export groupname success' - # 切換到Root的資料夾,預設是root,這是我建立資料夾link的方式,根目錄名稱叫root - dv root + if [ "$result" != "" ]; then + groupname_select=${resultarray[$result - 1]} + else + echo '[ERROR] groupname no match, or no select' fi + elif [ "${#resultarray[@]}" == "1" ]; then + groupname_select=${resultarray[0]} else - dialogitems=`cat $fast_change_dir_config/groupname.txt | awk -F"\n" '{ print $1 " \" \" " }' | tr "\n" ' '` - cmd=$( func_dialog_menu '請選擇專案代碼' '123' 70 "$dialogitems" "$tmpfile") + echo '[ERROR] groupname is not select or not exist!!' + fi - eval $cmd - result=`cat $tmpfile` + if [ "$groupname_select" != '' ]; then + export groupname=$groupname_select - if [ "$result" == "" ]; then - func_statusbar '你不選嗎,別忘了要選才能使用專案功能哦' + if [ -f $fast_change_dir_config/your-project-config-$groupname_select.sh ]; then + source $fast_change_dir_config/your-project-config-$groupname_select.sh + fast_change_dir_project_config=$fast_change_dir_your_project_config else - export groupname=$result - - if [ -f $fast_change_dir_config/your-project-config-$groupname.sh ]; then - source $fast_change_dir_config/your-project-config-$groupname.sh - fast_change_dir_project_config=$fast_change_dir_your_project_config - else - fast_change_dir_project_config=$fast_change_dir_config - fi - - echo '[OK] export groupname success' - # 切換到Root的資料夾,預設是root,這是我建立資料夾link的方式,根目錄名稱叫root - dv root + fast_change_dir_project_config=$fast_change_dir_config fi + + echo '[OK] export groupname success' + # 切換到Root的資料夾,預設是root,這是我建立資料夾link的方式,根目錄名稱叫root + dv root fi # 在確認一次,如果有選擇,接下來就檢查是否有定義專案設定檔 #if [ "$groupname" != "" ]; then # if [ -f $fast_change_dir_config/$groupname-your-project-config.sh ]; then # source $fast_change_dir_config/$groupname-your-project-config.sh # fast_change_dir_project_config=$fast_change_dir_your_project_config # else # fast_change_dir_project_config=$fast_change_dir_config # fi #fi -elif [ "$action" == "append" ]; then - if [ "$groupname" != "" ]; then - count=`grep -ir $groupname $fast_change_dir_config/groupname.txt | wc -l` +elif [ "$action_arg" == "append" ]; then + if [ "$groupname_arg" != "" ]; then + count=`grep -ir $groupname_arg $fast_change_dir_config/groupname.txt | wc -l` if [ "$count" == "0" ]; then - echo $groupname >> $fast_change_dir_config/groupname.txt - export groupname=$groupname + echo $groupname_arg >> $fast_change_dir_config/groupname.txt + export groupname=$groupname_arg echo '[OK] append and export groupname success' else - echo "[ERROR] groupname is exist by $groupname" + echo "[ERROR] groupname is exist by $groupname_arg" fi else echo "[ERROR] please fill groupname field by append action" fi -elif [ "$action" == "edit" ]; then +elif [ "$action_arg" == "edit" ]; then vim $fast_change_dir_config/groupname.txt else echo '[ERROR] no support action' fi
gisanfu/fast-change-dir
fc80df627a41232468e6af28a424b49fd0db9936
add dialog function by groupname
diff --git a/groupname.sh b/groupname.sh index 48570f5..d526e1d 100755 --- a/groupname.sh +++ b/groupname.sh @@ -1,92 +1,125 @@ #!/bin/bash # # 這個檔案,是選擇、以及增加專案代碼 # source "$fast_change_dir_func/dialog.sh" action=$1 groupname=$2 tmpfile="$fast_change_dir_tmp/`whoami`-dialog-$( date +%Y%m%d-%H%M ).txt" if [ -f $fast_change_dir_config/groupname.txt ]; then echo else # 如果檔案不存在,就建立文字檔案,以及建立一個預設空白的groupname touch $fast_change_dir_config/groupname.txt #echo '""' >> $fast_change_dir_config/groupname.txt fi if [ "$action" == "select" ]; then if [ "$groupname" != "" ]; then - count=`grep -ir $groupname $fast_change_dir_config/groupname.txt | wc -l` - if [ "$count" == "0" ]; then - export groupname="" - echo "[ERROR] groupname is not exist by $groupname" + # 這個變數是存放選擇後,或是match後的結果 + groupname_select='' + + resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) + + # 先處理與判斷,將結果存起來,最後才去處理那個結果 + if [ "${#resultarray[@]}" -gt "1" ]; then + # 把陣列轉成dialog,以數字來選單 + dialogitems='' + start=1 + for echothem in ${resultarray[@]} + do + dialogitems=" $dialogitems '$start' $echothem " + start=$(expr $start + 1) + done + tmpfile="$fast_change_dir_tmp/`whoami`-groupname-dialogselect-$( date +%Y%m%d-%H%M ).txt" + cmd=$( func_dialog_menu 'Please select groupname' 100 "$dialogitems" $tmpfile ) + + eval $cmd + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" != "" ]; then + groupname_select=${resultarray[$result - 1]} + echo $groupname_select + else + echo '[ERROR] groupname no match, or no select' + fi + elif [ "${#resultarray[@]}" == "1" ]; then + groupname_select=${resultarray[0]} else - export groupname=$groupname + echo '[ERROR] groupname is not select or not exist!!' + fi - if [ -f $fast_change_dir_config/your-project-config-$groupname.sh ]; then - source $fast_change_dir_config/your-project-config-$groupname.sh + if [ "$groupname_select" != '' ]; then + export groupname=$groupname_select + + if [ -f $fast_change_dir_config/your-project-config-$groupname_select.sh ]; then + source $fast_change_dir_config/your-project-config-$groupname_select.sh fast_change_dir_project_config=$fast_change_dir_your_project_config else fast_change_dir_project_config=$fast_change_dir_config fi echo '[OK] export groupname success' # 切換到Root的資料夾,預設是root,這是我建立資料夾link的方式,根目錄名稱叫root dv root fi else dialogitems=`cat $fast_change_dir_config/groupname.txt | awk -F"\n" '{ print $1 " \" \" " }' | tr "\n" ' '` cmd=$( func_dialog_menu '請選擇專案代碼' '123' 70 "$dialogitems" "$tmpfile") eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then func_statusbar '你不選嗎,別忘了要選才能使用專案功能哦' else export groupname=$result if [ -f $fast_change_dir_config/your-project-config-$groupname.sh ]; then source $fast_change_dir_config/your-project-config-$groupname.sh fast_change_dir_project_config=$fast_change_dir_your_project_config else fast_change_dir_project_config=$fast_change_dir_config fi echo '[OK] export groupname success' # 切換到Root的資料夾,預設是root,這是我建立資料夾link的方式,根目錄名稱叫root dv root fi fi # 在確認一次,如果有選擇,接下來就檢查是否有定義專案設定檔 #if [ "$groupname" != "" ]; then # if [ -f $fast_change_dir_config/$groupname-your-project-config.sh ]; then # source $fast_change_dir_config/$groupname-your-project-config.sh # fast_change_dir_project_config=$fast_change_dir_your_project_config # else # fast_change_dir_project_config=$fast_change_dir_config # fi #fi elif [ "$action" == "append" ]; then if [ "$groupname" != "" ]; then count=`grep -ir $groupname $fast_change_dir_config/groupname.txt | wc -l` if [ "$count" == "0" ]; then echo $groupname >> $fast_change_dir_config/groupname.txt export groupname=$groupname echo '[OK] append and export groupname success' else echo "[ERROR] groupname is exist by $groupname" fi else echo "[ERROR] please fill groupname field by append action" fi elif [ "$action" == "edit" ]; then vim $fast_change_dir_config/groupname.txt else echo '[ERROR] no support action' fi
gisanfu/fast-change-dir
9dc68080c27c279072e80cd8ed3f5d235f28de64
fix bug
diff --git a/abc-4.sh b/abc-4.sh index d56b226..a46f551 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,384 +1,387 @@ #!/bin/bash source "$fast_change_dir/config/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color while [ 1 ]; do clear if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array + unset cmd1 + unset cmd2 + unset cmd3 clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 智慧選取單項 (;) 分號' echo ' 上一層 (,) 逗點' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue #clear_var_all='1' continue elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd diff --git a/dirpoint.sh b/dirpoint.sh index 9635c2d..a33d7ec 100755 --- a/dirpoint.sh +++ b/dirpoint.sh @@ -1,75 +1,74 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" # default ifs value default_ifs=$' \t\n' # fix space to effect array result IFS=$'\012' dirpoint=$1 tmpfile="$fast_change_dir_tmp/`whoami`-dirpoint-dialog-$( date +%Y%m%d-%H%M ).txt" if [ "$groupname" != "" ]; then if [ ! -f $fast_change_dir_project_config/dirpoint-$groupname.txt ]; then touch $fast_change_dir_project_config/dirpoint-$groupname.txt fi if [ "$dirpoint" != "" ]; then result=`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f2` resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f2`) if [ "${#resultarray[@]}" -gt "1" ]; then cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `grep $dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | tr "\n" " " | tr ',' ' '` $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" == "" ]; then echo '[ERROR] dirpoint is empty' else dv $result fi elif [ "${#resultarray[@]}" == "1" ]; then cmd="cd $result" eval $cmd func_checkfilecount else echo '[ERROR] dirpoint is not exist!!' fi else resultvalue=`cat $fast_change_dir_project_config/dirpoint-$groupname.txt | grep -v "^#" | wc -l` if [ "$resultvalue" -ge "1" ]; then - echo ${#resultarray[@]} cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `cat $fast_change_dir_project_config/dirpoint-$groupname.txt | grep -v "^#" | tr "\n" " " | tr ',' ' '` $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" == "" ]; then echo '[ERROR] dirpoint is empty' else dv $result fi else echo '[ERROR] Please use DVV cmd to create dirpoint' fi fi else echo '[ERROR] groupname is empty, please use GA cmd' fi tmpfile='' IFS=$default_ifs
gisanfu/fast-change-dir
02427ce41e44f28a29251c54b87bcbbf37a28869
fix bug
diff --git a/dirpoint.sh b/dirpoint.sh index b146fe3..9635c2d 100755 --- a/dirpoint.sh +++ b/dirpoint.sh @@ -1,75 +1,75 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" # default ifs value default_ifs=$' \t\n' # fix space to effect array result IFS=$'\012' dirpoint=$1 tmpfile="$fast_change_dir_tmp/`whoami`-dirpoint-dialog-$( date +%Y%m%d-%H%M ).txt" if [ "$groupname" != "" ]; then if [ ! -f $fast_change_dir_project_config/dirpoint-$groupname.txt ]; then touch $fast_change_dir_project_config/dirpoint-$groupname.txt fi if [ "$dirpoint" != "" ]; then result=`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f2` resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f2`) if [ "${#resultarray[@]}" -gt "1" ]; then cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `grep $dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | tr "\n" " " | tr ',' ' '` $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" == "" ]; then echo '[ERROR] dirpoint is empty' else dv $result fi elif [ "${#resultarray[@]}" == "1" ]; then cmd="cd $result" eval $cmd func_checkfilecount else echo '[ERROR] dirpoint is not exist!!' fi else - resultvalue=`cat $fast_change_dir_project_config/dirpoint-$groupname.txt | wc -l` + resultvalue=`cat $fast_change_dir_project_config/dirpoint-$groupname.txt | grep -v "^#" | wc -l` if [ "$resultvalue" -ge "1" ]; then echo ${#resultarray[@]} - cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `cat $fast_change_dir_project_config/dirpoint-$groupname.txt | tr "\n" " " | tr ',' ' '` $tmpfile ) + cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `cat $fast_change_dir_project_config/dirpoint-$groupname.txt | grep -v "^#" | tr "\n" " " | tr ',' ' '` $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" == "" ]; then echo '[ERROR] dirpoint is empty' else dv $result fi else echo '[ERROR] Please use DVV cmd to create dirpoint' fi fi else echo '[ERROR] groupname is empty, please use GA cmd' fi tmpfile='' IFS=$default_ifs
gisanfu/fast-change-dir
eecdc40cb31e2a861dcc80c6004a0403d9164343
remove cache function
diff --git a/lib/func/relativeitem.sh b/lib/func/relativeitem.sh index 5ff1515..e7d7c13 100644 --- a/lib/func/relativeitem.sh +++ b/lib/func/relativeitem.sh @@ -1,165 +1,165 @@ #!/bin/bash source "$fast_change_dir_func/md5.sh" func_relative() { nextRelativeItem=$1 secondCondition=$2 # 檔案的位置 fileposition=$3 # 要搜尋哪裡的路徑,空白代表現行目錄 lspath=$4 # dir or file filetype=$5 # get all item flag # 0 or empty: do not get all # 1: Get All isgetall=$6 declare -a itemList declare -a itemListTmp declare -a relativeitem if [ "$lspath" == "" ]; then lspath=`pwd` elif [ "$lspath" == ".." ]; then lspath="`pwd`/../" fi if [ "$nextRelativeItem" == '' ]; then isgetall='1' fi tmpfile="$fast_change_dir_tmp/`whoami`-function-relativeitem-$( date +%Y%m%d-%H%M ).txt" # ignore file or dir # ignorelist=$(func_getlsignore) ignorelist='' Success="0" # 試著使用@來決定第一個grep,從最開啟來找字串 firstchar=${nextRelativeItem:0:1} isHeadSearch='' # 這裡要注意,不能夠使用井字號(#)來當做控制字元,會有問題 if [ "$firstchar" == '@' ]; then isHeadSearch='^' nextRelativeItem=${nextRelativeItem:1} #elif [ "$firstchar" == '*' ]; then # nextRelativeItem=${nextRelativeItem:1} else firstchar='' fi # 試著使用第二個引數的第一個字元,來判斷是不是position firstchar2=${secondCondition:0:1} if [[ "$firstchar2" == '@' && "$fileposition" == '' ]]; then fileposition=${secondCondition:1} secondCondition='' fi # 先把英文轉成數字,如果這個欄位有資料的話 fileposition=( `func_entonum "$fileposition"` ) if [ "$fileposition" != '' ]; then newposition=$(($fileposition - 1)) fi lucky='' if [ "$filetype" == "dir" ]; then filetype_ls_arg='' filetype_grep_arg='' if [[ -d "$lspath$nextRelativeItem" && "$isgetall" != '1' ]]; then echo "$nextRelativeItem" exit fi else filetype_ls_arg='--file-type' filetype_grep_arg='-v' if [[ -f "$lspath$nextRelativeItem" && "$isgetall" != '1' ]]; then echo "$nextRelativeItem" exit fi fi # default ifs value default_ifs=$' \t\n' IFS=$'\n' #cmd="ls -AFL $ignorelist $filetype_ls_arg $lspath | grep $filetype_grep_arg \"/$\"" cmd="ls -AFL $ignorelist --file-type $lspath" # 先去cache找看看,有沒有暫存的路徑檔案 - md5key=(`func_md5 $cmd`) - cachefile="$fast_change_dir_tmp/`whoami`-relativeitem-cache-$md5key.txt" + #md5key=(`func_md5 $cmd`) + #cachefile="$fast_change_dir_tmp/`whoami`-relativeitem-cache-$md5key.txt" # 如果該cache有存在,就改寫指令 # 如果不存在,那在處理之前,先寫入cache - if [ ! -f "$cachefile" ]; then - cmd="$cmd > $cachefile" - eval $cmd - fi + #if [ ! -f "$cachefile" ]; then + # cmd="$cmd > $cachefile" + # eval $cmd + #fi - cmd="cat $cachefile " + #cmd="cat $cachefile " cmd="$cmd | grep $filetype_grep_arg \"/$\"" if [ "$isgetall" != '1' ]; then cmd="$cmd | grep -ir $isHeadSearch$nextRelativeItem" fi if [ "$secondCondition" != '' ]; then cmd="$cmd | grep -ir $secondCondition" fi # 取得項目列表,存到陣列裡面,當然也會做空白的處理 declare -i num itemListTmp=(`eval $cmd`) for i in ${itemListTmp[@]} do # 為了要解決空白檔名的問題 itemList[$num]=`echo $i|sed 's/ /___/g'` num=$num+1 done IFS=$default_ifs num=0 if [ "$nextRelativeItem" != "" ]; then if [ "${#itemList[@]}" == "1" ]; then relativeitem=${itemList[0]} #func_statusbar 'USE-ITEM' elif [ "${#itemList[@]}" -gt "1" ]; then relativeitem=${itemList[@]} fi fi if [ "$isgetall" == '1' ]; then if [ "${#itemList[@]}" == "1" ]; then relativeitem=${itemList[0]} #func_statusbar 'USE-ITEM' elif [ "${#itemList[@]}" -gt "1" ]; then relativeitem=${itemList[@]} fi fi # return array的標準用法 if [ "$relativeitem" != '' ]; then if [ "$newposition" == '' ]; then echo ${relativeitem[@]} else # 先把含空格的文字,轉成陣列 aaa=(${relativeitem[@]}) # 然後在指定位置輸出 echo ${aaa[$newposition]} fi else echo '' fi }
gisanfu/fast-change-dir
ca729db6664896a4e296a1aeca94dadfd7623d70
fix bug
diff --git a/dirpoint.sh b/dirpoint.sh index 36ea10d..b146fe3 100755 --- a/dirpoint.sh +++ b/dirpoint.sh @@ -1,75 +1,75 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" # default ifs value default_ifs=$' \t\n' # fix space to effect array result IFS=$'\012' dirpoint=$1 tmpfile="$fast_change_dir_tmp/`whoami`-dirpoint-dialog-$( date +%Y%m%d-%H%M ).txt" if [ "$groupname" != "" ]; then if [ ! -f $fast_change_dir_project_config/dirpoint-$groupname.txt ]; then touch $fast_change_dir_project_config/dirpoint-$groupname.txt fi if [ "$dirpoint" != "" ]; then result=`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f2` resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f2`) if [ "${#resultarray[@]}" -gt "1" ]; then - cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `grep $dirpoint[[:alnum:]]*, $fast_change_dir_config/dirpoint-$groupname.txt | tr "\n" " " | tr ',' ' '` $tmpfile ) + cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `grep $dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | tr "\n" " " | tr ',' ' '` $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" == "" ]; then echo '[ERROR] dirpoint is empty' else dv $result fi elif [ "${#resultarray[@]}" == "1" ]; then cmd="cd $result" eval $cmd func_checkfilecount else echo '[ERROR] dirpoint is not exist!!' fi else resultvalue=`cat $fast_change_dir_project_config/dirpoint-$groupname.txt | wc -l` if [ "$resultvalue" -ge "1" ]; then echo ${#resultarray[@]} cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `cat $fast_change_dir_project_config/dirpoint-$groupname.txt | tr "\n" " " | tr ',' ' '` $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" == "" ]; then echo '[ERROR] dirpoint is empty' else dv $result fi else echo '[ERROR] Please use DVV cmd to create dirpoint' fi fi else echo '[ERROR] groupname is empty, please use GA cmd' fi tmpfile='' IFS=$default_ifs
gisanfu/fast-change-dir
2781c4d62d473fd724018061dc3b63730a262753
fix bug
diff --git a/abc-4.sh b/abc-4.sh index 9df88b9..d56b226 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,384 +1,384 @@ #!/bin/bash -source "$fast_change_dir/config.sh" +source "$fast_change_dir/config/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color while [ 1 ]; do clear if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 智慧選取單項 (;) 分號' echo ' 上一層 (,) 逗點' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue #clear_var_all='1' continue elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd
gisanfu/fast-change-dir
a32123224d8f1018ba853c08af3d9a6636b3d003
fix bug by abc-v4
diff --git a/abc-4.sh b/abc-4.sh index 67212cd..9df88b9 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,419 +1,384 @@ #!/bin/bash source "$fast_change_dir/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then - resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_config/dirpoint-$groupname.txt | cut -d, -f1`) + resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color while [ 1 ]; do clear if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 智慧選取單項 (;) 分號' echo ' 上一層 (,) 逗點' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue #clear_var_all='1' continue elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} - #if [ "$fast_change_dir_config_parent_enable" == '1' ]; then - # item_parent_file_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" ".." "file"` ) - # item_parent_dir_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" ".." "dir"` ) - - # # 決定誰是最佳人選,當你按了;分號或是.點 - # if [ ${#item_parent_file_array[@]} -eq 1 ]; then - # good_select=3 - # good_array=${item_parent_file_array[@]} - # elif [ ${#item_parent_dir_array[@]} -eq 1 ]; then - # good_select=4 - # good_array=${item_parent_dir_array[@]} - # fi - #fi - - #item_file_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) - #item_dir_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "dir"` ) - - ## 決定誰是最佳人選,當你按了;分號或是.點 - #if [ ${#item_file_array[@]} -eq 1 ]; then - # good_select=1 - # good_array=${item_file_array[@]} - #elif [ ${#item_dir_array[@]} -eq 1 ]; then - # good_select=2 - # good_array=${item_dir_array[@]} - #fi - - # 有些功能,只要看到第2個引數就會失效 - #if [ "$cmd2" == '' ]; then - # item_dirpoint_array=( `func_dirpoint "$cmd1"` ) - # item_groupname_array=( `func_groupname "$cmd1"` ) - #else - # unset item_dirpoint_array - # unset item_groupname_array - #fi - elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd diff --git a/dirpoint-append.sh b/dirpoint-append.sh index c0f15a1..7f91ce0 100755 --- a/dirpoint-append.sh +++ b/dirpoint-append.sh @@ -1,60 +1,60 @@ #!/bin/bash source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" dirpoint=$1 # cmd1、2是第一、二個關鍵字 cmd1=$2 cmd2=$3 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$4 if [ "$dirpoint" != "" ]; then item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "dir"` ) if [ "${#item_array[@]}" -gt 1 ]; then # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 tmpfile="$fast_change_dir_tmp/`whoami`-dirpointappend-dialogselect-$( date +%Y%m%d-%H%M ).txt" dialogitems='' for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then match=`echo $result | sed 's/___/ /g'` relativeitem=$match fi elif [ "${#item_array[@]}" -eq 1 ]; then relativeitem=${item_array[0]} fi if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then - echo "$dirpoint,`pwd`/$relativeitem" >> $fast_change_dir_config/dirpoint-$groupname.txt - cat $fast_change_dir_config/dirpoint-$groupname.txt + echo "$dirpoint,`pwd`/$relativeitem" >> $fast_change_dir_project_config/dirpoint-$groupname.txt + cat $fast_change_dir_project_config/dirpoint-$groupname.txt elif [ "$groupname" == "" ]; then echo '[ERROR] groupname is empty, please use GA cmd' fi else echo '[ERROR] "dirpoint-arg01" "nextRelativeItem-arg02" "secondCondition-arg03" "Position-arg04"' fi unset dirpoint unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset relativeitem diff --git a/dirpoint-edit.sh b/dirpoint-edit.sh index 2f96496..9ba6edb 100755 --- a/dirpoint-edit.sh +++ b/dirpoint-edit.sh @@ -1,7 +1,7 @@ #!/bin/bash if [ "$groupname" != "" ]; then - vim $fast_change_dir_config/dirpoint-$groupname.txt + vim $fast_change_dir_project_config/dirpoint-$groupname.txt else echo '[ERROR] groupname is empty' fi diff --git a/dirpoint.sh b/dirpoint.sh index 26c583f..36ea10d 100755 --- a/dirpoint.sh +++ b/dirpoint.sh @@ -1,75 +1,75 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" # default ifs value default_ifs=$' \t\n' # fix space to effect array result IFS=$'\012' dirpoint=$1 tmpfile="$fast_change_dir_tmp/`whoami`-dirpoint-dialog-$( date +%Y%m%d-%H%M ).txt" if [ "$groupname" != "" ]; then - if [ ! -f $fast_change_dir_config/dirpoint-$groupname.txt ]; then - touch $fast_change_dir_config/dirpoint-$groupname.txt + if [ ! -f $fast_change_dir_project_config/dirpoint-$groupname.txt ]; then + touch $fast_change_dir_project_config/dirpoint-$groupname.txt fi if [ "$dirpoint" != "" ]; then - result=`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_config/dirpoint-$groupname.txt | cut -d, -f2` - resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_config/dirpoint-$groupname.txt | cut -d, -f2`) + result=`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f2` + resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_project_config/dirpoint-$groupname.txt | cut -d, -f2`) if [ "${#resultarray[@]}" -gt "1" ]; then cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `grep $dirpoint[[:alnum:]]*, $fast_change_dir_config/dirpoint-$groupname.txt | tr "\n" " " | tr ',' ' '` $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" == "" ]; then echo '[ERROR] dirpoint is empty' else dv $result fi elif [ "${#resultarray[@]}" == "1" ]; then cmd="cd $result" eval $cmd func_checkfilecount else echo '[ERROR] dirpoint is not exist!!' fi else - resultvalue=`cat $fast_change_dir_config/dirpoint-$groupname.txt | wc -l` + resultvalue=`cat $fast_change_dir_project_config/dirpoint-$groupname.txt | wc -l` if [ "$resultvalue" -ge "1" ]; then echo ${#resultarray[@]} - cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `cat $fast_change_dir_config/dirpoint-$groupname.txt | tr "\n" " " | tr ',' ' '` $tmpfile ) + cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `cat $fast_change_dir_project_config/dirpoint-$groupname.txt | tr "\n" " " | tr ',' ' '` $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" == "" ]; then echo '[ERROR] dirpoint is empty' else dv $result fi else echo '[ERROR] Please use DVV cmd to create dirpoint' fi fi else echo '[ERROR] groupname is empty, please use GA cmd' fi tmpfile='' IFS=$default_ifs diff --git a/example-config/YOURGROUPNAME-your-project-config.sh b/example-config/your-project-config-YOURGROUPNAME.sh similarity index 100% rename from example-config/YOURGROUPNAME-your-project-config.sh rename to example-config/your-project-config-YOURGROUPNAME.sh diff --git a/groupname.sh b/groupname.sh index c9fc997..48570f5 100755 --- a/groupname.sh +++ b/groupname.sh @@ -1,76 +1,92 @@ #!/bin/bash # # 這個檔案,是選擇、以及增加專案代碼 # source "$fast_change_dir_func/dialog.sh" action=$1 groupname=$2 tmpfile="$fast_change_dir_tmp/`whoami`-dialog-$( date +%Y%m%d-%H%M ).txt" if [ -f $fast_change_dir_config/groupname.txt ]; then echo else # 如果檔案不存在,就建立文字檔案,以及建立一個預設空白的groupname touch $fast_change_dir_config/groupname.txt #echo '""' >> $fast_change_dir_config/groupname.txt fi if [ "$action" == "select" ]; then if [ "$groupname" != "" ]; then count=`grep -ir $groupname $fast_change_dir_config/groupname.txt | wc -l` if [ "$count" == "0" ]; then export groupname="" echo "[ERROR] groupname is not exist by $groupname" else export groupname=$groupname + + if [ -f $fast_change_dir_config/your-project-config-$groupname.sh ]; then + source $fast_change_dir_config/your-project-config-$groupname.sh + fast_change_dir_project_config=$fast_change_dir_your_project_config + else + fast_change_dir_project_config=$fast_change_dir_config + fi + echo '[OK] export groupname success' # 切換到Root的資料夾,預設是root,這是我建立資料夾link的方式,根目錄名稱叫root dv root fi else dialogitems=`cat $fast_change_dir_config/groupname.txt | awk -F"\n" '{ print $1 " \" \" " }' | tr "\n" ' '` cmd=$( func_dialog_menu '請選擇專案代碼' '123' 70 "$dialogitems" "$tmpfile") eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then func_statusbar '你不選嗎,別忘了要選才能使用專案功能哦' else export groupname=$result + + if [ -f $fast_change_dir_config/your-project-config-$groupname.sh ]; then + source $fast_change_dir_config/your-project-config-$groupname.sh + fast_change_dir_project_config=$fast_change_dir_your_project_config + else + fast_change_dir_project_config=$fast_change_dir_config + fi + echo '[OK] export groupname success' # 切換到Root的資料夾,預設是root,這是我建立資料夾link的方式,根目錄名稱叫root dv root fi fi # 在確認一次,如果有選擇,接下來就檢查是否有定義專案設定檔 - if [ "$groupname" != "" ]; then - if [ -f $fast_change_dir_config/$groupname-your-project-config.sh ]; then - source $fast_change_dir_config/$groupname-your-project-config.sh - fast_change_dir_project_config=$fast_change_dir_your_project_config - else - fast_change_dir_project_config=$fast_change_dir_config - fi - fi + #if [ "$groupname" != "" ]; then + # if [ -f $fast_change_dir_config/$groupname-your-project-config.sh ]; then + # source $fast_change_dir_config/$groupname-your-project-config.sh + # fast_change_dir_project_config=$fast_change_dir_your_project_config + # else + # fast_change_dir_project_config=$fast_change_dir_config + # fi + #fi elif [ "$action" == "append" ]; then if [ "$groupname" != "" ]; then count=`grep -ir $groupname $fast_change_dir_config/groupname.txt | wc -l` if [ "$count" == "0" ]; then echo $groupname >> $fast_change_dir_config/groupname.txt export groupname=$groupname echo '[OK] append and export groupname success' else echo "[ERROR] groupname is exist by $groupname" fi else echo "[ERROR] please fill groupname field by append action" fi elif [ "$action" == "edit" ]; then vim $fast_change_dir_config/groupname.txt else echo '[ERROR] no support action' fi diff --git a/abc-2.sh b/old/abc-2.sh similarity index 100% rename from abc-2.sh rename to old/abc-2.sh diff --git a/abc-3.sh b/old/abc-3.sh similarity index 100% rename from abc-3.sh rename to old/abc-3.sh diff --git a/abc.sh b/old/abc.sh similarity index 100% rename from abc.sh rename to old/abc.sh diff --git a/git.sh b/old/git.sh similarity index 100% rename from git.sh rename to old/git.sh diff --git a/vimlist-append.sh b/vimlist-append.sh index c35c202..caf71e9 100755 --- a/vimlist-append.sh +++ b/vimlist-append.sh @@ -1,125 +1,125 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 # 是否要vff,如果沒有指定,就是會詢問使用者 # 不詢問,不要vff的話,就放0 # 不詢問,要vff的話,就放1 isVFF=$4 if [ "$isVFF" == '' ]; then isVFF=1 fi item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' if [ ${#item_array[@]} -eq 1 ]; then relativeitem=${item_array[0]} elif [ ${#item_array[@]} -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems='' for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem=$result else relativeitem='' fi else relativeitem='' fi if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then if [ "$isVFF" == '0' ]; then inputchar='n' elif [ "$isVFF" == '1' ]; then inputchar='y' else isVFF='' fi # 這裡可以考慮在加上一項,就是不要append這一個檔案 if [ "$isVFF" == '' ]; then # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' echo '[WAIT] 或是編輯列表 [j]' echo '[WAIT] 還是清空它 [k]' read -n 1 inputchar fi # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append selectitem='' selectitem=`pwd`/$relativeitem - checkline=`grep "$selectitem" $fast_change_dir_config/vimlist-$groupname.txt | wc -l` + checkline=`grep "$selectitem" $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then - echo "\"$selectitem\"" >> $fast_change_dir_config/vimlist-$groupname.txt + echo "\"$selectitem\"" >> $fast_change_dir_project_config/vimlist-$groupname.txt else echo '[NOTICE] File is exist' fi if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... - checklinenumber=`cat $fast_change_dir_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` + checklinenumber=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` cmd='vff "vim' # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 # 查詢更多資訊請執行: "vim -h" if [ "$checklinenumber" -lt 10 ]; then for i in `seq 1 $checklinenumber` do cmd="$cmd +tabnext" done else echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' fi - cmd="$cmd -p $fast_change_dir_config/vimlist-$groupname.txt\"" + cmd="$cmd -p $fast_change_dir_project_config/vimlist-$groupname.txt\"" eval $cmd elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then echo "Your want append other file" elif [ "$inputchar" == 'j' ]; then vfff elif [ "$inputchar" == 'k' ]; then vffff else echo "Your want append other file" fi # 最後,顯示目前目錄的檔案 func_checkfilecount elif [ "$groupname" == "" ]; then echo '[ERROR] Argument or $groupname is empty' fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem diff --git a/vimlist-clear.sh b/vimlist-clear.sh index b4cfac9..bf02c3e 100755 --- a/vimlist-clear.sh +++ b/vimlist-clear.sh @@ -1,15 +1,15 @@ #!/bin/bash if [ "$groupname" != '' ]; then echo '你確定要清空vim暫存群組檔嗎?[Y1, n0]' read -s -n 1 inputvar if [[ "$inputvar" == 'n' || "$inputvar" == "0" ]]; then echo '己取消清空vim暫存群組檔' sleep 1 else - rm $fast_change_dir_config/vimlist-$groupname.txt - touch $fast_change_dir_config/vimlist-$groupname.txt + rm $fast_change_dir_project_config/vimlist-$groupname.txt + touch $fast_change_dir_project_config/vimlist-$groupname.txt echo '己清空' sleep 1 fi fi diff --git a/vimlist-edit.sh b/vimlist-edit.sh index 443e9d1..eeef7ce 100755 --- a/vimlist-edit.sh +++ b/vimlist-edit.sh @@ -1,14 +1,14 @@ #!/bin/bash if [ "$groupname" != "" ]; then - vim $fast_change_dir_config/vimlist-$groupname.txt + vim $fast_change_dir_project_config/vimlist-$groupname.txt # 詢問使用者,看要不要編輯list echo '[WAIT] 預設是編輯暫存檔案群,我指的是vff [Y1,n0]' read -n 1 inputchar if [[ "$inputchar" == 'y' || "$inputchar" == '1' || "$inputchar" == '' ]]; then vff fi else echo '[ERROR] groupname is empty' fi diff --git a/vimlist.sh b/vimlist.sh index d21821b..f1cf4f4 100755 --- a/vimlist.sh +++ b/vimlist.sh @@ -1,81 +1,81 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" program=$1 if [ "$groupname" != "" ]; then if [ "$program" == "" ]; then - program2="vim -p $fast_change_dir_config/vimlist-$groupname.txt" + program2="vim -p $fast_change_dir_project_config/vimlist-$groupname.txt" else program2=$program fi - cmdlist="cat $fast_change_dir_config/vimlist-$groupname.txt" + cmdlist="cat $fast_change_dir_project_config/vimlist-$groupname.txt" # 正規的外面要用雙引包起來 regex="^vim" # 如果program這個變數是空白,就代表會使用vim-p的指令 # 使用vim,當然不會去開一些binary的檔案 if [[ "$program" == '' || "$program" =~ $regex ]]; then # 先把一些己知的東西先ignore掉,例如壓縮檔 cmdlist="$cmdlist | grep -v .tar.gz | grep -v .zip | grep -v .png | grep -v .gif | grep -v .jpeg | grep -v .jpg" cmdlist="$cmdlist | xargs -n 1 $fast_change_dir_bin/only-text-filecontent.sh" fi # 這是多行文字檔內容,變成以空格分格成字串的步驟 cmdlist2='| tr "\n" " "' cmdlist="$cmdlist $cmdlist2" cmdlist_result=`eval $cmdlist` cmd="$program2 $cmdlist_result" # 檢查一下數量,如果是一筆的話,那就自動跳到那一筆 # 這樣子只有一筆的時候,會比較方便 # 會這樣子寫,是因為不要去影響其它程式的相依性 if [ "$program" == "" ]; then - count=`cat $fast_change_dir_config/vimlist-$groupname.txt | wc -l` + count=`cat $fast_change_dir_project_config/vimlist-$groupname.txt | wc -l` if [ "$count" == 1 ]; then cmd="$cmd +tabnext" fi # 如果大於1筆,就用選擇的方式,選擇第一次要看到的檔案 if [ "$count" -gt 1 ]; then - vimlist_array=(`cat $fast_change_dir_config/vimlist-$groupname.txt`) + vimlist_array=(`cat $fast_change_dir_project_config/vimlist-$groupname.txt`) tmpfile="$fast_change_dir_tmp/`whoami`-vimlist-dialogselect-$( date +%Y%m%d-%H%M ).txt" dialogitems='' start=1 for echothem in ${vimlist_array[@]} do dialogitems=" $dialogitems '$start' $echothem " start=$(expr $start + 1) done cmd2=$( func_dialog_menu '你想從哪一個位置開始編輯 ' 100 "$dialogitems" $tmpfile ) eval $cmd2 result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then for (( b=1; b<=$result; b++ )) do cmd="$cmd +tabnext" done else cmd="$cmd +tabnext" fi fi fi eval $cmd func_checkfilecount else echo '[ERROR] groupname is empty, please use GA cmd' fi unset vimlist_array
gisanfu/fast-change-dir
1977cf2fe0e93d2fe689389a9dd0f1258cf880b6
add new function, move config to project directory
diff --git a/example-config/YOURGROUPNAME-your-project-config.sh b/example-config/YOURGROUPNAME-your-project-config.sh new file mode 100644 index 0000000..2bc6eb1 --- /dev/null +++ b/example-config/YOURGROUPNAME-your-project-config.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# 這裡放的是設定檔重設路徑的位置 +# 目的是要跟隨專案資料夾,跟著帶走 + +fast_change_dir_your_project_config=~/hg/blha_blha_blha/misc/fast-change-dir diff --git a/example-config/bashrc.txt b/example-config/bashrc.txt index eaafaf6..38a146b 100644 --- a/example-config/bashrc.txt +++ b/example-config/bashrc.txt @@ -1,102 +1,105 @@ # fast-change-dir fast_change_dir_pwd=$HOME fast_change_dir="$fast_change_dir_pwd/gisanfu/fast-change-dir" fast_change_dir_bin="$fast_change_dir/bin" fast_change_dir_lib="$fast_change_dir/lib" fast_change_dir_func="$fast_change_dir_lib/func" +fast_change_dir_project_config="" -# 你可以依照使用習慣去修改 +# +# 這裡區塊,可以依照你的使用環境去修改 +# fast_change_dir_tmp='/tmp' fast_change_dir_config="$fast_change_dir_pwd" # fast-change-dir: use relative keyword alias ll="ls -la" # main function alias ide=". $fast_change_dir/abc-4.sh" # number function alias gre=". $fast_change_dir/grep.sh" alias sear=". $fast_change_dir/search.sh" alias abc=". $fast_change_dir/abc-4.sh" alias 123=". $fast_change_dir/123.sh" alias abc123=". $fast_change_dir/123-2.sh" # Version Controll alias svnn=". $fast_change_dir/svn-3.sh" alias gitt=". $fast_change_dir/git-2.sh" alias hgg=". $fast_change_dir/hg.sh" # # GroupName # # select or switch GroupName alias ga=". $fast_change_dir/groupname.sh select" # append GroupName alias gaa=". $fast_change_dir/groupname.sh append" # edit GroupName alias gaaa=". $fast_change_dir/groupname.sh edit" # # cd # alias d=". $fast_change_dir/cddir.sh" # cd point alias dv=". $fast_change_dir/dirpoint.sh" # append point alias dvv=". $fast_change_dir/dirpoint-append.sh" # edit point alias dvvv=". $fast_change_dir/dirpoint-edit.sh" # nopath, nolimit to change directory by keyword alias wv=". $fast_change_dir/nopath.sh" # vim alias v=". $fast_change_dir/editfile.sh" alias vf=". $fast_change_dir/vimlist-append.sh" alias vff=". $fast_change_dir/vimlist.sh" alias vfff=". $fast_change_dir/vimlist-edit.sh" alias vffff=". $fast_change_dir/vimlist-clear.sh" alias vfe=". $fast_change_dir/pos-vimlist-append.sh 1" alias vfee=". $fast_change_dir/pos-vimlist-append.sh 2" alias vfeee=". $fast_change_dir/pos-vimlist-append.sh 3" alias vfeeee=". $fast_change_dir/pos-vimlist-append.sh 4" alias vfeeeee=". $fast_change_dir/pos-vimlist-append.sh 5" alias vfeeeeee=". $fast_change_dir/pos-vimlist-append.sh 6" # # back, and cd dir # alias g=". $fast_change_dir/backdir.sh" # back back... layer dir alias ge=". $fast_change_dir/back-backdir.sh 1" alias gee=". $fast_change_dir/back-backdir.sh 2" alias geee=". $fast_change_dir/back-backdir.sh 3" alias geeee=". $fast_change_dir/back-backdir.sh 4" alias geeeee=". $fast_change_dir/back-backdir.sh 5" alias geeeeee=". $fast_change_dir/back-backdir.sh 6" # back and cd dir, use position alias gde=". $fast_change_dir/pos-backdir.sh 1" alias gdee=". $fast_change_dir/pos-backdir.sh 2" alias gdeee=". $fast_change_dir/pos-backdir.sh 3" alias gdeeee=". $fast_change_dir/pos-backdir.sh 4" alias gdeeeee=". $fast_change_dir/pos-backdir.sh 5" alias gdeeeeee=". $fast_change_dir/pos-backdir.sh 6" # fast-change-dir: cd dir, use position alias de=". $fast_change_dir/pos-cddir.sh 1" alias dee=". $fast_change_dir/pos-cddir.sh 2" alias deee=". $fast_change_dir/pos-cddir.sh 3" alias deeee=". $fast_change_dir/pos-cddir.sh 4" alias deeeee=". $fast_change_dir/pos-cddir.sh 5" alias deeeeee=". $fast_change_dir/pos-cddir.sh 6" # fast-change-dir: vim file, use position alias ve=". $fast_change_dir/pos-editfile.sh 1" alias vee=". $fast_change_dir/pos-editfile.sh 2" alias veee=". $fast_change_dir/pos-editfile.sh 3" alias veeee=". $fast_change_dir/pos-editfile.sh 4" alias veeeee=". $fast_change_dir/pos-editfile.sh 5" alias veeeeee=". $fast_change_dir/pos-editfile.sh 6" # 最後,啟動ide ide diff --git a/groupname.sh b/groupname.sh index 0085783..c9fc997 100755 --- a/groupname.sh +++ b/groupname.sh @@ -1,66 +1,76 @@ #!/bin/bash # # 這個檔案,是選擇、以及增加專案代碼 # source "$fast_change_dir_func/dialog.sh" action=$1 groupname=$2 tmpfile="$fast_change_dir_tmp/`whoami`-dialog-$( date +%Y%m%d-%H%M ).txt" if [ -f $fast_change_dir_config/groupname.txt ]; then echo else # 如果檔案不存在,就建立文字檔案,以及建立一個預設空白的groupname touch $fast_change_dir_config/groupname.txt - echo '""' >> $fast_change_dir_config/groupname.txt + #echo '""' >> $fast_change_dir_config/groupname.txt fi if [ "$action" == "select" ]; then if [ "$groupname" != "" ]; then count=`grep -ir $groupname $fast_change_dir_config/groupname.txt | wc -l` if [ "$count" == "0" ]; then export groupname="" echo "[ERROR] groupname is not exist by $groupname" else export groupname=$groupname echo '[OK] export groupname success' # 切換到Root的資料夾,預設是root,這是我建立資料夾link的方式,根目錄名稱叫root dv root fi else dialogitems=`cat $fast_change_dir_config/groupname.txt | awk -F"\n" '{ print $1 " \" \" " }' | tr "\n" ' '` cmd=$( func_dialog_menu '請選擇專案代碼' '123' 70 "$dialogitems" "$tmpfile") eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then func_statusbar '你不選嗎,別忘了要選才能使用專案功能哦' else export groupname=$result echo '[OK] export groupname success' # 切換到Root的資料夾,預設是root,這是我建立資料夾link的方式,根目錄名稱叫root dv root fi fi + + # 在確認一次,如果有選擇,接下來就檢查是否有定義專案設定檔 + if [ "$groupname" != "" ]; then + if [ -f $fast_change_dir_config/$groupname-your-project-config.sh ]; then + source $fast_change_dir_config/$groupname-your-project-config.sh + fast_change_dir_project_config=$fast_change_dir_your_project_config + else + fast_change_dir_project_config=$fast_change_dir_config + fi + fi elif [ "$action" == "append" ]; then if [ "$groupname" != "" ]; then count=`grep -ir $groupname $fast_change_dir_config/groupname.txt | wc -l` if [ "$count" == "0" ]; then echo $groupname >> $fast_change_dir_config/groupname.txt export groupname=$groupname echo '[OK] append and export groupname success' else echo "[ERROR] groupname is exist by $groupname" fi else echo "[ERROR] please fill groupname field by append action" fi elif [ "$action" == "edit" ]; then vim $fast_change_dir_config/groupname.txt else echo '[ERROR] no support action' fi diff --git a/hg.sh b/hg.sh index 4cbb864..c2a89da 100755 --- a/hg.sh +++ b/hg.sh @@ -194,513 +194,513 @@ func_relative_by_hg_append() fi fi # if no duplicate dirname then print them if [ $Success == "0" ]; then if [ "${#itemList2[@]}" -gt 0 ]; then relativeitem=${itemList2[@]} else relativeitem=${itemList[@]} fi fi fi fi # return array的標準用法 if [ "$relativeitem" != '' ]; then if [ "$newposition" == '' ]; then echo ${relativeitem[@]} else # 先把含空格的文字,轉成陣列 aaa=(${relativeitem[@]}) # 然後在指定位置輸出 echo ${aaa[$newposition]} fi fi } # 會寫這類的函式,是因為這個動作可能會被單項,會是多項來這裡進行觸發 func_hg_unknow_mode() { item=$1 # 不分兩次做,會出現前面少了一個空白,不知道為什麼 match=`echo $item | sed 's/___/X/'` match=`echo $match | sed 's/___/ /g'` # 這個變數,存的可能是?、! hgstatus=${match:0:1} if [ "$hgstatus" == '?' ]; then hg add ${match:2} elif [ "$hgstatus" == '!' ]; then hg remove ${match:2} fi } func_hg_commit_mode() { item=$1 # 不分兩次做,會出現前面少了一個空白,不知道為什麼 match=`echo $item | sed 's/___/X/'` match=`echo $match | sed 's/___/ /g'` # 這個變數,存的可能是A、D hgstatus=${match:0:1} if [ "$hgstatus" == 'A' ]; then hg revert ${match:2} elif [ "$hgstatus" == 'R' ]; then hg revert ${match:2} fi } func_hg_uncache_mode() { item=$1 # cache的檔名也是用變數控制 uncachefile=$2 cachefile=$3 cmd="grep '$item' $cachefile" tmp1=`eval $cmd` if [ "$tmp1" == '' ]; then cmd="echo '$item' >> $cachefile" eval $cmd fi # 先寫到暫存,然後在回寫回原來的檔案 cmd="sed '/$item/d' $uncachefile > ${uncachefile}-hg-tmp" eval $cmd cmd="cp ${uncachefile}-hg-tmp $uncachefile" eval $cmd cmd="rm -rf ${uncachefile}-hg-tmp" eval $cmd } func_hg_cache_mode() { item=$1 # cache的檔名也是用變數控制 uncachefile=$2 cachefile=$3 cmd="grep '$item' $uncachefile" tmp1=`eval $cmd` if [ "$tmp1" == '' ]; then cmd="echo '$item' >> $uncachefile" eval $cmd fi # 先寫到暫存,然後在回寫回原來的檔案 cmd="sed '/$item/d' $cachefile > ${cachefile}-hg-tmp" eval $cmd cmd="cp ${cachefile}-hg-tmp $cachefile" eval $cmd cmd="rm -rf ${cachefile}-hg-tmp" eval $cmd } unset cmd unset cmd1 unset cmd2 unset cmd3 # 只有第一次是1,有些只會執行一次,例如help first='1' # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 # Ctrl + h backspace=$(echo -e \\b\\c) # 這是模式,前面的括號是該模式的別名 # 1. [unknow] hg status, filter by untracked, or new file, 其它都沒有哦 # 2. [commit] hg status, filter by added, or deleted, modify一定會在裡面的(我想取commit list) # 3. [uncache] uncache list # 4. [cache] cache list mode='1' uncachefile="$fast_change_dir_tmp/hg-uncache-`whoami`.txt" cachefile="$fast_change_dir_tmp/hg-cache-`whoami`.txt" # 清理uncache的同時,也會一並清除cache,因為它們是有相依性的 func_hg_cache_controller "$uncachefile" "$cachefile" "clear-uncache" while [ 1 ]; do clear if [[ "$first" == '1' || "$clear_var_all" == '1' ]]; then unset cmd unset condition unset item_unknow_array unset item_commit_array unset item_uncache_array unset item_cache_array clear_var_all='' first='' fi echo 'Mercurial(Hg) (關鍵字)' echo '=================================================' echo "\"$groupname\" || `pwd`" echo '=================================================' if [ "$mode" == '1' ]; then echo "Unknow File List" elif [ "$mode" == '2' ]; then echo "Commit List" elif [ "$mode" == '3' ]; then echo "Uncache List" elif [ "$mode" == '4' ]; then echo "Cache List" else # 為了誤動作,或是程式發生了未知的問題 mode=1 echo "Unknow File List" fi echo '=================================================' if [ "$mode" == '1' ]; then # 問號是新的檔案,還未被新增進來,而驚嘆號是使用rm指令刪掉的狀況 cmd="hg status | grep -e '^?' -e '^!'" elif [ "$mode" == '2' ]; then cmd="hg status | grep -e '^A' -e '^M' -e '^R'" elif [ "$mode" == '3' ]; then cmd="cat $uncachefile" elif [ "$mode" == '4' ]; then cmd="cat $cachefile" fi eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi if [ "$condition" == '' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 智慧選取單項 (;.) 分號' echo ' 處理多項(*) 星號' echo ' 離開 (?)' echo -e "${color_txtgrn}Hg功能快速鍵:${color_none}" echo ' Change Normal Mode (A)' echo ' Change Cache Mode (B)' echo ' Commit (C)' echo ' Delete Cache/Uncache (D)' echo ' Push(send!!) (E)' echo ' Generate Uncache (G)' echo ' Update (U)' echo '輸入條件的結構:' echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' fi echo '=================================================' # 顯示重覆的Hg未知檔案 if [ "${#item_unknow_array[@]}" -gt 1 ]; then echo "重覆的未知Hg檔案數量: ${#item_unknow_array[@]} [*]" number=1 for bbb in ${item_unknow_array[@]} do echo "$number. $bbb" number=$((number + 1)) done elif [ "${#item_unknow_array[@]}" -eq 1 ]; then echo "未知的Hg檔案有找到一筆: ${item_unknow_array[0]} [;]" fi # 顯示己經準備送出,而且狀態是新增、與刪除 if [ "${#item_commit_array[@]}" -gt 1 ]; then echo "重覆的準備送出的Hg,狀態為A與R的檔案數量: ${#item_commit_array[@]} [*]" number=1 for bbb in ${item_commit_array[@]} do echo "$number. $bbb" number=$((number + 1)) done elif [ "${#item_commit_array[@]}" -eq 1 ]; then echo "準備送出的Hg,狀態為A與R的檔案有找到一筆: ${item_commit_array[0]} [;]" fi # 顯示Uncache項目 if [ "${#item_uncache_array[@]}" -gt 1 ]; then echo "重覆的Uncache檔案數量: ${#item_uncache_array[@]} [*]" number=1 for bbb in ${item_uncache_array[@]} do echo "$number. $bbb" number=$((number + 1)) done elif [ "${#item_uncache_array[@]}" -eq 1 ]; then echo "Uncache檔案有找到一筆: ${item_uncache_array[0]} [;]" fi # 顯示Cache項目 if [ "${#item_cache_array[@]}" -gt 1 ]; then echo "重覆的Cache檔案數量: ${#item_cache_array[@]} [*]" number=1 for bbb in ${item_cache_array[@]} do echo "$number. $bbb" number=$((number + 1)) done elif [ "${#item_cache_array[@]}" -eq 1 ]; then echo "Cache檔案有找到一筆: ${item_cache_array[0]} [;]" fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == '?' ]; then # 離開 clear break elif [ "$inputvar" == '/' ]; then clear_var_all='1' continue # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == 'A' ]; then if [ "$mode" == '1' ]; then mode='2' elif [ "$mode" == '2' ]; then mode='1' else mode='1' fi clear_var_all='1' continue elif [ "$inputvar" == 'B' ]; then if [ "$mode" == '3' ]; then mode='4' elif [ "$mode" == '4' ]; then mode='3' else mode='3' fi clear_var_all='1' continue elif [ "$inputvar" == 'C' ]; then if [[ "$mode" == '2' || "$mode" == '4' ]]; then echo '要送出囉,但是請先輸入changelog,輸入完按Enter後直接送出' read changelog if [ "$changelog" == '' ]; then echo '為什麼你沒有輸入changelog呢?還是我幫你填上預設值呢?(no comment)好嗎?[Y1,n0]' read inputvar2 if [[ "$inputvar2" == 'y' || "$inputvar2" == "1" ]]; then changelog='no comment' elif [[ "$inputvar2" == 'n' || "$inputvar2" == "0" ]]; then echo '如果不要預設值,那就算了' else echo '不好意思,不要預設值也不要來亂' fi fi if [ "$changelog" == '' ]; then echo '你並沒有輸入changelog,所以下次在見了,本次動作取消,倒數3秒後離開' sleep 3 else cmd="hg commit -m \"$changelog\" " if [ "$mode" == '4' ]; then cmdcat="cat $cachefile | wc -l" cmdcount=`eval $cmdcat` if [ "$cmdcount" -ge 1 ]; then cmdlist="cat $cachefile | tr '\n' ' '" cmdlist2=`eval $cmdlist` IFS=$'\n' cmdlist="cat $cachefile" cmdlist2=(`eval $cmdlist`) cmdlist3='' for i in ${cmdlist2[@]} do # 不分兩次做,會出現前面少了一個空白,不知道為什麼 match=`echo ${i} | sed 's/___/X/'` match=`echo $match | sed 's/___/ /g'` cmdlist3="$cmdlist3 \"${match:3}" done IFS=$default_ifs cmd="$cmd $cmdlist3" else echo '沒有可以送出的檔案,在cache裡面!!' fi fi eval $cmd changelog='' if [ "$?" -eq 0 ]; then #echo '設定Changelog成功,別忘了要選擇送出哦' echo '要不要送出(hg push)呢?[Y1,n0]' read inputvar3 if [[ "$inputvar3" == 'n' || "$inputvar3" == "0" ]]; then echo '不要送出的話,那就算了!' else hg push if [ "$?" -eq 0 ]; then echo '送出成功' func_hg_cache_controller "$uncachefile" "$cachefile" "clear-all" mode=1 else echo '送出失敗,請自行做檢查' fi fi fi echo '按任何鍵繼續...' read -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then if [ "$mode" == '3' ]; then func_hg_cache_controller "$uncachefile" "$cachefile" "clear-uncache" elif [ "$mode" == '4' ]; then func_hg_cache_controller "$uncachefile" "$cachefile" "clear-cache" fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then hg push if [ "$?" -eq 0 ]; then echo '更新本Hg資料夾成功' fi echo '按任何鍵繼續...' read -n 1 clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then # 匯出後,自動跳到模式3,就是Uncache mode func_hg_cache_controller "$uncachefile" "$cachefile" "hg-status-to-uncache" mode='3' clear_var_all='1' continue elif [ "$inputvar" == 'U' ]; then echo '己送出更新(pull)指令,等待中...' hg pull echo '己送出更新(update)指令,等待中...' hg update if [ "$?" -eq 0 ]; then echo '更新本HG資料夾成功' fi echo '按任何鍵繼續...' read -n 1 clear_var_all='1' continue elif [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then if [ ${#item_unknow_array[@]} -eq 1 ]; then func_hg_unknow_mode "${item_unknow_array[0]}" func_hg_cache_controller "$uncachefile" "$cachefile" "hg-status-to-uncache" clear_var_all='1' continue elif [ ${#item_commit_array[@]} -eq 1 ]; then func_hg_commit_mode "${item_commit_array[0]}" func_hg_cache_controller "$uncachefile" "$cachefile" "hg-status-to-uncache" clear_var_all='1' continue elif [ ${#item_uncache_array[@]} -eq 1 ]; then func_hg_uncache_mode "${item_uncache_array[0]}" "$uncachefile" "$cachefile" clear_var_all='1' continue elif [ ${#item_cache_array[@]} -eq 1 ]; then func_hg_cache_mode "${item_cache_array[0]}" "$uncachefile" "$cachefile" clear_var_all='1' continue fi elif [ "$inputvar" == '*' ]; then if [ "${#item_unknow_array[@]}" -gt 1 ]; then for bbb in ${item_unknow_array[@]} do func_hg_unknow_mode "$bbb" done func_hg_cache_controller "$uncachefile" "$cachefile" "hg-status-to-uncache" clear_var_all='1' continue elif [ "${#item_commit_array[@]}" -gt 1 ]; then for bbb in ${item_commit_array[@]} do func_hg_commit_mode "$bbb" done func_hg_cache_controller "$uncachefile" "$cachefile" "hg-status-to-uncache" clear_var_all='1' continue elif [ "${#item_uncache_array[@]}" -gt 1 ]; then for bbb in ${item_uncache_array[@]} do func_hg_uncache_mode "$bbb" "$uncachefile" "$cachefile" done clear_var_all='1' continue elif [ "${#item_cache_array[@]}" -gt 1 ]; then for bbb in ${item_cache_array[@]} do func_hg_cache_mode "$bbb" "$uncachefile" "$cachefile" done clear_var_all='1' continue fi fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} if [ "$mode" == '1' ]; then item_unknow_array=( `func_relative_by_hg_append "$cmd1" "$cmd2" "$cmd3" "unknow" "" ""` ) elif [ "$mode" == '2' ]; then item_commit_array=( `func_relative_by_hg_append "$cmd1" "$cmd2" "$cmd3" "commit" "" ""` ) elif [ "$mode" == '3' ]; then item_uncache_array=( `func_relative_by_hg_append "$cmd1" "$cmd2" "$cmd3" "uncache" "$uncachefile" "$cachefile"` ) elif [ "$mode" == '4' ]; then item_cache_array=( `func_relative_by_hg_append "$cmd1" "$cmd2" "$cmd3" "cache" "$uncachefile" "$cachefile"` ) fi elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' # 這裡不用在continue了,因為這裡是最後一行了 fi done # 離開前,在顯示一下現在資料夾裡面的東西 -eval $cmd +ls
gisanfu/fast-change-dir
41188209d6b6c1f41e1d402c34c6d84c30260295
add dir
diff --git a/123.txt b/123.txt new file mode 100644 index 0000000..e69de29
gisanfu/fast-change-dir
7178df11fe096ed907ceb774601434a6f3385c9a
remove comment
diff --git a/editfile.sh b/editfile.sh index c95527f..cf6fe71 100755 --- a/editfile.sh +++ b/editfile.sh @@ -1,59 +1,52 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' if [ "${#item_array[@]}" -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems='' for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem="$result" fi - #echo "重覆的檔案數量: 有${#item_array[@]}筆" - #number=1 - #for bbb in ${item_array[@]} - #do - # echo "$number. $bbb" - # number=$((number + 1)) - #done elif [ "${#item_array[@]}" -eq 1 ]; then relativeitem="${item_array[0]}" #cmd="vim \"${item_array[0]}\"" #eval $cmd # check file count and ls action func_checkfilecount fi if [ "$relativeitem" != '' ]; then vim $relativeitem fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset item_array diff --git a/vimlist-append.sh b/vimlist-append.sh index e84802d..c35c202 100755 --- a/vimlist-append.sh +++ b/vimlist-append.sh @@ -1,136 +1,125 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 # 是否要vff,如果沒有指定,就是會詢問使用者 # 不詢問,不要vff的話,就放0 # 不詢問,要vff的話,就放1 isVFF=$4 if [ "$isVFF" == '' ]; then isVFF=1 fi item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' -#if [ "${#item_array[@]}" -gt 1 ]; then -# echo "重覆的檔案數量: 有${#item_array[@]}筆" -# number=1 -# for bbb in ${item_array[@]} -# do -# echo "$number. $bbb" -# number=$((number + 1)) -# done -#elif [ "${#item_array[@]}" -eq 1 ]; then -# relativeitem=${item_array[0]} -#fi if [ ${#item_array[@]} -eq 1 ]; then relativeitem=${item_array[0]} elif [ ${#item_array[@]} -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems='' for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem=$result else relativeitem='' fi else relativeitem='' fi if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then if [ "$isVFF" == '0' ]; then inputchar='n' elif [ "$isVFF" == '1' ]; then inputchar='y' else isVFF='' fi # 這裡可以考慮在加上一項,就是不要append這一個檔案 if [ "$isVFF" == '' ]; then # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' echo '[WAIT] 或是編輯列表 [j]' echo '[WAIT] 還是清空它 [k]' read -n 1 inputchar fi # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append selectitem='' selectitem=`pwd`/$relativeitem checkline=`grep "$selectitem" $fast_change_dir_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_config/vimlist-$groupname.txt else echo '[NOTICE] File is exist' fi if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... checklinenumber=`cat $fast_change_dir_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` cmd='vff "vim' # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 # 查詢更多資訊請執行: "vim -h" if [ "$checklinenumber" -lt 10 ]; then for i in `seq 1 $checklinenumber` do cmd="$cmd +tabnext" done else echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' fi cmd="$cmd -p $fast_change_dir_config/vimlist-$groupname.txt\"" eval $cmd elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then echo "Your want append other file" elif [ "$inputchar" == 'j' ]; then vfff elif [ "$inputchar" == 'k' ]; then vffff else echo "Your want append other file" fi # 最後,顯示目前目錄的檔案 func_checkfilecount elif [ "$groupname" == "" ]; then echo '[ERROR] Argument or $groupname is empty' fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem
gisanfu/fast-change-dir
a5b591c74e5ebb318af760722231223a04ae204b
fix bug
diff --git a/abc-4.sh b/abc-4.sh index e11c5b8..67212cd 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,419 +1,419 @@ #!/bin/bash source "$fast_change_dir/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color while [ 1 ]; do clear if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 智慧選取單項 (;) 分號' echo ' 上一層 (,) 逗點' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 - #rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* + rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue #clear_var_all='1' continue elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} #if [ "$fast_change_dir_config_parent_enable" == '1' ]; then # item_parent_file_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" ".." "file"` ) # item_parent_dir_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" ".." "dir"` ) # # 決定誰是最佳人選,當你按了;分號或是.點 # if [ ${#item_parent_file_array[@]} -eq 1 ]; then # good_select=3 # good_array=${item_parent_file_array[@]} # elif [ ${#item_parent_dir_array[@]} -eq 1 ]; then # good_select=4 # good_array=${item_parent_dir_array[@]} # fi #fi #item_file_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) #item_dir_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "dir"` ) ## 決定誰是最佳人選,當你按了;分號或是.點 #if [ ${#item_file_array[@]} -eq 1 ]; then # good_select=1 # good_array=${item_file_array[@]} #elif [ ${#item_dir_array[@]} -eq 1 ]; then # good_select=2 # good_array=${item_dir_array[@]} #fi # 有些功能,只要看到第2個引數就會失效 #if [ "$cmd2" == '' ]; then # item_dirpoint_array=( `func_dirpoint "$cmd1"` ) # item_groupname_array=( `func_groupname "$cmd1"` ) #else # unset item_dirpoint_array # unset item_groupname_array #fi elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd diff --git a/editfile.sh b/editfile.sh index 4624d2a..c95527f 100755 --- a/editfile.sh +++ b/editfile.sh @@ -1,62 +1,59 @@ #!/bin/bash -# 這支檔案,碰到ggg.txt,就會查不到,不知道是什麼問題 -# 碰到function.menu_cart_count.php的檔名也是一樣 - source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' if [ "${#item_array[@]}" -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems='' for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem="$result" fi #echo "重覆的檔案數量: 有${#item_array[@]}筆" #number=1 #for bbb in ${item_array[@]} #do # echo "$number. $bbb" # number=$((number + 1)) #done elif [ "${#item_array[@]}" -eq 1 ]; then relativeitem="${item_array[0]}" #cmd="vim \"${item_array[0]}\"" #eval $cmd # check file count and ls action func_checkfilecount fi if [ "$relativeitem" != '' ]; then vim $relativeitem fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset item_array diff --git a/vimlist-append.sh b/vimlist-append.sh index c215360..e84802d 100755 --- a/vimlist-append.sh +++ b/vimlist-append.sh @@ -1,137 +1,136 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 # 是否要vff,如果沒有指定,就是會詢問使用者 # 不詢問,不要vff的話,就放0 # 不詢問,要vff的話,就放1 isVFF=$4 if [ "$isVFF" == '' ]; then isVFF=1 fi item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' #if [ "${#item_array[@]}" -gt 1 ]; then # echo "重覆的檔案數量: 有${#item_array[@]}筆" # number=1 # for bbb in ${item_array[@]} # do # echo "$number. $bbb" # number=$((number + 1)) # done #elif [ "${#item_array[@]}" -eq 1 ]; then # relativeitem=${item_array[0]} #fi if [ ${#item_array[@]} -eq 1 ]; then relativeitem=${item_array[0]} -#else elif [ ${#item_array[@]} -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems='' for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem=$result else relativeitem='' fi else relativeitem='' fi if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then if [ "$isVFF" == '0' ]; then inputchar='n' elif [ "$isVFF" == '1' ]; then inputchar='y' else isVFF='' fi # 這裡可以考慮在加上一項,就是不要append這一個檔案 if [ "$isVFF" == '' ]; then # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' echo '[WAIT] 或是編輯列表 [j]' echo '[WAIT] 還是清空它 [k]' read -n 1 inputchar fi # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append selectitem='' selectitem=`pwd`/$relativeitem checkline=`grep "$selectitem" $fast_change_dir_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_config/vimlist-$groupname.txt else echo '[NOTICE] File is exist' fi if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... checklinenumber=`cat $fast_change_dir_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` cmd='vff "vim' # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 # 查詢更多資訊請執行: "vim -h" if [ "$checklinenumber" -lt 10 ]; then for i in `seq 1 $checklinenumber` do cmd="$cmd +tabnext" done else echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' fi cmd="$cmd -p $fast_change_dir_config/vimlist-$groupname.txt\"" eval $cmd elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then echo "Your want append other file" elif [ "$inputchar" == 'j' ]; then vfff elif [ "$inputchar" == 'k' ]; then vffff else echo "Your want append other file" fi # 最後,顯示目前目錄的檔案 func_checkfilecount elif [ "$groupname" == "" ]; then echo '[ERROR] Argument or $groupname is empty' fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem
gisanfu/fast-change-dir
a084b848e68ad46b0f178942ced69c0f925b2ee5
add comment
diff --git a/editfile.sh b/editfile.sh index 5a0c70b..4624d2a 100755 --- a/editfile.sh +++ b/editfile.sh @@ -1,61 +1,62 @@ #!/bin/bash # 這支檔案,碰到ggg.txt,就會查不到,不知道是什麼問題 +# 碰到function.menu_cart_count.php的檔名也是一樣 source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' if [ "${#item_array[@]}" -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems='' for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem="$result" fi #echo "重覆的檔案數量: 有${#item_array[@]}筆" #number=1 #for bbb in ${item_array[@]} #do # echo "$number. $bbb" # number=$((number + 1)) #done elif [ "${#item_array[@]}" -eq 1 ]; then relativeitem="${item_array[0]}" #cmd="vim \"${item_array[0]}\"" #eval $cmd # check file count and ls action func_checkfilecount fi if [ "$relativeitem" != '' ]; then vim $relativeitem fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset item_array
gisanfu/fast-change-dir
cc60951af56990453d9bdd935820ef1e97a910f1
fix bug
diff --git a/editfile.sh b/editfile.sh index e578d1b..5a0c70b 100755 --- a/editfile.sh +++ b/editfile.sh @@ -1,61 +1,61 @@ #!/bin/bash # 這支檔案,碰到ggg.txt,就會查不到,不知道是什麼問題 source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' if [ "${#item_array[@]}" -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems='' for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem="$result" fi #echo "重覆的檔案數量: 有${#item_array[@]}筆" #number=1 #for bbb in ${item_array[@]} #do # echo "$number. $bbb" # number=$((number + 1)) #done elif [ "${#item_array[@]}" -eq 1 ]; then - relativeitem="\"${item_array[0]}\"" + relativeitem="${item_array[0]}" #cmd="vim \"${item_array[0]}\"" #eval $cmd # check file count and ls action func_checkfilecount fi if [ "$relativeitem" != '' ]; then vim $relativeitem fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset item_array
gisanfu/fast-change-dir
9bf5c780a5a8e741807c3d13c78804ed46acbda0
fix bug
diff --git a/editfile.sh b/editfile.sh index faf6d0d..e578d1b 100755 --- a/editfile.sh +++ b/editfile.sh @@ -1,35 +1,61 @@ #!/bin/bash +# 這支檔案,碰到ggg.txt,就會查不到,不知道是什麼問題 + source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) +relativeitem='' if [ "${#item_array[@]}" -gt 1 ]; then - echo "重覆的檔案數量: 有${#item_array[@]}筆" - number=1 - for bbb in ${item_array[@]} + tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" + dialogitems='' + for echothem in ${item_array[@]} do - echo "$number. $bbb" - number=$((number + 1)) + dialogitems=" $dialogitems $echothem '' " done -elif [ "${#item_array[@]}" -eq 1 ]; then - cmd="vim \"${item_array[0]}\"" + cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) + eval $cmd + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" != "" ]; then + relativeitem="$result" + fi + + #echo "重覆的檔案數量: 有${#item_array[@]}筆" + #number=1 + #for bbb in ${item_array[@]} + #do + # echo "$number. $bbb" + # number=$((number + 1)) + #done +elif [ "${#item_array[@]}" -eq 1 ]; then + relativeitem="\"${item_array[0]}\"" + #cmd="vim \"${item_array[0]}\"" + #eval $cmd # check file count and ls action func_checkfilecount fi +if [ "$relativeitem" != '' ]; then + vim $relativeitem +fi + unset cmd unset cmd1 unset cmd2 unset cmd3 -unset number unset item_array diff --git a/lib/func/relativeitem.sh b/lib/func/relativeitem.sh index 4bb9274..5ff1515 100644 --- a/lib/func/relativeitem.sh +++ b/lib/func/relativeitem.sh @@ -1,161 +1,165 @@ #!/bin/bash source "$fast_change_dir_func/md5.sh" func_relative() { nextRelativeItem=$1 secondCondition=$2 # 檔案的位置 fileposition=$3 # 要搜尋哪裡的路徑,空白代表現行目錄 lspath=$4 # dir or file filetype=$5 # get all item flag # 0 or empty: do not get all # 1: Get All isgetall=$6 declare -a itemList declare -a itemListTmp declare -a relativeitem if [ "$lspath" == "" ]; then lspath=`pwd` elif [ "$lspath" == ".." ]; then lspath="`pwd`/../" fi + if [ "$nextRelativeItem" == '' ]; then + isgetall='1' + fi + tmpfile="$fast_change_dir_tmp/`whoami`-function-relativeitem-$( date +%Y%m%d-%H%M ).txt" # ignore file or dir # ignorelist=$(func_getlsignore) ignorelist='' Success="0" # 試著使用@來決定第一個grep,從最開啟來找字串 firstchar=${nextRelativeItem:0:1} isHeadSearch='' # 這裡要注意,不能夠使用井字號(#)來當做控制字元,會有問題 if [ "$firstchar" == '@' ]; then isHeadSearch='^' nextRelativeItem=${nextRelativeItem:1} #elif [ "$firstchar" == '*' ]; then # nextRelativeItem=${nextRelativeItem:1} else firstchar='' fi # 試著使用第二個引數的第一個字元,來判斷是不是position firstchar2=${secondCondition:0:1} if [[ "$firstchar2" == '@' && "$fileposition" == '' ]]; then fileposition=${secondCondition:1} secondCondition='' fi # 先把英文轉成數字,如果這個欄位有資料的話 fileposition=( `func_entonum "$fileposition"` ) if [ "$fileposition" != '' ]; then newposition=$(($fileposition - 1)) fi lucky='' if [ "$filetype" == "dir" ]; then filetype_ls_arg='' filetype_grep_arg='' if [[ -d "$lspath$nextRelativeItem" && "$isgetall" != '1' ]]; then echo "$nextRelativeItem" exit fi else filetype_ls_arg='--file-type' filetype_grep_arg='-v' if [[ -f "$lspath$nextRelativeItem" && "$isgetall" != '1' ]]; then echo "$nextRelativeItem" exit fi fi # default ifs value default_ifs=$' \t\n' IFS=$'\n' #cmd="ls -AFL $ignorelist $filetype_ls_arg $lspath | grep $filetype_grep_arg \"/$\"" cmd="ls -AFL $ignorelist --file-type $lspath" # 先去cache找看看,有沒有暫存的路徑檔案 md5key=(`func_md5 $cmd`) cachefile="$fast_change_dir_tmp/`whoami`-relativeitem-cache-$md5key.txt" # 如果該cache有存在,就改寫指令 # 如果不存在,那在處理之前,先寫入cache if [ ! -f "$cachefile" ]; then cmd="$cmd > $cachefile" eval $cmd fi cmd="cat $cachefile " cmd="$cmd | grep $filetype_grep_arg \"/$\"" if [ "$isgetall" != '1' ]; then cmd="$cmd | grep -ir $isHeadSearch$nextRelativeItem" fi if [ "$secondCondition" != '' ]; then cmd="$cmd | grep -ir $secondCondition" fi # 取得項目列表,存到陣列裡面,當然也會做空白的處理 declare -i num itemListTmp=(`eval $cmd`) for i in ${itemListTmp[@]} do # 為了要解決空白檔名的問題 itemList[$num]=`echo $i|sed 's/ /___/g'` num=$num+1 done IFS=$default_ifs num=0 if [ "$nextRelativeItem" != "" ]; then if [ "${#itemList[@]}" == "1" ]; then relativeitem=${itemList[0]} #func_statusbar 'USE-ITEM' elif [ "${#itemList[@]}" -gt "1" ]; then relativeitem=${itemList[@]} fi fi if [ "$isgetall" == '1' ]; then if [ "${#itemList[@]}" == "1" ]; then relativeitem=${itemList[0]} #func_statusbar 'USE-ITEM' elif [ "${#itemList[@]}" -gt "1" ]; then relativeitem=${itemList[@]} fi fi # return array的標準用法 if [ "$relativeitem" != '' ]; then if [ "$newposition" == '' ]; then echo ${relativeitem[@]} else # 先把含空格的文字,轉成陣列 aaa=(${relativeitem[@]}) # 然後在指定位置輸出 echo ${aaa[$newposition]} fi else echo '' fi }
gisanfu/fast-change-dir
74b0b76d4e0338e139aadbb724d7379f1bb7a50c
fix bug
diff --git a/abc-4.sh b/abc-4.sh index c5128c4..e11c5b8 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,420 +1,419 @@ #!/bin/bash source "$fast_change_dir/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color while [ 1 ]; do clear if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 智慧選取單項 (;) 分號' echo ' 上一層 (,) 逗點' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 #rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue #clear_var_all='1' continue elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then - run="cd .. && d \"$cmd1\" \"$cmd2\" \"$cmd3\"" + run="g \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run - cd - clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} #if [ "$fast_change_dir_config_parent_enable" == '1' ]; then # item_parent_file_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" ".." "file"` ) # item_parent_dir_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" ".." "dir"` ) # # 決定誰是最佳人選,當你按了;分號或是.點 # if [ ${#item_parent_file_array[@]} -eq 1 ]; then # good_select=3 # good_array=${item_parent_file_array[@]} # elif [ ${#item_parent_dir_array[@]} -eq 1 ]; then # good_select=4 # good_array=${item_parent_dir_array[@]} # fi #fi #item_file_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) #item_dir_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "dir"` ) ## 決定誰是最佳人選,當你按了;分號或是.點 #if [ ${#item_file_array[@]} -eq 1 ]; then # good_select=1 # good_array=${item_file_array[@]} #elif [ ${#item_dir_array[@]} -eq 1 ]; then # good_select=2 # good_array=${item_dir_array[@]} #fi # 有些功能,只要看到第2個引數就會失效 #if [ "$cmd2" == '' ]; then # item_dirpoint_array=( `func_dirpoint "$cmd1"` ) # item_groupname_array=( `func_groupname "$cmd1"` ) #else # unset item_dirpoint_array # unset item_groupname_array #fi elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd
gisanfu/fast-change-dir
caf76fac3a8980507367b60b1e830557add6c54d
fix bug
diff --git a/vimlist-append.sh b/vimlist-append.sh index 57bc5cf..c215360 100755 --- a/vimlist-append.sh +++ b/vimlist-append.sh @@ -1,134 +1,137 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 # 是否要vff,如果沒有指定,就是會詢問使用者 # 不詢問,不要vff的話,就放0 # 不詢問,要vff的話,就放1 isVFF=$4 if [ "$isVFF" == '' ]; then isVFF=1 fi item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' #if [ "${#item_array[@]}" -gt 1 ]; then # echo "重覆的檔案數量: 有${#item_array[@]}筆" # number=1 # for bbb in ${item_array[@]} # do # echo "$number. $bbb" # number=$((number + 1)) # done #elif [ "${#item_array[@]}" -eq 1 ]; then # relativeitem=${item_array[0]} #fi if [ ${#item_array[@]} -eq 1 ]; then relativeitem=${item_array[0]} -else +#else +elif [ ${#item_array[@]} -gt 1 ]; then tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" dialogitems='' for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then relativeitem=$result else relativeitem='' fi +else + relativeitem='' fi if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then if [ "$isVFF" == '0' ]; then inputchar='n' elif [ "$isVFF" == '1' ]; then inputchar='y' else isVFF='' fi # 這裡可以考慮在加上一項,就是不要append這一個檔案 if [ "$isVFF" == '' ]; then # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' echo '[WAIT] 或是編輯列表 [j]' echo '[WAIT] 還是清空它 [k]' read -n 1 inputchar fi # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append selectitem='' selectitem=`pwd`/$relativeitem checkline=`grep "$selectitem" $fast_change_dir_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_config/vimlist-$groupname.txt else echo '[NOTICE] File is exist' fi if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... checklinenumber=`cat $fast_change_dir_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` cmd='vff "vim' # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 # 查詢更多資訊請執行: "vim -h" if [ "$checklinenumber" -lt 10 ]; then for i in `seq 1 $checklinenumber` do cmd="$cmd +tabnext" done else echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' fi cmd="$cmd -p $fast_change_dir_config/vimlist-$groupname.txt\"" eval $cmd elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then echo "Your want append other file" elif [ "$inputchar" == 'j' ]; then vfff elif [ "$inputchar" == 'k' ]; then vffff else echo "Your want append other file" fi # 最後,顯示目前目錄的檔案 func_checkfilecount elif [ "$groupname" == "" ]; then echo '[ERROR] Argument or $groupname is empty' fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem
gisanfu/fast-change-dir
09b5d4856ae5457ef74064c5d30ff30ac56c77ef
fix bug
diff --git a/abc-4.sh b/abc-4.sh index 3893cb1..c5128c4 100755 --- a/abc-4.sh +++ b/abc-4.sh @@ -1,419 +1,420 @@ #!/bin/bash source "$fast_change_dir/config.sh" source "$fast_change_dir_config/config.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/ignore.sh" source "$fast_change_dir_func/relativeitem.sh" # default ifs value default_ifs=$' \t\n' # 在這裡,優先權最高的(我指的是按.優先選擇的項目) # 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) func_dirpoint() { dirpoint=$1 if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_config/dirpoint-$groupname.txt | cut -d, -f1`) echo ${resultarray[@]} fi } func_groupname() { groupname=$1 resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) echo ${resultarray[@]} } unset cmd1 unset cmd2 unset cmd3 # 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 clear_var_all='' # 倒退鍵 backspace=$(echo -e \\b\\c) color_txtgrn='\e[0;32m' # Green color_txtred='\e[0;31m' # Red color_none='\e[0m' # No Color while [ 1 ]; do clear if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then unset condition + unset inputvar unset item_file_array unset item_dir_array unset item_parent_file_array unset item_parent_dir_array unset item_dirpoint_array unset item_groupname_array clear_var_all='' fi if [ "$needhelp" == '1' ]; then echo '即時切換資料夾 (關鍵字)' echo '=================================================' fi # 如果要看HELP,應該就暫時把其它東西hide起來 if [ "$needhelp" != '1' ]; then echo "`whoami` || \"$groupname\" || `pwd`" echo '=================================================' ignorelist=$(func_getlsignore) cmd="ls -AF $ignorelist --color=auto" eval $cmd if [ "$condition" == 'quit' ]; then break elif [ "$condition" != '' ]; then echo '=================================================' echo "目前您所輸入的搜尋條件: \"$condition\"" fi fi if [ "$needhelp" == '1' ]; then echo '=================================================' echo -e "${color_txtgrn}基本快速鍵:${color_none}" echo ' 倒退鍵 (Ctrl + H)' echo ' 重新輸入條件 (/)' echo ' 智慧選取單項 (;) 分號' echo ' 上一層 (,) 逗點' echo " 到數字切換資料夾功能 (') 單引號" echo ' 我忘了快速鍵了 (H)' echo ' 離開 (?)' echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" echo ' 檔案或資料夾建立刪除 (C) New item or Delete' echo ' 單項檔案 (F) 大寫F shift+f' echo ' 單項資料夾 (D)' echo ' 上一層單項檔案 (S)' echo ' 上一層單項資料夾 (A)' echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" echo ' 專案捷徑名稱 (L)' echo ' 群組名稱 (G)' echo ' 搜尋檔案的結果 (Z)' echo ' 搜尋資料夾的結果 (N)' echo ' 無路徑nopath的結果 (W)' echo -e "${color_txtgrn}VimList操作類:${color_none}" echo ' Do It! (I)' echo ' Modify (J)' echo ' Clear (K)' echo -e "${color_txtgrn}搜尋引擎類:${color_none}" echo ' Google Search (B)' echo -e "${color_txtgrn}版本控制群:${color_none}" echo ' Versions (V)' echo -e "${color_txtgrn}桌面互動類:${color_none}" echo ' Nautilus File Explorer (E)' echo ' Firefox Show (R)' echo -e "${color_txtgrn}系統類:${color_none}" echo ' Grep以關鍵字去搜尋檔案 (M)' echo ' SSH (P)' echo ' Sudo Root (Y)' echo ' History Bash (U)' echo ' 離開EXIT (X)(Q)' echo -e "${color_txtgrn}輸入條件的結構:${color_none}" echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' if [ "$needhelp" == '1' ]; then echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" read -s -n 1 unset needhelp clear_var_all='1' continue fi fi # 不加IFS=012的話,我輸入空格,read variable是讀不到的 IFS=$'\012' read -s -n 1 inputvar IFS=$default_ifs if [ "$inputvar" == ';' ]; then inputvar='F' elif [ "$inputvar" == '.' ]; then inputvar='D' fi #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" # dialogitems='file "" dir "" parent-file "" parent-dir "" ' # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) # eval $cmd # result=`cat $tmpfile` # if [ -f "$tmpfile" ]; then # rm -rf $tmpfile # fi # if [ "$result" == "file" ]; then # inputvar='F' # elif [ "$result" == "dir" ]; then # inputvar='D' # elif [ "$result" == "parent-file" ]; then # inputvar='S' # elif [ "$result" == "parent-dir" ]; then # inputvar='A' # fi #fi if [ "$inputvar" == '?' ]; then # 離開 clear break elif [ "$inputvar" == '/' ]; then # 重新讀取設定檔 source "$fast_change_dir_config/config.sh" # 砍掉relativeitem cache的檔案 #rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* clear_var_all='1' continue elif [ "$inputvar" == ',' ]; then cd .. clear_var_all='1' continue #clear_var_all='1' continue elif [ "$inputvar" == 'F' ]; then if [ "$groupname" != '' ]; then run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run clear_var_all='1' continue elif [ "$inputvar" == 'D' ]; then run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'S' ]; then if [ "$groupname" != '' ]; then run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" else run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" fi eval $run cd - clear_var_all='1' continue elif [[ "$inputvar" == 'A' ]]; then run="cd .. && d \"$cmd1\" \"$cmd2\" \"$cmd3\"" eval $run cd - clear_var_all='1' continue elif [ "$inputvar" == 'L' ]; then run="dv \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'G' ]; then run="ga \"$cmd1\"" eval $run clear_var_all='1' continue elif [ "$inputvar" == 'I' ]; then vff clear_var_all='1' continue elif [ "$inputvar" == 'J' ]; then vfff clear_var_all='1' continue elif [ "$inputvar" == 'K' ]; then vffff clear_var_all='1' continue elif [ "$inputvar" == 'V' ]; then # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 if [ -d '.git' ]; then gitt clear_var_all='1' continue elif [ -d '.svn' ]; then svnn clear_var_all='1' continue elif [ -d '.hg' ]; then hgg clear_var_all='1' continue fi echo "請輸入版本控制名稱的前綴,或按Enter離開" echo "Git (gG)" echo "Svn (sS)" echo "Hg (hH)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then gitt elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then svnn elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then hgg fi clear_var_all='1' continue elif [ "$inputvar" == 'E' ]; then nautilus . clear_var_all='1' continue elif [ "$inputvar" == 'R' ]; then $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly clear_var_all='1' continue elif [ "$inputvar" == 'M' ]; then gre clear_var_all='1' continue elif [ "$inputvar" == 'Y' ]; then sudo su - clear_var_all='1' continue # [W] Nopath 簡稱無路徑 elif [ "$inputvar" == 'W' ]; then match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` run="wv \"$match\"" eval $run clear_var_all='1' continue # [C] Create elif [ "$inputvar" == 'C' ]; then # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 # 這時是可以輸入大寫的檔名,或是資料夾名稱 if [ "$condition" == '' ]; then tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) eval $cmd result=`cat $tmpfile` if [ "$result" == "" ]; then clear_var_all='1' continue else condition="$result" fi fi echo "請選擇你要做的動作:" echo "File Touch(Ff)" echo "Create Directory And Goto DIR (Dd)" read -s -n 1 inputvar2 if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then if [[ -f "$condition" || -d "$condition" ]]; then echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 else touch $condition vf $condition fi elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then mkdir $condition if [ "$?" -eq 0 ]; then d $condition sleep 2 else echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." read -s -n 1 fi fi clear_var_all='1' continue elif [ "$inputvar" == 'H' ]; then needhelp='1' clear_var_all='1' continue elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then exit # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 elif [ "$inputvar" == $backspace ]; then condition="${condition:0:(${#condition} - 1)}" inputvar='' elif [ "$inputvar" == "'" ]; then abc123 clear_var_all='1' continue fi condition="$condition$inputvar" if [[ "$condition" =~ [[:alnum:]] ]]; then cmds=($condition) cmd1=${cmds[0]} cmd2=${cmds[1]} # 第三個引數,是位置 cmd3=${cmds[2]} #if [ "$fast_change_dir_config_parent_enable" == '1' ]; then # item_parent_file_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" ".." "file"` ) # item_parent_dir_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" ".." "dir"` ) # # 決定誰是最佳人選,當你按了;分號或是.點 # if [ ${#item_parent_file_array[@]} -eq 1 ]; then # good_select=3 # good_array=${item_parent_file_array[@]} # elif [ ${#item_parent_dir_array[@]} -eq 1 ]; then # good_select=4 # good_array=${item_parent_dir_array[@]} # fi #fi #item_file_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) #item_dir_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "dir"` ) ## 決定誰是最佳人選,當你按了;分號或是.點 #if [ ${#item_file_array[@]} -eq 1 ]; then # good_select=1 # good_array=${item_file_array[@]} #elif [ ${#item_dir_array[@]} -eq 1 ]; then # good_select=2 # good_array=${item_dir_array[@]} #fi # 有些功能,只要看到第2個引數就會失效 #if [ "$cmd2" == '' ]; then # item_dirpoint_array=( `func_dirpoint "$cmd1"` ) # item_groupname_array=( `func_groupname "$cmd1"` ) #else # unset item_dirpoint_array # unset item_groupname_array #fi elif [ "$condition" == '' ]; then # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 clear_var_all='1' continue fi done # 離開前,在顯示一下現在資料夾裡面的東西 eval $cmd diff --git a/cddir.sh b/cddir.sh index 2acce51..12325c3 100755 --- a/cddir.sh +++ b/cddir.sh @@ -1,53 +1,55 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/dialog.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "dir"` ) if [ "${#item_array[@]}" -gt 1 ]; then # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 tmpfile="$fast_change_dir_tmp/`whoami`-cddir-dialogselect-$( date +%Y%m%d-%H%M ).txt" dialogitems='' for echothem in ${item_array[@]} do dialogitems=" $dialogitems $echothem '' " done cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) eval $cmd result=`cat $tmpfile` if [ -f "$tmpfile" ]; then rm -rf $tmpfile fi if [ "$result" != "" ]; then match=`echo $result | sed 's/___/ /g'` run="cd \"$match\"" fi elif [ "${#item_array[@]}" -eq 1 ]; then run="cd \"${item_array[0]}\"" +else + run='' fi if [ "$run" != '' ]; then eval $run # check file count and ls action func_checkfilecount fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset run unset number unset item_array
gisanfu/fast-change-dir
4bc746dcada4c21bd2b925b692ca1993592326f9
fix bug
diff --git a/vimlist-append.sh b/vimlist-append.sh index ac41352..57bc5cf 100755 --- a/vimlist-append.sh +++ b/vimlist-append.sh @@ -1,130 +1,134 @@ #!/bin/bash source "$fast_change_dir_func/normal.sh" source "$fast_change_dir_func/entonum.sh" source "$fast_change_dir_func/relativeitem.sh" # cmd1、2是第一、二個關鍵字 cmd1=$1 cmd2=$2 # 位置,例如e就代表1,或者你也可以輸入1 cmd3=$3 # 是否要vff,如果沒有指定,就是會詢問使用者 # 不詢問,不要vff的話,就放0 # 不詢問,要vff的話,就放1 isVFF=$4 if [ "$isVFF" == '' ]; then isVFF=1 fi item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) relativeitem='' #if [ "${#item_array[@]}" -gt 1 ]; then # echo "重覆的檔案數量: 有${#item_array[@]}筆" # number=1 # for bbb in ${item_array[@]} # do # echo "$number. $bbb" # number=$((number + 1)) # done #elif [ "${#item_array[@]}" -eq 1 ]; then # relativeitem=${item_array[0]} #fi -tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" -dialogitems='' -for echothem in ${item_array[@]} -do - dialogitems=" $dialogitems $echothem '' " -done -cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) - -eval $cmd -result=`cat $tmpfile` - -if [ -f "$tmpfile" ]; then - rm -rf $tmpfile -fi - -if [ "$result" != "" ]; then - relativeitem=$result +if [ ${#item_array[@]} -eq 1 ]; then + relativeitem=${item_array[0]} else - relativeitem='' + tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" + dialogitems='' + for echothem in ${item_array[@]} + do + dialogitems=" $dialogitems $echothem '' " + done + cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) + + eval $cmd + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" != "" ]; then + relativeitem=$result + else + relativeitem='' + fi fi if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then if [ "$isVFF" == '0' ]; then inputchar='n' elif [ "$isVFF" == '1' ]; then inputchar='y' else isVFF='' fi # 這裡可以考慮在加上一項,就是不要append這一個檔案 if [ "$isVFF" == '' ]; then # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' echo '[WAIT] 或是編輯列表 [j]' echo '[WAIT] 還是清空它 [k]' read -n 1 inputchar fi # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append selectitem='' selectitem=`pwd`/$relativeitem checkline=`grep "$selectitem" $fast_change_dir_config/vimlist-$groupname.txt | wc -l` if [ "$checkline" -lt 1 ]; then echo "\"$selectitem\"" >> $fast_change_dir_config/vimlist-$groupname.txt else echo '[NOTICE] File is exist' fi if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... checklinenumber=`cat $fast_change_dir_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` cmd='vff "vim' # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 # 查詢更多資訊請執行: "vim -h" if [ "$checklinenumber" -lt 10 ]; then for i in `seq 1 $checklinenumber` do cmd="$cmd +tabnext" done else echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' fi cmd="$cmd -p $fast_change_dir_config/vimlist-$groupname.txt\"" eval $cmd elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then echo "Your want append other file" elif [ "$inputchar" == 'j' ]; then vfff elif [ "$inputchar" == 'k' ]; then vffff else echo "Your want append other file" fi # 最後,顯示目前目錄的檔案 func_checkfilecount elif [ "$groupname" == "" ]; then echo '[ERROR] Argument or $groupname is empty' fi unset cmd unset cmd1 unset cmd2 unset cmd3 unset number unset item_array unset checklinenumber unset relativeitem unset selectitem
gisanfu/fast-change-dir
d2fca12c5f0c68f0ff5c6a0ea00f2e4070cea8c5
modify file
diff --git a/123-2.sh b/123-2.sh new file mode 100755 index 0000000..5554f07 --- /dev/null +++ b/123-2.sh @@ -0,0 +1,233 @@ +#!/bin/bash + +source "$fast_change_dir_func/entonum.sh" +source "$fast_change_dir_func/ignore.sh" + +# 這個版本的新特色 +# 1. 選擇完、或是選擇到以後,就會離開了 +# 2. 可以輸入數字,與輸入英文的數字,不過主要還是輸入英文 +# 3. 這個版本,主要是要配合英文模式所設計的 + +# 顯示現在的檔案,並且加上編號以及顏色 +# 編號想要紅色,檔案各有各的顏色 +func_lsItemAndNumber() +{ + lspath=$1 + # 檔案的位置,這個是數值(12345...) + fileposition=$2 + # 是否顯示其它相關的數字,0是不顯示,預設是空白(顯示) + other=$3 + + # 都是粗體的顏色 + color_bldred='\e[1;31m' # Red + color_bldgrn='\e[1;32m' # Green + color_none='\e[0m' # No Color + + declare -a value_color + declare -a value_nocolor + # 加上數字的定義,下面的運算就可以很簡單 + declare -i loop_array_num + declare -i loop_item_num + + ignorelist=$(func_getlsignore) + + cmd="ls -AFL1 $ignorelist $lspath" + + # default ifs value + default_ifs=$' \t\n' + + # 先取得沒有顏色的列表 + IFS=$'\n' + list=(`eval $cmd`) + for i in ${list[@]} + do + # 為了要解決空白檔名的問題 + list2[$loop_array_num]=`echo $i|sed 's/ /___/g'` + loop_array_num=$loop_array_num+1 + done + IFS=$default_ifs + loop_array_num=0 + + # 看是不是資料夾 + regex_isdir="^(.*)/$" + + for i in ${list2[@]} + do + # 如果開始的數字不符合,就會是0 + position_regex_match='' + loop_item_num=$loop_item_num+1 + # 加上顏色的數字編號 + item_num_color="${color_bldred}${loop_item_num}${color_none} " + item_num_nocolor="${loop_item_num} " + + if [ "$fileposition" != '' ]; then + regex_match_startnum="^$fileposition" + if [[ "$loop_item_num" =~ $regex_match_startnum ]]; then + position_regex_match='' + else + position_regex_match='0' + fi + fi + + # 目前只做資料夾的顏色,和位置的標註 + if [[ "$i" =~ $regex_isdir && "$position_regex_match" != '0' ]]; then + value_color[$loop_array_num]="${item_num_color}${color_bldgrn}${BASH_REMATCH[1]}${color_none}/" + value_nocolor[$loop_array_num]="${item_num_nocolor}${BASH_REMATCH[1]}/" + elif [ "$position_regex_match" != '0' ]; then + value_color[$loop_array_num]="${item_num_color}$i${color_none}" + value_nocolor[$loop_array_num]="${item_num_nocolor}$i" + fi + + loop_array_num=$loop_array_num+1 + done + + regex_splitNumByFullSpace="^(.*) (.*)$" + + if [ "${#value_color[@]}" == 1 ]; then + if [ "$other" == '0' ]; then + for i in ${value_nocolor[@]} + do + if [[ "$i" =~ $regex_splitNumByFullSpace ]]; then + echo ${BASH_REMATCH[2]} + break + fi + done + else + echo ${value_color[@]} + fi + + #if [[ "${value_nocolor[@]}" =~ $regex_splitNumByFullSpace ]]; then + # echo ${BASH_REMATCH[2]} + #fi + else + if [ "$other" == '0' ]; then + for i in ${value_nocolor[@]} + do + if [[ "$i" =~ $regex_splitNumByFullSpace ]]; then + echo ${BASH_REMATCH[2]} + break + fi + done + else + echo ${value_color[@]} + fi + fi + + IFS=$default_ifs +} + +unset other +unset condition +unset item_array + +# 只有第一次是1,有些只會執行一次,例如help +first='1' + +# default ifs value +default_ifs=$' \t\n' + +while [ 1 ]; +do + clear + + if [ "$first" == '1' ]; then + echo '即時切換資料夾 (數字) 切換後離開' + echo '=================================================' + fi + + echo "\"$groupname\" || `pwd`" + echo '=================================================' + + # 避免現行資料夾裡面,只有一個item的狀況發生 + if [ "$condition" == '' ]; then + item_array=( `func_lsItemAndNumber "" ""` ) + else + # 先把英文轉成數字 + condition=( `func_entonum "$condition"` ) + + item_array=( `func_lsItemAndNumber "" "$condition" "$other"` ) + + if [ "${#item_array[@]}" == '1' ]; then + # 如果是一筆,就重抓一次沒有顏色的一筆 + if [ "$other" == '' ]; then + item_array=( `func_lsItemAndNumber "" "$condition" "0"` ) + fi + + regex_isdir="^(.*)/$" + if [[ "${item_array[@]}" =~ $regex_isdir ]]; then + match=`echo ${BASH_REMATCH[1]} | sed 's/___/ /g'` + run="cd \"$match\"" + eval $run + unset other + unset condition + unset item_array + break + else + match=`echo ${item_array[@]} | sed 's/___/ /g'` + if [ "$groupname" == '' ]; then + run="vim \"$match\"" + else + run="vf \"$match\"" + fi + eval $run + unset other + unset condition + unset item_array + break + fi + fi + fi + + IFS=$'\n' + echo -e "${item_array[*]}" + IFS=$default_ifs + + if [ "$condition" == 'quit' ]; then + break + elif [ "$condition" != '' ]; then + echo '=================================================' + echo "目前您所輸入的搜尋條件: \"$condition\"" + fi + + if [ "$first" == '1' ]; then + echo '=================================================' + echo '快速鍵:' + echo ' 重新輸入條件 (/)' + echo ' 智慧選取單項 (;.)' + echo ' 上一層 (-,)' + echo ' 離開 (*?)' + first='' + fi + + echo '=================================================' + + # 不加IFS=012的話,我輸入空格,read variable是讀不到的 + IFS=$'\012' + read -s -n 1 inputvar + IFS=$default_ifs + + if [ "$inputvar" == '/' ]; then + unset other + unset condition + unset item_array + continue + elif [[ "$inputvar" == '.' || "$inputvar" == ';' ]]; then + other='0' + continue + elif [[ "$inputvar" == '-' || "$inputvar" == ',' ]]; then + cd .. + unset other + unset condition + unset item_array + continue + elif [[ "$inputvar" == '*' || "$inputvar" == '?' ]]; then + unset other + unset condition + unset item_array + # 離開 + clear + break + fi + + condition="$condition$inputvar" +done diff --git a/123.sh b/123.sh new file mode 100755 index 0000000..0bd6b53 --- /dev/null +++ b/123.sh @@ -0,0 +1,248 @@ +#!/bin/bash + +source "$fast_change_dir_func/ignore.sh" + +# 這個檔案是純數字模式在使用的 + +# 數字切換資料夾的功能比較單純, +# 不會像英文模式一樣,檢查本層,同時也檢查上一層 +# 顯示檔案,也會以ls -la來顯示 + +# 在這裡,優先權最高的(我指的是按.優先選擇的項目) +# 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) + +# 顯示現在的檔案,並且加上編號以及顏色 +# 編號想要紅色,檔案各有各的顏色 +func_lsItemAndNumber() +{ + lspath=$1 + # 檔案的位置,這個是數值(12345...) + fileposition=$2 + # 是否顯示其它相關的數字,0是不顯示,預設是空白(顯示) + other=$3 + + # 都是粗體的顏色 + color_bldred='\e[1;31m' # Red + color_bldgrn='\e[1;32m' # Green + color_none='\e[0m' # No Color + + declare -a value_color + declare -a value_nocolor + # 加上數字的定義,下面的運算就可以很簡單 + declare -i loop_array_num + declare -i loop_item_num + + ignorelist=$(func_getlsignore) + + cmd="ls -AFL1 $ignorelist $lspath" + + # default ifs value + default_ifs=$' \t\n' + + # 先取得沒有顏色的列表 + IFS=$'\n' + list=(`eval $cmd`) + for i in ${list[@]} + do + # 為了要解決空白檔名的問題 + list2[$loop_array_num]=`echo $i|sed 's/ /___/g'` + loop_array_num=$loop_array_num+1 + done + IFS=$default_ifs + loop_array_num=0 + + # 看是不是資料夾 + regex_isdir="^(.*)/$" + + for i in ${list2[@]} + do + # 如果開始的數字不符合,就會是0 + position_regex_match='' + loop_item_num=$loop_item_num+1 + # 加上顏色的數字編號 + item_num_color="${color_bldred}${loop_item_num}${color_none} " + item_num_nocolor="${loop_item_num} " + + if [ "$fileposition" != '' ]; then + regex_match_startnum="^$fileposition" + if [[ "$loop_item_num" =~ $regex_match_startnum ]]; then + position_regex_match='' + else + position_regex_match='0' + fi + fi + + # 目前只做資料夾的顏色,和位置的標註 + if [[ "$i" =~ $regex_isdir && "$position_regex_match" != '0' ]]; then + value_color[$loop_array_num]="${item_num_color}${color_bldgrn}${BASH_REMATCH[1]}${color_none}/" + value_nocolor[$loop_array_num]="${item_num_nocolor}${BASH_REMATCH[1]}/" + elif [ "$position_regex_match" != '0' ]; then + value_color[$loop_array_num]="${item_num_color}$i${color_none}" + value_nocolor[$loop_array_num]="${item_num_nocolor}$i" + fi + + loop_array_num=$loop_array_num+1 + done + + regex_splitNumByFullSpace="^(.*) (.*)$" + + if [ "${#value_color[@]}" == 1 ]; then + if [ "$other" == '0' ]; then + for i in ${value_nocolor[@]} + do + if [[ "$i" =~ $regex_splitNumByFullSpace ]]; then + echo ${BASH_REMATCH[2]} + break + fi + done + else + echo ${value_color[@]} + fi + + #if [[ "${value_nocolor[@]}" =~ $regex_splitNumByFullSpace ]]; then + # echo ${BASH_REMATCH[2]} + #fi + else + if [ "$other" == '0' ]; then + for i in ${value_nocolor[@]} + do + if [[ "$i" =~ $regex_splitNumByFullSpace ]]; then + echo ${BASH_REMATCH[2]} + break + fi + done + else + echo ${value_color[@]} + fi + fi + + IFS=$default_ifs +} + +unset other +unset condition +unset item_array + +# 只有第一次是1,有些只會執行一次,例如help +first='1' + +# default ifs value +default_ifs=$' \t\n' + +while [ 1 ]; +do + clear + + if [ "$first" == '1' ]; then + echo '即時切換資料夾 (數字)' + echo '=================================================' + fi + + echo "\"$groupname\" || `pwd`" + echo '=================================================' + + # 避免現行資料夾裡面,只有一個item的狀況發生 + if [ "$condition" == '' ]; then + item_array=( `func_lsItemAndNumber "" ""` ) + else + item_array=( `func_lsItemAndNumber "" "$condition" "$other"` ) + + if [ "${#item_array[@]}" == '1' ]; then + # 如果是一筆,就重抓一次沒有顏色的一筆 + if [ "$other" == '' ]; then + item_array=( `func_lsItemAndNumber "" "$condition" "0"` ) + fi + + regex_isdir="^(.*)/$" + if [[ "${item_array[@]}" =~ $regex_isdir ]]; then + match=`echo ${BASH_REMATCH[1]} | sed 's/___/ /g'` + run="cd \"$match\"" + eval $run + unset other + unset condition + unset item_array + continue + else + match=`echo ${item_array[@]} | sed 's/___/ /g'` + if [ "$groupname" == '' ]; then + run="vim \"$match\"" + else + run="vf \"$match\"" + fi + eval $run + unset other + unset condition + unset item_array + continue + fi + fi + fi + + IFS=$'\n' + echo -e "${item_array[*]}" + IFS=$default_ifs + + if [ "$condition" == 'quit' ]; then + break + elif [ "$condition" != '' ]; then + echo '=================================================' + echo "目前您所輸入的搜尋條件: \"$condition\"" + fi + + if [ "$first" == '1' ]; then + echo '=================================================' + echo '快速鍵:' + echo ' 重新輸入條件 (/)' + echo ' 智慧選取單項 (.;)' + echo ' 上一層 (-,)' + echo " 到關鍵字切換資料夾功能 (+')" + echo ' 離開 (*?)' + first='' + fi + + echo '=================================================' + + # 不加IFS=012的話,我輸入空格,read variable是讀不到的 + IFS=$'\012' + read -s -n 1 inputvar + IFS=$default_ifs + + if [ "$inputvar" == '/' ]; then + unset other + unset condition + unset item_array + continue + elif [[ "$inputvar" == '.' || "$inputvar" == ';' ]]; then + other='0' + continue + elif [[ "$inputvar" == '-' || "$inputvar" == ',' ]]; then + cd .. + unset other + unset condition + unset item_array + continue + elif [[ "$inputvar" == '*' || "$inputvar" == '?' ]]; then + unset other + unset condition + unset item_array + # 離開 + clear + break + elif [[ "$inputvar" == '+' || "$inputvar" == "'" ]]; then + unset other + unset condition + unset item_array + # 離開 + clear + break + fi + + condition="$condition$inputvar" +done + +# 離開前,在顯示一下現在資料夾裡面的東西 +ls -AF + +if [[ "$inputvar" == '+' || "$inputvar" == "'" ]]; then + abc +fi diff --git a/COMMAND.mkd b/COMMAND.mkd new file mode 100644 index 0000000..9e19319 --- /dev/null +++ b/COMMAND.mkd @@ -0,0 +1,153 @@ +## 操作文件 + +這裡會分成兩個大區塊 + +- CLI + + 在command-line的時候,可以使用的指令 + +- IDE + + 在IDE階段的時候,可以使用的指令 + +CLI和IDE的使用方式是很類似的,因為CLI等於是IDE的base。 + +### Define + +在說明指令前,先做一些專有名詞的定義 + +#### Position + +可能是某些同類型的item,它的位置所在, + + 1234567890 + +為了方便,我使用無蝦米的方式來重新命名這些數字,比較好輸入位置,當然你也可以輸入數字, + + ersfwlcbko + +#### keyword[N] + +關鍵字 + +假設我使用了以下的指令 + + $ v ddd fff + +也就代表keyword1是ddd,而keyword2是fff, + +如果以`grep`這個指令來說明,就可以會像以下的狀況 + + $ ls | grep ddd | grep fff + +#### 智慧選擇 + +這個是在IDE功能內的名詞,以下是順序 + +- file +- dir +- parent file +- parent dir + +總共4個順位, + +如果是檔案類,可以使用`;`直接丟到vim cache file裡面,然後直接開啟vim做編輯, + +而`.`的話,也是直接丟到vim cache file裡面,差別是不編輯, + +如果是資料夾類,`;`和`.`是一樣的功能。 + +### CLI + +#### Chdir + +使用`d`取代平時所使用的`cd`,並改變習慣,使用以下的語法來操作 + + 語法: d [keyword1] [keyword2] [position] + +範例1,如果你要進去本層的`abcdef`資料夾,而本層只有這一個資料夾,你可以使用以下的指令 + + $ d abc + +或是使用只支援6個位置的chdir position指令,因為只有一個資料夾,所以你可以換使用`進去第幾個資料夾`的指令 + + $ de + +補充,如果它是在資料夾裡面的第二個資料夾,可以使用以下指令,這樣子的狀況,可以使用到第6個,也就是會有6個e + + $ dee + +範例2,如果本層還有另一個資料夾名稱,叫做`abc123`,那你可以換成以下的指令 + + $ d abc def + +範例3,如果本層有另一個資料夾叫做`hhhabc`,可以在第一個關鍵字前面加上`@`小老鼠 + + $ d @abc + +範例4,如果本層有`aaa`和`aab`資料夾,而且順序是如下: + + 1. aaa + 2. aab + +你想要aaa的話,可以輸入以下的指令: + + $ d aa @1 + +或者是: + + $ d aa @e + +#### Edit file + +使用`v`指令來取代平時所使用的`vi`或是`vim`, + +使用的方式,跟Chdir一樣,以下會說明多了哪些功能。 + + 語法: v [keyword1] [keyword2] [position] + +範例1,如果你想要把這一個檔案加入到暫存區,檔名叫做def.txt + +使用這個指令之前,要先建立、以及選擇group,請參考`README.markdown`的檔案 + + $ vf def + +範例2,這個檔案,是在檔案內的第二順位(不包含資料夾),那你可以換成以下的指令,一樣,最多6個e + + $ vfee + +範例3,如果你想要看暫存區內的檔案列表 + + $ vfff + +範例4,如果你想要編輯暫存區裡面的檔案 + + $ vff + +範例5,如果你想使用vimdiff來對暫存區裡面的檔案做diff + +假設暫存清單內有兩個檔案 + + $ vff "vimdiff" + +### IDE + +輸入以下的指令,可以啟動IDE + + ide + +或者是 + + abc + +#### Chdir + +跟CLI的使用方式一模一樣,只要輸入所需的引數,然後透過`Shift+d`(本層), + +或是`Shift+a`(上一層)來切換到該資料夾內, + +如果你想使用智慧選取,請參照上面Define section。 + +#### Edit file + +也是跟CLI的一樣,請參考help裡面的快速鍵說明`Shift+h` diff --git a/IDEA b/IDEA new file mode 100644 index 0000000..86074cc --- /dev/null +++ b/IDEA @@ -0,0 +1,739 @@ +# 2011-04-17 + +想要寫abc第4個版本 + +這個版本的特色為: +- 不會即時搜尋各功能 +- 當然也不會顯示搜尋後的結果 +- 點確認以後,才會開始搜尋,以及各功能所會做的動作 +- 為了要增加執行的效率,才會做這一個版本 +- 先做基本的功能(本層、上層的檔案和資料夾處理),如果效率沒有問題,在加寫其它的功能 +- 如果有重覆的,就用dialog menu +- relativeitem或許可以取消cache功能 +- 使用各快速鍵來啟動該功能,例如我輸入了eeee,然後按大寫F,來搜尋本層的檔案,如果只有一筆,那就加入暫存列表,並直接編輯它 + +# 2011-04-16 + +想用python重寫relativeitem + +當有人在問它的時候,就會同時找以下的東西: +1. 本層的檔案和資料夾 +2. 上一層的檔案和資料夾 + +找到了以後,第一次會將列表寫入檔案, +可能會給檔案一個編號當檔名,這個編號也會回傳給bash abc-v3主程式 +當下一個relative開始,就會帶著這個編號去問新的程式, +這時新的程式,可以用這個編號去找檔案,而不用重新取得列表。 + +# 2011-04-15 + +1. 在vff的前面,加一個flow,選擇你要編輯的檔案 +2. 正在想,要不要加入其它的語言,為了增加效率 + +# 2011-04-14 + +可以把各專案的設定檔,放到各專案的資料夾裡面, +不過關於這一點,可能要改很多地方。 + +# 2011-04-12 + +想要把資料夾和檔案的檔名,寫到一支文字檔裡面, +然後增加一個功能,對那個文字檔做控制 + +# 2011-03-22 + +可以把Groupname,在abc version3裡面,加上dialog的選擇功能 + +# 2011-03-01 + +在ide階段,想要不輸入東西,就可以使用F和D以及上一層的功能, +使用的方式為dialog。 +增加這個功能了以後,感覺更好用了。 + +想要在vf詢問的地方,加上"是否使用純vim編輯,而不列入暫存"的選項 +詢問過後,程式才會決定要不要寫入暫存 + +# 2011-02-21 + +看能不能在啟動ide之前,先去update(應該是說git pull)最新的資料, +這樣子就可以做最快速的同步, +希望目前原有的fast-change-dir-config的目標,能夠改成自己的git repo,比較安全, +不過這裡是點奇怪的,又想要private repo,但又想要密碼驗證,然後又想要安全性, +最好的方式,應該是每一個target或者說是End端,都要有一個類似驗證碼的東西, +送上去的時候,不是我的人就不能送上去, + +目前還沒有想到一個比較好的方式。 + +應該是說,可以抓下去,要透過驗證碼 +(每一台,或是每一個權限,使用的驗證碼都不一樣), +要送上去的時候,是需要密碼的,這樣子的方式應該是比較好的方式。 + +送上去的時候,可能是送到我自己的svn repo, +送上去以後,會export到某一個http的路徑, +然後我透過http simple auth,讓該權限來下載東西,或是更新東西下去, +但如果是這種作法的話,要怎麼樣上傳呢? +好像想的太複雜了@@。 + +# 2011-02-18 + +有想到一個功能, +如果我想要去一個資料夾, +它是在某一個資料下底下, + +這種狀況常常會發生,就是進去上一個資料夾以後,就忘了下一個資料夾要去哪裡了。 + +所以想做一個功能,就是先輸入下一個條件,在然在進去第一個資料夾, +當第一個資料夾進去了以後,就會自動處理在暫存的指令, +不過後來想一想,其實如果是在本機操作,也可以進去第一層,然後按"R",啟動nautilus, +用GUI去操作。 + +# 2011-02-16 + +想要加上git的路徑(我指的是1.7的git) +不然又需要root權限了 + +想要多錯字處理的功能, +例如我輸入了misc, +打錯成為mics, +這時是可以判斷的,不過細節的部份要在思考一下, +而且這個功能,可能也會造成速度變慢,或許是不需要做的 + +# 2011-02-14 + +想要做一個功能,是不受groupname限制的, +很像是ssh txtfile的功能, +就是輸入一個關鍵字,可能就會跳到那一個資料夾裡面, +因為有時候很累的時候,跟本就沒有辦法輸入快速鍵。 + +# 2011-02-10 + +想要寫一支script,針對Zend Framework的架構, +匯出dirpoint的檔案出來, +可能可以針對root、module name等變數來做組合,以及匯出。 + +# 2011-02-01 + +想要把function放到lib/func資料夾裡面。 +想要把片段程式碼放到lib/某一個資料夾裡面,可能是several, +想在abc-v3的第二個引數,加上@小老鼠,使用在position + +還想要更改所有的文字檔到指定的某個位置, +除了路徑以外,檔名都要是變數,都是可以被修改的。 +例如是放在~/git/公司名稱_某分類名稱/, +然後如果在公司做到一個地方,可以把裡面的東西,先存起來, +將整個設定和環境一起帶到另外一台電腦上面。 +暫存的路徑是需要的,但是檔名應該先不需要, +其它的應該都是需要的。 + +# 2011-01-31 + +目前己經有一個輸入@小老鼠,可以為grep加上^的指令, + +我想加一個#井字號,告訴程式我想要使用dialog menu的方式來選擇我要的東西, +經測試了以後,發現不能夠在bash function裡面,下dialog的指令, +所以這個功能必需要在函式以外的地方先處理, +感覺很麻煩,不過也蠻實用的。 + +# 2011-01-30 + +能不能讓每一個group,都有自己的設定檔, +例如home的group,可能就會啟動parent-item的功能, +而某程式設計的專案,可能就會因為感覺良好,而關閉它。 + +# 2011-01-29 + +能不能在同一個func_relative裡面, +同時做同個資料夾的item處理,以及上一層資料夾內的item處理呢? + +能否使用C語言來改寫func_relative的函式, +然後讓bash來呼叫,看能不能改善效率, +讓反應速度能夠跟上我的操作速度, +在呈現的部份。 + +# 2011-01-28 + +有機會想要做web的部份。 + +關於資料夾、或是檔案碰到多筆的狀況, +可以多一個使用dialog menu的選擇來協助, +關於資料夾的部份,可以使用.(點)的快速鍵。 + +不過好像太麻煩了,可以試著按斜線清掉執行鍵, +然後想想如何使用更好的關鍵字來對它選取, +然後將它記錄在腦海裡面,下次就使用新的或是更好的方式來選擇該項目。 + +# 2011-01-27 + +對於vf按y和n,有想到一個方式 +就是先把.(點)改回來, +可能把點使用在append-vff, +而;(分號),就是append+vff, +這樣子keyin的數量應該會少很多, +效率應該會比較快。 + +不過這個idea可能不會用在數字模式上,因為狀況不同 + +另外,如果輸入錯了快速鍵,或是打錯關鍵字, +想要暫停2秒鐘,然後自動清除關鍵字,並重來, +這樣子可能也多多少少增加一些速度, +不然打錯了還要手動去按一下/(斜線) +有時候按斜線還會按錯 + +分號,在切換資料夾的時候,可以想看看有沒有什麼其它的應用。 + +關鍵字的部份好像有點問題, +如果某一個物件名稱是aaabbb, +我輸入aa bb是可以找得到的, +但是如果我輸入bb aa好像是找不到的。 + +# 2011-01-26 + +想要把abc v3的第一次顯示help的部份拿掉 + +想加上更多操作檔案的功能 +例如之前idea前寫過的: +執行檔案(依照副檔名) +刪除檔案(當然要可以刪除單檔、多檔,或是針對資料夾,或是混合) +更改名稱 +移動路徑 + +想要在touch檔案以後,順便去編輯它 +如果是在有啟動groupname的時候,步驟就會走到詢問你要不要vff的階段 + +touch檔案,應該是使用dialog的方式才對 + +刪除的功能,在C的快速鍵中,感覺不是很實用 + +目前是用C來當做Create,感覺還不錯 +看要不要在建立另外一個關鍵字,來做刪除的動作 + +刪除的動作,也可以考慮不要做,改用cli, or nautilus來做會比較保險。 + +# 2011-01-25 + +想要在每一個版本控制功能中, +都加上R功能,也就是切換到Browser。 + +# 2011-01-22 + +想要在按分號的時候,就直接編輯檔案(如果是選檔案是在第一項) +就不要在按Y的,很麻煩,也為了可以簡化。 +但是,如果我只是想append,但還沒有要edit,那這時怎麼辦呢? +是不是也是要維持現在的使用方式就可以了呢? + +可以在append,詢問Y和N的地方,加上分號,或是F當做Y, +但這樣子不知道會不會換右手酸了。 + +目的還是要簡少按鍵數量。 + +或是在多一個快速鍵,跟F結合在一起,可能是寫在F,裡面在多一個判斷, +目的是要把append檔案的部份,分一個Y的,和一個N的。 + +另外,想加一個C快速鍵,就是選到項目的時候所使用的, +裡面可以刪除檔案、等其它額外擴充的功能 + +還有,別忘了還有一個IDEA需要被完成,就是判斷副檔名的部份。 +就是在vim -p files...的時候,如果副檔名是.tar.gz、zip、image file等東西, +在vim的部份,就是會ignore它們。 + +# 2011-01-18 + +想要把原先放在/bin下的執行檔,都改放在自己的家目錄, +這樣子在有些沒有root的環境下,才可以使用, +而且這樣子也比較合理 + +不過有些檔案的目標路徑,是寫死的, +利用這個idea把它們都做個修正。 + +# 2011-01-17 + +想要在vimlist的功能,加上判斷副檔名的功能, +如果是使用vim編輯的話,就會乎略掉某些副檔名, +例如tar.gz, zip, images, videos, music + +# 2011-01-13 + +想要在vf的地方,加上以下的功能項目: +1. execute +2. delete + +execute的部份,可能就會判斷副檔名, +刪除的部份,可能會用D的關鍵字來做。 + +# 2011-01-11 + +想要在/斜線的地方,加上重新去include檔案的程式碼, +這樣子如果修改了searchfile, or searchdir,把它設定為啟動, +這時只要按一下斜線,就可以生效了 + +設定檔的地方,想要在加上bash history, 以及google search function + +另外,以現在的使用方式,是增加判斷式和google groupname, +這樣子的使用方式,跟我新增設定檔的目標是很像的, +打算選擇設定檔的方式,在加上面的idea,可能會比較好使用。 + +# 2011-01-09 + +想要在各version control裡面的push之前, +加上"處理中..."的字眼,或者是顯示執行的指令。 + +在要增加一些功能的開關設定, +因為不管是在比較慢的電腦,或是比較快的,上執行這套程式,會很慢, +例如搜尋檔案的功能,或者是搜尋bash history的功能, +或許我可以把這些開關的設定,寫在某一支bash file裡面, +要使用的時候,才去修改它, +然後abc-v3就去include它。 + +# 2011-01-07 + +想要加一個快速鍵,來show/hide Help,應該就是大寫的H了 + +想要加上一個功能,就是按下vim的F8,就會離開vim,以及重新啟動vimlist的功能, +當然這個功能要先選擇groupname,這個功能是可以做的, +可能就離開前先寫入文字檔,然後abc-v3去判斷文字檔內是否有內容, +有的話在重新啟動vimlist的功能,因為不是很重要,所以暫時先不用寫 + +有沒有可能在vim裡面,按某一個快速鍵,然後就會把menu列出來讓你選擇, +或是可以讓你用快速鍵去選擇裡面的項目。 + +# 2011-01-03 + +想要加上切換到firefox的快速鍵 + +以及想要把切換的程式,加上引數,可以選擇切換後,要不要按下重整的按鈕。 + +另外,想要在啟動ide and abc-v3的時候,如果groupname是空白,就自動補上home, +關於這個idea在想想看,因為空groupname也是有我設計的理念在裡面,先不要拿掉好了。 + +# 2011-01-01 + +在abc-v3的V快速鍵中, +想要check current dir是否有.svn or .hg or .git的資料夾, +如果有的話,就直接啟用該版本控制, +還有,這個功能選擇版本控制的快速鍵,想要大小寫都可以使用。 + +我想在各版本控制的介面中,加上抓repo的功能下來,但這個IDEA好像不是很實用。 + +# 2010-12-31 + +想要將版本控制都放在一起, + +例如按V(Version),就代表版本控制, +然後就會出現H(hg), G(git), S(Svn), C(cvs這個應該不會做) +一樣也是按快速鍵去執行它 + +在要加上第2層的判斷, +可能試著執行status,例如git status, +如果有正常的反應,我指的是在正確的repo裡面, +那這時我就會判斷正常,來執行指定的版本控制的指令。 + +# 2010-12-26 + +想要思考一下,怎麼樣在commander與cli之間做快速的切換, + +有想到幾種方式: +1. 輸入一個快速鍵,然後會顯示讓你輸入指令的地方,只執行一次就會回到commander +2. 離開commander以後,可以任意的輸入指令,然後透過輸入某個指令,就會回到commander +3. 利用Ctrl+Z,把現在執行的東西放到background,透過fg把commander叫起來 +4. 把MC啟動很慢的問題解決掉 +5. 開2個視窗,用alt + tab切換 +6. 開2個電腦,分別用不同的鍵盤 + +目前有加上nautilus,在abc裡面,所以未來我可以直接離開,或是不使用ide的指令, +如果要執行指令的時候,直接離開abc,如果指令打完,在輸入abc啟動ide就可以了。 + +# 2010-12-16 + +想要更改現在目前爛爛的svnn功能, +以及想要新增hg進來,不然就叫做hgg。 + +另外,svnn和hg,想要加上一個功能, +commit cache的功能, +就是送出指定的檔案, +會想加上這個功能, +是因為有些檔案是我不想要送的檔案, +或是說,有些檔案己經完成了,但其它的檔案還在修改當中。 + +這個cache,想要寫在一個文字檔裡面,類似vimlist, +以svn來說,只要commit,就會送出了,這是與hg不同的地方, +我打算在送出了之後,就清空這個cache, +這個cache,我想取名為svnlist(svn commit list) + +關於cache的功能,有一些想法: +1. 全部列入(或取消)cache +2. 關鍵字選擇單項(或多項)項目列入(或取消)cache +3. 觀看修改的內容,使用svn diff的指令,跟最後一個版本做比較 +4. svn add的功能 +5. 可以選擇清除cache, and uncache file +6. 可以選擇重新建立uncache file + +這個會比較複雜,會有4種模式(gitv2只有2種) +每一個模式都可以下commit的指令 +1. svn status, filter by untracked, or new file, 其它都沒有哦 +2. svn status, filter by added, or deleted, modify一定會在裡面的(我想取commit list) +3. uncache list(這個還是要有,會比較方便) +4. cache list + +在模式1的時候,可以使用關鍵字來對沒有被svn add的檔案操作, +然後會忽略掉modify或是己被svn add的檔案, +commit list反之。 + +關於模式3,只要模式1有動作,就會重新輸出uncache file,也會清空cache file, +會這樣子做,是因為沒有svn-add的檔案(狀態為問號),是沒有辦法被commit的,請注意! + +還是把模式1,變成狀態只能是問號的 + +另外,我想把寫入檔案這個動作,寫成bash function, +因為這個動作看起來還蠻常用的。 + +# 2010-12-15 + +搜尋google的功能, +除了想獨立一個功能來做以外, +還想要在abc3也想加上這一個功能, +不過可能只會搜尋一筆, +因為如果很多筆的話,abc3會變的很亂。 + +# 2010-12-14 + +想要加上搜尋google的功能, +請參考study/google-search.pl檔案, + +當輸入關鍵字的時候,就會順便去搜尋Google, +然後我可以去選擇我想要的項目編號, + +選了之後,就會用firefox指令去開啟該網址, +並且切換到firefox的視窗。 + +可能會新增一個項目,來放這個新功能, +然後英文模式在透過某一個快速鍵來連到這一個功能 + +另外,我在想要不要使用firefox, +理論上來說,我應該選擇的是links或是其它文字型的瀏覽器。 + +我看,還是做一個選項之類的東西,來切換瀏覽器。 + +後來找到了w3m,打算使用這一個。 + +如果要使用這個功能,請建立google這一個groupname。 + +使用text browser有一個好處,因為很多主機是沒有圖型介面的, +而且都是放在機房,如果沒有帶自己筆記型電腦過去,是上不了Google查資料的。 + +# 2010-12-10 + +想要加一個功能,是在輸入關鍵字的時候, +也順便去搜尋底下的資料夾, +當選擇的時候,當然是進去那一個資料夾裡面。 + +不過這個功能我不打算加入groupname功能內。 + +# 2010-12-03 + +在想要不要把MC加進來, +在create, delete資料夾或是文字檔的時候, +或是在copy, move, rename的時候, +轉使用MC工具,不過MC啟動的時候有點慢,大約要10秒鐘, +而且使用-s or -b的引數都還是很慢, +我在找找看有沒有其它的使用選擇。 + +# 2010-11-30 + +在想要不要增加一些系統的元素進來, +例如: +sudo or leave sudo +edit hosts +edit php.ini +edit apache conf(s) +edit or tail message, dmesg +start restart service +search bash history(只是有些指令在cli下執行會卡住) +ssh remote server + +以上這個話題,可以分一些思考點出來 +1. 編輯檔案的部份,可以參考dirpoint的作法 +2. 搜尋檔案內容的部份,就比較單純 +3. sudo 可能就要在想一下了,可能就下sudo的指令,然後我可能不要打密碼, +接下來會切換到root,這時會自動用root來執行ide或是abc。 +4. start restart service, 可能需要搭配dialog來做。 +5. ssh remote server, 這可能會蠻實用的,我可能會先寫入一個文字檔列表, +這個功能應該很單純,然後是全域的,不會被groupname所區分。 + +關於上述第1點, +可以設定檔案的virtual徑捷,例如我輸入config,這時可能會出現aaa.xml出來, +可能要想一下,這一點是否真的實用才做。 +後來想一想,可能不太實用,因為我還有搜尋的功能,假設在任何地方輸入aaa, +還是會出現aaa.xml + +有些功能,我在想,可能不需要,或是不能用.(點)來做選擇, +一定要用所指定的快速鍵來選擇該功能,這樣可能比較不會有誤動作。 + +# 2010-11-24 + +我新增了一個study,是可以自動切換到指定的視窗,然後送指令. + +我想利用這個study,做以下的動作: +1. In Gnome-terminal vim edit file +2. 離開vim,然後執行某一個快速鍵,這時會切到firefox,然後重新整理頁面 +3. 也會在回到vim + +這個動作可能可以想一下應用 + +# 2010-11-18 + +想把abc裡面的重覆項目, +做一些功能選擇, +1. 將這些項目,append到vimlist +2. 在這些項目中做多項的選擇,一樣會把所選擇的結果append到vimlist中 + +應該除了ga和dvv功能以外,其它功能都想要套用以上的功能 + +另外,gitt也想要加這個功能,就可能輸入關鍵字,然後如果是多項的話, +就一次把他們加入。 + +多項的選擇,本來是用ers(123)的方式,只要加上星號,就可以選多項了, +或是輸入e|r|s之類的,來選其它的多項。 + +然後找找看,如果以vim -p來開啟檔案,能不能指向要以哪一個先顯示, +結論是可以的,請參考vim.txt這個study檔案 + +# 2010-11-17 + +想要增加一個功能在abc裡面, +當我在輸入關鍵字的時候,會即時去搜尋資料夾的檔案。 + +另外,想要增加效率,這個要在看一下程式能不能在做修改。 + +想要在clear vimlist的時候,寫入history, +這個history是要查詢用的,這樣子如果剛才需修改的檔案, +可以在重新呈現在vimlist裡面。 + +# 2010-11-15 + +想要在abc中,加上touch新檔案,以及建立新資料夾的功能 +可以先輸入一個關鍵字,然後透過某一個快速鍵來啟用這個功能, +當然會詢問使用者是要touch或是建立資料夾。 + +# 2010-11-14 + +想要做一個介面,是git add在使用的, +會顯示Untracked Item, +然後我可以輸入關鍵字,來append item to index。 + +# 2010-11-12 + +打算在cli顯示的訊息,跟在ide顯示的不一樣, +為的還是直覺反應的速度。 + +今天找到另外一個問題, +可能要把一開始的clear,給拿掉, +讓整個介面變成跟一般的CLI一樣, +字會往上推,不過測試的結果,是會很亂。 + +# 2010-11-11 + +關於Q1, +可以將數字模式,設計成打英文的數字模式 +例如12,可能就是打er。 + +關於Q2, +其實也還好,反正進來IDE以後,按[a]鍵也是只有第1次只會按到的鍵。 + +關於Q3,Q4 +其實也沒這麼嚴重,因為一般的IDE(例如Zend, or other editor), +也是一樣,要先用mouse去關該檔案的tab, +然後在用mouse去找新檔案。 + +另外,補充Q4, +可以修正vf的功能, +把編輯list和清空list的功能寫在一起,這樣應該會比較順,試試看。 + +# 2010-11-10 + +今天在用的時候,覺得很不順, +在加上寫程式的同時,還要去思考現在是處在什麼模式下, +有時會卡住或是想不通。 + +不順的地方有以下的幾點: +Q1. 英文模式,有時會需要切換到數字模式, + 找要要編輯的檔案過後,或是資料夾後, + 都會以為現在是英文模式,都會打英文而造成找不到項目的狀況。 +A1. 可以在數字模式中,選定項目後,會自動切回英文模式, + 不過,全數字模式的操作,也是蠻特別的,還是需要留下來。 + +Q2. 以現在的設計方式,IDE是第一個看到的介面, + 然後在看切換到什麼地方去工作, + 有時看到IDE介面,會不知道下一步要做什麼動作。 + +A2. 可以把第一個介面,改成英文模式, + 因為英文模式以我的感覺,是距離最近使用者的介面。 + +Q3. vimlist的功能,是輔助vim用的編輯清單, + 不過vim的tab,數量會有限制, + 另外,vimlist如果要去掉裡面某一個檔案, + 然後在增加另外一個檔案,還真的有一點麻煩。 + +Q4. 英文模式自從加上了2個功能的關連之後(groupname, and dirpoint) + 感覺很實用,但用到了vimlist功能,就覺得卡卡的, + 整個流程還是有瑕疪。 + +# 2010-11-07 + +1. 在abc裡面,加上groupname的關連 +2. 在abc裡面,加上bash_history的關連 +3. 在abc裡的dirpoint關連,如果使用者輸入了cmd2, +那就取消dirpoint功能, +因為輸入cmd2,很明顯的,使用者不是要使用dirpoint功能。 + +# 2010-11-06 + +在abc裡面,加上dirpoint的關鍵,然後快速鍵是(L) + +# 2010-11-04 + +想要做一個讓我輸入指令的地方, +然後下面會顯示一些輔助的東西出來, +目前我只有想到search history, +假設我輸入mysql,可能下面就會出現sudo /etc/init.d/mysql start, +然後我只要輸入某些快速鍵,就會讓我用dialog去選擇己存在的指定。 + +在ide的地方,多顯示groupname的欄位 + +# 2010-10-19 + +打算在ide的地方,加上svn(s) +和git(t)的快速鍵 + +# 2010-10-16 + +關於gitt的功能, +可能會參考abc and 123, +包含顏色的部份, +只是差在可以新增或加入檔案到git, +以及送出, +送出可能是會用dialog來做 + +# 2010-10-12 + +想把svnn的功能,加到ide裡面, +另外,想把svn status -q的下一步,變成是送出, +送出的部份想要用dialog來輸入, + +然後想增加gitt(git)的功能,在ide之內, +git add的部份,想要做成是輸入數字鍵, +利用輸入數字鍵,來add檔案, +然後changelog的部份,也想要用dialog來做 + +# 2010-10-10 + +想到一個情境, +一個視窗,是vim, +另外一個是ide, + +vim那一個視窗,按某一個鍵,會儲存以及關閉所有視窗, +回到cli了以後,可能會檢查groupname variable,然後在重新啟動vff + +ide的視窗,就負責選取檔案,列入暫存的動作。 + +只是這樣子不知道會不會要切來切去呢? + +# 2010-10-06 + +想要現在的num名稱,改成abc +然後數字選擇的功能,改名為123 + +數字選擇的功能,會混合檔案和資料夾, +在ls的時候,為它們加上編號, +然後輸入的時候,當然是輸入數字, +如果^(你輸入的數字)有符合1筆條件,就會看它是檔案還是資料夾, +如果你輸入的^數字,有符合1筆以上的條件, +例如目前目錄有20個檔案,假設你按2,這時會出現2和20, +這時你應該可以按.(點)來選擇2,或是按0來選擇20。 + +# 2010-10-05 + +想加上數字選擇的功能,在num上, +現在己經增加了第3個關鍵字引數上,用來選擇重覆的項目。 + +現在想要另外加上到第1個引數上面, +假設輸入了2,就會顯示本層的檔案和資料夾,與上一層第2個位置的東西, +但是目前還沒有想要數字要怎麼輸入, +並且設計了之後,會不會跟現有的功能發生沖突 + +# 2010-10-04 + +想要加上數字選擇的功能,在num的功能上面, +發生於多項的時候 + +# 2010-09-17 + +想做web(ex: links http://127.0.0.1/fast-change-dir),然後用按的來進去資料夾,或將檔案列入暫存, +還有多寫一個功能,是follow dir功能, +讓web cli,與其它cli能夠協同作業。 + +另外,這個web,主是要給觸控螢幕使用。 + +# 2010-09-16 + +延續9月11號的idea, +可能會用9月13號的方式,用數字來選擇檔案, +選擇後用vf加入暫存, +搜尋會從ga的root開始搜尋, +如果沒有選擇ga,就會從現行資料夾搜尋,並以vim來編輯。 + +# 2010-09-13 + +想做一個cli, +是用數字鍵做控制, +可能1是第一個位置, +然後程式會去判斷第一個位置是資料夾還是檔案, +如果是資料夾,就會問你是要進去,還是其它的動作, +如果是檔案,就會問你是要編輯,還是列入暫存, +減號(-)可能就是回到上一層, +星號(*)可能就是顯示grouplist(ga), +斜線(/)可能就是顯示專案虛擬資料夾列表(dv)。 + +會想到這個idea,是為了要減少左手的壓力, +並且加快流程,以及讓整體更流暢。 + +# 2010-09-11 + +想要做一個搜尋檔案的東西, +會用dialog來做, +假設輸入關鍵字support, +如果環境是Zend, +會去搜尋所有資料夾裡面的檔案名稱, +含有support關鍵字的給列出來, +看我是選擇編輯,還是其它的動作(加入vf暫存、加入暫存並vff編輯) +另外還要加上可以排除不想搜尋的資料夾欄位。 + +# 2010-08-07 + +想要做vim結合svn +可能是要寫在gisanfu-svn.sh裡面 + +就是輸入一個版本號,然後就使用vim -p blha1 blha2 +去編輯這個版本號裡面的相關檔案 + +# add: 2010-04-04 01 + +關於dv(切換到指定dirpoint) and dvv(建立dirpoint)的設計邏輯 +因為最主要的鍵盤動作是在切換,所以指令的順位,我排它為第一 +另外一點,會使用d加上v,是因為df己有指令使用了,所以才選v +盡量只用一手來處理這些事情 + +# add: 2010-04-02 02 + +將群組名稱輸出成環境變數 + +利用輸出環境變數,來做不同工作的事情切割 + +# add: 2010-04-02 01 + +將point與對應的資料夾名稱,寫入到文字檔裡面 +可能是空白分隔 + +然後輸入point,可以切換到該資料夾 + +另外一個,在增加一層群組名稱 +可以輸入群組名稱去切換 diff --git a/INSTALL.mkd b/INSTALL.mkd new file mode 100644 index 0000000..661ea33 --- /dev/null +++ b/INSTALL.mkd @@ -0,0 +1,72 @@ +# Fast Change Dir # + +author: gisanfu + +## Request environment + +- BASH +- dialog +- wmctrl +- xmacro +- git 1.7+ + +## Develop environment + +ubuntu 9.10 + +### 己測試過的環境 + +- centos 5.2+ +- ubuntu 9.04 +- ubuntu 9.10 +- ubuntu 10.10 + +### INSTALL + +1. goto to your home directory + + $ cd ~ + $ mkdir gisanfu + $ cd gisanfu + +- get code + + $ git clone git://github.com/gisanfu/fast-change-dir + $ cd fast-change-dir + +- copy bashrc.txt line to your .bashrc + + $ cat bashrc.txt >> ~/.bashrc + +- copy main config file to your home directory + +預設是開啟所有的功能,你可以把它們都關掉,在速度比較慢的電腦上面, + +等到要使用的使用,在把`0`改成`1`,回到`ide`以後,在按一下`/`就可以啟用了 + + + $ cp gisanfu-config.sh ~ + +- restart your terminal, with exit ide,離開的方式,請輸入問號 + + ? + +- with my vimrc + + $ cd /YOUR-GIT-DIR-TARGET + $ git clone git://github.com/gisanfu/vimrc.git + $ cd vimrc + $ cat vimrc >> ~/.vimrc + +- create first groupname, name is **home** + + $ cd ~ + $ cd .. + $ gaa YOUR-HOME-NAME + $ ga YOUR-HOME-NAME + $ dvv root YOUR-HOME-NAME + +- restart terminal, and test change groupname and test cmd + + $ ide + homeGrootL,,rootL,root; diff --git a/NOTE.mkd b/NOTE.mkd new file mode 100644 index 0000000..b5031b1 --- /dev/null +++ b/NOTE.mkd @@ -0,0 +1,123 @@ +### NOTE + +#### 2011-02-04 + +- 想要修改路徑和檔名 +- 關於有點的項目,我發現很像有問題,會有選擇不到的狀況 + +#### 2011-02-02 + +想把我的名子拿掉,範圍全部, + +並且把函式放到lib裡面的func資料夾裡面, + +之前會加上名子,是因為要跟/bin資料夾裡面的檔案放在一起的關係。 + +己完成的項目: + +- 123-2.sh +- abc-3.sh +- back-backdir.sh +- backdir.sh +- cddir.sh +- dirpoint-append.sh +- dirpoint.sh +- editfile.sh +- git-2.sh +- grep.sh +- groupname.sh +- hg.sh +- pos-backdir.sh +- pos-cddir.sh +- pos-editfile.sh +- pos-vimlist-append.sh +- search.sh +- svn-3.sh +- vimlist-append.sh +- vimlist.sh + +#### 2011-01-29 + +在函式裡面可以使用echo和exit,看一下什麼地方還可以這樣子用 + +關於dirpoint,例如adminview(代表admin module裡面的view), +設計方式應該可以改成av,這樣子做快速切換的時候,可能會比較快, +或者是兩者都存在。 + +另外,當我把上一層的兩個處理項目拿掉,速度就接近正常了, +覺得還蠻可惜的,有些情況下,是蠻方便的, +在小筆電的速度也加快了不少。 + +#### 2011-01-28 + +以下這幾個檔案也tune一下,改成使用source gisanfu-function-relativeitem的檔案 + +gisanfu-dirpoint-append.sh: . $fast_change_dir/gisanfu-relative.sh ***OK*** +gisanfu-editfile.sh:. $fast_change_dir/gisanfu-relative.sh ***OK*** +gisanfu-vimlist-append.sh:. $fast_change_dir/gisanfu-relative.sh ***OK*** +gisanfu-git-2.sh +gisanfu-hg.sh +gisanfu-svn-3.sh + +有一個bug,如果有aaa, and aaab,我輸入aaa,這時會出現aaa和aaab, +這種狀況應該是只有aaa而以(fixed) + +#### 2011-01-27 + +func_relative有一個bug + +如果第一個關鍵字有一筆以上,第二個關鍵字亂打, + +都還會有結果出現, + +試著修改,發現不是很好改, + +可能要重新規劃,並且重寫, + +我試著用最簡單的方式,grep,如果有第二個引數,就做第二次的grep, + +目前感覺還可以,不錯用,但是速度好像還是沒有改善。 + + +另外,例如aaa和gggaaa的item,如果我輸入aaa,會兩項都出現, + +這就有點不習慣了,或許我可以加上一些特殊字元(可能是`@`),讓函式可以在grep中,加上`^`, + +或者是使用dialog來做選擇,透過某些按鍵trigger,例如`'` + +#### 2011-01-26 + +想要在C的關鍵字,在abc-v3裡面 + +在dialog的section的下面,加上判斷F-array,和D-array, + +詢問使用者是不是要刪除它。 + +另外,想要查一下,gitignore能不能忽略掉己加入repo的檔案, + +例如後續的設定檔修改。 + + git update-index --assume-unchanged <file> + git update-index --no-assume-unchanged <file> + +<http://www.pagebakers.nl/2009/01/29/git-ignoring-changes-in-tracked-files/> + +#### 2011-01-18 + +現在要做路徑的變更,把`/bin` => `~/gisanfu/fast-change-dir` + +AM 12:00 + +只修改好`bashrc.txt`裡面的ide alias而以,己測試OK + +AM 12:57 + +己修改好`bashrc.txt`,和INSTALL.mkd + +以下的檔案,需要做路徑上的修改 + +- abc-v3 **OK** +- grep **OK** +- groupname **OK** +- pos-backdir **OK** +- pos-vimlist-append **OK** diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..dfba1f5 --- /dev/null +++ b/README.markdown @@ -0,0 +1,299 @@ +# Fast Change Dir # + +author: gisanfu + +## 這是什麼東西? + +算是以下幾種東西的結合: + +- Command-Line Helper +- Simple File Manager +- Simple Version Control UI + +## 什麼人適合用? + +- MIS 網管 +- 程式設計師 + +## 主要特色 + +- 平行切換資料夾 +- 捷徑切換資料夾 +- 2層式關鍵字定位 +- 相對名稱定位 +- 絕對位置定位 +- 多檔名暫存以及執行 +- 進入資料夾自動顯示檔案列表 +- 快速回上N層資料夾 +- 操作物件(含資料夾與檔案),目前有定位以及模糊方式 +- 即時搜尋檔案名稱 +- 即時搜尋關鍵字 +- 即時搜尋SSH目標主機列表 +- 即時搜尋bash history +- 即時關鍵字操作物件 +- 即時數字鍵操作物件 +- 版本控制功能(Git, Subversion, Mercurial) +- 主控台(整合快速鍵) + +## 其它文件 + +### 安裝文件 + +請參考`INSTALL.mkd`檔案 + +### 操作文件 + +請參考`COMMAND.mkd`檔案 + +## 簡易影片Demo + +<http://www.youtube.com/watch?v=t1zYZF0UzMw> + +來看看我輸入了哪些指令 + + ide<cr> + a + git. + fast. + dirF + gtgtgt + <f4> + homeG + desktopL + , + git. + fast. + stu. + find.y + <f4> + bash.y + gt + dd + <f4> + I + gt + <f4> + , + cdF + gt + dd + <f4> + I + <f4> + ? + q + +對照一般的CLI,我其實輸入以下的指令, + +這還不包含給vim所使用的暫存指令 + + cd ~<cr> + cd git<cr> + ls<cr> + cd fast-change-dir<cr> + ls<cr> + vim -p *dir*<cr> + gtgtgt + :qa<cr> + cd ~<cr> + ls<cr> + cd 桌面<cr> + ls<cr> + cd ..<cr> + ls<cr> + cd git<cr> + ls<cr> + cd fast-change-dir<cr> + ls<cr> + cd study<cr> + ls<cr> + vim -p *find*<cr> + :qa<cr> + vim -p *bash*<cr> + :qa<cr> + ls<cr> + cd ..<cr> + ls<cr> + vim -p *cd*<cr> + :qa<cr> + +## 比較 + +使用這種方式,來切換資料夾,以及寫程式, + +跟一般使用GUI editor或是IDE的差別。 + +### 缺點: + +- 功能可能沒有IDE來的完整 +- 小電腦或是速度不快的電腦可能會有點慢 + +*由其是安裝了Ubuntu 10.04 or 10.10的小電腦* + +*或者是開啟了所有功能* + +### 優點: + +- 在切換資料夾或是選取物件,如果熟悉的話,可以暫時讓眼睛休息,可以使用這個程式所提供的各種方式(請看上面的特色)來選擇項目 +- 把CLI, Editor, Browser的距離拉近,而不是三個視窗 +- 跨平台,免安裝(因為是在CLI的環境下,不同作業系統下,只要透過ssh protocol連進來就可以開始開發) +- 跟CLI相比,可以不用常按Enter,或是Tab鍵,還有ls(顯示現在這一層的內容) + +### 同時是優點也是缺點: + +- 滑鼠用的機率會少很多 +- 鍵盤會很常用 +- 有兩種主要的使用方式,CLI和IDE,可以依照狀況來選擇您要的方式,例如網管可以使用CLI方式,加速CLI的操作速度,如果是程式設計師,可以使用IDE的方式 + +## CLI部份使用方式 + +### if directory is + + aaa + +-- dddd + abc + bbb + +-- eeee + ccc + +-- ffff + +-- ggggg + +-- hhhhhh + +### show list + +$ ls -la + + drwxr-xr-x 8 blha blha 4096 200X-XX-XX XX:XX aaa + drwxr-xr-x 8 blha blha 4096 200X-XX-XX XX:XX abc + drwxr-xr-x 8 blha blha 4096 200X-XX-XX XX:XX bbb + drwxr-xr-x 8 blha blha 4096 200X-XX-XX XX:XX ccc + drwxr-xr-x 8 blha blha 4096 200X-XX-XX XX:XX gggg + drwxr-xr-x 8 blha blha 4096 200X-XX-XX XX:XX ggfff + +### into bbb + + deee + +### into aaa + + cd aaa (it's standard, you know) + +### goto parent directory + + cd .. (you know) + +### replace cd to d + + d aaa + +[PWD]=>/aaa + +ddd/ + +### replace cd .. to g + +$ g (goto parent directory) + +[PWD]=>/ + +aaa/ bbb/ ccc/ abc/ + +### input several `^`keyword, if duplicate, then show them + + d a + +aaa/ + +abc/ + +### input no duplicate keyword + + d aa + +### goto many directory + +$ d ccc + +$ d ffff + +$ d ggggg + +$ d hhhhhh + +### return to parent dir for 4 layer + +$ geeee (maximum layer is 6) + +### goto the last time directory(old command is => cd -) + +$ d + +### goto directory by two condition + +$ d gg ff + +### edit position 3 file use vim + +$ veee + +### set groupname to environment variable + +$ export groupname=project01 + +### add filename to vim argument list buffer + +$ vf + +### vim argument list buffer (vim -p aaa.txt bbb.txt ....) + +$ vff + +### vimdiff + +$ vff vimdiff + +### rm buffer file + +$ vff "rm -rf" + +### edit ~/gisanfu-vimlist-${groupname}.txt file + +$ vfff + +### add dirpoint to buffer(library is point) + +$ dvv library /home/user01/zend/library + +### switch to dirpoint + +$ dv library + +### edit ~/gisanfu-dirpoint-${groupname}.txt file + +$ dvvv + +## IDE部份使用方式 + +會有IDE的方式,剛開始的想法,主要是要擺脫CLI的一些先天的缺點, + +例如我要進入一個資料夾,就必需要輸入`cd dir01` [Enter], + +如果輸入錯誤,當下是不知道的,當你打錯成`cd dir02`,這時你是必需要重打指令的, + +不然你就是要輸入cd di`<tab><tab>`r`<tab><tab>`0`<tab><tab>`, + +如果使用IDE裡面的英文選擇功能的話(abc),就可以輸入dir02[.點], + +當你在輸入的時候,程式就會告訴你是否能直接選擇這個項目、這個項目是dir or file、等等, + +另外,IDE目前己經整合大部份CLI的指令,而且做了所多的改版。 + +### 啟動IDE功能 + +*輸入以下指令,啟動IDE,不管輸入ide或是abc都是英文選擇模式 + + ide + 或 + abc + +![abc](http://pic.pimg.tw/gisanfu/4569bf373a01ac17f245e9cf392035ae.png) diff --git a/abc-2.sh b/abc-2.sh new file mode 100755 index 0000000..6f71baa --- /dev/null +++ b/abc-2.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +# 這個函式,是要做行和列的位置排序 +func_ls_sort() +{ + # terminal's width, my IBM nb is 100 + width=`tput cols` +} + +func_ls() +{ + color_dir='\e[1;34m' # Blue + color_file_run='\e[1;32m' # Green + color_none='\e[0m' # No Color, or color end + + tmpdir=/tmp/`whoami`-func_ls-$( date +%Y%m%d-%H%M ) + + # 如果是現行資料夾的話,這個變數可以為空白 + lspath=$1 + + filelist=(`ls -AFQm -I .git -I .svn $lspath | tr "\n" " " | tr ", " " "`) + + # 包含顏色字元的結果變數 + # 這是用在最後顯示所使用 + color_result='' + + # 這跟color_result變數很類似 + # 但這個是運算用的 + result='' + + item_number=1 + + for bbb in ${filelist[@]} + do + regex_dir="^\"(.*)\"/$" + regex_file="^\"(.*)\"$" + regex_file_run="^\"(.*)\"\*$" + regex_symbolic="^\"(.*)\"@$" + + if [[ "$bbb" =~ $regex_dir ]]; then + color="$color_dir" + elif [[ "$bbb" =~ $regex_symbolic ]]; then + # 如果是link,就看看它是資料夾還是檔案,各有各的顏色 + symcheck=`ls -LF | grep ^${BASH_REMATCH[1]}` + if [[ "$symcheck" =~ $regex_dir ]]; then + color="$color_dir" + elif [[ "$bbb" =~ $regex_file ]]; then + color="" + elif [[ "$bbb" =~ $regex_file_run ]]; then + color="" + fi + elif [[ "$bbb" =~ $regex_file ]]; then + color="" + elif [[ "$bbb" =~ $regex_file_run ]]; then + color="$color_file_run" + fi + + #if [ "$bbb" != '' ]; then + item="($item_number)${BASH_REMATCH[1]}" + #fi + + if [ "$color_result" == '' ]; then + color_result="\"$color$item\"" + else + color_result="$color_result \"$color$item" + fi + + # 如果有顏色,就在後面補上顏色的結尾,也就是沒有顏色 + if [ "$color" != '' ]; then + color_result="$color_result$color_none\"" + fi + + # 這個result變數是沒有在存放顏色的,是拿來算長度用的 + if [ "$result" == '' ]; then + result="$item" + else + result="$result $item" + fi + + item_number=$(($item_number+1)) + + done + + mkdir_result=(`echo $result`) + + for bbb in ${mkdir_result[@]} + do + mkdir -p $tmpdir/$bbb + done + + #echo -e "$color_result" + ls $tmpdir --color=auto + + rm -rf $tmpdir +} + +func_ls '.' diff --git a/abc-3.sh b/abc-3.sh new file mode 100755 index 0000000..baa3567 --- /dev/null +++ b/abc-3.sh @@ -0,0 +1,1106 @@ +#!/bin/bash + +source "$fast_change_dir/config.sh" +source "$fast_change_dir_config/config.sh" + +source "$fast_change_dir_func/dialog.sh" +source "$fast_change_dir_func/entonum.sh" +source "$fast_change_dir_func/ignore.sh" +source "$fast_change_dir_func/relativeitem.sh" + +# default ifs value +default_ifs=$' \t\n' + +# 在這裡,優先權最高的(我指的是按.優先選擇的項目) +# 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) + +func_dirpoint() +{ + dirpoint=$1 + + if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then + resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_config/dirpoint-$groupname.txt | cut -d, -f1`) + echo ${resultarray[@]} + fi +} + +# 無路徑 +# 這個功能類似dirpoint,差別在於不受groupname的限制 +# 在任何地方都可以切換,不過必需透過快速鍵去做選擇,不納入快速選擇的功能範圍內。 +func_nopath() +{ + nopath=$1 + + if [ "$nopath" != '' ]; then + resultarray=(`grep ^$nopath[[:alnum:]]*, $fast_change_dir_config/nopath.txt | cut -d, -f1`) + echo ${resultarray[@]} + fi +} + +func_groupname() +{ + groupname=$1 + + resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) + echo ${resultarray[@]} +} + +# 會去搜尋bash_history裡面的字串 +func_search_bash_history() +{ + keyword=$1 + second=$2 + position=$3 + + declare -a resultarray + declare -a resultarraytmp + + # 先把英文轉成數字,如果這個欄位有資料的話 + position=( `func_entonum "$position"` ) + + if [ "$position" != '' ]; then + newposition=$(($position - 1)) + fi + + if [ ! -f "~/.bash_history" ]; then + touch ~/.bash_history + fi + + if [ "$keyword" != '' ]; then + cmd="cat ~/.bash_history | grep $keyword" + if [ "$second" != '' ]; then + cmd="$cmd | grep $second" + fi + + # 因為bash_history檔裡面,可能會有很多重覆的指令,所以要把它們濾掉 + cmd="$cmd | sort -u" + + num=0 + IFS=$'\n' + resultarraytmp=(`eval $cmd`) + for i in ${resultarraytmp[@]} + do + # 為了要解決空白的問題 + resultarray[$num]=`echo $i|sed 's/ /___/g'` + num=$num+1 + done + IFS=$default_ifs + num=0 + + if [ "${#resultarray[@]}" -gt 0 ]; then + if [ "$newposition" == '' ]; then + echo ${resultarray[@]} + else + # 先把含空格的文字,轉成陣列 + aaa=(${resultarray[@]}) + # 然後在指定位置輸出 + echo ${aaa[$newposition]} + fi + fi + fi +} + +# 會去搜尋home裡面的ssh.txt檔案內容 +# 如果有找到,就會用ssh連線過去 +# 檔案內容如下: +# servername1 +# servername2 +# ... +func_ssh() +{ + keyword=$1 + second=$2 + position=$3 + + declare -a resultarray + declare -a resultarraytmp + + # 先把英文轉成數字,如果這個欄位有資料的話 + position=( `func_entonum "$position"` ) + + if [ "$position" != '' ]; then + newposition=$(($position - 1)) + fi + + if [ ! -f "$fast_change_dir_config/ssh.txt" ]; then + touch $fast_change_dir_config/ssh.txt + fi + + if [ "$keyword" != '' ]; then + cmd="cat $fast_change_dir_config/ssh.txt | grep $keyword" + if [ "$second" != '' ]; then + cmd="$cmd | grep $second" + fi + + num=0 + IFS=$'\n' + resultarraytmp=(`eval $cmd`) + for i in ${resultarraytmp[@]} + do + # 為了要解決空白的問題 + resultarray[$num]=`echo $i|sed 's/ /___/g'` + num=$num+1 + done + IFS=$default_ifs + num=0 + + if [ "${#resultarray[@]}" -gt 0 ]; then + if [ "$newposition" == '' ]; then + echo ${resultarray[@]} + else + # 先把含空格的文字,轉成陣列 + aaa=(${resultarray[@]}) + # 然後在指定位置輸出 + echo ${aaa[$newposition]} + fi + fi + fi +} + +# 呼叫這個函式的前面,別忘了要加上至少3個字母的判斷式 +func_search() +{ + keyword=$1 + second=$2 + position=$3 + + # 可能是file, or dir + itemtype=$4 + + declare -a resultarray + declare -a resultarraytmp + + # 預設的find指令搜尋的對像,我設定為檔案 + findtype='f' + + # 先把英文轉成數字,如果這個欄位有資料的話 + position=( `func_entonum "$position"` ) + + if [ "$position" != '' ]; then + newposition=$(($position - 1)) + fi + + if [ "$itemtype" == '' ]; then + itemtype='file' + fi + + if [ "$itemtype" == 'file' ]; then + findtype='f' + elif [ "$itemtype" == 'dir' ]; then + findtype='d' + fi + + if [ "$keyword" != '' ]; then + if [ "$groupname" != '' ]; then + # 先取得root資料夾位置 + dirpoint_roots=(`cat $fast_change_dir_config/dirpoint-$groupname.txt | grep ^root | head -n 1 | tr "," " "`) + path=${dirpoint_roots[1]} + else + path='.' + fi + + cmd="find $path -iname \*$keyword\* -type $findtype" + + if [ "$second" != '' ]; then + cmd="$cmd | grep $second" + fi + + num=0 + IFS=$'\n' + resultarraytmp=(`eval $cmd`) + for i in ${resultarraytmp[@]} + do + # 為了要解決空白檔名的問題 + resultarray[$num]=`echo $i|sed 's/ /___/g'` + num=$num+1 + done + IFS=$default_ifs + num=0 + + if [ "${#resultarray[@]}" -gt 0 ]; then + if [ "$newposition" == '' ]; then + echo ${resultarray[@]:0:5} + else + # 先把含空格的文字,轉成陣列 + aaa=(${resultarray[@]:0:5}) + # 然後在指定位置輸出 + echo ${aaa[$newposition]} + fi + fi + fi +} + +# 呼叫這個函式的前面,別忘了要加上至少3個字母的判斷式 +func_search_google() +{ + keyword=$1 + #second=$2 + position=$2 + + # 先把英文轉成數字,如果這個欄位有資料的話 + position=( `func_entonum "$position"` ) + + filename="$fast_change_dir_tmp/abc3-google-search-`whoami`.txt" + + if [ "$keyword" != '' ]; then + cmd="perl $fast_change_dir_bin/google-search.pl $keyword" + + #if [ "$second" != '' ]; then + # cmd="$cmd $second" + #fi + + cmd="$cmd > $filename" + eval $cmd + + if [ "$position" -gt 0 ]; then + cmd2="sed -n $(($position*3+$position-1))p $filename" + eval $cmd2 + fi + + fi +} + +unset cmd1 +unset cmd2 +unset cmd3 + +# 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 +clear_var_all='' + +# 倒退鍵 +backspace=$(echo -e \\b\\c) + +color_txtgrn='\e[0;32m' # Green +color_txtred='\e[0;31m' # Red +color_none='\e[0m' # No Color + +while [ 1 ]; +do + clear + + if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then + unset condition + unset item_file_array + unset item_dir_array + unset item_parent_file_array + unset item_parent_dir_array + unset item_dirpoint_array + unset item_nopath_array + unset item_groupname_array + unset item_search_file_array + unset item_search_dir_array + unset item_ssh_array + unset item_search_bash_history_array + unset item_search_google_string + unset good_select + unset good_array + rm -rf $fast_change_dir_tmp/abc3-google-search-`whoami`.txt + clear_var_all='' + fi + + if [ "$needhelp" == '1' ]; then + echo '即時切換資料夾 (關鍵字)' + echo '=================================================' + fi + + + # 如果要看HELP,應該就暫時把其它東西hide起來 + if [ "$needhelp" != '1' ]; then + echo "`whoami` || \"$groupname\" || `pwd`" + echo '=================================================' + + ignorelist=$(func_getlsignore) + cmd="ls -AF $ignorelist --color=auto" + eval $cmd + + if [ "$condition" == 'quit' ]; then + break + elif [ "$condition" != '' ]; then + echo '=================================================' + echo "目前您所輸入的搜尋條件: \"$condition\"" + fi + fi + + if [ "$needhelp" == '1' ]; then + echo '=================================================' + echo -e "${color_txtgrn}基本快速鍵:${color_none}" + echo ' 倒退鍵 (Ctrl + H)' + echo ' 重新輸入條件 (/)' + echo ' 智慧選取單項 (;) 分號' + echo ' 上一層 (,) 逗點' + echo " 到數字切換資料夾功能 (') 單引號" + echo ' 我忘了快速鍵了 (H)' + echo ' 離開 (?)' + echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" + echo ' 檔案或資料夾建立刪除 (C) New item or Delete' + echo ' 單項檔案 (F) 大寫F shift+f' + echo ' 單項資料夾 (D)' + echo ' 上一層單項檔案 (S)' + echo ' 上一層單項資料夾 (A)' + echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" + echo ' 專案捷徑名稱 (L)' + echo ' 群組名稱 (G)' + echo ' 搜尋檔案的結果 (Z)' + echo ' 搜尋資料夾的結果 (N)' + echo ' 無路徑nopath的結果 (W)' + echo -e "${color_txtgrn}VimList操作類:${color_none}" + echo ' Do It! (I)' + echo ' Modify (J)' + echo ' Clear (K)' + echo -e "${color_txtgrn}搜尋引擎類:${color_none}" + echo ' Google Search (B)' + echo -e "${color_txtgrn}版本控制群:${color_none}" + echo ' Versions (V)' + echo -e "${color_txtgrn}桌面互動類:${color_none}" + echo ' Nautilus File Explorer (E)' + echo ' Firefox Show (R)' + echo -e "${color_txtgrn}系統類:${color_none}" + echo ' Grep以關鍵字去搜尋檔案 (M)' + echo ' SSH (P)' + echo ' Sudo Root (Y)' + echo ' History Bash (U)' + echo ' 離開EXIT (X)(Q)' + echo -e "${color_txtgrn}輸入條件的結構:${color_none}" + echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' + if [ "$needhelp" == '1' ]; then + echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" + read -s -n 1 + unset needhelp + clear_var_all='1' + continue + fi + fi + + # 這個應該就不顯示了,記得了就好 + #if [ "$condition" != '' ]; then + # echo '=================================================' + # echo '檔案或資料夾建立刪除 [C]' + #fi + + if [ "$fast_change_dir_config_duplicate_enable" == '1' ]; then + if [ "${#item_file_array[@]}" -gt 0 ]; then + echo '=================================================' + fi + + # 顯示重覆檔案 + if [ "${#item_file_array[@]}" -gt 1 ]; then + echo "重覆的檔案數量(有多項的功能)[F]: 有${#item_file_array[@]}筆" + number=1 + for bbb in ${item_file_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_file_array[@]}" -eq 1 ]; then + echo "檔案有找到一筆哦[F]: ${item_file_array[0]}" + fi + + if [ "${#item_dir_array[@]}" -gt 0 ]; then + echo '=================================================' + fi + + # 顯示重覆資料夾 + if [ "${#item_dir_array[@]}" -gt 1 ]; then + echo "重覆的資料夾數量[D]: 有${#item_dir_array[@]}筆" + number=1 + for bbb in ${item_dir_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_dir_array[@]}" -eq 1 ]; then + echo "資料夾有找到一筆哦[D]: ${item_dir_array[0]}" + fi + + if [ "${#item_parent_file_array[@]}" -gt 0 ]; then + echo '=================================================' + fi + + # 顯示重覆檔案(上一層) + if [ "${#item_parent_file_array[@]}" -gt 1 ]; then + echo "重覆的檔案數量 (有多項的功能) (上一層)[S]: 有${#item_parent_file_array[@]}筆" + number=1 + for bbb in ${item_parent_file_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_parent_file_array[@]}" -eq 1 ]; then + echo "檔案有找到一筆哦(上一層)[S]: ${item_parent_file_array[0]}" + fi + + if [ "${#item_parent_dir_array[@]}" -gt 0 ]; then + echo '=================================================' + fi + + # 顯示重覆資料夾(上一層) + if [ "${#item_parent_dir_array[@]}" -gt 1 ]; then + echo "重覆的資料夾數量(上一層)[A]: 有${#item_parent_dir_array[@]}筆" + number=1 + for bbb in ${item_parent_dir_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_parent_dir_array[@]}" -eq 1 ]; then + echo "資料夾有找到一筆哦(上一層)[A]: ${item_parent_dir_array[0]}" + fi + + if [ "${#item_dirpoint_array[@]}" -gt 0 ]; then + echo '=================================================' + fi + + # 顯示重覆的捷徑 + if [ "${#item_dirpoint_array[@]}" -gt 1 ]; then + echo "重覆的捷徑: 有${#item_dirpoint_array[@]}筆" + number=1 + for bbb in ${item_dirpoint_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_dirpoint_array[@]}" -eq 1 ]; then + echo "捷徑有找到一筆哦[L]: ${item_dirpoint_array[0]}" + fi + + if [ "${#item_groupname_array[@]}" -gt 0 ]; then + echo '=================================================' + fi + + # 顯示重覆的群組名稱 + if [ "${#item_groupname_array[@]}" -gt 1 ]; then + echo "重覆的群組名稱: 有${#item_groupname_array[@]}筆" + number=1 + for bbb in ${item_groupname_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_groupname_array[@]}" -eq 1 ]; then + echo "群組名稱有找到一筆哦[G]: ${item_groupname_array[0]}" + fi + + if [ "${#item_search_file_array[@]}" -gt 0 ]; then + echo '=================================================' + fi + + # 顯示重覆的搜尋檔案結果項目 + if [ "${#item_search_file_array[@]}" -gt 1 ]; then + echo "重覆的搜尋檔案結果(有多項的功能)[Z]: 有${#item_search_file_array[@]}筆" + number=1 + for bbb in ${item_search_file_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_search_file_array[@]}" -eq 1 ]; then + echo "搜尋檔案的結果有找到一筆哦[Z]: ${item_search_file_array[0]}" + fi + + if [ "${#item_search_dir_array[@]}" -gt 0 ]; then + echo '=================================================' + fi + + # 顯示重覆的搜尋資料夾結果項目 + if [ "${#item_search_dir_array[@]}" -gt 1 ]; then + echo "重覆的搜尋資料夾結果: 有${#item_search_dir_array[@]}筆" + number=1 + for bbb in ${item_search_dir_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_search_dir_array[@]}" -eq 1 ]; then + echo "搜尋資料夾的結果有找到一筆哦[N]: ${item_search_dir_array[0]}" + fi + + if [ "${#item_ssh_array[@]}" -gt 0 ]; then + echo '=================================================' + fi + + # 顯示重覆的SSH清單 + if [ "${#item_ssh_array[@]}" -gt 1 ]; then + echo "重覆的SSH清單列表: 有${#item_ssh_array[@]}筆" + number=1 + for bbb in ${item_ssh_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_ssh_array[@]}" -eq 1 ]; then + echo "SSH目標有找到一筆哦[P]: ${item_ssh_array[0]}" + fi + + if [ "${#item_search_bash_history_array[@]}" -gt 0 ]; then + echo '=================================================' + fi + + # 顯示重覆的Bash History搜尋結果 + if [ "${#item_search_bash_history_array[@]}" -gt 1 ]; then + echo "重覆的Bash History列表: 有${#item_search_bash_history_array[@]}筆" + number=1 + for bbb in ${item_search_bash_history_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_search_bash_history_array[@]}" -eq 1 ]; then + echo "Bash History有找到一筆哦[U]: ${item_search_bash_history_array[0]}" + fi + + # Google搜尋結果的處理區塊己經包含分隔線了 + # ========================================================= + + # 顯示重覆的Google搜尋結果 + if [ "$item_search_google_string" == '' ]; then + if [ -f "$fast_change_dir_tmp/abc3-google-search-`whoami`.txt" ]; then + echo '=================================================' + echo "Google有找到資料哦:" + cat "$fast_change_dir_tmp/abc3-google-search-`whoami`.txt" + fi + else + echo '=================================================' + echo "Google有找到一筆哦[B]: $item_search_google_string" + fi + + if [ "${#item_nopath_array[@]}" -gt 0 ]; then + echo '=================================================' + fi + + # 顯示重覆的nopath + if [ "${#item_nopath_array[@]}" -gt 1 ]; then + echo "重覆的nopath: 有${#item_nopath_array[@]}筆" + number=1 + for bbb in ${item_nopath_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_nopath_array[@]}" -eq 1 ]; then + echo "Nopath有找到一筆哦[W]: ${item_nopath_array[0]}" + fi + fi + + # 不加IFS=012的話,我輸入空格,read variable是讀不到的 + IFS=$'\012' + read -s -n 1 inputvar + IFS=$default_ifs + + if [ "$inputvar" == '?' ]; then + # 離開 + clear + break + elif [ "$inputvar" == '/' ]; then + # 重新讀取設定檔 + source "$fast_change_dir_config/config.sh" + + # 砍掉relativeitem cache的檔案 + rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* + + clear_var_all='1' + continue + elif [ "$inputvar" == ',' ]; then + cd .. + clear_var_all='1' + continue + elif [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then + + # 這裡改成強制一定要有一項被選中才能走到這裡面 + # 另外,也改成僅支援檔案和資料夾的功能才能使用 + if [ "$good_select" == '' ]; then + clear_var_all='1' + continue + fi + + # 這樣子做,就不用問我要append還是不要 + if [ "$inputvar" == ';' ]; then + isvff='1' + elif [ "$inputvar" == '.' ]; then + isvff='0' + else + isvff='' + fi + + + run='' + match=`echo ${good_array[0]} | sed 's/___/ /g'` + + case $good_select in + 1 ) + if [ "$groupname" != '' ]; then + run="vf \"$match\" \"\" \"\" $isvff" + else + run="vim \"$match\"" + fi + ;; + 2 ) + run="cd \"$match\"" + ;; + 3 ) + if [ "$groupname" != '' ]; then + run="cd .. && vf \"$match\" \"\" \"\" $isvff" + else + run="vim ../\"$match\"" + fi + ;; + 4 ) + match=`echo ${item_parent_dir_array[0]} | sed 's/___/ /g'` + run="cd ../\"$match\"" + ;; + esac + + if [ "$run" != '' ]; then + eval $run + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'F' ]; then + run='' + if [ "${#item_file_array[@]}" -eq 1 ]; then + match=`echo ${item_file_array[0]} | sed 's/___/ /g'` + if [ "$groupname" != '' ]; then + run="vf \"$match\"" + else + run="vim \"$match\"" + fi + elif [ "${#item_file_array[@]}" -gt 1 ]; then + run=". $fast_change_dir/vimlist-append-files.sh " + for bbb in ${item_file_array[@]} + do + match=`echo $bbb | sed 's/___/ /g'` + run="$run \"$match\"" + done + else + item_file_array=( `func_relative "" "" "" "" "file" "1"` ) + + tmpfile="$fast_change_dir_tmp/`whoami`-abc3-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" + dialogitems='' + for echothem in ${item_file_array[@]} + do + dialogitems=" $dialogitems $echothem '' " + done + cmd=$( func_dialog_menu '請從裡面挑一項你所要的(本層的檔案)' 100 "$dialogitems" $tmpfile ) + + eval $cmd + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" != "" ]; then + match=`echo $result | sed 's/___/ /g'` + if [ "$groupname" != '' ]; then + run="vf \"$match\"" + else + run="vim \"$match\"" + fi + else + clear_var_all='1' + continue + fi + fi + + if [ "$run" != '' ]; then + eval $run + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'D' ]; then + run='' + if [ "${#item_dir_array[@]}" == 1 ]; then + match=`echo ${item_dir_array[0]} | sed 's/___/ /g'` + run="cd \"$match\"" + else + if [ "${#item_dir_array[@]}" -lt 1 ]; then + item_dir_array=( `func_relative "" "" "" "" "dir" "1"` ) + fi + + # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 + tmpfile="$fast_change_dir_tmp/`whoami`-abc3-dialog-select-parent-dir-$( date +%Y%m%d-%H%M ).txt" + dialogitems='' + for echothem in ${item_dir_array[@]} + do + dialogitems=" $dialogitems $echothem '' " + done + cmd=$( func_dialog_menu '請從裡面挑一項你所要的(本層的資料夾)' 100 "$dialogitems" $tmpfile ) + + eval $cmd + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" != "" ]; then + match=`echo $result | sed 's/___/ /g'` + run="cd \"$match\"" + else + clear_var_all='1' + continue + fi + fi + + if [ "$run" != '' ]; then + eval $run + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'S' ]; then + if [ "${#item_parent_file_array[@]}" -eq 1 ]; then + match=`echo ${item_parent_file_array[0]} | sed 's/___/ /g'` + if [ "$groupname" != '' ]; then + # 會這樣子寫,是因為我的底層並沒有這個功能 + run="cd .. && vf \"$match\"" + else + run="vim ../\"$match\"" + fi + elif [ "${#item_parent_file_array[@]}" -gt 1 ]; then + run=". $fast_change_dir/vimlist-append-files.sh " + for bbb in ${item_parent_file_array[@]} + do + match=`echo $bbb | sed 's/___/ /g'` + run="$run \"../$match\"" + done + else + item_parent_file_array=( `func_relative "" "" "" ".." "file" "1"` ) + + tmpfile="$fast_change_dir_tmp/`whoami`-abc3-dialogselect-only-parent-file-$( date +%Y%m%d-%H%M ).txt" + dialogitems='' + for echothem in ${item_parent_file_array[@]} + do + dialogitems=" $dialogitems $echothem '' " + done + cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) + + eval $cmd + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" != "" ]; then + match=`echo $result | sed 's/___/ /g'` + if [ "$groupname" != '' ]; then + run="cd .. && vf \"$match\"" + else + run="vim ../\"$match\"" + fi + else + clear_var_all='1' + continue + fi + fi + eval $run + clear_var_all='1' + continue + elif [[ "$inputvar" == 'A' ]]; then + if [ "${#item_parent_dir_array[@]}" == 1 ]; then + match=`echo ${item_parent_dir_array[0]} | sed 's/___/ /g'` + run="cd ../\"$match\"" + else + if [ "${#item_parent_dir_array[@]}" -lt 1 ]; then + item_parent_dir_array=( `func_relative "" "" "" ".." "dir" "1"` ) + fi + + # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 + tmpfile="$fast_change_dir_tmp/`whoami`-abc3-dialog-select-parent-dir-$( date +%Y%m%d-%H%M ).txt" + dialogitems='' + for echothem in ${item_parent_dir_array[@]} + do + dialogitems=" $dialogitems $echothem '' " + done + cmd=$( func_dialog_menu '請從裡面挑一項你所要的(上層的資料夾)' 100 "$dialogitems" $tmpfile ) + + eval $cmd + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" != "" ]; then + match=`echo $result | sed 's/___/ /g'` + run="cd ../\"$match\"" + else + clear_var_all='1' + continue + fi + fi + + if [ "$run" != '' ]; then + eval $run + fi + + clear_var_all='1' + continue + elif [[ "$inputvar" == 'L' && "${#item_dirpoint_array[@]}" == 1 ]]; then + match=`echo ${item_dirpoint_array[0]} | sed 's/___/ /g'` + run="dv \"$match\"" + eval $run + clear_var_all='1' + continue + elif [[ "$inputvar" == 'G' && "${#item_groupname_array[@]}" == 1 ]]; then + match=`echo ${item_groupname_array[0]} | sed 's/___/ /g'` + run="ga \"$match\"" + eval $run + clear_var_all='1' + continue + elif [ "$inputvar" == 'Z' ]; then + if [ "${#item_search_file_array[@]}" -eq 1 ]; then + match=`echo ${item_search_file_array[0]} | sed 's/___/ /g'` + if [ "${match:0:1}" == '.' ]; then + run=". $fast_change_dir/vimlist-append-with-path.sh \"\" \"$match\"" + else + run=". $fast_change_dir/vimlist-append-with-path.sh \"$match\" \"\"" + fi + elif [ "${#item_search_file_array[@]}" -gt 1 ]; then + run=". $fast_change_dir/vimlist-append-files.sh " + for bbb in ${item_search_file_array[@]} + do + match=`echo $bbb | sed 's/___/ /g'` + run="$run \"$match\"" + done + fi + eval $run + clear_var_all='1' + continue + elif [[ "$inputvar" == 'N' && "${#item_search_dir_array[@]}" == 1 ]]; then + match=`echo ${item_search_dir_array[0]} | sed 's/___/ /g'` + run="cd \"$match\"" + eval $run + clear_var_all='1' + continue + elif [[ "$inputvar" == 'P' && "${#item_ssh_array[@]}" == 1 ]]; then + match=`echo ${item_ssh_array[0]} | sed 's/___/ /g'` + run="ssh \"$match\"" + eval $run + clear_var_all='1' + continue + elif [[ "$inputvar" == 'U' && "${#item_search_bash_history_array[@]}" == 1 ]]; then + match=`echo ${item_search_bash_history_array[0]} | sed 's/___/ /g'` + #run="\"$match\"" + #eval $run + eval "$match" + clear_var_all='1' + continue + elif [[ "$inputvar" == 'B' && "$item_search_google_string" != '' ]]; then + run="w3m \"$item_search_google_string\"" + eval $run + clear_var_all='1' + continue + elif [ "$inputvar" == 'I' ]; then + vff + clear_var_all='1' + continue + elif [ "$inputvar" == 'J' ]; then + vfff + clear_var_all='1' + continue + elif [ "$inputvar" == 'K' ]; then + vffff + clear_var_all='1' + continue + elif [ "$inputvar" == 'V' ]; then + # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 + if [ -d '.git' ]; then + gitt + clear_var_all='1' + continue + elif [ -d '.svn' ]; then + svnn + clear_var_all='1' + continue + elif [ -d '.hg' ]; then + hgg + clear_var_all='1' + continue + fi + + echo "請輸入版本控制名稱的前綴,或按Enter離開" + echo "Git (gG)" + echo "Svn (sS)" + echo "Hg (hH)" + read -s -n 1 inputvar2 + + if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then + gitt + elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then + svnn + elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then + hgg + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'E' ]; then + nautilus . + clear_var_all='1' + continue + elif [ "$inputvar" == 'R' ]; then + $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly + clear_var_all='1' + continue + elif [ "$inputvar" == 'M' ]; then + gre + clear_var_all='1' + continue + elif [ "$inputvar" == 'Y' ]; then + sudo su - + clear_var_all='1' + continue + # [W] Nopath 簡稱無路徑 + elif [ "$inputvar" == 'W' ]; then + match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` + run="wv \"$match\"" + eval $run + clear_var_all='1' + continue + # [C] Create + elif [ "$inputvar" == 'C' ]; then + # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 + # 這時是可以輸入大寫的檔名,或是資料夾名稱 + if [ "$condition" == '' ]; then + tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" + cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) + + eval $cmd + result=`cat $tmpfile` + + if [ "$result" == "" ]; then + clear_var_all='1' + continue + else + condition="$result" + fi + fi + + echo "請選擇你要做的動作:" + echo "File Touch(Ff)" + echo "Create Directory And Goto DIR (Dd)" + read -s -n 1 inputvar2 + + if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then + if [[ -f "$condition" || -d "$condition" ]]; then + echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." + read -s -n 1 + else + touch $condition + vf $condition + fi + elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then + mkdir $condition + if [ "$?" -eq 0 ]; then + d $condition + sleep 2 + else + echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." + read -s -n 1 + fi + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'H' ]; then + needhelp='1' + clear_var_all='1' + continue + elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then + exit + # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 + elif [ "$inputvar" == $backspace ]; then + condition="${condition:0:(${#condition} - 1)}" + inputvar='' + elif [ "$inputvar" == "'" ]; then + abc123 + clear_var_all='1' + continue + fi + + condition="$condition$inputvar" + + if [[ "$condition" =~ [[:alnum:]] ]]; then + cmds=($condition) + cmd1=${cmds[0]} + cmd2=${cmds[1]} + # 第三個引數,是位置 + cmd3=${cmds[2]} + + if [ "$fast_change_dir_config_parent_enable" == '1' ]; then + item_parent_file_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" ".." "file"` ) + item_parent_dir_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" ".." "dir"` ) + + # 決定誰是最佳人選,當你按了;分號或是.點 + if [ ${#item_parent_file_array[@]} -eq 1 ]; then + good_select=3 + good_array=${item_parent_file_array[@]} + elif [ ${#item_parent_dir_array[@]} -eq 1 ]; then + good_select=4 + good_array=${item_parent_dir_array[@]} + fi + fi + + item_file_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) + item_dir_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "dir"` ) + + # 決定誰是最佳人選,當你按了;分號或是.點 + if [ ${#item_file_array[@]} -eq 1 ]; then + good_select=1 + good_array=${item_file_array[@]} + elif [ ${#item_dir_array[@]} -eq 1 ]; then + good_select=2 + good_array=${item_dir_array[@]} + fi + + item_ssh_array=( `func_ssh "$cmd1" "$cmd2" "$cmd3" "$fast_change_dir_config"` ) + + if [ "$fast_change_dir_config_bashhistorysearch_enable" == '1' ]; then + if [ "${#cmd1}" -gt 3 ]; then + item_search_bash_history_array=( `func_search_bash_history "$cmd1" "$cmd2" "$cmd3"` ) + fi + fi + + # 長度大於3的關鍵字才能做搜尋的動作 + if [[ "${#cmd1}" -gt 3 && "$groupname" != 'home' && "$groupname" != '' ]]; then + if [ "$fast_change_dir_config_searchfile_enable" == '1' ]; then + item_search_file_array=( `func_search "$cmd1" "$cmd2" "$cmd3" "file" ` ) + fi + + if [ "$fast_change_dir_config_searchdir_enable" == '1' ]; then + item_search_dir_array=( `func_search "$cmd1" "$cmd2" "$cmd3" "dir" ` ) + fi + fi + + # 有些功能,只要看到第2個引數就會失效 + if [ "$cmd2" == '' ]; then + item_dirpoint_array=( `func_dirpoint "$cmd1"` ) + item_nopath_array=( `func_nopath "$cmd1"` ) + item_groupname_array=( `func_groupname "$cmd1"` ) + else + unset item_dirpoint_array + unset item_groupname_array + fi + + # 這個功能不錯用,但是會拖累整個操作速度 + if [ "$fast_change_dir_config_googlesearch_enable" == '1' ]; then + if [[ "${#cmd1}" -gt 3 && "${#cmd2}" -le 2 ]]; then + item_search_google_string=`func_search_google "$cmd1" "$cmd2" ` + else + unset item_search_google_string + rm $fast_change_dir_tmp/abc3-google-search-`whoami`.txt + fi + fi + elif [ "$condition" == '' ]; then + # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 + clear_var_all='1' + continue + fi + +done + +# 離開前,在顯示一下現在資料夾裡面的東西 +eval $cmd diff --git a/abc-4.sh b/abc-4.sh new file mode 100755 index 0000000..3893cb1 --- /dev/null +++ b/abc-4.sh @@ -0,0 +1,419 @@ +#!/bin/bash + +source "$fast_change_dir/config.sh" +source "$fast_change_dir_config/config.sh" + +source "$fast_change_dir_func/dialog.sh" +source "$fast_change_dir_func/entonum.sh" +source "$fast_change_dir_func/ignore.sh" +source "$fast_change_dir_func/relativeitem.sh" + +# default ifs value +default_ifs=$' \t\n' + +# 在這裡,優先權最高的(我指的是按.優先選擇的項目) +# 是檔案(^D) > 資料夾(^F) > 上一層的檔案(^A) > 上一層的資料夾(^S) + +func_dirpoint() +{ + dirpoint=$1 + + if [[ "$groupname" != '' && "$dirpoint" != '' ]]; then + resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_config/dirpoint-$groupname.txt | cut -d, -f1`) + echo ${resultarray[@]} + fi +} + +func_groupname() +{ + groupname=$1 + + resultarray=(`grep $groupname $fast_change_dir_config/groupname.txt`) + echo ${resultarray[@]} +} + +unset cmd1 +unset cmd2 +unset cmd3 + +# 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 +clear_var_all='' + +# 倒退鍵 +backspace=$(echo -e \\b\\c) + +color_txtgrn='\e[0;32m' # Green +color_txtred='\e[0;31m' # Red +color_none='\e[0m' # No Color + +while [ 1 ]; +do + clear + + if [[ "$clear_var_all" == '1' || "$needhelp" == '1' ]]; then + unset condition + unset item_file_array + unset item_dir_array + unset item_parent_file_array + unset item_parent_dir_array + unset item_dirpoint_array + unset item_groupname_array + clear_var_all='' + fi + + if [ "$needhelp" == '1' ]; then + echo '即時切換資料夾 (關鍵字)' + echo '=================================================' + fi + + + # 如果要看HELP,應該就暫時把其它東西hide起來 + if [ "$needhelp" != '1' ]; then + echo "`whoami` || \"$groupname\" || `pwd`" + echo '=================================================' + + ignorelist=$(func_getlsignore) + cmd="ls -AF $ignorelist --color=auto" + eval $cmd + + if [ "$condition" == 'quit' ]; then + break + elif [ "$condition" != '' ]; then + echo '=================================================' + echo "目前您所輸入的搜尋條件: \"$condition\"" + fi + fi + + if [ "$needhelp" == '1' ]; then + echo '=================================================' + echo -e "${color_txtgrn}基本快速鍵:${color_none}" + echo ' 倒退鍵 (Ctrl + H)' + echo ' 重新輸入條件 (/)' + echo ' 智慧選取單項 (;) 分號' + echo ' 上一層 (,) 逗點' + echo " 到數字切換資料夾功能 (') 單引號" + echo ' 我忘了快速鍵了 (H)' + echo ' 離開 (?)' + echo -e "${color_txtgrn}即時關鍵字選擇用的快速鍵:${color_none}" + echo ' 檔案或資料夾建立刪除 (C) New item or Delete' + echo ' 單項檔案 (F) 大寫F shift+f' + echo ' 單項資料夾 (D)' + echo ' 上一層單項檔案 (S)' + echo ' 上一層單項資料夾 (A)' + echo -e "${color_txtgrn}只能使用快速鍵來選擇關鍵字所帶出來的項目:${color_none}" + echo ' 專案捷徑名稱 (L)' + echo ' 群組名稱 (G)' + echo ' 搜尋檔案的結果 (Z)' + echo ' 搜尋資料夾的結果 (N)' + echo ' 無路徑nopath的結果 (W)' + echo -e "${color_txtgrn}VimList操作類:${color_none}" + echo ' Do It! (I)' + echo ' Modify (J)' + echo ' Clear (K)' + echo -e "${color_txtgrn}搜尋引擎類:${color_none}" + echo ' Google Search (B)' + echo -e "${color_txtgrn}版本控制群:${color_none}" + echo ' Versions (V)' + echo -e "${color_txtgrn}桌面互動類:${color_none}" + echo ' Nautilus File Explorer (E)' + echo ' Firefox Show (R)' + echo -e "${color_txtgrn}系統類:${color_none}" + echo ' Grep以關鍵字去搜尋檔案 (M)' + echo ' SSH (P)' + echo ' Sudo Root (Y)' + echo ' History Bash (U)' + echo ' 離開EXIT (X)(Q)' + echo -e "${color_txtgrn}輸入條件的結構:${color_none}" + echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' + if [ "$needhelp" == '1' ]; then + echo -e "${color_txtred}你記得快速鍵了嗎?記得的話,按任何鍵繼續...${color_none}" + read -s -n 1 + unset needhelp + clear_var_all='1' + continue + fi + fi + + # 不加IFS=012的話,我輸入空格,read variable是讀不到的 + IFS=$'\012' + read -s -n 1 inputvar + IFS=$default_ifs + + if [ "$inputvar" == ';' ]; then + inputvar='F' + elif [ "$inputvar" == '.' ]; then + inputvar='D' + fi + + #if [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then + # # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 + # tmpfile="$fast_change_dir_tmp/`whoami`-abc4-dialog-select-action-$( date +%Y%m%d-%H%M ).txt" + # dialogitems='file "" dir "" parent-file "" parent-dir "" ' + # cmd=$( func_dialog_menu '您要做什麼動作?' 100 "$dialogitems" $tmpfile ) + + # eval $cmd + # result=`cat $tmpfile` + + # if [ -f "$tmpfile" ]; then + # rm -rf $tmpfile + # fi + + # if [ "$result" == "file" ]; then + # inputvar='F' + # elif [ "$result" == "dir" ]; then + # inputvar='D' + # elif [ "$result" == "parent-file" ]; then + # inputvar='S' + # elif [ "$result" == "parent-dir" ]; then + # inputvar='A' + # fi + #fi + + if [ "$inputvar" == '?' ]; then + # 離開 + clear + break + elif [ "$inputvar" == '/' ]; then + # 重新讀取設定檔 + source "$fast_change_dir_config/config.sh" + + # 砍掉relativeitem cache的檔案 + #rm -rf $fast_change_dir_tmp/`whoami`-relativeitem-cache-* + + clear_var_all='1' + continue + elif [ "$inputvar" == ',' ]; then + cd .. + clear_var_all='1' + continue + + #clear_var_all='1' + continue + elif [ "$inputvar" == 'F' ]; then + if [ "$groupname" != '' ]; then + run="vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" + else + run="v \"$cmd1\" \"$cmd2\" \"$cmd3\"" + fi + + eval $run + + clear_var_all='1' + continue + elif [ "$inputvar" == 'D' ]; then + run="d \"$cmd1\" \"$cmd2\" \"$cmd3\"" + eval $run + + clear_var_all='1' + continue + elif [ "$inputvar" == 'S' ]; then + if [ "$groupname" != '' ]; then + run="cd .. && vf \"$cmd1\" \"$cmd2\" \"$cmd3\"" + else + run="cd .. && v \"$cmd1\" \"$cmd2\" \"$cmd3\"" + fi + + eval $run + cd - + + clear_var_all='1' + continue + elif [[ "$inputvar" == 'A' ]]; then + run="cd .. && d \"$cmd1\" \"$cmd2\" \"$cmd3\"" + eval $run + cd - + + clear_var_all='1' + continue + elif [ "$inputvar" == 'L' ]; then + run="dv \"$cmd1\"" + eval $run + clear_var_all='1' + continue + elif [ "$inputvar" == 'G' ]; then + run="ga \"$cmd1\"" + eval $run + clear_var_all='1' + continue + elif [ "$inputvar" == 'I' ]; then + vff + clear_var_all='1' + continue + elif [ "$inputvar" == 'J' ]; then + vfff + clear_var_all='1' + continue + elif [ "$inputvar" == 'K' ]; then + vffff + clear_var_all='1' + continue + elif [ "$inputvar" == 'V' ]; then + # 先檢查現在的資料夾裡,是否含有版本控制的隱藏資料夾在內 + if [ -d '.git' ]; then + gitt + clear_var_all='1' + continue + elif [ -d '.svn' ]; then + svnn + clear_var_all='1' + continue + elif [ -d '.hg' ]; then + hgg + clear_var_all='1' + continue + fi + + echo "請輸入版本控制名稱的前綴,或按Enter離開" + echo "Git (gG)" + echo "Svn (sS)" + echo "Hg (hH)" + read -s -n 1 inputvar2 + + if [[ "$inputvar2" == 'G' || "$inputvar2" == 'g' ]]; then + gitt + elif [[ "$inputvar2" == 'S' || "$inputvar2" == 's' ]]; then + svnn + elif [[ "$inputvar2" == 'H' || "$inputvar2" == 'h' ]]; then + hgg + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'E' ]; then + nautilus . + clear_var_all='1' + continue + elif [ "$inputvar" == 'R' ]; then + $fast_change_dir_bin/cmd-refresh-firefox.sh switchonly + clear_var_all='1' + continue + elif [ "$inputvar" == 'M' ]; then + gre + clear_var_all='1' + continue + elif [ "$inputvar" == 'Y' ]; then + sudo su - + clear_var_all='1' + continue + # [W] Nopath 簡稱無路徑 + elif [ "$inputvar" == 'W' ]; then + match=`echo ${item_nopath_array[0]} | sed 's/___/ /g'` + run="wv \"$match\"" + eval $run + clear_var_all='1' + continue + # [C] Create + elif [ "$inputvar" == 'C' ]; then + # 如果沒有輸入關鍵字,那就用dialog來詢問使用者 + # 這時是可以輸入大寫的檔名,或是資料夾名稱 + if [ "$condition" == '' ]; then + tmpfile="$fast_change_dir_tmp/`whoami`-abc3-filemanage-$( date +%Y%m%d-%H%M ).txt" + cmd=$( func_dialog_input '請輸入檔案或資料夾名稱' "" 70 "$tmpfile" ) + + eval $cmd + result=`cat $tmpfile` + + if [ "$result" == "" ]; then + clear_var_all='1' + continue + else + condition="$result" + fi + fi + + echo "請選擇你要做的動作:" + echo "File Touch(Ff)" + echo "Create Directory And Goto DIR (Dd)" + read -s -n 1 inputvar2 + + if [[ "$inputvar2" == 'F' || "$inputvar2" == 'f' ]]; then + if [[ -f "$condition" || -d "$condition" ]]; then + echo -e "${color_txtred}[ERROR]${color_none} 不能建立空白檔案,因為有同名的檔案或資料夾己經存在,請按任意鍵離開..." + read -s -n 1 + else + touch $condition + vf $condition + fi + elif [[ "$inputvar2" == 'D' || "$inputvar2" == 'd' ]]; then + mkdir $condition + if [ "$?" -eq 0 ]; then + d $condition + sleep 2 + else + echo -e "${color_txtred}[ERROR]${color_none} 建立資料夾失敗,應該是有同名的檔案或資料夾己經存在,請按任意鍵離開..." + read -s -n 1 + fi + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'H' ]; then + needhelp='1' + clear_var_all='1' + continue + elif [[ "$inputvar" == 'X' || "$inputvar" == 'Q' ]]; then + exit + # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 + elif [ "$inputvar" == $backspace ]; then + condition="${condition:0:(${#condition} - 1)}" + inputvar='' + elif [ "$inputvar" == "'" ]; then + abc123 + clear_var_all='1' + continue + fi + + condition="$condition$inputvar" + + if [[ "$condition" =~ [[:alnum:]] ]]; then + cmds=($condition) + cmd1=${cmds[0]} + cmd2=${cmds[1]} + # 第三個引數,是位置 + cmd3=${cmds[2]} + + #if [ "$fast_change_dir_config_parent_enable" == '1' ]; then + # item_parent_file_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" ".." "file"` ) + # item_parent_dir_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" ".." "dir"` ) + + # # 決定誰是最佳人選,當你按了;分號或是.點 + # if [ ${#item_parent_file_array[@]} -eq 1 ]; then + # good_select=3 + # good_array=${item_parent_file_array[@]} + # elif [ ${#item_parent_dir_array[@]} -eq 1 ]; then + # good_select=4 + # good_array=${item_parent_dir_array[@]} + # fi + #fi + + #item_file_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) + #item_dir_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "dir"` ) + + ## 決定誰是最佳人選,當你按了;分號或是.點 + #if [ ${#item_file_array[@]} -eq 1 ]; then + # good_select=1 + # good_array=${item_file_array[@]} + #elif [ ${#item_dir_array[@]} -eq 1 ]; then + # good_select=2 + # good_array=${item_dir_array[@]} + #fi + + # 有些功能,只要看到第2個引數就會失效 + #if [ "$cmd2" == '' ]; then + # item_dirpoint_array=( `func_dirpoint "$cmd1"` ) + # item_groupname_array=( `func_groupname "$cmd1"` ) + #else + # unset item_dirpoint_array + # unset item_groupname_array + #fi + + elif [ "$condition" == '' ]; then + # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 + clear_var_all='1' + continue + fi + +done + +# 離開前,在顯示一下現在資料夾裡面的東西 +eval $cmd diff --git a/abc.sh b/abc.sh new file mode 100755 index 0000000..1d5e7ea --- /dev/null +++ b/abc.sh @@ -0,0 +1,179 @@ +#!/bin/bash + +# IDEA +# 1. 按數字1,可能就顯示跟1有關係的項目,例如1、1N、1NN +# 2. filelist=all的時候,每一個項目都會加上數字, +# 當我選數字的時候,會自動去判斷這個項目是資料夾還是檔案 + +# 3種檔案變數 +# 1.檔案顯示模式(mode) +# 指的是"ls -A"指令,要不要加上l +# a.有l的是列出所有檔案(直式) - detail +# b.沒有加的是跟著前面列出來(橫式) - normal +# 2.檔案列表方式(list) +# a.顯示所有檔案和資料夾(不會加上任何的指令) - all +# b.只顯示資料夾,後面也是會加上編號 - dir +# c.只顯示檔案,檔案後面還會加上編號 - file +# 3.檔案指標種類(point) +# 這個應該不會在使用 + +funcGetMode() +{ + filemode=$1 + filelist=$2 + + cmd='ls -AF --color=auto' + + if [ "$filemode" == 'detail' ]; then + cmd="$cmd -l" + fi + + #if [[ "$filelist" == 'dir' || "$filelist" == 'file' ]]; then + # if [ "$filemode" == 'detail' ]; then + # cmd="$cmd | head -n -1" + # fi + #fi + + if [ "$filelist" == 'dir' ]; then + cmd="$cmd | grep \/$ | nl -s': '" + elif [ "$filelist" == 'file' ]; then + # 行號行0開始的原因是,第一行的總數弄不掉...@@ + cmd="$cmd | grep -v \/ | nl -v0 -s': '" + fi + + echo $cmd +} + +# 我想還是不要一開始就選好了 +#ga + +# -A 代表不顯示.和..,這個參數不能跟小a一起使用 +# ls -A --color=auto' +filemode='detail' + +# all 顯示所有檔案,含資料夾和檔案 +# dir 只顯示資料夾,並把位置列出來 +# file 跟上面一樣,不過是檔案 +filelist='all' + +# 當使用者檔案列表方式是all,然後選擇了某一個項目 +# 這時這個變數就會是1,要告訴使用者要先選擇file or dir的檔案列表方式 +filelisterr='0' + +while [ 1 ]; +do + clear + echo '工具列表(/斜線) 列表切換(*星號) 上一層(-減號) 檔案[夾]切換(0零) 列表依據切換(.點)' + echo '=================================================' + echo "目前顯示模式$filemode" + echo "目前列表方式$filelist" + echo '=================================================' + + if [ "$filelisterr" == '1' ]; then + echo '[ERROR] 請按.(點)先切換檔案列表方式為file或是dir' + #filelisterr='0' + fi + + filecmd=$( funcGetMode "$filemode" "$filelist" ) + echo "debug => $filecmd" + echo "debug => $filelist" + eval $filecmd + + # 只是做一個分隔而以 + echo '=================================================' + + if [ "$filelisterr" == '1' ]; then + echo '[ERROR] 請按.(點)先切換檔案列表方式為file或是dir' + filelisterr='0' + fi + + # 請使用者做第一次的輸入指令 + echo '請輸入指令:' + + read -n 1 cmd + + if [ "$cmd" == "q" ]; then + echo '謝謝您的使用' + break + elif [ "$cmd" == "+" ]; then + echo '請輸入9以上的數字項目' + read cmd + elif [ "$cmd" == "*" ]; then + if [ "$filemode" == "normal" ]; then + filemode='detail' + else + filemode='normal' + fi + elif [ "$cmd" == "." ]; then + if [ "$filelist" == "all" ]; then + filelist='dir' + elif [ "$filelist" == "dir" ]; then + filelist='file' + else + filelist='all' + fi + elif [ "$cmd" == "-" ]; then + ge + filelist='all' + elif [ "$cmd" == "/" ]; then + echo '(1) ga 選擇專案' + echo '(2) dv 顯示虛擬資料夾' + echo '(3) vff 將暫存檔案用VIM逐一打開' + echo '(4) vfff VIM編輯暫存檔案列表' + echo '(5) 清除VIM編輯暫存檔案列表' + echo '(Enter) 取消' + echo '請輸入指令:' + read -n 1 cmdslash + if [ "$cmdslash" == "1" ]; then + ga + cmd='' + elif [ "$cmdslash" == "2" ]; then + dv + elif [ "$cmdslash" == "3" ]; then + vff + elif [ "$cmdslash" == "4" ]; then + vfff + elif [ "$cmdslash" == "5" ]; then + if [ "$groupname" != '' ]; then + rm ~/gisanfu-vimlist-$groupname.txt + touch ~/gisanfu-vimlist-$groupname.txt + fi + fi + fi + + # 只是做一個分隔而以 + echo '=================================================' + + if [[ "$cmd" =~ [[:digit:]] ]]; then + if [ "$filelist" == 'all' ]; then + echo '請選擇列表方式,才能繼續下一步' + echo '(1) 資料夾(預設)' + echo '(2) 檔案' + echo '請輸入指令:' + read -n 1 cmdslash + + if [ "$cmdslash" == "2" ]; then + filelist='file' + else + filelist='dir' + fi + fi + + if [ "$filelist" == "dir" ]; then + selectitem=". /bin/gisanfu-pos-cddir.sh $cmd" + eval $selectitem + filelist='all' + else + # 以groupname(ga)來選擇動作,這樣子可能會比較順 + if [ "$groupname" == "" ]; then + selectitem=". /bin/gisanfu-pos-editfile.sh $cmd" + eval $selectitem + else + selectitem=". /bin/gisanfu-pos-vimlist-append.sh $cmd" + eval $selectitem + fi + filelist='all' + fi + + fi +done diff --git a/back-backdir.sh b/back-backdir.sh new file mode 100755 index 0000000..ad1b882 --- /dev/null +++ b/back-backdir.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +source "$fast_change_dir_func/normal.sh" + +Position=$1 +dot='../' +dots='' + +for (( i=1;i<=$Position;i++)); do + dots=$dots$dot +done +cd $dots + +# check file count and ls action +func_checkfilecount diff --git a/backdir.sh b/backdir.sh new file mode 100755 index 0000000..f6836c7 --- /dev/null +++ b/backdir.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +source "$fast_change_dir_func/normal.sh" +source "$fast_change_dir_func/dialog.sh" +source "$fast_change_dir_func/entonum.sh" +source "$fast_change_dir_func/relativeitem.sh" + +# cmd1、2是第一、二個關鍵字 +cmd1=$1 +cmd2=$2 +# 位置,例如e就代表1,或者你也可以輸入1 +cmd3=$3 + +item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" ".." "dir"` ) + +if [ "${#item_array[@]}" -gt 1 ]; then + # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 + tmpfile="$fast_change_dir_tmp/`whoami`-cddir-dialogselect-$( date +%Y%m%d-%H%M ).txt" + dialogitems='' + for echothem in ${item_array[@]} + do + dialogitems=" $dialogitems $echothem '' " + done + cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) + + eval $cmd + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" != "" ]; then + match=`echo $result | sed 's/___/ /g'` + run="cd ../\"$match\"" + fi +elif [ "${#item_array[@]}" -eq 1 ]; then + run="cd ../\"${item_array[0]}\"" +fi + +if [ "$run" != '' ]; then + eval $run + # check file count and ls action + func_checkfilecount +fi + +unset cmd +unset cmd1 +unset cmd2 +unset cmd3 +unset number +unset item_array diff --git a/bashrc.txt b/bashrc.txt new file mode 100644 index 0000000..eaafaf6 --- /dev/null +++ b/bashrc.txt @@ -0,0 +1,102 @@ +# fast-change-dir +fast_change_dir_pwd=$HOME +fast_change_dir="$fast_change_dir_pwd/gisanfu/fast-change-dir" +fast_change_dir_bin="$fast_change_dir/bin" +fast_change_dir_lib="$fast_change_dir/lib" +fast_change_dir_func="$fast_change_dir_lib/func" + +# 你可以依照使用習慣去修改 +fast_change_dir_tmp='/tmp' +fast_change_dir_config="$fast_change_dir_pwd" + +# fast-change-dir: use relative keyword +alias ll="ls -la" + +# main function +alias ide=". $fast_change_dir/abc-4.sh" + +# number function +alias gre=". $fast_change_dir/grep.sh" +alias sear=". $fast_change_dir/search.sh" +alias abc=". $fast_change_dir/abc-4.sh" +alias 123=". $fast_change_dir/123.sh" +alias abc123=". $fast_change_dir/123-2.sh" + +# Version Controll +alias svnn=". $fast_change_dir/svn-3.sh" +alias gitt=". $fast_change_dir/git-2.sh" +alias hgg=". $fast_change_dir/hg.sh" + +# +# GroupName +# +# select or switch GroupName +alias ga=". $fast_change_dir/groupname.sh select" +# append GroupName +alias gaa=". $fast_change_dir/groupname.sh append" +# edit GroupName +alias gaaa=". $fast_change_dir/groupname.sh edit" + +# +# cd +# +alias d=". $fast_change_dir/cddir.sh" +# cd point +alias dv=". $fast_change_dir/dirpoint.sh" +# append point +alias dvv=". $fast_change_dir/dirpoint-append.sh" +# edit point +alias dvvv=". $fast_change_dir/dirpoint-edit.sh" +# nopath, nolimit to change directory by keyword +alias wv=". $fast_change_dir/nopath.sh" + +# vim +alias v=". $fast_change_dir/editfile.sh" +alias vf=". $fast_change_dir/vimlist-append.sh" +alias vff=". $fast_change_dir/vimlist.sh" +alias vfff=". $fast_change_dir/vimlist-edit.sh" +alias vffff=". $fast_change_dir/vimlist-clear.sh" +alias vfe=". $fast_change_dir/pos-vimlist-append.sh 1" +alias vfee=". $fast_change_dir/pos-vimlist-append.sh 2" +alias vfeee=". $fast_change_dir/pos-vimlist-append.sh 3" +alias vfeeee=". $fast_change_dir/pos-vimlist-append.sh 4" +alias vfeeeee=". $fast_change_dir/pos-vimlist-append.sh 5" +alias vfeeeeee=". $fast_change_dir/pos-vimlist-append.sh 6" + +# +# back, and cd dir +# +alias g=". $fast_change_dir/backdir.sh" +# back back... layer dir +alias ge=". $fast_change_dir/back-backdir.sh 1" +alias gee=". $fast_change_dir/back-backdir.sh 2" +alias geee=". $fast_change_dir/back-backdir.sh 3" +alias geeee=". $fast_change_dir/back-backdir.sh 4" +alias geeeee=". $fast_change_dir/back-backdir.sh 5" +alias geeeeee=". $fast_change_dir/back-backdir.sh 6" +# back and cd dir, use position +alias gde=". $fast_change_dir/pos-backdir.sh 1" +alias gdee=". $fast_change_dir/pos-backdir.sh 2" +alias gdeee=". $fast_change_dir/pos-backdir.sh 3" +alias gdeeee=". $fast_change_dir/pos-backdir.sh 4" +alias gdeeeee=". $fast_change_dir/pos-backdir.sh 5" +alias gdeeeeee=". $fast_change_dir/pos-backdir.sh 6" + +# fast-change-dir: cd dir, use position +alias de=". $fast_change_dir/pos-cddir.sh 1" +alias dee=". $fast_change_dir/pos-cddir.sh 2" +alias deee=". $fast_change_dir/pos-cddir.sh 3" +alias deeee=". $fast_change_dir/pos-cddir.sh 4" +alias deeeee=". $fast_change_dir/pos-cddir.sh 5" +alias deeeeee=". $fast_change_dir/pos-cddir.sh 6" + +# fast-change-dir: vim file, use position +alias ve=". $fast_change_dir/pos-editfile.sh 1" +alias vee=". $fast_change_dir/pos-editfile.sh 2" +alias veee=". $fast_change_dir/pos-editfile.sh 3" +alias veeee=". $fast_change_dir/pos-editfile.sh 4" +alias veeeee=". $fast_change_dir/pos-editfile.sh 5" +alias veeeeee=". $fast_change_dir/pos-editfile.sh 6" + +# 最後,啟動ide +ide diff --git a/bin/cmd-refresh-firefox.sh b/bin/cmd-refresh-firefox.sh new file mode 100755 index 0000000..b087964 --- /dev/null +++ b/bin/cmd-refresh-firefox.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# 切換到firefox的視窗,然後按下Ctrl+r重新refresh + +cmd=$1 + +if [ "$cmd" == '' ]; then + echo '[INPUT] 請選擇切換到firefox後的動作' + echo 'Refresh (YRr)*' + echo 'Switch Only (Nn)' + read -n 1 inputvar + if [[ "$inputvar" == 'Y' || "$inputvar" == 'y' || "$inputvar" == 'R' || "$inputvar" == 'r' ]]; then + cmd='refresh' + elif [[ "$inputvar" == 'N' || "$inputvar" == 'n' ]]; then + cmd='switchonly' + else + cmd='refresh' + fi +fi + +wmctrl -R "firefox" + +if [ "$cmd" == 'refresh' ]; then + xmacroplay -d 10 $DISPLAY << ~~~ +KeyStrPress Control_L +KeyStrPress r +KeyStrRelease r +KeyStrRelease Control_L +~~~ +fi diff --git a/bin/google-search.pl b/bin/google-search.pl new file mode 100644 index 0000000..41376f1 --- /dev/null +++ b/bin/google-search.pl @@ -0,0 +1,72 @@ +#!/usr/bin/perl +# google.pl - command line tool to search google +# +# Since I wrote goosh.org I get asked all the time if it could be used on the command line. +# Goosh.org is written in Javascript, so the answer is no. But google search in the shell +# is really simple, so I wrote this as an example. Nothing fancy, just a starting point. +# +# 2009 by Stefan Grothkopp, this code is public domain use it as you wish! + +use LWP::Simple; +use Term::ANSIColor; + +# 參考http://blog.wu-boy.com/2009/07/01/1492/ +# 沒有加這一段的話,可能會出現以下的錯誤訊息 +# Wide character in print... +use utf8; +binmode(STDIN, ':encoding(utf8)'); +binmode(STDOUT, ':encoding(utf8)'); +binmode(STDERR, ':encoding(utf8)'); + +# change this to false for b/w output +$use_color = 0; +#result size: filtered_cse=10, large=8, small=4 +$result_size = "filtered_cse"; + +# unescape unicode characters in" content" +sub unescape { + my($str) = splice(@_); + $str =~ s/\\u(.{4})/chr(hex($1))/eg; + return $str; +} + +# number of command line args +$numArgs = $#ARGV + 1; + +if($numArgs ==0){ + # print usage info if no argument is given + print "[ERROR] Usage:\n"; + print "$0 <searchterm>\n"; +} else { + # use first argument as query string + $q = $ARGV[0]; + # url encode query string + $q =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg; + + # get json encoded search result from google ajax api + my $content = get("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&start=0&rsz=$result_size&q=$q"); #Get web page in content + die "[ERROR]" if (!defined $content); + + $i = 1; + # ugly result parsing (did not want to depend on a parser lib for this quick hack) + while($content =~ s/"unescapedUrl":"([^"]*)".*?"titleNoFormatting":"([^"]*)".*?"content":"([^"]*)"//){ + + # those three data items are extrated, there are more + $title = unescape($2); + $desc = unescape($3); + $url = unescape($1); + + # print result + if($use_color){ + print colored ['red'], "[$i] "; + print colored ['blue'], "$title\n"; + print "$desc\n"; + print colored ['green'], "$url\n\n"; + print color 'reset'; + } + else{ + print "[$i] $title\n$desc\n$url\n\n"; + } + $i++; + } +} diff --git a/bin/only-text-filecontent.sh b/bin/only-text-filecontent.sh new file mode 100755 index 0000000..459ac53 --- /dev/null +++ b/bin/only-text-filecontent.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# 本程式目的 +# 忽略掉純文字以外的檔案,例如壓縮檔 + +# 如果你要使用這支程式來當做pipe使用 +# 請使用your-runfilename | xargs -n 1 this-file-name + +aaa=$1 + +bbb=`file $aaa | grep -e text -e empty | wc -l` + +if [ "$bbb" -gt 0 ]; then + echo $aaa +fi diff --git a/bin/relativeitem.sh b/bin/relativeitem.sh new file mode 100644 index 0000000..fe89985 --- /dev/null +++ b/bin/relativeitem.sh @@ -0,0 +1,170 @@ +#!/bin/bash + +# 這個檔案,請試著用shc去編譯它 +# 然後全面的把abc version3裡面的func_relative替換掉 +# 試試看這樣子的效率有沒有比較快 + +# 結論就是沒有比較快,還是一樣很慢 + +# 把英文變成數字,例如er就是12 +func_entonum() +{ + en=$1 + + return=$en + + for i in ${en[@]} + do + return=`echo $return | sed 's/e/1/'` + return=`echo $return | sed 's/r/2/'` + return=`echo $return | sed 's/s/3/'` + return=`echo $return | sed 's/f/4/'` + return=`echo $return | sed 's/w/5/'` + return=`echo $return | sed 's/l/6/'` + return=`echo $return | sed 's/c/7/'` + return=`echo $return | sed 's/b/8/'` + return=`echo $return | sed 's/k/9/'` + + # 零 + return=`echo $return | sed 's/o/0/'` + return=`echo $return | sed 's/z/0/'` + done + + echo $return +} + +#func_relative() +#{ + nextRelativeItem=$1 + secondCondition=$2 + + # 檔案的位置 + fileposition=$3 + + # 要搜尋哪裡的路徑,空白代表現行目錄 + lspath=$4 + + # dir or file + filetype=$5 + + # get all item flag + # 0 or empty: do not get all + # 1: Get All + isgetall=$6 + + declare -a itemList + declare -a itemListTmp + declare -a relativeitem + + + tmpfile="$fast_change_dir_tmp/`whoami`-function-relativeitem-$( date +%Y%m%d-%H%M ).txt" + + # ignore file or dir + # ignorelist=$(func_getlsignore) + ignorelist='' + Success="0" + + # 試著使用@來決定第一個grep,從最開啟來找字串 + firstchar=${nextRelativeItem:0:1} + isHeadSearch='' + + # 這裡要注意,不能夠使用井字號(#)來當做控制字元,會有問題 + if [ "$firstchar" == '@' ]; then + isHeadSearch='^' + nextRelativeItem=${nextRelativeItem:1} + #elif [ "$firstchar" == '*' ]; then + # nextRelativeItem=${nextRelativeItem:1} + else + firstchar='' + fi + + # 試著使用第二個引數的第一個字元,來判斷是不是position + firstchar2=${secondCondition:0:1} + + if [[ "$firstchar2" == '@' && "$fileposition" == '' ]]; then + fileposition=${secondCondition:1} + secondCondition='' + fi + + # 先把英文轉成數字,如果這個欄位有資料的話 + fileposition=( `func_entonum "$fileposition"` ) + + if [ "$fileposition" != '' ]; then + newposition=$(($fileposition - 1)) + fi + + lucky='' + if [ "$filetype" == "dir" ]; then + filetype_ls_arg='' + filetype_grep_arg='' + if [[ -d "$lspath$nextRelativeItem" && "$isgetall" != '1' ]]; then + echo "$nextRelativeItem" + exit + fi + else + filetype_ls_arg='--file-type' + filetype_grep_arg='-v' + if [[ -f "$lspath$nextRelativeItem" && "$isgetall" != '1' ]]; then + echo "$nextRelativeItem" + exit + fi + fi + + # default ifs value + default_ifs=$' \t\n' + + IFS=$'\n' + cmd="ls -AFL $ignorelist $filetype_ls_arg $lspath | grep $filetype_grep_arg \"/$\"" + + if [ "$isgetall" != '1' ]; then + cmd="$cmd | grep -ir $isHeadSearch$nextRelativeItem" + fi + + if [ "$secondCondition" != '' ]; then + cmd="$cmd | grep -ir $secondCondition" + fi + + # 取得項目列表,存到陣列裡面,當然也會做空白的處理 + declare -i num + itemListTmp=(`eval $cmd`) + for i in ${itemListTmp[@]} + do + # 為了要解決空白檔名的問題 + itemList[$num]=`echo $i|sed 's/ /___/g'` + num=$num+1 + done + IFS=$default_ifs + num=0 + + if [ "$nextRelativeItem" != "" ]; then + if [ "${#itemList[@]}" == "1" ]; then + relativeitem=${itemList[0]} + #func_statusbar 'USE-ITEM' + elif [ "${#itemList[@]}" -gt "1" ]; then + relativeitem=${itemList[@]} + fi + fi + + if [ "$isgetall" == '1' ]; then + if [ "${#itemList[@]}" == "1" ]; then + relativeitem=${itemList[0]} + #func_statusbar 'USE-ITEM' + elif [ "${#itemList[@]}" -gt "1" ]; then + relativeitem=${itemList[@]} + fi + fi + + # return array的標準用法 + if [ "$relativeitem" != '' ]; then + if [ "$newposition" == '' ]; then + echo ${relativeitem[@]} + else + # 先把含空格的文字,轉成陣列 + aaa=(${relativeitem[@]}) + # 然後在指定位置輸出 + echo ${aaa[$newposition]} + fi + else + echo '' + fi +#} diff --git a/cddir.sh b/cddir.sh new file mode 100755 index 0000000..2acce51 --- /dev/null +++ b/cddir.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +source "$fast_change_dir_func/normal.sh" +source "$fast_change_dir_func/dialog.sh" +source "$fast_change_dir_func/entonum.sh" +source "$fast_change_dir_func/relativeitem.sh" + +# cmd1、2是第一、二個關鍵字 +cmd1=$1 +cmd2=$2 +# 位置,例如e就代表1,或者你也可以輸入1 +cmd3=$3 + +item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "dir"` ) + +if [ "${#item_array[@]}" -gt 1 ]; then + # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 + tmpfile="$fast_change_dir_tmp/`whoami`-cddir-dialogselect-$( date +%Y%m%d-%H%M ).txt" + dialogitems='' + for echothem in ${item_array[@]} + do + dialogitems=" $dialogitems $echothem '' " + done + cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) + + eval $cmd + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" != "" ]; then + match=`echo $result | sed 's/___/ /g'` + run="cd \"$match\"" + fi +elif [ "${#item_array[@]}" -eq 1 ]; then + run="cd \"${item_array[0]}\"" +fi + +if [ "$run" != '' ]; then + eval $run + # check file count and ls action + func_checkfilecount +fi + +unset cmd +unset cmd1 +unset cmd2 +unset cmd3 +unset run +unset number +unset item_array diff --git a/config.sh b/config.sh new file mode 100644 index 0000000..2bc6f79 --- /dev/null +++ b/config.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# 這個是fast-change-dir專案的設定檔 +# 預設值,應該是要設定成啟動 +# 然後使用者可以在他自己的家目錄設定 +# 檔名也是config.sh + +# 目前先加搜尋檔案/資料夾的功能啟用設定 +# 因為這兩個影響速度最明顯 +fast_change_dir_config_searchfile_enable='1' +fast_change_dir_config_searchdir_enable='1' + +fast_change_dir_config_googlesearch_enable='1' +fast_change_dir_config_bashhistorysearch_enable='1' + +# 上一層的兩個功能,合併在同一項控制 +fast_change_dir_config_parent_enable='1' + +# 重覆項目的顯示開關 +fast_change_dir_config_duplicate_enable='1' diff --git a/dirpoint-append.sh b/dirpoint-append.sh new file mode 100755 index 0000000..c0f15a1 --- /dev/null +++ b/dirpoint-append.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +source "$fast_change_dir_func/dialog.sh" +source "$fast_change_dir_func/entonum.sh" +source "$fast_change_dir_func/relativeitem.sh" + +dirpoint=$1 +# cmd1、2是第一、二個關鍵字 +cmd1=$2 +cmd2=$3 +# 位置,例如e就代表1,或者你也可以輸入1 +cmd3=$4 + +if [ "$dirpoint" != "" ]; then + + item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "dir"` ) + + if [ "${#item_array[@]}" -gt 1 ]; then + # 雖然沒有選到資料夾,不過可以用dialog試著來輔助 + tmpfile="$fast_change_dir_tmp/`whoami`-dirpointappend-dialogselect-$( date +%Y%m%d-%H%M ).txt" + dialogitems='' + for echothem in ${item_array[@]} + do + dialogitems=" $dialogitems $echothem '' " + done + cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) + + eval $cmd + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" != "" ]; then + match=`echo $result | sed 's/___/ /g'` + relativeitem=$match + fi + elif [ "${#item_array[@]}" -eq 1 ]; then + relativeitem=${item_array[0]} + fi + + if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then + echo "$dirpoint,`pwd`/$relativeitem" >> $fast_change_dir_config/dirpoint-$groupname.txt + cat $fast_change_dir_config/dirpoint-$groupname.txt + elif [ "$groupname" == "" ]; then + echo '[ERROR] groupname is empty, please use GA cmd' + fi +else + echo '[ERROR] "dirpoint-arg01" "nextRelativeItem-arg02" "secondCondition-arg03" "Position-arg04"' +fi + +unset dirpoint +unset cmd +unset cmd1 +unset cmd2 +unset cmd3 +unset number +unset item_array +unset relativeitem diff --git a/dirpoint-edit.sh b/dirpoint-edit.sh new file mode 100755 index 0000000..2f96496 --- /dev/null +++ b/dirpoint-edit.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if [ "$groupname" != "" ]; then + vim $fast_change_dir_config/dirpoint-$groupname.txt +else + echo '[ERROR] groupname is empty' +fi diff --git a/dirpoint.sh b/dirpoint.sh new file mode 100755 index 0000000..26c583f --- /dev/null +++ b/dirpoint.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +source "$fast_change_dir_func/normal.sh" +source "$fast_change_dir_func/dialog.sh" + +# default ifs value +default_ifs=$' \t\n' + +# fix space to effect array result +IFS=$'\012' + +dirpoint=$1 +tmpfile="$fast_change_dir_tmp/`whoami`-dirpoint-dialog-$( date +%Y%m%d-%H%M ).txt" + +if [ "$groupname" != "" ]; then + + if [ ! -f $fast_change_dir_config/dirpoint-$groupname.txt ]; then + touch $fast_change_dir_config/dirpoint-$groupname.txt + fi + + if [ "$dirpoint" != "" ]; then + result=`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_config/dirpoint-$groupname.txt | cut -d, -f2` + resultarray=(`grep ^$dirpoint[[:alnum:]]*, $fast_change_dir_config/dirpoint-$groupname.txt | cut -d, -f2`) + + if [ "${#resultarray[@]}" -gt "1" ]; then + cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `grep $dirpoint[[:alnum:]]*, $fast_change_dir_config/dirpoint-$groupname.txt | tr "\n" " " | tr ',' ' '` $tmpfile ) + + eval $cmd + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" == "" ]; then + echo '[ERROR] dirpoint is empty' + else + dv $result + fi + elif [ "${#resultarray[@]}" == "1" ]; then + cmd="cd $result" + eval $cmd + func_checkfilecount + else + echo '[ERROR] dirpoint is not exist!!' + fi + else + resultvalue=`cat $fast_change_dir_config/dirpoint-$groupname.txt | wc -l` + + if [ "$resultvalue" -ge "1" ]; then + echo ${#resultarray[@]} + cmd=$( func_dialog_menu 'Please Select DirPoint' 100 `cat $fast_change_dir_config/dirpoint-$groupname.txt | tr "\n" " " | tr ',' ' '` $tmpfile ) + eval $cmd + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" == "" ]; then + echo '[ERROR] dirpoint is empty' + else + dv $result + fi + else + echo '[ERROR] Please use DVV cmd to create dirpoint' + fi + + fi +else + echo '[ERROR] groupname is empty, please use GA cmd' +fi + +tmpfile='' +IFS=$default_ifs diff --git a/editfile.sh b/editfile.sh new file mode 100755 index 0000000..faf6d0d --- /dev/null +++ b/editfile.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +source "$fast_change_dir_func/normal.sh" +source "$fast_change_dir_func/entonum.sh" +source "$fast_change_dir_func/relativeitem.sh" + +# cmd1、2是第一、二個關鍵字 +cmd1=$1 +cmd2=$2 +# 位置,例如e就代表1,或者你也可以輸入1 +cmd3=$3 + +item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) + +if [ "${#item_array[@]}" -gt 1 ]; then + echo "重覆的檔案數量: 有${#item_array[@]}筆" + number=1 + for bbb in ${item_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done +elif [ "${#item_array[@]}" -eq 1 ]; then + cmd="vim \"${item_array[0]}\"" + eval $cmd + # check file count and ls action + func_checkfilecount +fi + +unset cmd +unset cmd1 +unset cmd2 +unset cmd3 +unset number +unset item_array diff --git a/git-2.sh b/git-2.sh new file mode 100755 index 0000000..960ee82 --- /dev/null +++ b/git-2.sh @@ -0,0 +1,362 @@ +#!/bin/bash + +source "$fast_change_dir_func/entonum.sh" + +# default ifs value +default_ifs=$' \t\n' + +func_relative_by_git_append() +{ + nextRelativeItem=$1 + secondCondition=$2 + + # 檔案的位置 + fileposition=$3 + + # 顯示的方式,可能是untracked or tracked + trackstatus=$4 + + declare -a itemList + declare -a itemListTmp + declare -a itemList2 + declare -a itemList2Tmp + declare -a relativeitem + + # 先把英文轉成數字,如果這個欄位有資料的話 + fileposition=( `func_entonum "$fileposition"` ) + + if [ "$fileposition" != '' ]; then + newposition=$(($fileposition - 1)) + fi + + # ignore file or dir + Success="0" + + # default ifs value + default_ifs=$' \t\n' + + IFS=$'\n' + declare -i num + + if [ "$trackstatus" == 'untracked' ]; then + itemListTmp=(`git status -s | grep -e '^ ' -e '^??' | grep -ir $nextRelativeItem`) + else + itemListTmp=(`git status -s | grep -e '^A' -e '^M' -e '^D' | grep -ir $nextRelativeItem`) + fi + + for i in ${itemListTmp[@]} + do + # 為了要解決空白檔名的問題 + itemList[$num]=`echo $i|sed 's/ /___/g'` + num=$num+1 + done + IFS=$default_ifs + num=0 + + if [[ "${#itemList[@]}" -gt "1" && "$secondCondition" != '' ]]; then + + IFS=$'\n' + + if [ "$trackstatus" == 'untracked' ]; then + itemList2Tmp=(`git status -s | grep -e '^ ' -e '^??' | grep -ir $nextRelativeItem | grep -ir $secondCondition`) + else + itemList2Tmp=(`git status -s | grep -e '^A' -e '^M' -e '^D' | grep -ir $nextRelativeItem | grep -ir $secondCondition`) + fi + + for i in ${itemList2Tmp[@]} + do + # 為了要解決空白檔名的問題 + itemList2[$num]=`echo $i|sed 's/ /___/g'` + num=$num+1 + done + IFS=$default_ifs + num=0 + fi + + # if empty of variable, then go back directory + if [ "$nextRelativeItem" != "" ]; then + if [ "${#itemList[@]}" == "1" ]; then + relativeitem=${itemList[0]} + #func_statusbar 'USE-ITEM' + elif [ "${#itemList[@]}" -gt 1 ]; then + + if [ "$secondCondition" != '' ]; then + # if have secondCondition, DO secondCheck + if [ "${#itemList2[@]}" == "1" ]; then + relativeitem=${itemList2[0]} + + #func_statusbar 'USE-LUCK-ITEM-BY-SECOND-CONDITION' + + Success="1" + elif [ "${#itemList2[@]}" -gt "1" ]; then + relativeitem=${itemList2[@]} + #relativeitem=$itemList2 + Success="1" + fi + fi + + # if no duplicate dirname then print them + if [ $Success == "0" ]; then + if [ "${#itemList2[@]}" -gt 0 ]; then + relativeitem=${itemList2[@]} + else + relativeitem=${itemList[@]} + fi + fi + fi + fi + + # return array的標準用法 + if [ "$relativeitem" != '' ]; then + if [ "$newposition" == '' ]; then + echo ${relativeitem[@]} + else + # 先把含空格的文字,轉成陣列 + aaa=(${relativeitem[@]}) + # 然後在指定位置輸出 + echo ${aaa[$newposition]} + fi + fi +} + +func_git_handle_status() +{ + item=$1 + + # 不分兩次做,會出現前面少了一個空白,不知道為什麼 + match=`echo $item | sed 's/___/X/'` + match=`echo $match | sed 's/___/ /g'` + + # 這個變數,存的可能是XD, DX, AX.... + gitstatus=${match:0:2} + + if [ "$untracked" == '1' ]; then + if [ "$gitstatus" == 'XD' ]; then + # 把檔案救回來 + git checkout ${match:3} + else + git add ${match:3} + fi + else + if [ "$gitstatus" == 'DX' ]; then + # 把檔案救回來 + git checkout HEAD ${match:3} + else + git reset ${match:3} + fi + fi +} + +unset cmd1 +unset cmd2 +unset cmd3 + +# 只有第一次是1,有些只會執行一次,例如help +first='1' + +# 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 +clear_var_all='' + +# 倒退鍵 +backspace=$(echo -e \\b\\c) + +# 預設是顯示untracked列表 +untracked='1' + +while [ 1 ]; +do + clear + + if [[ "$first" == '1' || "$clear_var_all" == '1' ]]; then + unset cmd + unset condition + unset item_array + clear_var_all='' + first='' + fi + + echo 'Git (關鍵字)' + echo '=================================================' + echo "\"$groupname\" || `pwd`" + echo '=================================================' + if [ "$untracked" == '1' ]; then + echo "Untracked List" + else + echo "Tracked List" + fi + echo '=================================================' + + if [ "$untracked" == '1' ]; then + cmd="git status -s | grep -e '^ ' -e '^??'" + else + cmd="git status -s | grep -e '^A' -e '^M' -e '^D' -e '^R'" + fi + eval $cmd + + if [ "$condition" == 'quit' ]; then + break + elif [ "$condition" != '' ]; then + echo '=================================================' + echo "目前您所輸入的搜尋條件: \"$condition\"" + fi + + if [ "$condition" == '' ]; then + echo '=================================================' + echo -e "${color_txtgrn}基本快速鍵:${color_none}" + echo ' 倒退鍵 (Ctrl + H)' + echo ' 重新輸入條件 (/)' + echo ' 智慧選取單項 (;) 分號' + echo ' 處理多項(*) 星號' + echo ' 離開 (?)' + echo -e "${color_txtgrn}Git功能快速鍵:${color_none}" + echo ' Change Untracked or Tracked (A)' + echo ' Commit(keyin changelog, and send by ask!) (C)' + echo ' Push(send!!) (E)' + echo ' Update(Pull) (U)' + #echo -e "${color_txtgrn}選擇用的快速鍵:${color_none}" + #echo ' 是否加入 (B)' + #echo ' 是否刪除 (D)' + echo '輸入條件的結構:' + echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' + fi + + echo '=================================================' + + # 顯示重覆檔案 + if [ "${#item_array[@]}" -gt 1 ]; then + echo "重覆的檔案數量: ${#item_array[@]} [*]" + number=1 + for bbb in ${item_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_array[@]}" -eq 1 ]; then + echo "檔案有找到一筆: ${item_array[0]} [;.]" + fi + + # 不加IFS=012的話,我輸入空格,read variable是讀不到的 + IFS=$'\012' + read -s -n 1 inputvar + IFS=$default_ifs + + if [ "$inputvar" == '?' ]; then + # 離開 + clear + break + elif [ "$inputvar" == '/' ]; then + clear_var_all='1' + continue + elif [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then + if [ ${#item_array[@]} -eq 1 ]; then + func_git_handle_status "${item_array[0]}" + clear_var_all='1' + continue + fi + elif [ "$inputvar" == '*' ]; then + if [ "${#item_array[@]}" -gt 1 ]; then + for bbb in ${item_array[@]} + do + func_git_handle_status "$bbb" + done + clear_var_all='1' + continue + fi + # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 + elif [ "$inputvar" == $backspace ]; then + condition="${condition:0:(${#condition} - 1)}" + inputvar='' + elif [ "$inputvar" == 'A' ]; then + if [ "$untracked" == '1' ]; then + untracked='0' + else + untracked='1' + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'C' ]; then + echo '要送出了,但是請先輸入changelog,輸入完請按Enter' + read changelog + if [ "$changelog" == '' ]; then + echo '為什麼你沒有輸入changelog呢?還是我幫你填上預設值呢?(no comment)好嗎?[Y1,n0]' + read inputvar2 + if [[ "$inputvar2" == 'y' || "$inputvar2" == "1" ]]; then + changelog='no comment' + elif [[ "$inputvar2" == 'n' || "$inputvar2" == "0" ]]; then + echo '如果不要預設值,那就算了' + else + echo '不好意思,不要預設值也不要來亂' + fi + fi + if [ "$changelog" == '' ]; then + echo '你並沒有輸入changelog,所以下次在見了,本次動作取消,倒數3秒後離開' + sleep 3 + else + git commit -m "$changelog" + changelog='' + if [ "$?" -eq 0 ]; then + #echo '設定Changelog成功,別忘了要選擇送出哦' + echo '要不要送出(git push)呢?[Y1,n0]' + read inputvar3 + if [[ "$inputvar3" == 'n' || "$inputvar3" == "0" ]]; then + echo '不要送出的話,那就算了!' + else + git push + fi + fi + echo '按任何鍵繼續...' + read -n 1 + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'U' ]; then + echo '己送出更新(pull)指令,等待中...' + git pull + if [ "$?" -eq 0 ]; then + echo '更新本GIT資料夾成功' + fi + echo '按任何鍵繼續...' + read -n 1 + + clear_var_all='1' + continue + elif [ "$inputvar" == 'E' ]; then + echo '己送出push指令,等待中...' + git push + if [ "$?" -eq 0 ]; then + echo '更新本GIT資料夾成功' + fi + echo '按任何鍵繼續...' + read -n 1 + + clear_var_all='1' + continue + fi + + condition="$condition$inputvar" + + if [[ "$condition" =~ [[:alnum:]] ]]; then + cmds=($condition) + cmd1=${cmds[0]} + cmd2=${cmds[1]} + # 第三個引數,是位置 + cmd3=${cmds[2]} + + if [ "$untracked" == '1' ]; then + item_array=( `func_relative_by_git_append "$cmd1" "$cmd2" "$cmd3" "untracked"` ) + else + item_array=( `func_relative_by_git_append "$cmd1" "$cmd2" "$cmd3" "tracked"` ) + fi + elif [ "$condition" == '' ]; then + # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 + unset condition + unset gitstatus + unset item_array + fi + +done + +# 離開前,在顯示一下現在資料夾裡面的東西 +eval $cmd diff --git a/git.sh b/git.sh new file mode 100755 index 0000000..9ba569a --- /dev/null +++ b/git.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +gitpath='/usr/local/git/bin/git' + +while [ 1 ]; +do + clear + + echo 'Git指令模式 (英文字母)' + echo '=================================================' + echo "現行資料夾: `pwd`" + echo '=================================================' + echo '基本快速鍵:' + echo ' 離開 (?)' + echo 'Git功能快速鍵:' + echo ' a. Status -s' + echo ' b. Status' + echo ' c. Update(Pull)' + echo ' d. Commit(keyin changelog, and send by ask!)' + echo ' e. Push(send!!)' + echo '=================================================' + + read -s -n 1 inputvar + + if [ "$inputvar" == '?' ]; then + # 離開 + clear + break + elif [[ "$inputvar" == 'a' || "$inputvar" == 'A' ]]; then + cmd="$gitpath status -s" + eval $cmd + if [ "$?" -eq 0 ]; then + echo '顯示本資料夾的GIT簡易狀態' + fi + echo '按任何鍵繼續...' + read -n 1 + elif [[ "$inputvar" == 'b' || "$inputvar" == 'B' ]]; then + git status + if [ "$?" -eq 0 ]; then + echo '顯示本資料夾的GIT簡易狀態' + fi + echo '按任何鍵繼續...' + read -n 1 + elif [[ "$inputvar" == 'c' || "$inputvar" == 'C' ]]; then + git pull + if [ "$?" -eq 0 ]; then + echo '更新本GIT資料夾成功' + fi + echo '按任何鍵繼續...' + read -n 1 + elif [[ "$inputvar" == 'd' || "$inputvar" == 'D' ]]; then + echo '要送出了,但是請先輸入changelog,輸入完請按Enter' + read changelog + if [ "$changelog" == '' ]; then + echo '為什麼你沒有輸入changelog呢?還是我幫你填上預設值呢?(no comment)好嗎?[Y1,n0]' + read inputvar2 + if [[ "$inputvar2" == 'y' || "$inputvar2" == "1" ]]; then + changelog='no comment' + elif [[ "$inputvar2" == 'n' || "$inputvar2" == "0" ]]; then + echo '如果不要預設值,那就算了' + else + echo '不好意思,不要預設值也不要來亂' + fi + fi + if [ "$changelog" == '' ]; then + echo '你並沒有輸入changelog,所以下次在見了,本次動作取消,倒數3秒後離開' + sleep 3 + else + git commit -m "$changelog" + changelog='' + if [ "$?" -eq 0 ]; then + #echo '設定Changelog成功,別忘了要選擇送出哦' + echo '要不要送出(git push)呢?[Y1,n0]' + read inputvar3 + if [[ "$inputvar2" == 'n' || "$inputvar2" == "0" ]]; then + echo '不要送出的話,那就算了!' + else + git push + fi + fi + echo '按任何鍵繼續...' + read -n 1 + fi + elif [[ "$inputvar" == 'e' || "$inputvar" == 'E' ]]; then + git push + if [ "$?" -eq 0 ]; then + echo '更新本GIT資料夾成功' + fi + echo '按任何鍵繼續...' + read -n 1 + fi + +done + +# 離開前,在顯示一下現在資料夾裡面的東西 +eval $cmd diff --git a/grep.sh b/grep.sh new file mode 100755 index 0000000..536d87c --- /dev/null +++ b/grep.sh @@ -0,0 +1,91 @@ +#!/bin/bash + +if [ "$groupname" != '' ]; then + dv root +fi + +tmpfile=/tmp/`whoami`-grep-$( date +%Y%m%d-%H%M ).txt + +nowpath=`pwd` + +unset condition +unset count + +while [ 1 ]; +do + clear + + if [ "$condition" == '' ]; then + echo '即時搜尋檔案內容' + echo '=================================================' + echo "\"$groupname\" || $nowpath" + echo '=================================================' + fi + + if [ "$condition" == 'quit' ]; then + clear + break + elif [ "$condition" != '' ]; then + echo "目前您所輸入的搜尋關鍵字的條件: $condition" + echo '=================================================' + grep -ir $condition * --exclude-dir Zend --exclude-dir .svn --no-messages | sort --unique | nl -s: -w1 > $tmpfile + # 這裡建議加上顯色,比較好懂 + cat $tmpfile + elif [ "$condition" == '' ]; then + echo '快速鍵:' + echo ' 倒退鍵 (Ctrl + H)' + echo ' 重新輸入條件 (/)' + echo ' 以數字選擇項目 (單引號)' + echo ' 離開 (?)' + echo '=================================================' + fi + + echo '輸入完請按Enter,或者是輸入一個單引號,來選擇搜尋出來的編號' + + read inputvar + + condition="$inputvar" + + if [ "$inputvar" == '?' ]; then + # 離開 + clear + break + elif [ "$inputvar" == '/' ]; then + unset condition + continue + elif [[ "$inputvar" == "'" ]]; then + echo '請輸入編號,輸入完請按Enter,輸入0是取消' + read inputvar2 + selectfile=`grep "^$inputvar2:" $tmpfile | sed "s/^$inputvar2://" | cut -d: -f1` + + if [[ "$groupname" == '' && "$inputvar2" != '0' ]]; then + run="vim $selectfile" + eval $run + elif [[ "$groupname" != '' && "$inputvar2" != '0' ]]; then + # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append + selectitem='' + selectitem=`pwd`/$selectfile + checkline=`grep "$selectitem" ~/gisanfu-vimlist-$groupname.txt | wc -l` + if [ "$checkline" -lt 1 ]; then + echo "\"$selectitem\"" >> ~/gisanfu-vimlist-$groupname.txt + cat ~/gisanfu-vimlist-$groupname.txt + else + echo '[NOTICE] File is exist' + fi + selectitem='' + + # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 + echo '[WAIT] 確定,是編輯暫存檔案[N0,y1]' + read -n 1 inputvar3 + if [[ "$inputvar3" == 'y' || "$inputvar3" == "1" ]]; then + vff + elif [[ "$inputvar3" == 'n' || "$inputvar3" == "0" ]]; then + echo "Your want append other file" + else + echo "Your want append other file" + fi + fi + unset condition + fi + +done diff --git a/groupname.sh b/groupname.sh new file mode 100755 index 0000000..0085783 --- /dev/null +++ b/groupname.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# +# 這個檔案,是選擇、以及增加專案代碼 +# + +source "$fast_change_dir_func/dialog.sh" + +action=$1 +groupname=$2 +tmpfile="$fast_change_dir_tmp/`whoami`-dialog-$( date +%Y%m%d-%H%M ).txt" + +if [ -f $fast_change_dir_config/groupname.txt ]; then + echo +else + # 如果檔案不存在,就建立文字檔案,以及建立一個預設空白的groupname + touch $fast_change_dir_config/groupname.txt + echo '""' >> $fast_change_dir_config/groupname.txt +fi + +if [ "$action" == "select" ]; then + if [ "$groupname" != "" ]; then + count=`grep -ir $groupname $fast_change_dir_config/groupname.txt | wc -l` + if [ "$count" == "0" ]; then + export groupname="" + echo "[ERROR] groupname is not exist by $groupname" + else + export groupname=$groupname + echo '[OK] export groupname success' + # 切換到Root的資料夾,預設是root,這是我建立資料夾link的方式,根目錄名稱叫root + dv root + fi + else + dialogitems=`cat $fast_change_dir_config/groupname.txt | awk -F"\n" '{ print $1 " \" \" " }' | tr "\n" ' '` + cmd=$( func_dialog_menu '請選擇專案代碼' '123' 70 "$dialogitems" "$tmpfile") + + eval $cmd + result=`cat $tmpfile` + + if [ "$result" == "" ]; then + func_statusbar '你不選嗎,別忘了要選才能使用專案功能哦' + else + export groupname=$result + echo '[OK] export groupname success' + # 切換到Root的資料夾,預設是root,這是我建立資料夾link的方式,根目錄名稱叫root + dv root + fi + fi +elif [ "$action" == "append" ]; then + if [ "$groupname" != "" ]; then + count=`grep -ir $groupname $fast_change_dir_config/groupname.txt | wc -l` + if [ "$count" == "0" ]; then + echo $groupname >> $fast_change_dir_config/groupname.txt + export groupname=$groupname + echo '[OK] append and export groupname success' + else + echo "[ERROR] groupname is exist by $groupname" + fi + else + echo "[ERROR] please fill groupname field by append action" + fi +elif [ "$action" == "edit" ]; then + vim $fast_change_dir_config/groupname.txt +else + echo '[ERROR] no support action' +fi diff --git a/hg.sh b/hg.sh new file mode 100755 index 0000000..4cbb864 --- /dev/null +++ b/hg.sh @@ -0,0 +1,706 @@ +#!/bin/bash + +source "$fast_change_dir_func/entonum.sh" + +# 這是複制svn-v3過來修改的,應該流程是有點類似的 + +# default ifs value +default_ifs=$' \t\n' + +func_hg_cache_controller() +{ + # cache的檔名也是用變數控制 + uncachefile=$1 + cachefile=$2 + + modestatus=$3 + + + # 預設都是不動作的 + clear_cache='0' + clear_uncache='0' + generate_uncache='0' + + # default ifs value + default_ifs=$' \t\n' + + if [ "$modestatus" == 'hg-status-to-uncache' ]; then + generate_uncache='1' + # 會清除,是因為是有相依性的 + clear_cache='1' + elif [ "$modestatus" == 'clear-cache' ]; then + generate_uncache='1' + # 會清除,是因為是有相依性的 + clear_cache='1' + elif [ "$modestatus" == 'clear-uncache' ]; then + clear_uncache='1' + clear_cache='1' + elif [ "$modestatus" == 'clear-all' ]; then + clear_uncache='1' + clear_cache='1' + fi + + if [ "$generate_uncache" == '1' ]; then + IFS=$'\n' + declare -a itemList + declare -a itemListTmp + declare -i num + + itemListTmp=(`hg status | grep -e '^A' -e '^M' -e '^R'`) + + cmd="rm -rf $uncachefile" + eval $cmd + + for i in ${itemListTmp[@]} + do + handle1=`echo $i | sed 's/ /___/'` + handle2=`echo $handle1 | sed 's/ /___/g'` + # 為了要解決空白檔名的問題 + itemList[$num]=$handle2 + num=$num+1 + done + num=0 + + for bbb in ${itemList[@]} + do + cmd="echo '\"$bbb\"' >> $uncachefile" + eval $cmd + done + + IFS=$default_ifs + fi + + if [ "$clear_cache" == '1' ]; then + cmd="rm -rf $cachefile" + eval $cmd + cmd="touch $cachefile" + eval $cmd + fi + + if [ "$clear_uncache" == '1' ]; then + cmd="rm -rf $uncachefile" + eval $cmd + cmd="touch $uncachefile" + eval $cmd + fi + +} + +func_relative_by_hg_append() +{ + nextRelativeItem=$1 + secondCondition=$2 + + # 檔案的位置 + fileposition=$3 + + # 顯示的方式,可能是untracked or tracked + modestatus=$4 + + # cache的檔名也是用變數控制 + uncachefile=$5 + cachefile=$6 + + declare -a itemList + declare -a itemListTmp + declare -a itemList2 + declare -a itemList2Tmp + declare -a relativeitem + + # 先把英文轉成數字,如果這個欄位有資料的話 + fileposition=( `func_entonum "$fileposition"` ) + + if [ "$fileposition" != '' ]; then + newposition=$(($fileposition - 1)) + fi + + # ignore file or dir + Success="0" + + # default ifs value + default_ifs=$' \t\n' + + IFS=$'\n' + declare -i num + + if [ "$modestatus" == 'unknow' ]; then + itemListTmp=(`hg status | grep -e '^?' -e '^!' | grep -ir $nextRelativeItem`) + elif [ "$modestatus" == 'commit' ]; then + itemListTmp=(`hg status | grep -e '^A' -e '^D' | grep -ir $nextRelativeItem`) + elif [ "$modestatus" == 'uncache' ]; then + cmd="cat $uncachefile | grep -ir $nextRelativeItem" + itemListTmp=(`eval $cmd`) + elif [ "$modestatus" == 'cache' ]; then + cmd="cat $cachefile | grep -ir $nextRelativeItem" + itemListTmp=(`eval $cmd`) + fi + + for i in ${itemListTmp[@]} + do + handle1=`echo $i | sed 's/ /___/'` + handle2=`echo $handle1 | sed 's/ /___/g'` + # 為了要解決空白檔名的問題 + itemList[$num]=$handle2 + num=$num+1 + done + IFS=$default_ifs + num=0 + + if [[ "${#itemList[@]}" -gt "1" && "$secondCondition" != '' ]]; then + + IFS=$'\n' + + if [ "$modestatus" == 'unknow' ]; then + itemList2Tmp=(`hg status | grep -e '^?' -e '^!' | grep -ir $nextRelativeItem | grep -ir $secondCondition`) + elif [ "$modestatus" == 'commit' ]; then + itemList2Tmp=(`hg status | grep -e '^A' -e '^D' | grep -ir $nextRelativeItem | grep -ir $secondCondition`) + elif [ "$modestatus" == 'uncache' ]; then + itemList2Tmp=(`cat $uncachefile | grep -ir $nextRelativeItem | grep -ir $secondCondition`) + elif [ "$modestatus" == 'cache' ]; then + itemList2Tmp=(`cat $cachefile | grep -ir $nextRelativeItem | grep -ir $secondCondition`) + fi + + for i in ${itemList2Tmp[@]} + do + handle1=`echo $i | sed 's/ /___/'` + handle2=`echo $handle1 | sed 's/ /___/g'` + # 為了要解決空白檔名的問題 + itemList2[$num]=$handle2 + num=$num+1 + done + IFS=$default_ifs + num=0 + fi + + # if empty of variable, then go back directory + if [ "$nextRelativeItem" != "" ]; then + if [ "${#itemList[@]}" == "1" ]; then + relativeitem=${itemList[0]} + #func_statusbar 'USE-ITEM' + elif [ "${#itemList[@]}" -gt 1 ]; then + + if [ "$secondCondition" != '' ]; then + # if have secondCondition, DO secondCheck + if [ "${#itemList2[@]}" == "1" ]; then + relativeitem=${itemList2[0]} + + #func_statusbar 'USE-LUCK-ITEM-BY-SECOND-CONDITION' + + Success="1" + elif [ "${#itemList2[@]}" -gt "1" ]; then + relativeitem=${itemList2[@]} + #relativeitem=$itemList2 + Success="1" + fi + fi + + # if no duplicate dirname then print them + if [ $Success == "0" ]; then + if [ "${#itemList2[@]}" -gt 0 ]; then + relativeitem=${itemList2[@]} + else + relativeitem=${itemList[@]} + fi + fi + fi + fi + + # return array的標準用法 + if [ "$relativeitem" != '' ]; then + if [ "$newposition" == '' ]; then + echo ${relativeitem[@]} + else + # 先把含空格的文字,轉成陣列 + aaa=(${relativeitem[@]}) + # 然後在指定位置輸出 + echo ${aaa[$newposition]} + fi + fi +} + +# 會寫這類的函式,是因為這個動作可能會被單項,會是多項來這裡進行觸發 +func_hg_unknow_mode() +{ + item=$1 + + # 不分兩次做,會出現前面少了一個空白,不知道為什麼 + match=`echo $item | sed 's/___/X/'` + match=`echo $match | sed 's/___/ /g'` + + # 這個變數,存的可能是?、! + hgstatus=${match:0:1} + + if [ "$hgstatus" == '?' ]; then + hg add ${match:2} + elif [ "$hgstatus" == '!' ]; then + hg remove ${match:2} + fi +} + +func_hg_commit_mode() +{ + item=$1 + + # 不分兩次做,會出現前面少了一個空白,不知道為什麼 + match=`echo $item | sed 's/___/X/'` + match=`echo $match | sed 's/___/ /g'` + + # 這個變數,存的可能是A、D + hgstatus=${match:0:1} + + if [ "$hgstatus" == 'A' ]; then + hg revert ${match:2} + elif [ "$hgstatus" == 'R' ]; then + hg revert ${match:2} + fi +} + +func_hg_uncache_mode() +{ + item=$1 + + # cache的檔名也是用變數控制 + uncachefile=$2 + cachefile=$3 + + cmd="grep '$item' $cachefile" + tmp1=`eval $cmd` + + if [ "$tmp1" == '' ]; then + cmd="echo '$item' >> $cachefile" + eval $cmd + fi + + # 先寫到暫存,然後在回寫回原來的檔案 + cmd="sed '/$item/d' $uncachefile > ${uncachefile}-hg-tmp" + eval $cmd + cmd="cp ${uncachefile}-hg-tmp $uncachefile" + eval $cmd + cmd="rm -rf ${uncachefile}-hg-tmp" + eval $cmd +} + +func_hg_cache_mode() +{ + item=$1 + + # cache的檔名也是用變數控制 + uncachefile=$2 + cachefile=$3 + + cmd="grep '$item' $uncachefile" + tmp1=`eval $cmd` + + if [ "$tmp1" == '' ]; then + cmd="echo '$item' >> $uncachefile" + eval $cmd + fi + + # 先寫到暫存,然後在回寫回原來的檔案 + cmd="sed '/$item/d' $cachefile > ${cachefile}-hg-tmp" + eval $cmd + cmd="cp ${cachefile}-hg-tmp $cachefile" + eval $cmd + cmd="rm -rf ${cachefile}-hg-tmp" + eval $cmd +} + +unset cmd +unset cmd1 +unset cmd2 +unset cmd3 + +# 只有第一次是1,有些只會執行一次,例如help +first='1' + +# 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 +clear_var_all='' + +# 倒退鍵 +# Ctrl + h +backspace=$(echo -e \\b\\c) + +# 這是模式,前面的括號是該模式的別名 +# 1. [unknow] hg status, filter by untracked, or new file, 其它都沒有哦 +# 2. [commit] hg status, filter by added, or deleted, modify一定會在裡面的(我想取commit list) +# 3. [uncache] uncache list +# 4. [cache] cache list +mode='1' + +uncachefile="$fast_change_dir_tmp/hg-uncache-`whoami`.txt" +cachefile="$fast_change_dir_tmp/hg-cache-`whoami`.txt" + +# 清理uncache的同時,也會一並清除cache,因為它們是有相依性的 +func_hg_cache_controller "$uncachefile" "$cachefile" "clear-uncache" + +while [ 1 ]; +do + clear + + if [[ "$first" == '1' || "$clear_var_all" == '1' ]]; then + unset cmd + unset condition + unset item_unknow_array + unset item_commit_array + unset item_uncache_array + unset item_cache_array + clear_var_all='' + first='' + fi + + echo 'Mercurial(Hg) (關鍵字)' + echo '=================================================' + echo "\"$groupname\" || `pwd`" + echo '=================================================' + if [ "$mode" == '1' ]; then + echo "Unknow File List" + elif [ "$mode" == '2' ]; then + echo "Commit List" + elif [ "$mode" == '3' ]; then + echo "Uncache List" + elif [ "$mode" == '4' ]; then + echo "Cache List" + else + # 為了誤動作,或是程式發生了未知的問題 + mode=1 + echo "Unknow File List" + fi + echo '=================================================' + + if [ "$mode" == '1' ]; then + # 問號是新的檔案,還未被新增進來,而驚嘆號是使用rm指令刪掉的狀況 + cmd="hg status | grep -e '^?' -e '^!'" + elif [ "$mode" == '2' ]; then + cmd="hg status | grep -e '^A' -e '^M' -e '^R'" + elif [ "$mode" == '3' ]; then + cmd="cat $uncachefile" + elif [ "$mode" == '4' ]; then + cmd="cat $cachefile" + fi + eval $cmd + + if [ "$condition" == 'quit' ]; then + break + elif [ "$condition" != '' ]; then + echo '=================================================' + echo "目前您所輸入的搜尋條件: \"$condition\"" + fi + + if [ "$condition" == '' ]; then + echo '=================================================' + echo -e "${color_txtgrn}基本快速鍵:${color_none}" + echo ' 倒退鍵 (Ctrl + H)' + echo ' 重新輸入條件 (/)' + echo ' 智慧選取單項 (;.) 分號' + echo ' 處理多項(*) 星號' + echo ' 離開 (?)' + echo -e "${color_txtgrn}Hg功能快速鍵:${color_none}" + echo ' Change Normal Mode (A)' + echo ' Change Cache Mode (B)' + echo ' Commit (C)' + echo ' Delete Cache/Uncache (D)' + echo ' Push(send!!) (E)' + echo ' Generate Uncache (G)' + echo ' Update (U)' + echo '輸入條件的結構:' + echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' + fi + + echo '=================================================' + + # 顯示重覆的Hg未知檔案 + if [ "${#item_unknow_array[@]}" -gt 1 ]; then + echo "重覆的未知Hg檔案數量: ${#item_unknow_array[@]} [*]" + number=1 + for bbb in ${item_unknow_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_unknow_array[@]}" -eq 1 ]; then + echo "未知的Hg檔案有找到一筆: ${item_unknow_array[0]} [;]" + fi + + # 顯示己經準備送出,而且狀態是新增、與刪除 + if [ "${#item_commit_array[@]}" -gt 1 ]; then + echo "重覆的準備送出的Hg,狀態為A與R的檔案數量: ${#item_commit_array[@]} [*]" + number=1 + for bbb in ${item_commit_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_commit_array[@]}" -eq 1 ]; then + echo "準備送出的Hg,狀態為A與R的檔案有找到一筆: ${item_commit_array[0]} [;]" + fi + + # 顯示Uncache項目 + if [ "${#item_uncache_array[@]}" -gt 1 ]; then + echo "重覆的Uncache檔案數量: ${#item_uncache_array[@]} [*]" + number=1 + for bbb in ${item_uncache_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_uncache_array[@]}" -eq 1 ]; then + echo "Uncache檔案有找到一筆: ${item_uncache_array[0]} [;]" + fi + + # 顯示Cache項目 + if [ "${#item_cache_array[@]}" -gt 1 ]; then + echo "重覆的Cache檔案數量: ${#item_cache_array[@]} [*]" + number=1 + for bbb in ${item_cache_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_cache_array[@]}" -eq 1 ]; then + echo "Cache檔案有找到一筆: ${item_cache_array[0]} [;]" + fi + + # 不加IFS=012的話,我輸入空格,read variable是讀不到的 + IFS=$'\012' + read -s -n 1 inputvar + IFS=$default_ifs + + if [ "$inputvar" == '?' ]; then + # 離開 + clear + break + elif [ "$inputvar" == '/' ]; then + clear_var_all='1' + continue + # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 + elif [ "$inputvar" == $backspace ]; then + condition="${condition:0:(${#condition} - 1)}" + inputvar='' + elif [ "$inputvar" == 'A' ]; then + if [ "$mode" == '1' ]; then + mode='2' + elif [ "$mode" == '2' ]; then + mode='1' + else + mode='1' + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'B' ]; then + if [ "$mode" == '3' ]; then + mode='4' + elif [ "$mode" == '4' ]; then + mode='3' + else + mode='3' + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'C' ]; then + if [[ "$mode" == '2' || "$mode" == '4' ]]; then + echo '要送出囉,但是請先輸入changelog,輸入完按Enter後直接送出' + read changelog + + if [ "$changelog" == '' ]; then + echo '為什麼你沒有輸入changelog呢?還是我幫你填上預設值呢?(no comment)好嗎?[Y1,n0]' + read inputvar2 + if [[ "$inputvar2" == 'y' || "$inputvar2" == "1" ]]; then + changelog='no comment' + elif [[ "$inputvar2" == 'n' || "$inputvar2" == "0" ]]; then + echo '如果不要預設值,那就算了' + else + echo '不好意思,不要預設值也不要來亂' + fi + fi + + if [ "$changelog" == '' ]; then + echo '你並沒有輸入changelog,所以下次在見了,本次動作取消,倒數3秒後離開' + sleep 3 + else + cmd="hg commit -m \"$changelog\" " + + if [ "$mode" == '4' ]; then + cmdcat="cat $cachefile | wc -l" + cmdcount=`eval $cmdcat` + + if [ "$cmdcount" -ge 1 ]; then + cmdlist="cat $cachefile | tr '\n' ' '" + cmdlist2=`eval $cmdlist` + + + IFS=$'\n' + cmdlist="cat $cachefile" + cmdlist2=(`eval $cmdlist`) + cmdlist3='' + + for i in ${cmdlist2[@]} + do + # 不分兩次做,會出現前面少了一個空白,不知道為什麼 + match=`echo ${i} | sed 's/___/X/'` + match=`echo $match | sed 's/___/ /g'` + cmdlist3="$cmdlist3 \"${match:3}" + done + + IFS=$default_ifs + + cmd="$cmd $cmdlist3" + else + echo '沒有可以送出的檔案,在cache裡面!!' + fi + fi + + eval $cmd + changelog='' + + if [ "$?" -eq 0 ]; then + #echo '設定Changelog成功,別忘了要選擇送出哦' + echo '要不要送出(hg push)呢?[Y1,n0]' + read inputvar3 + if [[ "$inputvar3" == 'n' || "$inputvar3" == "0" ]]; then + echo '不要送出的話,那就算了!' + else + hg push + + if [ "$?" -eq 0 ]; then + echo '送出成功' + func_hg_cache_controller "$uncachefile" "$cachefile" "clear-all" + mode=1 + else + echo '送出失敗,請自行做檢查' + fi + fi + fi + + echo '按任何鍵繼續...' + read -n 1 + fi + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'D' ]; then + if [ "$mode" == '3' ]; then + func_hg_cache_controller "$uncachefile" "$cachefile" "clear-uncache" + elif [ "$mode" == '4' ]; then + func_hg_cache_controller "$uncachefile" "$cachefile" "clear-cache" + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'E' ]; then + hg push + if [ "$?" -eq 0 ]; then + echo '更新本Hg資料夾成功' + fi + echo '按任何鍵繼續...' + read -n 1 + + clear_var_all='1' + continue + elif [ "$inputvar" == 'G' ]; then + # 匯出後,自動跳到模式3,就是Uncache mode + func_hg_cache_controller "$uncachefile" "$cachefile" "hg-status-to-uncache" + mode='3' + + clear_var_all='1' + continue + elif [ "$inputvar" == 'U' ]; then + echo '己送出更新(pull)指令,等待中...' + hg pull + echo '己送出更新(update)指令,等待中...' + hg update + + if [ "$?" -eq 0 ]; then + echo '更新本HG資料夾成功' + fi + + echo '按任何鍵繼續...' + read -n 1 + + clear_var_all='1' + continue + elif [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then + if [ ${#item_unknow_array[@]} -eq 1 ]; then + func_hg_unknow_mode "${item_unknow_array[0]}" + func_hg_cache_controller "$uncachefile" "$cachefile" "hg-status-to-uncache" + clear_var_all='1' + continue + elif [ ${#item_commit_array[@]} -eq 1 ]; then + func_hg_commit_mode "${item_commit_array[0]}" + func_hg_cache_controller "$uncachefile" "$cachefile" "hg-status-to-uncache" + clear_var_all='1' + continue + elif [ ${#item_uncache_array[@]} -eq 1 ]; then + func_hg_uncache_mode "${item_uncache_array[0]}" "$uncachefile" "$cachefile" + clear_var_all='1' + continue + elif [ ${#item_cache_array[@]} -eq 1 ]; then + func_hg_cache_mode "${item_cache_array[0]}" "$uncachefile" "$cachefile" + clear_var_all='1' + continue + fi + elif [ "$inputvar" == '*' ]; then + if [ "${#item_unknow_array[@]}" -gt 1 ]; then + for bbb in ${item_unknow_array[@]} + do + func_hg_unknow_mode "$bbb" + done + func_hg_cache_controller "$uncachefile" "$cachefile" "hg-status-to-uncache" + clear_var_all='1' + continue + elif [ "${#item_commit_array[@]}" -gt 1 ]; then + for bbb in ${item_commit_array[@]} + do + func_hg_commit_mode "$bbb" + done + func_hg_cache_controller "$uncachefile" "$cachefile" "hg-status-to-uncache" + clear_var_all='1' + continue + elif [ "${#item_uncache_array[@]}" -gt 1 ]; then + for bbb in ${item_uncache_array[@]} + do + func_hg_uncache_mode "$bbb" "$uncachefile" "$cachefile" + done + clear_var_all='1' + continue + elif [ "${#item_cache_array[@]}" -gt 1 ]; then + for bbb in ${item_cache_array[@]} + do + func_hg_cache_mode "$bbb" "$uncachefile" "$cachefile" + done + clear_var_all='1' + continue + fi + fi + + condition="$condition$inputvar" + + if [[ "$condition" =~ [[:alnum:]] ]]; then + cmds=($condition) + cmd1=${cmds[0]} + cmd2=${cmds[1]} + # 第三個引數,是位置 + cmd3=${cmds[2]} + + if [ "$mode" == '1' ]; then + item_unknow_array=( `func_relative_by_hg_append "$cmd1" "$cmd2" "$cmd3" "unknow" "" ""` ) + elif [ "$mode" == '2' ]; then + item_commit_array=( `func_relative_by_hg_append "$cmd1" "$cmd2" "$cmd3" "commit" "" ""` ) + elif [ "$mode" == '3' ]; then + item_uncache_array=( `func_relative_by_hg_append "$cmd1" "$cmd2" "$cmd3" "uncache" "$uncachefile" "$cachefile"` ) + elif [ "$mode" == '4' ]; then + item_cache_array=( `func_relative_by_hg_append "$cmd1" "$cmd2" "$cmd3" "cache" "$uncachefile" "$cachefile"` ) + fi + elif [ "$condition" == '' ]; then + # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 + clear_var_all='1' + + # 這裡不用在continue了,因為這裡是最後一行了 + fi + +done + +# 離開前,在顯示一下現在資料夾裡面的東西 +eval $cmd diff --git a/ide.sh b/ide.sh new file mode 100755 index 0000000..1ca7b12 --- /dev/null +++ b/ide.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +color_txtred='\e[0;31m' # Red +color_txtgrn='\e[0;32m' # Green +color_none='\e[0m' # No Color + +while [ 1 ]; +do + clear + echo '選擇指令介面 (ide)' + echo '=================================================' + echo "`whoami` || \"$groupname\" || `pwd`" + echo '=================================================' + echo -e "${color_txtgrn}檔案工具類:${color_none}" + echo '' + echo 'a. 英文模式 (abc)' + echo 'b. 純數字模式 (123)' + echo 'c. Search By File (sear)' + echo 'd. Search By Keyword (gre)' + echo 'e. File Explorer (nautilus .)' + echo '=================================================' + echo -e "${color_txtgrn}專案類:${color_none}" + echo '' + echo 'g. Select Project (ga)' + echo 'h. Select Shortcut (dv)' + echo '=================================================' + echo -e "${color_txtgrn}檔案操作類:${color_none}" + echo '' + echo 'i. Show Groupfile (vff)' + echo 'j. Edit Groupfile (vfff)' + echo 'k. Clear Groupfile (vffff)' + echo '=================================================' + echo -e "${color_txtgrn}版本控制類:${color_none}" + echo '' + echo 's. SVN (svnn)' + echo 't. GIT (gitt)' + echo '=================================================' + + echo -e "請輸入指令編號,或按${color_txtred}q${color_none}離開:" + + read -s -n 1 inputvar + + if [ "$inputvar" == 'q' ]; then + break + elif [ "$inputvar" == 'a' ]; then + abc + elif [ "$inputvar" == 'b' ]; then + 123 + elif [ "$inputvar" == 'c' ]; then + sear + elif [ "$inputvar" == 'd' ]; then + gre + elif [ "$inputvar" == 'e' ]; then + nautilus . + elif [ "$inputvar" == 'g' ]; then + ga + elif [ "$inputvar" == 'h' ]; then + dv + elif [ "$inputvar" == 'i' ]; then + vff + elif [ "$inputvar" == 'j' ]; then + vfff + elif [ "$inputvar" == 'k' ]; then + vffff + elif [ "$inputvar" == 's' ]; then + svnn + elif [ "$inputvar" == 't' ]; then + gitt + fi +done + +# 離開後,顯示現在所在資料夾的檔案 +clear +ls diff --git a/lib/func/dialog.sh b/lib/func/dialog.sh new file mode 100644 index 0000000..4003a8f --- /dev/null +++ b/lib/func/dialog.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# 這個是Dialog指令的選單功能 +func_dialog_menu() +{ + text=$1 + width=$2 + content=$3 + tmp=$4 + + cmd="dialog --menu '$text' 0 $width 20 $content 2> $tmp" + echo $cmd +} + +# 這個是Dialog指令的YesNo功能 +func_dialog_yesno() +{ + title=$1 + text=$2 + width=$3 + + cmd="dialog --title '$title' --yesno '$text' 7 $width" + echo $cmd +} + +# 這個是Dialog指令的inputbox功能 +func_dialog_input() +{ + title=$1 + text=$2 + width=$3 + tmp=$4 + + cmd="dialog --title '$title' --inputbox '$text' 7 $width 2> $tmp" + echo $cmd +} diff --git a/lib/func/entonum.sh b/lib/func/entonum.sh new file mode 100644 index 0000000..d7c7c1d --- /dev/null +++ b/lib/func/entonum.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# 把英文變成數字,例如er就是12 +func_entonum() +{ + en=$1 + + return=$en + + for i in ${en[@]} + do + return=`echo $return | sed 's/e/1/'` + return=`echo $return | sed 's/r/2/'` + return=`echo $return | sed 's/s/3/'` + return=`echo $return | sed 's/f/4/'` + return=`echo $return | sed 's/w/5/'` + return=`echo $return | sed 's/l/6/'` + return=`echo $return | sed 's/c/7/'` + return=`echo $return | sed 's/b/8/'` + return=`echo $return | sed 's/k/9/'` + + # 零 + return=`echo $return | sed 's/o/0/'` + return=`echo $return | sed 's/z/0/'` + done + + echo $return +} diff --git a/lib/func/ignore.sh b/lib/func/ignore.sh new file mode 100644 index 0000000..bacadb2 --- /dev/null +++ b/lib/func/ignore.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# 單純的把ls的忽略清單回傳而以 +func_getlsignore() +{ + #echo '-I .svn -I .git' + echo '' +} diff --git a/lib/func/md5.sh b/lib/func/md5.sh new file mode 100644 index 0000000..0ea4430 --- /dev/null +++ b/lib/func/md5.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +function func_md5() { +local length=${2:-32} +local string=$( echo "$1" | md5sum | awk '{ print $1 }' ) +echo ${string:0:${length}} +} diff --git a/lib/func/normal.sh b/lib/func/normal.sh new file mode 100644 index 0000000..8346e5b --- /dev/null +++ b/lib/func/normal.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# +--------+----------------------+ +# |FUNCTION| func_statusbar | +# +--------+----------------------+ +# |ARGUMENT| $1: Action Name | +# +--------+----------------------+ +func_statusbar() +{ + echo "[ACT]=>$1" + #echo "[PWD]=>`pwd`" +} + +# +--------+----------------------+ +# |FUNCTION| func_checkfilecount | +# +--------+----------------------+ +# |ARGUMENT| | +# +--------+----------------------+ +func_checkfilecount() +{ + echo "[PWD]=>`pwd`" + filecount=`ls | wc -l` + if [ "$filecount" == "0" ]; then + echo "[EMPTY]" + elif [ "$filecount" -le "6" ]; then + ls -la + else + ls + fi +} diff --git a/lib/func/relativeitem.sh b/lib/func/relativeitem.sh new file mode 100644 index 0000000..4bb9274 --- /dev/null +++ b/lib/func/relativeitem.sh @@ -0,0 +1,161 @@ +#!/bin/bash + +source "$fast_change_dir_func/md5.sh" + +func_relative() +{ + nextRelativeItem=$1 + secondCondition=$2 + + # 檔案的位置 + fileposition=$3 + + # 要搜尋哪裡的路徑,空白代表現行目錄 + lspath=$4 + + # dir or file + filetype=$5 + + # get all item flag + # 0 or empty: do not get all + # 1: Get All + isgetall=$6 + + declare -a itemList + declare -a itemListTmp + declare -a relativeitem + + if [ "$lspath" == "" ]; then + lspath=`pwd` + elif [ "$lspath" == ".." ]; then + lspath="`pwd`/../" + fi + + tmpfile="$fast_change_dir_tmp/`whoami`-function-relativeitem-$( date +%Y%m%d-%H%M ).txt" + + # ignore file or dir + # ignorelist=$(func_getlsignore) + ignorelist='' + Success="0" + + # 試著使用@來決定第一個grep,從最開啟來找字串 + firstchar=${nextRelativeItem:0:1} + isHeadSearch='' + + # 這裡要注意,不能夠使用井字號(#)來當做控制字元,會有問題 + if [ "$firstchar" == '@' ]; then + isHeadSearch='^' + nextRelativeItem=${nextRelativeItem:1} + #elif [ "$firstchar" == '*' ]; then + # nextRelativeItem=${nextRelativeItem:1} + else + firstchar='' + fi + + # 試著使用第二個引數的第一個字元,來判斷是不是position + firstchar2=${secondCondition:0:1} + + if [[ "$firstchar2" == '@' && "$fileposition" == '' ]]; then + fileposition=${secondCondition:1} + secondCondition='' + fi + + # 先把英文轉成數字,如果這個欄位有資料的話 + fileposition=( `func_entonum "$fileposition"` ) + + if [ "$fileposition" != '' ]; then + newposition=$(($fileposition - 1)) + fi + + lucky='' + if [ "$filetype" == "dir" ]; then + filetype_ls_arg='' + filetype_grep_arg='' + if [[ -d "$lspath$nextRelativeItem" && "$isgetall" != '1' ]]; then + echo "$nextRelativeItem" + exit + fi + else + filetype_ls_arg='--file-type' + filetype_grep_arg='-v' + if [[ -f "$lspath$nextRelativeItem" && "$isgetall" != '1' ]]; then + echo "$nextRelativeItem" + exit + fi + fi + + # default ifs value + default_ifs=$' \t\n' + + IFS=$'\n' + #cmd="ls -AFL $ignorelist $filetype_ls_arg $lspath | grep $filetype_grep_arg \"/$\"" + + cmd="ls -AFL $ignorelist --file-type $lspath" + + # 先去cache找看看,有沒有暫存的路徑檔案 + md5key=(`func_md5 $cmd`) + cachefile="$fast_change_dir_tmp/`whoami`-relativeitem-cache-$md5key.txt" + + # 如果該cache有存在,就改寫指令 + # 如果不存在,那在處理之前,先寫入cache + if [ ! -f "$cachefile" ]; then + cmd="$cmd > $cachefile" + eval $cmd + fi + + cmd="cat $cachefile " + + cmd="$cmd | grep $filetype_grep_arg \"/$\"" + + if [ "$isgetall" != '1' ]; then + cmd="$cmd | grep -ir $isHeadSearch$nextRelativeItem" + fi + + if [ "$secondCondition" != '' ]; then + cmd="$cmd | grep -ir $secondCondition" + fi + + # 取得項目列表,存到陣列裡面,當然也會做空白的處理 + declare -i num + itemListTmp=(`eval $cmd`) + for i in ${itemListTmp[@]} + do + # 為了要解決空白檔名的問題 + itemList[$num]=`echo $i|sed 's/ /___/g'` + num=$num+1 + done + IFS=$default_ifs + num=0 + + if [ "$nextRelativeItem" != "" ]; then + if [ "${#itemList[@]}" == "1" ]; then + relativeitem=${itemList[0]} + #func_statusbar 'USE-ITEM' + elif [ "${#itemList[@]}" -gt "1" ]; then + relativeitem=${itemList[@]} + fi + fi + + if [ "$isgetall" == '1' ]; then + if [ "${#itemList[@]}" == "1" ]; then + relativeitem=${itemList[0]} + #func_statusbar 'USE-ITEM' + elif [ "${#itemList[@]}" -gt "1" ]; then + relativeitem=${itemList[@]} + fi + fi + + # return array的標準用法 + if [ "$relativeitem" != '' ]; then + if [ "$newposition" == '' ]; then + echo ${relativeitem[@]} + else + # 先把含空格的文字,轉成陣列 + aaa=(${relativeitem[@]}) + # 然後在指定位置輸出 + echo ${aaa[$newposition]} + fi + else + echo '' + fi +} diff --git a/nopath.sh b/nopath.sh new file mode 100755 index 0000000..8c4d0d7 --- /dev/null +++ b/nopath.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +source "$fast_change_dir_func/normal.sh" +source "$fast_change_dir_func/dialog.sh" + +# default ifs value +default_ifs=$' \t\n' + +# fix space to effect array result +IFS=$'\012' + +nopath=$1 +tmpfile="$fast_change_dir_tmp/`whoami`-nopath-dialog-$( date +%Y%m%d-%H%M ).txt" + +if [ ! -f $fast_change_dir_config/nopath.txt ]; then + touch $fast_change_dir_config/nopath.txt +fi + +if [ "$nopath" != "" ]; then + result=`grep ^$nopath[[:alnum:]]*, $fast_change_dir_config/nopath.txt | cut -d, -f2` + resultarray=(`grep ^$nopath[[:alnum:]]*, $fast_change_dir_config/nopath.txt | cut -d, -f2`) + + if [ "${#resultarray[@]}" -gt "1" ]; then + cmd=$( func_dialog_menu 'Please Select nopath' 100 `grep $nopath[[:alnum:]]*, $fast_change_dir_config/nopath.txt | tr "\n" " " | tr ',' ' '` $tmpfile ) + + eval $cmd + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" == "" ]; then + echo '[ERROR] nopath is empty' + else + wv $result + fi + elif [ "${#resultarray[@]}" == "1" ]; then + cmd="cd $result" + eval $cmd + func_checkfilecount + else + echo '[ERROR] nopath is not exist!!' + fi +else + resultvalue=`cat $fast_change_dir_config/nopath.txt | wc -l` + + if [ "$resultvalue" -ge "1" ]; then + echo ${#resultarray[@]} + cmd=$( func_dialog_menu 'Please Select nopath' 100 `cat $fast_change_dir_config/nopath.txt | tr "\n" " " | tr ',' ' '` $tmpfile ) + eval $cmd + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" == "" ]; then + echo '[ERROR] nopath is empty' + else + wv $result + fi + else + echo '[ERROR] Please modify nopath file in your text config file' + fi + +fi + +tmpfile='' +IFS=$default_ifs diff --git a/pos-backdir.sh b/pos-backdir.sh new file mode 100755 index 0000000..48bd2af --- /dev/null +++ b/pos-backdir.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +Position=$1 +cd .. && . $fast_change_dir/pos-cddir.sh $Position diff --git a/pos-cddir.sh b/pos-cddir.sh new file mode 100755 index 0000000..1b6acaf --- /dev/null +++ b/pos-cddir.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# 這支檔案的運作方式,很簡單, +# 先做列表,針對資料夾,並存在陣列, +# 接下來就看你要編號多少的陣列元素,取出來而以。 + +source "$fast_change_dir_func/normal.sh" + +# default ifs value +default_ifs=$' \t\n' + +# fix space to effect array result +IFS=$'\012' + +dirPosition=$1 + +if [ "$dirPosition" != "" ]; then + dirList=(`ls -AFL | grep "/$"`) + if [ "${#dirList[@]}" -lt 1 ]; then + func_statusbar 'THERE-IS-NO-DIR' + else + if [ "${dirList[$dirPosition - 1]}" == "" ]; then + func_statusbar 'THIS-POSITION-IS-NO-DIR' + else + cd ${dirList[$dirPosition - 1]} + # check file count and ls action + func_checkfilecount + fi + fi +else + func_statusbar 'PLEASE-INPUT-ARG01' +fi + +IFS=$default_ifs diff --git a/pos-editfile.sh b/pos-editfile.sh new file mode 100755 index 0000000..3c5a7e7 --- /dev/null +++ b/pos-editfile.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +source "$fast_change_dir_func/normal.sh" + +# default ifs value +default_ifs=$' \t\n' + +# fix space to effect array result +IFS=$'\012' + +filePosition=$1 + +if [ "$filePosition" != "" ]; then + fileList=(`ls -AFL --file-type|grep -v "/$"`) + if [ "${#fileList[@]}" -lt 1 ]; then + func_statusbar 'THERE-IS-NO-FILE' + else + if [ "${fileList[$filePosition - 1]}" == "" ]; then + func_statusbar 'THIS-POSITION-IS-NO-FILE' + else + vim ${fileList[$filePosition - 1]} + fi + fi +else + func_statusbar 'PLEASE-INPUT-ARG01' +fi + +IFS=$default_ifs diff --git a/pos-vimlist-append.sh b/pos-vimlist-append.sh new file mode 100755 index 0000000..adf8ef4 --- /dev/null +++ b/pos-vimlist-append.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +source "$fast_change_dir_func/normal.sh" + +# default ifs value +default_ifs=$' \t\n' + +# fix space to effect array result +IFS=$'\012' + +filePosition=$1 + +if [ "$filePosition" != "" ]; then + fileList=(`ls -AFL --file-type|grep -v "/$"`) + if [ "${#fileList[@]}" -lt 1 ]; then + func_statusbar 'THERE-IS-NO-FILE' + else + if [ "${fileList[$filePosition - 1]}" == "" ]; then + func_statusbar 'THIS-POSITION-IS-NO-FILE' + else + . $fast_change_dir/vimlist-append.sh ${fileList[$filePosition - 1]} + fi + fi +else + func_statusbar 'PLEASE-INPUT-ARG01' +fi + +IFS=$default_ifs diff --git a/search.sh b/search.sh new file mode 100755 index 0000000..df3eac5 --- /dev/null +++ b/search.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +# IDEA +# 本程式想要寫搜尋專案裡面的檔案 +# 然後,編輯搜尋到的結果 + +if [ "$groupname" != '' ]; then + dv root +fi + +tmpfile="$fast_change_dir_tmp/`whoami`-search-$( date +%Y%m%d-%H%M ).txt" + +nowpath=`pwd` + +unset condition + +while [ 1 ]; +do + clear + + if [ "$condition" == '' ]; then + echo '即時搜尋檔案名稱' + echo '=================================================' + echo "\"$groupname\" || $nowpath" + echo '=================================================' + fi + + if [ "$condition" == 'quit' ]; then + clear + break + elif [ "$condition" != '' ]; then + echo "目前您所輸入的搜尋檔案名稱的條件: $condition" + echo '=================================================' + find . -iname \*$condition\* | grep -v "\.svn" | grep -v "\.git" | grep -v "Zend" | nl -s: -w1 > $tmpfile + cat $tmpfile + elif [ "$condition" == '' ]; then + echo '快速鍵:' + echo ' 倒退鍵 (Ctrl + H)' + echo ' 重新輸入條件 (/)' + echo ' 以數字選擇項目 (單引號)' + echo ' 離開 (?)' + echo '=================================================' + fi + + + read -s -n 1 inputvar + + condition="$condition$inputvar" + + if [ "$inputvar" == '?' ]; then + # 離開 + clear + break + elif [ "$inputvar" == '/' ]; then + unset condition + continue + elif [[ "$inputvar" == "'" && "$condition" != "'" ]]; then + echo '請輸入編號,輸入完請按Enter,輸入0是取消' + read inputvar2 + selectfile=`grep "^$inputvar2:" $tmpfile | sed "s/^$inputvar2:\.\///"` + + if [[ "$groupname" == '' && "$inputvar2" != '0' ]]; then + run="vim $selectfile" + eval $run + elif [[ "$groupname" != '' && "$inputvar2" != '0' ]]; then + # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append + selectitem='' + selectitem=`pwd`/$selectfile + checkline=`grep "$selectitem" $fast_change_dir_config/vimlist-$groupname.txt | wc -l` + if [ "$checkline" -lt 1 ]; then + echo "\"$selectitem\"" >> $fast_change_dir_config/vimlist-$groupname.txt + cat $fast_change_dir_config/vimlist-$groupname.txt + else + echo '[NOTICE] File is exist' + fi + selectitem='' + + # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 + echo '[WAIT] 確定,是編輯暫存檔案[N0,y1]' + read -n 1 inputvar3 + if [[ "$inputvar3" == 'y' || "$inputvar3" == "1" ]]; then + vff + elif [[ "$inputvar3" == 'n' || "$inputvar3" == "0" ]]; then + echo "Your want append other file" + else + echo "Your want append other file" + fi + fi + unset condition + fi + +done diff --git a/study/IFS.txt b/study/IFS.txt new file mode 100644 index 0000000..dc6fc57 --- /dev/null +++ b/study/IFS.txt @@ -0,0 +1,28 @@ +http://fvue.nl/wiki/Bash:_Show_IFS_value + + Problem + +How do I check the value of the IFS (Internal Field Separator) variable? The default value is space, tab and newline so echo $IFS would show me just whitespace... +Solution 1: od + +$ echo -n "$IFS" | od -abc +0000000 sp ht nl + 040 011 012 + \t \n +0000003 + +Solution 2: cat + +$ echo -n "$IFS" | cat -vTE + ^I$ + +Restore default IFS + +$ IFS=$' \t\n' + +Backup and restore IFS + +$ OLDIFS=$IFS IFS=$'\n' +$ # do something +$ IFS=$OLDIFS + diff --git a/study/array.sh b/study/array.sh new file mode 100644 index 0000000..e3d4b5e --- /dev/null +++ b/study/array.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +aaa=(123 456 789) + +# echo all array element +#echo ${aaa[@]} + +# echo first array element +echo ${aaa[0]} diff --git a/study/backspace.sh b/study/backspace.sh new file mode 100644 index 0000000..56fce61 --- /dev/null +++ b/study/backspace.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +backspace=$(echo -e \\b\\c) + +echo 'please input backspace' +# 您可以利用Ctrl + H,就可以讀取到"倒退鍵" +read inputvar + +if [ "$inputvar" == $backspace ]; then + echo 'READ backspace!' +fi diff --git a/study/bash-disable-input.mkd b/study/bash-disable-input.mkd new file mode 100644 index 0000000..82b47a0 --- /dev/null +++ b/study/bash-disable-input.mkd @@ -0,0 +1,17 @@ +### Bash disable input + +bash可不可以取消輸入指令, + +我是希望在某些狀況下, + +例如錯誤的時候,後面幾秒鐘是不能夠輸入指令的。 + +可以試著使用以下的指令 + +就是2秒鐘內的輸入,都會被它吃掉,試試看 + +但是它的說明,timeout內時間沒有輸入,是return false的 + + read -n 1 -t 2 + +<http://www.lslnet.com/linux/f/docs1/i62/big5409687.htm> diff --git a/study/bash-many-param.sh b/study/bash-many-param.sh new file mode 100644 index 0000000..5daca13 --- /dev/null +++ b/study/bash-many-param.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# http://www.ibm.com/developerworks/library/l-bash-parameters.html?ca=drs- + +echo "$# parameters" +echo "$@" + +#aaa=($@) +#echo ${#aaa[@]} diff --git a/study/beep.mkd b/study/beep.mkd new file mode 100644 index 0000000..7950bdd --- /dev/null +++ b/study/beep.mkd @@ -0,0 +1,9 @@ +### 如何讓這個專案有聲音 + +我可能在輸入錯指令的時候,就會出個聲音,讓我知道 + +#### 參考的網址 + +可以在bash, vim等地方設定disable sound + +<http://fvue.nl/wiki/Bash:_Beep> diff --git a/study/color.sh b/study/color.sh new file mode 100644 index 0000000..a54f3cf --- /dev/null +++ b/study/color.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +txtblk='\e[0;30m' # Black - Regular +txtred='\e[0;31m' # Red +txtgrn='\e[0;32m' # Green +txtylw='\e[0;33m' # Yellow +txtblu='\e[0;34m' # Blue +txtpur='\e[0;35m' # Purple +txtcyn='\e[0;36m' # Cyan +txtwht='\e[0;37m' # White +bldblk='\e[1;30m' # Black - Bold +bldred='\e[1;31m' # Red +bldgrn='\e[1;32m' # Green +bldylw='\e[1;33m' # Yellow +bldblu='\e[1;34m' # Blue +bldpur='\e[1;35m' # Purple +bldcyn='\e[1;36m' # Cyan +bldwht='\e[1;37m' # White +unkblk='\e[4;30m' # Black - Underline +undred='\e[4;31m' # Red +undgrn='\e[4;32m' # Green +undylw='\e[4;33m' # Yellow +undblu='\e[4;34m' # Blue +undpur='\e[4;35m' # Purple +undcyn='\e[4;36m' # Cyan +undwht='\e[4;37m' # White +bakblk='\e[40m' # Black - Background +bakred='\e[41m' # Red +badgrn='\e[42m' # Green +bakylw='\e[43m' # Yellow +bakblu='\e[44m' # Blue +bakpur='\e[45m' # Purple +bakcyn='\e[46m' # Cyan +bakwht='\e[47m' # White +txtrst='\e[0m' # Text Reset +NC='\e[0m' # No Color + +echo -e "${bldgrn}dir${NC}" + diff --git a/study/cut-by-length.sh b/study/cut-by-length.sh new file mode 100644 index 0000000..e0273e0 --- /dev/null +++ b/study/cut-by-length.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +aaa='123456' + +# result: 456 +echo ${aaa:3} diff --git a/study/find.txt b/study/find.txt new file mode 100644 index 0000000..b972040 --- /dev/null +++ b/study/find.txt @@ -0,0 +1,41 @@ +# update: 2010-09-26 + +find 的指令使用方式 + +最基本的搜尋方式 +搜尋本資料夾底下的所有副檔名是txt的檔案 +find . -name \*.txt +另外,-iname是不管大小寫的,這個可能比較實用 + +-prune +不顯示經過的資料夾與子資料夾, +只顯示搜尋的資料夾,與搜尋的結果 + +-type +如果引數是f,就是搜尋檔案 +如果是d,就是搜尋資料夾 +還可以搜尋socket(s)等其它 + +-xtype +搜尋symbolink用的,也就是會跟隨連結 + +-f(ls|print) file +將結果寫入檔案 +如果是-fprint0或者是-print0 +出現的結果都是沒有斷行的,我也不知道這要用在什麼地方 + +-printf +依照指定的格式,把檔案顯示出來 + +-delete +將找到的東西,給砍了 + +-empty +尋找空白的檔案 + +另外,如果是用find .(點)來搜尋檔案的話, +會出現以下的搜尋結果: +./aaa.txt +如果我想取得它的絕對路徑要怎麼做呢? +使用以下的指令: +readlink -m ./aaa.txt diff --git a/study/getwidth.sh b/study/getwidth.sh new file mode 100644 index 0000000..b3e7133 --- /dev/null +++ b/study/getwidth.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# 顯示Terminal的寬度 + +width=`tput cols` +echo $width diff --git a/study/git.txt b/study/git.txt new file mode 100644 index 0000000..77cfcae --- /dev/null +++ b/study/git.txt @@ -0,0 +1,53 @@ +# update: 2011-01-27 + +如何把tracked的檔案,給忽略掉 + + git update-index --assume-unchanged <file> + git update-index --no-assume-unchanged <file> + +http://www.pagebakers.nl/2009/01/29/git-ignoring-changes-in-tracked-files/ + +# update: 2010-11-14 + +如果要使用git status -s(short)的功能 +必需要git 1.7.1以上(可能),因為我剛開始是拿ubuntu 10.10來試的 + +因為ubuntu 9.10所裝的,是1.6.3.3 +所以必需要自己compile + +depend package: +zlib +http://sourceforge.net/projects/libpng/files/zlib/1.2.5/zlib-1.2.5.tar.gz/download + +main package: +git 1.7.1 +http://www.kernel.org/pub/software/scm/git/git-1.7.1.1.tar.gz + +接下來,是git status的應用 +輸入git status -s,就會出現以下的狀況 + +如果是這樣子,代表是新增加的檔案,而還未加入到index的狀態 +?? study/123.sh + +如果是這樣子,代表是新增加的檔案,己經加入到index裡面 +A study/123.sh + +如果是這樣,代表是修改過後,但等待加入index裡面 + M bashrc.txt + +如果是這樣,代表己加入到index裡面 +M bashrc.txt + +以下這個指令,可以把加入到index裡面的項目,變更成未加入 +這個指令,適用於Modify and Add +git reset [filepath and filename] + +如果要回復git rm指令的話, +可以試著用git reset --hard指令,不過這個指令會把所有檔案回到head的版本。 + +如果直接刪除online的檔案,會出現Changed but not updated +如果是用git rm 來刪除檔案,會出現Changes to be committed +如果不要刪掉那個檔案,想救回來,那就使用git checkout FILE指令 + +參考網址: +http://bbs.nkfust.edu.tw/cgi-bin/bbscon?board=linux&file=M.1230247848.A&num=589 diff --git a/study/google-search.pl b/study/google-search.pl new file mode 100644 index 0000000..6df1117 --- /dev/null +++ b/study/google-search.pl @@ -0,0 +1,75 @@ +#!/usr/bin/perl +# google.pl - command line tool to search google +# +# Since I wrote goosh.org I get asked all the time if it could be used on the command line. +# Goosh.org is written in Javascript, so the answer is no. But google search in the shell +# is really simple, so I wrote this as an example. Nothing fancy, just a starting point. +# +# 2009 by Stefan Grothkopp, this code is public domain use it as you wish! + +# 這個檔案是參考用的,如果要修改,請看上一層的gisanfu-google-search.pl + +use LWP::Simple; +use Term::ANSIColor; + +# 參考http://blog.wu-boy.com/2009/07/01/1492/ +# 沒有加這一段的話,可能會出現以下的錯誤訊息 +# Wide character in print... +use utf8; +binmode(STDIN, ':encoding(utf8)'); +binmode(STDOUT, ':encoding(utf8)'); +binmode(STDERR, ':encoding(utf8)'); + +# change this to false for b/w output +$use_color = 0; +#result size: large=8, small=4 +$result_size = "large"; + +# unescape unicode characters in" content" +sub unescape { + my($str) = splice(@_); + $str =~ s/\\u(.{4})/chr(hex($1))/eg; + return $str; +} + +# number of command line args +$numArgs = $#ARGV + 1; + +if($numArgs ==0){ + # print usage info if no argument is given + print "[ERROR] Usage:\n"; + print "$0 <searchterm>\n"; +} +else { + # use first argument as query string + $q = $ARGV[0]; + # url encode query string + $q =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg; + + # get json encoded search result from google ajax api + my $content = get("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&start=0&rsz=$result_size&q=$q"); #Get web page in content + die "[ERROR]" if (!defined $content); + + $i = 1; + # ugly result parsing (did not want to depend on a parser lib for this quick hack) + while($content =~ s/"unescapedUrl":"([^"]*)".*?"titleNoFormatting":"([^"]*)".*?"content":"([^"]*)"//){ + + # those three data items are extrated, there are more + $title = unescape($2); + $desc = unescape($3); + $url = unescape($1); + + # print result + if($use_color){ + print colored ['red'], "[$i] "; + print colored ['blue'], "$title\n"; + print "$desc\n"; + print colored ['green'], "$url\n\n"; + print color 'reset'; + } + else{ + print "[$i] $title\n$desc\n$url\n\n"; + } + $i++; + } +} diff --git a/study/grep.txt b/study/grep.txt new file mode 100644 index 0000000..1da769d --- /dev/null +++ b/study/grep.txt @@ -0,0 +1,3 @@ +# update: 2010-09-26 + + diff --git a/study/hg.txt b/study/hg.txt new file mode 100644 index 0000000..91aa3f0 --- /dev/null +++ b/study/hg.txt @@ -0,0 +1,25 @@ +# update: 2010-12-16 + +hg status +這個指令可以看到修改或是沒有新增的檔案等。 + +hg revert +將特定的檔案或目錄回復成較早的狀態 +有修改過的檔案,如果之前己送進去過,那狀態會變成M, +如果這時候下hg revert file的話,會回復之前的狀態, +然後會變這個修改過後的內容,在回復狀態之前,會複製成file.orig的檔案(只要加上--no-backup引數,就不會複製了)。 +如果刪除了一個檔案,也可以用這個指令來回復。 +如果你用的是hg remove來刪除的話,一樣可以回復。 + +hg pull +http://cb.esast.com/cb/wiki/19277 +以上這個網址,可以看得到pull和update的差異性 + +hg remove +可以刪檔案,刪了以後,檔案的狀態會變成R, +如果你是直接用系統指令rm來砍的話,狀態會變成!, +這兩種方式都可以用hg revert來回復。 + +# 參考文章 +http://inet6.blogspot.com/2010/09/mercurial.html +http://liluo.org/2010/11/%E5%AD%A6%E4%B9%A0hgmercurial%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/ diff --git a/study/ls.txt b/study/ls.txt new file mode 100644 index 0000000..2c504bc --- /dev/null +++ b/study/ls.txt @@ -0,0 +1,60 @@ +# update: 2010-09-25 + +ls 指令研究 + +-I [ignore file or dir name] +--ignore +另外,--hide好像有相反的結果 +範例 +-I .svn -I *.txt -I *.as + +-Gg +其實是分成-G和-g,我只是寫在一起而以 +ignore owner and group + +-1 +一般預設的ls,會顯示橫的 +而這個指令讓它變成直的 + +-A +不顯示.和.. + +-F +資料夾後面加斜線 +執行檔後面加上星號 +symlink後面加上小老鼠(@) + +--file-type +跟-A加上-F(也就是-AF)的結果是一樣的 + +-R +每一個資料夾都跑一下 + +-Q +--quote-name +在每個項目都加上雙引號, +這對有空白的項目是有幫助的 + +-m +每個項目,都用逗點隔開 +這個選項會去replace其它的設定 + +-x +--format=h +--format=horizontal +如果是純ls的指令,加上-x, +那就會是下面的顯示方式 +1 4 7 +2 5 8 +3 6 9 +如果是-C(vertical) +就會是下面的樣子 +1 2 3 +4 5 6 +7 8 9 + +--quoting-style=(literal|shell|shell-always|c|c-maybe|escape|locale|clocale) +如果是c,就會加上雙引,如果是escape,就會在需要的時候,加上跳脫字元 + +--width=COLS +可以指定寬度,讓純ls橫向顯示的檔案,能夠依照固定的寬度來的顯示 diff --git a/study/microsoft-natural-ergonomic-4000-ubuntu.txt b/study/microsoft-natural-ergonomic-4000-ubuntu.txt new file mode 100644 index 0000000..a6b33d2 --- /dev/null +++ b/study/microsoft-natural-ergonomic-4000-ubuntu.txt @@ -0,0 +1,19 @@ +Microsoft Natural Ergonomic 4000 keyboard +這一個鍵盤,我在想,上面有5個快速鍵,Ubuntu的用戶可以使用它們嗎? +答案是可以的,請參考以下的網址 + +http://superuser.com/questions/57720/can-i-use-the-my-favorites-keys-of-the-microsoft-natural-ergonomic-4000-keyboard + +在terminal的時候,可能就按最愛1 +在firefox的時候,可能就按最愛2 + +最愛1的設定方式 +就直接呼叫那支gisanfu-cmd-refresh-firefox.sh + +最愛2的設定方式 +1. 在"gnome-terminal"的地方,選"編輯/設定組合偏好設定" +2. 選擇"標題與指令"的tab +3. 在"當終端機指定設為他們本身的標題"的那一項,選下拉"添加初始標題" +4. 依據上面的網址,裡面的設定方式,輸入以下的指令 + +wmctrl -R "終端機" diff --git a/study/nautilus.txt b/study/nautilus.txt new file mode 100644 index 0000000..ee20513 --- /dev/null +++ b/study/nautilus.txt @@ -0,0 +1,8 @@ +# update: 2010-12-07 + +使用ubuntu 9.10的時候,有可能會出現Eel-CRITICAL的問題 + +請照以下的作法來修正 + +add-apt-repository ppa:erez-volk/nautilus +apt-get upgrade diff --git a/study/regex.sh b/study/regex.sh new file mode 100644 index 0000000..6ced525 --- /dev/null +++ b/study/regex.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +item='"dir"@' +# 正規的外面要用雙引包起來 +regex="^\"(.*)\"@$" + +if [[ "$item" =~ $regex ]]; then + echo 'match symbolic' + echo ${BASH_REMATCH[1]} +fi diff --git a/study/sed.txt b/study/sed.txt new file mode 100644 index 0000000..3b2c21e --- /dev/null +++ b/study/sed.txt @@ -0,0 +1,8 @@ +# update: 2010-12-30 + +如何刪掉一行,使用某一個關鍵字 +使用下面那一個指令,會把123.txt的文字檔倒出來,但是會忽略關鍵字為aaabbbccc + +sed "/aaabbbccc/d" 123.txt + +http://www.linuxquestions.org/questions/general-10/how-to-delete-a-line-from-a-text-file-with-shell-script-programming-139785/ diff --git a/study/sort.txt b/study/sort.txt new file mode 100644 index 0000000..91180f0 --- /dev/null +++ b/study/sort.txt @@ -0,0 +1,5 @@ +# update: 2010-12-02 + +sort + +-u --unique 相同的行內容,只會顯示一行 diff --git a/study/split.sh b/study/split.sh new file mode 100644 index 0000000..f9b07bd --- /dev/null +++ b/study/split.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +aaa='aaa,bbb,ccc' + +#echo ${aaa#*,} +arr1=(`echo "$aaa" | tr "," " "`) + +for bbb in ${arr1[@]} +do + echo $bbb +done diff --git a/study/string_length.sh b/study/string_length.sh new file mode 100644 index 0000000..e03e4b0 --- /dev/null +++ b/study/string_length.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +aaa='123456' + +echo ${#aaa} diff --git a/study/sudo.mkd b/study/sudo.mkd new file mode 100644 index 0000000..512875b --- /dev/null +++ b/study/sudo.mkd @@ -0,0 +1,29 @@ +### SUDO + +相關說明內容 + +### 在Ubuntu以及Centos都可以使用的作法 + +先輸入以下的指令 + + # visudo + +然後參考以下的設定 + + Defaults env_reset , timestamp_timeout=0 + +`timestamp_timeout`設定成0,就可以每次都要require password + +<http://www.webupd8.org/2010/04/how-to-change-sudo-password-time-out-in.html> + +### 如何讓sudo後,馬上忘記密碼 + +<http://www.wains.be/index.php/2008/01/23/sudo-password-timeout/> + +<http://www.linuxquestions.org/questions/linux-general-1/being-su-or-sudo-is-there-a-time-out-764491/> + +<http://crunchbanglinux.org/forums/topic/9263/solveddrop-sudo-privileges/> + +以上的連結都試不成功,目前只知道,在登入前,可以先下個`sudo -k`的指令 + +<http://ubuntuforums.org/showthread.php?p=9804691> diff --git a/study/vim.txt b/study/vim.txt new file mode 100644 index 0000000..7addf32 --- /dev/null +++ b/study/vim.txt @@ -0,0 +1,9 @@ +# update: 2010-11-18 + +Q: vim如何跳到最後append進來的檔案 + +A: 假設最後append進來的是bbb.txt檔案,那就執行以下的指令 + vim -p aaa.txt bbb.txt +tabnext + + 如果是3個檔案,然後要移到第3個檔案,那就下以下的指令 + vim -p aaa.txt bbb.txt ccc.txt +tabnext +tabnext diff --git a/study/window.sh b/study/window.sh new file mode 100644 index 0000000..1e21097 --- /dev/null +++ b/study/window.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# 切換到firefox的視窗,然後按下Ctrl+r重新refresh + +wmctrl -R "firefox" + +xmacroplay -d 10 $DISPLAY << ~~~ +KeyStrPress Control_L +KeyStrPress r +KeyStrRelease r +KeyStrRelease Control_L +~~~ + diff --git a/svn-2.sh b/svn-2.sh new file mode 100755 index 0000000..c526e30 --- /dev/null +++ b/svn-2.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +# 這是svn第2個版本, +# 主要的功能,是用快速鍵來操作 + +while [ 1 ]; +do + clear + + echo 'SVN (英文字母)' + echo '=================================================' + echo "現行資料夾: `pwd`" + echo '=================================================' + echo '基本快速鍵:' + echo ' 離開 (?)' + echo 'Svn功能快速鍵:' + echo ' a. Status -q' + echo ' b. Status' + echo ' c. Update' + echo ' d. Commit' + echo '其它相關功能:' + echo ' i. 以版本號編輯檔案 (別忘了使用前要先update一下) [需要ga]' + echo '=================================================' + + read -s -n 1 inputvar + + if [ "$inputvar" == '?' ]; then + # 離開 + clear + break + elif [[ "$inputvar" == 'a' || "$inputvar" == 'A' ]]; then + svn status -q + if [ "$?" -eq 0 ]; then + echo '顯示本資料夾的SVN狀態,但不顯示問號的動作成功' + fi + echo '按任何鍵繼續...' + read -n 1 + elif [[ "$inputvar" == 'b' || "$inputvar" == 'B' ]]; then + svn status + if [ "$?" -eq 0 ]; then + echo '顯示本資料夾的SVN狀態成功' + fi + echo '按任何鍵繼續...' + read -n 1 + elif [[ "$inputvar" == 'c' || "$inputvar" == 'C' ]]; then + svn update + if [ "$?" -eq 0 ]; then + echo '更新本SVN資料夾成功' + fi + echo '按任何鍵繼續...' + read -n 1 + elif [[ "$inputvar" == 'd' || "$inputvar" == 'D' ]]; then + echo '要送出了,但是請先輸入changelog,別忘了要大於5個字元,輸入完請按Enter' + read changelog + if [ "$changelog" == '' ]; then + echo '為什麼你沒有輸入changelog呢?還是我幫你填上預設值呢?(no comment)好嗎?[Y1,n0]' + read inputvar2 + if [[ "$inputvar2" == 'y' || "$inputvar2" == "1" ]]; then + changelog='no comment' + elif [[ "$inputvar2" == 'n' || "$inputvar2" == "0" ]]; then + echo '如果不要預設值,那就算了' + else + echo '不好意思,不要預設值也不要來亂' + fi + fi + if [ "$changelog" == '' ]; then + echo '你並沒有輸入changelog,所以下次在見了,本次動作取消,倒數3秒後離開' + sleep 3 + else + svn commit -m "$changelog" + changelog='' + if [ "$?" -eq 0 ]; then + echo 'Commit成功' + fi + echo '按任何鍵繼續...' + read -n 1 + fi + elif [[ "$inputvar" == 'i' || "$inputvar" == 'I' ]]; then + . /bin/gisanfu-dirpoint.sh root && svn log -v | more && /bin/gisanfu-svn-edit-revision.sh && cd - + fi + +done + +# 離開前,在顯示一下現在資料夾裡面的東西 +eval $cmd diff --git a/svn-3.sh b/svn-3.sh new file mode 100755 index 0000000..b995f76 --- /dev/null +++ b/svn-3.sh @@ -0,0 +1,692 @@ +#!/bin/bash + +source "$fast_change_dir_func/entonum.sh" + +# 這是svn第3個版本 +# 主要的特色是增加了svnlist的功能 +# 可以只針對某一些檔案做送出 +# 這個版本是不會去處理沖衝的狀態 + +# default ifs value +default_ifs=$' \t\n' + +func_svn_cache_controller() +{ + # cache的檔名也是用變數控制 + uncachefile=$1 + cachefile=$2 + + modestatus=$3 + + + # 預設都是不動作的 + clear_cache='0' + clear_uncache='0' + generate_uncache='0' + + # default ifs value + default_ifs=$' \t\n' + + if [ "$modestatus" == 'svn-status-to-uncache' ]; then + generate_uncache='1' + # 會清除,是因為是有相依性的 + clear_cache='1' + elif [ "$modestatus" == 'clear-cache' ]; then + generate_uncache='1' + # 會清除,是因為是有相依性的 + clear_cache='1' + elif [ "$modestatus" == 'clear-uncache' ]; then + clear_uncache='1' + clear_cache='1' + elif [ "$modestatus" == 'clear-all' ]; then + clear_uncache='1' + clear_cache='1' + fi + + if [ "$generate_uncache" == '1' ]; then + IFS=$'\n' + declare -a itemList + declare -a itemListTmp + declare -i num + + itemListTmp=(`svn status | grep -e '^A' -e '^M' -e '^D'`) + + cmd="rm -rf $uncachefile" + eval $cmd + + for i in ${itemListTmp[@]} + do + # 解決狀態與物件間的7個空白 + # XXXXXXXXXXXXXXXXXXXXXXXX1234567X + handle1=`echo $i | sed 's/ /___/'` + handle2=`echo $handle1 | sed 's/ /___/g'` + # 為了要解決空白檔名的問題 + itemList[$num]=$handle2 + num=$num+1 + done + num=0 + + for bbb in ${itemList[@]} + do + cmd="echo '\"$bbb\"' >> $uncachefile" + eval $cmd + done + + IFS=$default_ifs + fi + + if [ "$clear_cache" == '1' ]; then + cmd="rm -rf $cachefile" + eval $cmd + cmd="touch $cachefile" + eval $cmd + fi + + if [ "$clear_uncache" == '1' ]; then + cmd="rm -rf $uncachefile" + eval $cmd + cmd="touch $uncachefile" + eval $cmd + fi + +} + +func_relative_by_svn_append() +{ + nextRelativeItem=$1 + secondCondition=$2 + + # 檔案的位置 + fileposition=$3 + + # 顯示的方式,可能是untracked or tracked + modestatus=$4 + + # cache的檔名也是用變數控制 + uncachefile=$5 + cachefile=$6 + + declare -a itemList + declare -a itemListTmp + declare -a itemList2 + declare -a itemList2Tmp + declare -a relativeitem + + # 先把英文轉成數字,如果這個欄位有資料的話 + fileposition=( `func_entonum "$fileposition"` ) + + if [ "$fileposition" != '' ]; then + newposition=$(($fileposition - 1)) + fi + + # ignore file or dir + Success="0" + + # default ifs value + default_ifs=$' \t\n' + + IFS=$'\n' + declare -i num + + if [ "$modestatus" == 'unknow' ]; then + itemListTmp=(`svn status | grep -e '^?' -e '^!' | grep -ir $nextRelativeItem`) + elif [ "$modestatus" == 'commit' ]; then + itemListTmp=(`svn status | grep -e '^A' -e '^D' | grep -ir $nextRelativeItem`) + elif [ "$modestatus" == 'uncache' ]; then + cmd="cat $uncachefile | grep -ir $nextRelativeItem" + itemListTmp=(`eval $cmd`) + elif [ "$modestatus" == 'cache' ]; then + cmd="cat $cachefile | grep -ir $nextRelativeItem" + itemListTmp=(`eval $cmd`) + fi + + for i in ${itemListTmp[@]} + do + # 解決狀態與物件間的7個空白 + # XXXXXXXXXXXXXXXXXXXXXXXX1234567X + handle1=`echo $i | sed 's/ /___/'` + handle2=`echo $handle1 | sed 's/ /___/g'` + # 為了要解決空白檔名的問題 + itemList[$num]=$handle2 + num=$num+1 + done + IFS=$default_ifs + num=0 + + if [[ "${#itemList[@]}" -gt "1" && "$secondCondition" != '' ]]; then + + IFS=$'\n' + + if [ "$modestatus" == 'unknow' ]; then + itemList2Tmp=(`svn status | grep -e '^?' -e '^!' | grep -ir $nextRelativeItem | grep -ir $secondCondition`) + elif [ "$modestatus" == 'commit' ]; then + itemList2Tmp=(`svn status | grep -e '^A' -e '^D' | grep -ir $nextRelativeItem | grep -ir $secondCondition`) + elif [ "$modestatus" == 'uncache' ]; then + itemList2Tmp=(`cat $uncachefile | grep -ir $nextRelativeItem | grep -ir $secondCondition`) + elif [ "$modestatus" == 'cache' ]; then + itemList2Tmp=(`cat $cachefile | grep -ir $nextRelativeItem | grep -ir $secondCondition`) + fi + + for i in ${itemList2Tmp[@]} + do + # 解決狀態與物件間的7個空白 + # XXXXXXXXXXXXXXXXXXXXXXXX1234567X + handle1=`echo $i | sed 's/ /___/'` + handle2=`echo $handle1 | sed 's/ /___/g'` + # 為了要解決空白檔名的問題 + itemList2[$num]=$handle2 + num=$num+1 + done + IFS=$default_ifs + num=0 + fi + + # if empty of variable, then go back directory + if [ "$nextRelativeItem" != "" ]; then + if [ "${#itemList[@]}" == "1" ]; then + relativeitem=${itemList[0]} + #func_statusbar 'USE-ITEM' + elif [ "${#itemList[@]}" -gt 1 ]; then + + if [ "$secondCondition" != '' ]; then + # if have secondCondition, DO secondCheck + if [ "${#itemList2[@]}" == "1" ]; then + relativeitem=${itemList2[0]} + + #func_statusbar 'USE-LUCK-ITEM-BY-SECOND-CONDITION' + + Success="1" + elif [ "${#itemList2[@]}" -gt "1" ]; then + relativeitem=${itemList2[@]} + #relativeitem=$itemList2 + Success="1" + fi + fi + + # if no duplicate dirname then print them + if [ $Success == "0" ]; then + if [ "${#itemList2[@]}" -gt 0 ]; then + relativeitem=${itemList2[@]} + else + relativeitem=${itemList[@]} + fi + fi + fi + fi + + # return array的標準用法 + if [ "$relativeitem" != '' ]; then + if [ "$newposition" == '' ]; then + echo ${relativeitem[@]} + else + # 先把含空格的文字,轉成陣列 + aaa=(${relativeitem[@]}) + # 然後在指定位置輸出 + echo ${aaa[$newposition]} + fi + fi +} + +# 會寫這類的函式,是因為這個動作可能會被單項,會是多項來這裡進行觸發 +func_svn_unknow_mode() +{ + item=$1 + + # 不分兩次做,會出現前面少了一個空白,不知道為什麼 + match=`echo $item | sed 's/___/X/'` + match=`echo $match | sed 's/___/ /g'` + + # 這個變數,存的可能是?、! + svnstatus=${match:0:1} + + if [ "$svnstatus" == '?' ]; then + svn add ${match:2} + elif [ "$svnstatus" == '!' ]; then + svn rm ${match:2} + fi +} + +func_svn_commit_mode() +{ + item=$1 + + # 不分兩次做,會出現前面少了一個空白,不知道為什麼 + match=`echo $item | sed 's/___/X/'` + match=`echo $match | sed 's/___/ /g'` + + # 這個變數,存的可能是A、D + svnstatus=${match:0:1} + + if [ "$svnstatus" == 'A' ]; then + svn revert ${match:2} + elif [ "$svnstatus" == 'D' ]; then + svn revert ${match:2} + fi +} + +func_svn_uncache_mode() +{ + item=$1 + + # cache的檔名也是用變數控制 + uncachefile=$2 + cachefile=$3 + + cmd="grep '$item' $cachefile" + tmp1=`eval $cmd` + + if [ "$tmp1" == '' ]; then + cmd="echo '$item' >> $cachefile" + eval $cmd + fi + + # 先寫到暫存,然後在回寫回原來的檔案 + cmd="sed '/$item/d' $uncachefile > ${uncachefile}-svn-tmp" + eval $cmd + cmd="cp ${uncachefile}-svn-tmp $uncachefile" + eval $cmd + cmd="rm -rf ${uncachefile}-svn-tmp" + eval $cmd +} + +func_svn_cache_mode() +{ + item=$1 + + # cache的檔名也是用變數控制 + uncachefile=$2 + cachefile=$3 + + cmd="grep '$item' $uncachefile" + tmp1=`eval $cmd` + + if [ "$tmp1" == '' ]; then + cmd="echo '$item' >> $uncachefile" + eval $cmd + fi + + # 先寫到暫存,然後在回寫回原來的檔案 + cmd="sed '/$item/d' $cachefile > ${cachefile}-svn-tmp" + eval $cmd + cmd="cp ${cachefile}-svn-tmp $cachefile" + eval $cmd + cmd="rm -rf ${cachefile}-svn-tmp" + eval $cmd +} + +unset cmd +unset cmd1 +unset cmd2 +unset cmd3 + +# 只有第一次是1,有些只會執行一次,例如help +first='1' + +# 當符合某些條件以後,所以動作都要重來,這時需要清除掉某一些變數的內容 +clear_var_all='' + +# 倒退鍵 +# Ctrl + h +backspace=$(echo -e \\b\\c) + +# 這是模式,前面的括號是該模式的別名 +# 1. [unknow] svn status, filter by untracked, or new file, 其它都沒有哦 +# 2. [commit] svn status, filter by added, or deleted, modify一定會在裡面的(我想取commit list) +# 3. [uncache] uncache list +# 4. [cache] cache list +mode='1' + +uncachefile="$fast_change_dir_tmp/svn3-uncache-`whoami`.txt" +cachefile="$fast_change_dir_tmp/svn3-cache`whoami`.txt" + +# 清理uncache的同時,也會一並清除cache,因為它們是有相依性的 +func_svn_cache_controller "$uncachefile" "$cachefile" "clear-uncache" + +while [ 1 ]; +do + clear + + if [[ "$first" == '1' || "$clear_var_all" == '1' ]]; then + unset condition + unset cmd + unset item_unknow_array + unset item_commit_array + unset item_uncache_array + unset item_cache_array + clear_var_all='' + first='' + fi + + echo 'Svn (關鍵字)' + echo '=================================================' + echo "\"$groupname\" || `pwd`" + echo '=================================================' + if [ "$mode" == '1' ]; then + echo "Unknow File List" + elif [ "$mode" == '2' ]; then + echo "Commit List" + elif [ "$mode" == '3' ]; then + echo "Uncache List" + elif [ "$mode" == '4' ]; then + echo "Cache List" + else + # 為了誤動作,或是程式發生了未知的問題 + mode=1 + echo "Unknow File List" + fi + echo '=================================================' + + if [ "$mode" == '1' ]; then + # 問號是新的檔案,還未被新增進來,而驚嘆號是使用rm指令刪掉的狀況 + cmd="svn status | grep -e '^?' -e '^!'" + elif [ "$mode" == '2' ]; then + cmd="svn status | grep -e '^A' -e '^M' -e '^D'" + elif [ "$mode" == '3' ]; then + cmd="cat $uncachefile" + elif [ "$mode" == '4' ]; then + cmd="cat $cachefile" + fi + eval $cmd + + if [ "$condition" == 'quit' ]; then + break + elif [ "$condition" != '' ]; then + echo '=================================================' + echo "目前您所輸入的搜尋條件: \"$condition\"" + fi + + if [ "$condition" == '' ]; then + echo '=================================================' + echo -e "${color_txtgrn}基本快速鍵:${color_none}" + echo ' 倒退鍵 (Ctrl + H)' + echo ' 重新輸入條件 (/)' + echo ' 智慧選取單項 (;.) 分號' + echo ' 處理多項(*) 星號' + echo ' 離開 (?)' + echo -e "${color_txtgrn}Svn功能快速鍵:${color_none}" + echo ' Change Normal Mode (A)' + echo ' Change Cache Mode (B)' + echo ' Commit (C)' + echo ' Delete Cache/Uncache (D)' + echo ' Generate Uncache (G)' + echo ' Update (U)' + echo '輸入條件的結構:' + echo ' "關鍵字1" [space] "關鍵字2" [space] "英文位置ersfwlcbko(1234567890)"' + fi + + echo '=================================================' + + # 顯示重覆的SVN未知檔案 + if [ "${#item_unknow_array[@]}" -gt 1 ]; then + echo "重覆的未知SVN檔案數量: ${#item_unknow_array[@]} [*]" + number=1 + for bbb in ${item_unknow_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_unknow_array[@]}" -eq 1 ]; then + echo "未知的SVN檔案有找到一筆: ${item_unknow_array[0]} [;]" + fi + + # 顯示己經準備送出,而且狀態是新增、與刪除 + if [ "${#item_commit_array[@]}" -gt 1 ]; then + echo "重覆的準備送出的SVN,狀態為A與D的檔案數量: ${#item_commit_array[@]} [*]" + number=1 + for bbb in ${item_commit_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_commit_array[@]}" -eq 1 ]; then + echo "準備送出的SVN,狀態為A與D的檔案有找到一筆: ${item_commit_array[0]} [;]" + fi + + # 顯示Uncache項目 + if [ "${#item_uncache_array[@]}" -gt 1 ]; then + echo "重覆的Uncache檔案數量: ${#item_uncache_array[@]} [*]" + number=1 + for bbb in ${item_uncache_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_uncache_array[@]}" -eq 1 ]; then + echo "Uncache檔案有找到一筆: ${item_uncache_array[0]} [;]" + fi + + # 顯示Cache項目 + if [ "${#item_cache_array[@]}" -gt 1 ]; then + echo "重覆的Cache檔案數量: ${#item_cache_array[@]} [*]" + number=1 + for bbb in ${item_cache_array[@]} + do + echo "$number. $bbb" + number=$((number + 1)) + done + elif [ "${#item_cache_array[@]}" -eq 1 ]; then + echo "Cache檔案有找到一筆: ${item_cache_array[0]} [;]" + fi + + # 不加IFS=012的話,我輸入空格,read variable是讀不到的 + IFS=$'\012' + read -s -n 1 inputvar + IFS=$default_ifs + + if [ "$inputvar" == '?' ]; then + # 離開 + clear + break + elif [ "$inputvar" == '/' ]; then + clear_var_all='1' + continue + # 我也不知道,為什麼只能用Ctrl + H 來觸發倒退鍵的事件 + elif [ "$inputvar" == $backspace ]; then + condition="${condition:0:(${#condition} - 1)}" + inputvar='' + elif [ "$inputvar" == 'A' ]; then + if [ "$mode" == '1' ]; then + mode='2' + elif [ "$mode" == '2' ]; then + mode='1' + else + mode='1' + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'B' ]; then + if [ "$mode" == '3' ]; then + mode='4' + elif [ "$mode" == '4' ]; then + mode='3' + else + mode='3' + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'C' ]; then + if [[ "$mode" == '2' || "$mode" == '4' ]]; then + echo '要送出囉,但是請先輸入changelog,輸入完按Enter後直接送出' + read changelog + + if [ "$changelog" == '' ]; then + echo '為什麼你沒有輸入changelog呢?還是我幫你填上預設值呢?(no comment)好嗎?[Y1,n0]' + read inputvar2 + if [[ "$inputvar2" == 'y' || "$inputvar2" == "1" ]]; then + changelog='no comment' + elif [[ "$inputvar2" == 'n' || "$inputvar2" == "0" ]]; then + echo '如果不要預設值,那就算了' + else + echo '不好意思,不要預設值也不要來亂' + fi + fi + + if [ "$changelog" == '' ]; then + echo '你並沒有輸入changelog,所以下次在見了,本次動作取消,倒數3秒後離開' + sleep 3 + else + cmd="svn commit -m \"$changelog\" " + + if [ "$mode" == '4' ]; then + cmdcat="cat $cachefile | wc -l" + cmdcount=`eval $cmdcat` + + if [ "$cmdcount" -ge 1 ]; then + cmdlist="cat $cachefile | tr '\n' ' '" + cmdlist2=`eval $cmdlist` + + + IFS=$'\n' + cmdlist="cat $cachefile" + cmdlist2=(`eval $cmdlist`) + cmdlist3='' + + for i in ${cmdlist2[@]} + do + # 不分兩次做,會出現前面少了一個空白,不知道為什麼 + match=`echo ${i} | sed 's/___/X/'` + match=`echo $match | sed 's/___/ /g'` + cmdlist3="$cmdlist3 \"${match:3}" + done + + IFS=$default_ifs + + cmd="$cmd $cmdlist3" + else + echo '沒有可以送出的檔案,在cache裡面!!' + fi + fi + + eval $cmd + changelog='' + + if [ "$?" -eq 0 ]; then + echo '送出成功' + func_svn_cache_controller "$uncachefile" "$cachefile" "clear-all" + mode=1 + else + echo '送出失敗,請自行做檢查' + fi + + echo '按任何鍵繼續...' + read -n 1 + fi + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'D' ]; then + if [ "$mode" == '3' ]; then + func_svn_cache_controller "$uncachefile" "$cachefile" "clear-uncache" + elif [ "$mode" == '4' ]; then + func_svn_cache_controller "$uncachefile" "$cachefile" "clear-cache" + fi + + clear_var_all='1' + continue + elif [ "$inputvar" == 'G' ]; then + # 匯出後,自動跳到模式3,就是Uncache mode + func_svn_cache_controller "$uncachefile" "$cachefile" "svn-status-to-uncache" + mode='3' + + clear_var_all='1' + continue + elif [ "$inputvar" == 'U' ]; then + svn update + if [ "$?" -eq 0 ]; then + echo '更新本GIT資料夾成功' + fi + echo '按任何鍵繼續...' + read -n 1 + + clear_var_all='1' + continue + elif [[ "$inputvar" == ';' || "$inputvar" == '.' ]]; then + if [ ${#item_unknow_array[@]} -eq 1 ]; then + func_svn_unknow_mode "${item_unknow_array[0]}" + func_svn_cache_controller "$uncachefile" "$cachefile" "svn-status-to-uncache" + clear_var_all='1' + continue + elif [ ${#item_commit_array[@]} -eq 1 ]; then + func_svn_commit_mode "${item_commit_array[0]}" + func_svn_cache_controller "$uncachefile" "$cachefile" "svn-status-to-uncache" + clear_var_all='1' + continue + elif [ ${#item_uncache_array[@]} -eq 1 ]; then + func_svn_uncache_mode "${item_uncache_array[0]}" "$uncachefile" "$cachefile" + clear_var_all='1' + continue + elif [ ${#item_cache_array[@]} -eq 1 ]; then + func_svn_cache_mode "${item_cache_array[0]}" "$uncachefile" "$cachefile" + clear_var_all='1' + continue + fi + elif [ "$inputvar" == '*' ]; then + if [ "${#item_unknow_array[@]}" -gt 1 ]; then + for bbb in ${item_unknow_array[@]} + do + func_svn_unknow_mode "$bbb" + done + func_svn_cache_controller "$uncachefile" "$cachefile" "svn-status-to-uncache" + clear_var_all='1' + continue + elif [ "${#item_commit_array[@]}" -gt 1 ]; then + for bbb in ${item_commit_array[@]} + do + func_svn_commit_mode "$bbb" + done + func_svn_cache_controller "$uncachefile" "$cachefile" "svn-status-to-uncache" + clear_var_all='1' + continue + elif [ "${#item_uncache_array[@]}" -gt 1 ]; then + for bbb in ${item_uncache_array[@]} + do + func_svn_uncache_mode "$bbb" "$uncachefile" "$cachefile" + done + clear_var_all='1' + continue + elif [ "${#item_cache_array[@]}" -gt 1 ]; then + for bbb in ${item_cache_array[@]} + do + func_svn_cache_mode "$bbb" "$uncachefile" "$cachefile" + done + clear_var_all='1' + continue + fi + fi + + condition="$condition$inputvar" + + if [[ "$condition" =~ [[:alnum:]] ]]; then + cmds=($condition) + cmd1=${cmds[0]} + cmd2=${cmds[1]} + # 第三個引數,是位置 + cmd3=${cmds[2]} + + if [ "$mode" == '1' ]; then + item_unknow_array=( `func_relative_by_svn_append "$cmd1" "$cmd2" "$cmd3" "unknow" "" ""` ) + elif [ "$mode" == '2' ]; then + item_commit_array=( `func_relative_by_svn_append "$cmd1" "$cmd2" "$cmd3" "commit" "" ""` ) + elif [ "$mode" == '3' ]; then + item_uncache_array=( `func_relative_by_svn_append "$cmd1" "$cmd2" "$cmd3" "uncache" "$uncachefile" "$cachefile"` ) + elif [ "$mode" == '4' ]; then + item_cache_array=( `func_relative_by_svn_append "$cmd1" "$cmd2" "$cmd3" "cache" "$uncachefile" "$cachefile"` ) + fi + elif [ "$condition" == '' ]; then + # 會符合這裡的條件,是使用Ctrl + H 倒退鍵,把字元都砍光了以後會發生的狀況 + unset cmd + unset condition + unset svnstatus + unset item_unknow_array + unset item_commit_array + unset item_uncache_array + unset item_cache_array + fi + +done + +# 離開前,在顯示一下現在資料夾裡面的東西 +eval $cmd diff --git a/svn-edit-revision.sh b/svn-edit-revision.sh new file mode 100755 index 0000000..4d26246 --- /dev/null +++ b/svn-edit-revision.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# 這個檔案,是要讓svn.sh所呼叫的 +# 方便以vim編輯某個版本號裡面的檔案群 + +revision=$1 +tmpfile=/tmp/`whoami`-dialog-$( date +%Y%m%d-%H%M ).txt + +if [ "$revision" == "" ]; then + revisioncmd='/usr/bin/dialog --inputbox "請輸入版本號,以下為範例=> 123:125(版本從123到125)、123:head(版本從123到最近)、123,125,129(不連續或者是連續且多筆的版本號)、127(等同於127:head)" 0 0' + revisioncmd="$revisioncmd 2> $tmpfile" + + eval $revisioncmd + revision=`cat $tmpfile` + + if [ "$revision" == "" ]; then + echo '[ERROR] 使用者取消動作,或是沒有輸入版本號' + exit + fi +fi + +items=(`svn log -v -r $revision | grep -e "^ M" -e "^ A" | sed 's/^ M \///g' | sed 's/^ A \///g' | sort -u`) + +for item in ${items[@]} +do + if [ -f $item ]; then + vimitems="$vimitems $item" + fi +done + +vim -p $vimitems diff --git a/svn.sh b/svn.sh new file mode 100755 index 0000000..4ec747e --- /dev/null +++ b/svn.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# 這個檔案是加上一些常用的SVN指令在裡面 +# 這是第一個版本,主要是用Dialog,然後用上下鍵,好像也可以用數字鍵來操作 + +source 'gisanfu-function.sh' + +tmpfile=/tmp/gisanfu_svn.log + +svnitems='' +#svnitems="$svnitems 'svn status|grep -e ^M -e ^A' '狀態'" +svnitems="$svnitems 'svn status -q' '狀態'" +svnitems="$svnitems 'svn update' '更新'" +svnitems="$svnitems 'svn commit -m fixbug && svn update' '提交'" +svnitems="$svnitems '. /bin/gisanfu-dirpoint.sh root && svn log -v | more && svn update && /bin/gisanfu-svn-edit-revision.sh && cd -' '以版本號編輯檔案'" + +cmd=$( func_dialog_menu '請選擇Svn指令' 80 "$svnitems" "$tmpfile" ) + +eval $cmd +result=`cat $tmpfile` + +if [ "$result" == "" ]; then + func_statusbar '你沒有選擇任何Svn的指令哦' +else + eval $result +fi diff --git a/test/test-func-relative.sh b/test/test-func-relative.sh new file mode 100755 index 0000000..e8fa080 --- /dev/null +++ b/test/test-func-relative.sh @@ -0,0 +1,203 @@ +#!/bin/bash + +# 單純的把ls的忽略清單回傳而以 +func_getlsignore() +{ + echo '-I .svn -I .git' +} + +# 把英文變成數字,例如er就是12 +func_entonum() +{ + en=$1 + + return=$en + + for i in ${en[@]} + do + return=`echo $return | sed 's/e/1/'` + return=`echo $return | sed 's/r/2/'` + return=`echo $return | sed 's/s/3/'` + return=`echo $return | sed 's/f/4/'` + return=`echo $return | sed 's/w/5/'` + return=`echo $return | sed 's/l/6/'` + return=`echo $return | sed 's/c/7/'` + return=`echo $return | sed 's/b/8/'` + return=`echo $return | sed 's/k/9/'` + + # 零 + return=`echo $return | sed 's/o/0/'` + return=`echo $return | sed 's/z/0/'` + done + + echo $return +} + +# 這個是Dialog指令的選單功能 +func_dialog_menu() +{ + text=$1 + width=$2 + content=$3 + tmp=$4 + + cmd="dialog --menu '$text' 0 $width 20 $content 2> $tmp" + echo $cmd +} + +func_relative() +{ + nextRelativeItem=$1 + secondCondition=$2 + + # 檔案的位置 + fileposition=$3 + + # 要搜尋哪裡的路徑,空白代表現行目錄 + lspath=$4 + + # dir or file + filetype=$5 + + # get all item flag + # 0 or empty: do not get all + # 1: Get All + isgetall=$6 + + declare -a itemList + declare -a itemListTmp + declare -a relativeitem + + + tmpfile="$fast_change_dir_tmp/`whoami`-function-relativeitem-$( date +%Y%m%d-%H%M ).txt" + + # ignore file or dir + # ignorelist=$(func_getlsignore) + ignorelist='' + Success="0" + + # 試著使用@來決定第一個grep,從最開啟來找字串 + firstchar=${nextRelativeItem:0:1} + isHeadSearch='' + + # 這裡要注意,不能夠使用井字號(#)來當做控制字元,會有問題 + if [ "$firstchar" == '@' ]; then + isHeadSearch='^' + nextRelativeItem=${nextRelativeItem:1} + #elif [ "$firstchar" == '*' ]; then + # nextRelativeItem=${nextRelativeItem:1} + else + firstchar='' + fi + + # 試著使用第二個引數的第一個字元,來判斷是不是position + firstchar2=${secondCondition:0:1} + + if [[ "$firstchar2" == '@' && "$fileposition" == '' ]]; then + fileposition=${secondCondition:1} + secondCondition='' + fi + + # 先把英文轉成數字,如果這個欄位有資料的話 + fileposition=( `func_entonum "$fileposition"` ) + + if [ "$fileposition" != '' ]; then + newposition=$(($fileposition - 1)) + fi + + lucky='' + if [ "$filetype" == "dir" ]; then + filetype_ls_arg='' + filetype_grep_arg='' + if [[ -d "$lspath$nextRelativeItem" && "$isgetall" != '1' ]]; then + echo "$nextRelativeItem" + exit + fi + else + filetype_ls_arg='--file-type' + filetype_grep_arg='-v' + if [[ -f "$lspath$nextRelativeItem" && "$isgetall" != '1' ]]; then + echo "$nextRelativeItem" + exit + fi + fi + + # default ifs value + default_ifs=$' \t\n' + + IFS=$'\n' + cmd="ls -AFL $ignorelist $filetype_ls_arg $lspath | grep $filetype_grep_arg \"/$\"" + + if [ "$isgetall" != '1' ]; then + cmd="$cmd | grep -ir $isHeadSearch$nextRelativeItem" + fi + + if [ "$secondCondition" != '' ]; then + cmd="$cmd | grep -ir $secondCondition" + fi + + # 取得項目列表,存到陣列裡面,當然也會做空白的處理 + declare -i num + itemListTmp=(`eval $cmd`) + for i in ${itemListTmp[@]} + do + # 為了要解決空白檔名的問題 + itemList[$num]=`echo $i|sed 's/ /___/g'` + num=$num+1 + done + IFS=$default_ifs + num=0 + + if [ "$nextRelativeItem" != "" ]; then + if [ "${#itemList[@]}" == "1" ]; then + relativeitem=${itemList[0]} + #func_statusbar 'USE-ITEM' + elif [ "${#itemList[@]}" -gt "1" ]; then + relativeitem=${itemList[@]} + fi + fi + + if [ "$isgetall" == '1' ]; then + if [ "${#itemList[@]}" == "1" ]; then + relativeitem=${itemList[0]} + #func_statusbar 'USE-ITEM' + elif [ "${#itemList[@]}" -gt "1" ]; then + relativeitem=${itemList[@]} + fi + fi + + # return array的標準用法 + if [ "$relativeitem" != '' ]; then + if [ "$newposition" == '' ]; then + echo ${relativeitem[@]} + else + # 先把含空格的文字,轉成陣列 + aaa=(${relativeitem[@]}) + # 然後在指定位置輸出 + echo ${aaa[$newposition]} + fi + else + echo '' + fi +} + +cmd1=$1 +cmd2=$2 +cmd3=$3 + +firstchar=${cmd1:0:1} +if [ "$firstchar" == '#' ]; then + cmd1=${cmd1:1} +else + firstchar='' +fi + +#item_file_array=( `func_relative2 "$cmd1" "$cmd2" "$cmd3" "/home/gisanfu/test" "dir"` ) +item_file_array=( `func_relative "" "" "" "../" "dir" "1"` ) + +number=1 +for bbb in ${item_file_array[@]} +do + echo "$number. $bbb" + number=$((number + 1)) +done diff --git a/test/test.sh b/test/test.sh new file mode 100755 index 0000000..01c27ea --- /dev/null +++ b/test/test.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo '123' + +return + +echo '456' diff --git a/vimlist-append-files.sh b/vimlist-append-files.sh new file mode 100755 index 0000000..93a08bd --- /dev/null +++ b/vimlist-append-files.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# 這支程式是設計給搜尋功能,用來append多個檔案所使用 + +files=($@) + +if [ "$groupname" != '' ]; then + for file in ${files[@]} + do + # 取得實際的路徑 + # 這裡可能有以下幾種狀況: + # ../aaa.txt + # ./aaa.txt + # aaa.txt + # /home/user/aaa.txt + absoluteitem_path=`readlink -m $file` + checkline=`grep "$absoluteitem_path" $fast_change_dir_config/vimlist-$groupname.txt | wc -l` + if [ "$checkline" -lt 1 ]; then + echo "\"$absoluteitem_path\"" >> $fast_change_dir_config/vimlist-$groupname.txt + fi + done + + # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 + echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' + echo '[WAIT] 或是編輯列表 [j]' + echo '[WAIT] 還是清空它 [k]' + read -n 1 inputchar + if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then + # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... + checklinenumber=`cat $fast_change_dir_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$absoluteitem_path" | head -n 1 | awk -F: '{print $1}'` + cmd='vff "vim' + + # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 + # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 + # 查詢更多資訊請執行: "vim -h" + if [ "$checklinenumber" -lt 10 ]; then + for i in `seq 1 $checklinenumber` + do + cmd="$cmd +tabnext" + done + else + echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' + fi + + cmd="$cmd -p $fast_change_dir_config/vimlist-$groupname.txt\"" + eval $cmd + elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then + echo "Your want append other file" + elif [ "$inputchar" == 'j' ]; then + vfff + elif [ "$inputchar" == 'k' ]; then + vffff + else + echo "Your want append other file" + fi +else + vim -p ${files[@]} +fi + +# 結束前,把這裡所用到的變數給清空 +files='' +file='' +inputvar='' +checkline='' +cmd='' +checklinenumber='' diff --git a/vimlist-append-with-path.sh b/vimlist-append-with-path.sh new file mode 100755 index 0000000..6febb94 --- /dev/null +++ b/vimlist-append-with-path.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +# 這支程式最初是要設計給abc v3裡面的搜尋檔案函式所使用 + +absoluteitem_path=$1 +relativeitem_path=$2 + +if [[ "$absoluteitem_path" != '' && "$groupname" != '' ]]; then + checkline=`grep "$absoluteitem_path" $fast_change_dir_config/vimlist-$groupname.txt | wc -l` + if [ "$checkline" -lt 1 ]; then + echo "\"$absoluteitem_path\"" >> $fast_change_dir_config/vimlist-$groupname.txt + else + echo '[NOTICE] File is exist' + fi +elif [[ "$relativeitem_path" != '' && "$groupname" != '' ]]; then + # 要把前面那個點拿掉 + # 我指的是./aaa.txt前面那一個點 + selectitem=`pwd`/${relativeitem_path:1} + checkline=`grep "$selectitem" $fast_change_dir_config/vimlist-$groupname.txt | wc -l` + if [ "$checkline" -lt 1 ]; then + echo "\"$selectitem\"" >> $fast_change_dir_config/vimlist-$groupname.txt + else + echo '[NOTICE] File is exist' + fi +fi + +if [ "$groupname" != '' ]; then + # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 + echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' + echo '[WAIT] 或是編輯列表 [j]' + echo '[WAIT] 還是清空它 [k]' + read -n 1 inputchar + if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then + # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... + checklinenumber=`cat $fast_change_dir_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` + cmd='vff "vim' + + # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 + # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 + # 查詢更多資訊請執行: "vim -h" + if [ "$checklinenumber" -lt 10 ]; then + for i in `seq 1 $checklinenumber` + do + cmd="$cmd +tabnext" + done + else + echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' + fi + + cmd="$cmd -p $fast_change_dir_config/vimlist-$groupname.txt\"" + eval $cmd + elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then + echo "Your want append other file" + elif [ "$inputchar" == 'j' ]; then + vfff + elif [ "$inputchar" == 'k' ]; then + vffff + else + echo "Your want append other file" + fi +else + if [ "$absoluteitem_path" != '' ]; then + vim $absoluteitem_path + else + vim $relativeitem_path + fi +fi + +# 結束前,把這裡所用到的變數給清空 +relativeitem_path='' +absoluteitem_path='' +inputvar='' +checkline='' +selectitem='' +cmd='' +checklinenumber='' diff --git a/vimlist-append.sh b/vimlist-append.sh new file mode 100755 index 0000000..ac41352 --- /dev/null +++ b/vimlist-append.sh @@ -0,0 +1,130 @@ +#!/bin/bash + +source "$fast_change_dir_func/normal.sh" +source "$fast_change_dir_func/entonum.sh" +source "$fast_change_dir_func/relativeitem.sh" + +# cmd1、2是第一、二個關鍵字 +cmd1=$1 +cmd2=$2 +# 位置,例如e就代表1,或者你也可以輸入1 +cmd3=$3 + +# 是否要vff,如果沒有指定,就是會詢問使用者 +# 不詢問,不要vff的話,就放0 +# 不詢問,要vff的話,就放1 +isVFF=$4 + +if [ "$isVFF" == '' ]; then + isVFF=1 +fi + +item_array=( `func_relative "$cmd1" "$cmd2" "$cmd3" "" "file"` ) + +relativeitem='' +#if [ "${#item_array[@]}" -gt 1 ]; then +# echo "重覆的檔案數量: 有${#item_array[@]}筆" +# number=1 +# for bbb in ${item_array[@]} +# do +# echo "$number. $bbb" +# number=$((number + 1)) +# done +#elif [ "${#item_array[@]}" -eq 1 ]; then +# relativeitem=${item_array[0]} +#fi + +tmpfile="$fast_change_dir_tmp/`whoami`-vf-dialog-select-only-file-$( date +%Y%m%d-%H%M ).txt" +dialogitems='' +for echothem in ${item_array[@]} +do + dialogitems=" $dialogitems $echothem '' " +done +cmd=$( func_dialog_menu '請從裡面挑一項你所要的' 100 "$dialogitems" $tmpfile ) + +eval $cmd +result=`cat $tmpfile` + +if [ -f "$tmpfile" ]; then + rm -rf $tmpfile +fi + +if [ "$result" != "" ]; then + relativeitem=$result +else + relativeitem='' +fi + +if [[ "$relativeitem" != "" && "$groupname" != "" ]]; then + if [ "$isVFF" == '0' ]; then + inputchar='n' + elif [ "$isVFF" == '1' ]; then + inputchar='y' + else + isVFF='' + fi + + # 這裡可以考慮在加上一項,就是不要append這一個檔案 + if [ "$isVFF" == '' ]; then + # 問使用者,看要不要編輯這些檔案,或者是繼續Append其它的檔案進來 + echo '[WAIT] 預設是只暫存所選取的檔案 [N0,y1]' + echo '[WAIT] 或是編輯列表 [j]' + echo '[WAIT] 還是清空它 [k]' + read -n 1 inputchar + fi + + # 檢查一下,看文字檔裡面有沒有這個內容,如果有,當然就不需要在append + selectitem='' + selectitem=`pwd`/$relativeitem + checkline=`grep "$selectitem" $fast_change_dir_config/vimlist-$groupname.txt | wc -l` + if [ "$checkline" -lt 1 ]; then + echo "\"$selectitem\"" >> $fast_change_dir_config/vimlist-$groupname.txt + else + echo '[NOTICE] File is exist' + fi + + if [[ "$inputchar" == 'y' || "$inputchar" == "1" ]]; then + # 取得最後append的檔案位置,這樣子vim -p以後就可以直接跳過該位置,就不用一直在gt..gt..gt..gt... + checklinenumber=`cat $fast_change_dir_config/vimlist-$groupname.txt | nl -w1 -s: | grep "$selectitem" | head -n 1 | awk -F: '{print $1}'` + cmd='vff "vim' + + # 不知道為什麼不能超過10,超過會出現以下的錯誤訊息 + # 太多 "+command" 、 "-c command" 或 "--cmd command" 參數 + # 查詢更多資訊請執行: "vim -h" + if [ "$checklinenumber" -lt 10 ]; then + for i in `seq 1 $checklinenumber` + do + cmd="$cmd +tabnext" + done + else + echo '[NOTICE] 10以上的tabnext會有問題,所以我略過了:p' + fi + + cmd="$cmd -p $fast_change_dir_config/vimlist-$groupname.txt\"" + eval $cmd + elif [[ "$inputchar" == 'n' || "$inputchar" == "0" ]]; then + echo "Your want append other file" + elif [ "$inputchar" == 'j' ]; then + vfff + elif [ "$inputchar" == 'k' ]; then + vffff + else + echo "Your want append other file" + fi + + # 最後,顯示目前目錄的檔案 + func_checkfilecount + +elif [ "$groupname" == "" ]; then + echo '[ERROR] Argument or $groupname is empty' +fi + +unset cmd +unset cmd1 +unset cmd2 +unset cmd3 +unset number +unset item_array +unset checklinenumber +unset relativeitem +unset selectitem diff --git a/vimlist-clear.sh b/vimlist-clear.sh new file mode 100755 index 0000000..b4cfac9 --- /dev/null +++ b/vimlist-clear.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +if [ "$groupname" != '' ]; then + echo '你確定要清空vim暫存群組檔嗎?[Y1, n0]' + read -s -n 1 inputvar + if [[ "$inputvar" == 'n' || "$inputvar" == "0" ]]; then + echo '己取消清空vim暫存群組檔' + sleep 1 + else + rm $fast_change_dir_config/vimlist-$groupname.txt + touch $fast_change_dir_config/vimlist-$groupname.txt + echo '己清空' + sleep 1 + fi +fi diff --git a/vimlist-edit.sh b/vimlist-edit.sh new file mode 100755 index 0000000..443e9d1 --- /dev/null +++ b/vimlist-edit.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +if [ "$groupname" != "" ]; then + vim $fast_change_dir_config/vimlist-$groupname.txt + + # 詢問使用者,看要不要編輯list + echo '[WAIT] 預設是編輯暫存檔案群,我指的是vff [Y1,n0]' + read -n 1 inputchar + if [[ "$inputchar" == 'y' || "$inputchar" == '1' || "$inputchar" == '' ]]; then + vff + fi +else + echo '[ERROR] groupname is empty' +fi diff --git a/vimlist.sh b/vimlist.sh new file mode 100755 index 0000000..d21821b --- /dev/null +++ b/vimlist.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +source "$fast_change_dir_func/normal.sh" +source "$fast_change_dir_func/dialog.sh" + +program=$1 + +if [ "$groupname" != "" ]; then + if [ "$program" == "" ]; then + program2="vim -p $fast_change_dir_config/vimlist-$groupname.txt" + else + program2=$program + fi + + cmdlist="cat $fast_change_dir_config/vimlist-$groupname.txt" + + # 正規的外面要用雙引包起來 + regex="^vim" + + # 如果program這個變數是空白,就代表會使用vim-p的指令 + # 使用vim,當然不會去開一些binary的檔案 + if [[ "$program" == '' || "$program" =~ $regex ]]; then + # 先把一些己知的東西先ignore掉,例如壓縮檔 + cmdlist="$cmdlist | grep -v .tar.gz | grep -v .zip | grep -v .png | grep -v .gif | grep -v .jpeg | grep -v .jpg" + cmdlist="$cmdlist | xargs -n 1 $fast_change_dir_bin/only-text-filecontent.sh" + fi + + # 這是多行文字檔內容,變成以空格分格成字串的步驟 + cmdlist2='| tr "\n" " "' + cmdlist="$cmdlist $cmdlist2" + cmdlist_result=`eval $cmdlist` + cmd="$program2 $cmdlist_result" + + # 檢查一下數量,如果是一筆的話,那就自動跳到那一筆 + # 這樣子只有一筆的時候,會比較方便 + # 會這樣子寫,是因為不要去影響其它程式的相依性 + if [ "$program" == "" ]; then + count=`cat $fast_change_dir_config/vimlist-$groupname.txt | wc -l` + + if [ "$count" == 1 ]; then + cmd="$cmd +tabnext" + fi + + # 如果大於1筆,就用選擇的方式,選擇第一次要看到的檔案 + if [ "$count" -gt 1 ]; then + vimlist_array=(`cat $fast_change_dir_config/vimlist-$groupname.txt`) + tmpfile="$fast_change_dir_tmp/`whoami`-vimlist-dialogselect-$( date +%Y%m%d-%H%M ).txt" + dialogitems='' + start=1 + for echothem in ${vimlist_array[@]} + do + dialogitems=" $dialogitems '$start' $echothem " + start=$(expr $start + 1) + done + cmd2=$( func_dialog_menu '你想從哪一個位置開始編輯 ' 100 "$dialogitems" $tmpfile ) + + eval $cmd2 + result=`cat $tmpfile` + + if [ -f "$tmpfile" ]; then + rm -rf $tmpfile + fi + + if [ "$result" != "" ]; then + for (( b=1; b<=$result; b++ )) + do + cmd="$cmd +tabnext" + done + else + cmd="$cmd +tabnext" + fi + fi + fi + + eval $cmd + func_checkfilecount +else + echo '[ERROR] groupname is empty, please use GA cmd' +fi + +unset vimlist_array
hotchpotch/as3rails2u
89225bdf87e93299810925add5bb85cd35bcb00d
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@83 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/utils/TweenerUtil.as b/src/com/rails2u/utils/TweenerUtil.as new file mode 100644 index 0000000..85fe638 --- /dev/null +++ b/src/com/rails2u/utils/TweenerUtil.as @@ -0,0 +1,166 @@ +package com.rails2u.utils { + import caurina.transitions.Equations; + public class TweenerUtil { + + /* + public static function easingSerial(...easings):Function { + init(); + var len:uint = easings.length; + if (len < 2) throw new ArgumentError('needs 2 =< args.'); + + var easing:*; + return function easeOutInBounce(t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number { + var i:uint = Math.floor(t/d*len); + + easing = easings[i]; + if (easing is String){ + easing = transitions[easing.toLowerCase()]; + easings[i] = easing; + } + return easing.call(null, + t * len, + b + ((len-i)/len * (c-b)), + c, + d * len, + p_params); + } + } + */ + + public static function easingParallel(...easings):Function { + init(); + var len:uint = easings.length; + if (len < 2) throw new ArgumentError('needs 2 =< args.'); + + var easing:*; + return function easeOutInBounce(t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number { + var res:Number = 0; + for (var i:uint = 0; i < len; i++) { + easing = easings[i]; + if (easing is String){ + easing = transitions[easing.toLowerCase()]; + easings[i] = easing; + } + res += easing.call(null, t, b/len, c/len, d, p_params); + } + return res; + }; + } + + private static var inited:Boolean = false; + public static var transitions:Object = {}; + public static function init():void { + if (!inited) { + registerTransition("easenone", Equations.easeNone); + registerTransition("linear", Equations.easeNone); // mx.transitions.easing.None.easeNone + registerTransition("easeinquad", Equations.easeInQuad); // mx.transitions.easing.Regular.easeIn + registerTransition("easeoutquad", Equations.easeOutQuad); // mx.transitions.easing.Regular.easeOut + registerTransition("easeinoutquad", Equations.easeInOutQuad); // mx.transitions.easing.Regular.easeInOut + registerTransition("easeoutinquad", Equations.easeOutInQuad); + registerTransition("easeincubic", Equations.easeInCubic); + registerTransition("easeoutcubic", Equations.easeOutCubic); + registerTransition("easeinoutcubic", Equations.easeInOutCubic); + registerTransition("easeoutincubic", Equations.easeOutInCubic); + registerTransition("easeinquart", Equations.easeInQuart); + registerTransition("easeoutquart", Equations.easeOutQuart); + registerTransition("easeinoutquart", Equations.easeInOutQuart); + registerTransition("easeoutinquart", Equations.easeOutInQuart); + registerTransition("easeinquint", Equations.easeInQuint); + registerTransition("easeoutquint", Equations.easeOutQuint); + registerTransition("easeinoutquint", Equations.easeInOutQuint); + registerTransition("easeoutinquint", Equations.easeOutInQuint); + registerTransition("easeinsine", Equations.easeInSine); + registerTransition("easeoutsine", Equations.easeOutSine); + registerTransition("easeinoutsine", Equations.easeInOutSine); + registerTransition("easeoutinsine", Equations.easeOutInSine); + registerTransition("easeincirc", Equations.easeInCirc); + registerTransition("easeoutcirc", Equations.easeOutCirc); + registerTransition("easeinoutcirc", Equations.easeInOutCirc); + registerTransition("easeoutincirc", Equations.easeOutInCirc); + + registerTransition("easeinexpo", Equations.easeInExpo); // mx.transitions.easing.Strong.easeIn + registerTransition("easeoutexpo", Equations.easeOutExpo); // mx.transitions.easing.Strong.easeOut + registerTransition("easeinoutexpo", Equations.easeInOutExpo); // mx.transitions.easing.Strong.easeInOut + registerTransition("easeoutinexpo", Equations.easeOutInExpo); + + registerTransition("easeinelastic", Equations.easeInElastic); // mx.transitions.easing.Elastic.easeIn + registerTransition("easeoutelastic", Equations.easeOutElastic); // mx.transitions.easing.Elastic.easeOut + registerTransition("easeinoutelastic", Equations.easeInOutElastic); // mx.transitions.easing.Elastic.easeInOut + registerTransition("easeoutinelastic", Equations.easeOutInElastic); + + registerTransition("easeinback", Equations.easeInBack); // mx.transitions.easing.Back.easeIn + registerTransition("easeoutback", Equations.easeOutBack); // mx.transitions.easing.Back.easeOut + registerTransition("easeinoutback", Equations.easeInOutBack); // mx.transitions.easing.Back.easeInOut + registerTransition("easeoutinback", Equations.easeOutInBack); + + registerTransition("easeinbounce", Equations.easeInBounce); // mx.transitions.easing.Bounce.easeIn + registerTransition("easeoutbounce", Equations.easeOutBounce); // mx.transitions.easing.Bounce.easeOut + registerTransition("easeinoutbounce", Equations.easeInOutBounce); // mx.transitions.easing.Bounce.easeInOut + registerTransition("easeoutinbounce", Equations.easeOutInBounce); + inited = true; + } + } + + public static function registerTransition(name:String, easing:Function):void { + transitions[name.toLowerCase()] = easing; + } + } +} + /* + * @param t Current time (in frames or seconds). + * @param b Starting value. + * @param c Change needed in value. + * @param d Expected easing duration (in frames or seconds). + Tweener.registerTransition("easenone", easeNone); + Tweener.registerTransition("linear", easeNone); // mx.transitions.easing.None.easeNone + + Tweener.registerTransition("easeinquad", easeInQuad); // mx.transitions.easing.Regular.easeIn + Tweener.registerTransition("easeoutquad", easeOutQuad); // mx.transitions.easing.Regular.easeOut + Tweener.registerTransition("easeinoutquad", easeInOutQuad); // mx.transitions.easing.Regular.easeInOut + Tweener.registerTransition("easeoutinquad", easeOutInQuad); + + Tweener.registerTransition("easeincubic", easeInCubic); + Tweener.registerTransition("easeoutcubic", easeOutCubic); + Tweener.registerTransition("easeinoutcubic", easeInOutCubic); + Tweener.registerTransition("easeoutincubic", easeOutInCubic); + + Tweener.registerTransition("easeinquart", easeInQuart); + Tweener.registerTransition("easeoutquart", easeOutQuart); + Tweener.registerTransition("easeinoutquart", easeInOutQuart); + Tweener.registerTransition("easeoutinquart", easeOutInQuart); + + Tweener.registerTransition("easeinquint", easeInQuint); + Tweener.registerTransition("easeoutquint", easeOutQuint); + Tweener.registerTransition("easeinoutquint", easeInOutQuint); + Tweener.registerTransition("easeoutinquint", easeOutInQuint); + + Tweener.registerTransition("easeinsine", easeInSine); + Tweener.registerTransition("easeoutsine", easeOutSine); + Tweener.registerTransition("easeinoutsine", easeInOutSine); + Tweener.registerTransition("easeoutinsine", easeOutInSine); + + Tweener.registerTransition("easeincirc", easeInCirc); + Tweener.registerTransition("easeoutcirc", easeOutCirc); + Tweener.registerTransition("easeinoutcirc", easeInOutCirc); + Tweener.registerTransition("easeoutincirc", easeOutInCirc); + + Tweener.registerTransition("easeinexpo", easeInExpo); // mx.transitions.easing.Strong.easeIn + Tweener.registerTransition("easeoutexpo", easeOutExpo); // mx.transitions.easing.Strong.easeOut + Tweener.registerTransition("easeinoutexpo", easeInOutExpo); // mx.transitions.easing.Strong.easeInOut + Tweener.registerTransition("easeoutinexpo", easeOutInExpo); + + Tweener.registerTransition("easeinelastic", easeInElastic); // mx.transitions.easing.Elastic.easeIn + Tweener.registerTransition("easeoutelastic", easeOutElastic); // mx.transitions.easing.Elastic.easeOut + Tweener.registerTransition("easeinoutelastic", easeInOutElastic); // mx.transitions.easing.Elastic.easeInOut + Tweener.registerTransition("easeoutinelastic", easeOutInElastic); + + Tweener.registerTransition("easeinback", easeInBack); // mx.transitions.easing.Back.easeIn + Tweener.registerTransition("easeoutback", easeOutBack); // mx.transitions.easing.Back.easeOut + Tweener.registerTransition("easeinoutback", easeInOutBack); // mx.transitions.easing.Back.easeInOut + Tweener.registerTransition("easeoutinback", easeOutInBack); + + Tweener.registerTransition("easeinbounce", easeInBounce); // mx.transitions.easing.Bounce.easeIn + Tweener.registerTransition("easeoutbounce", easeOutBounce); // mx.transitions.easing.Bounce.easeOut + Tweener.registerTransition("easeinoutbounce", easeInOutBounce); // mx.transitions.easing.Bounce.easeInOut + Tweener.registerTransition("easeoutinbounce", easeOutInBounce); + */
hotchpotch/as3rails2u
4b0f3e2adbbc4393929a3e4771afea1ee2abe972
refactaring key handler
diff --git a/src/com/rails2u/utils/KeyTypeListener.as b/src/com/rails2u/utils/KeyTypeListener.as index ca3f40a..7a7965d 100644 --- a/src/com/rails2u/utils/KeyTypeListener.as +++ b/src/com/rails2u/utils/KeyTypeListener.as @@ -1,166 +1,159 @@ package com.rails2u.utils { import flash.events.KeyboardEvent; import flash.utils.describeType; import flash.ui.Keyboard; import flash.display.InteractiveObject; import flash.utils.Dictionary; use namespace key_down; use namespace key_up; /** * KeyTypeListener attach keytype events(KEY_DOWN, KEY_UP) utility. * * How to use: * please see examples dir. */ public class KeyTypeListener { private static var objects:Dictionary = new Dictionary; public static function attach( obj:InteractiveObject, currentTarget:Object = null, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false ):KeyTypeListener { var instance:KeyTypeListener = new KeyTypeListener(obj, currentTarget, useCapture, priority, useWeakReference); instance.bindKey(KeyboardEvent.KEY_DOWN); instance.bindKey(KeyboardEvent.KEY_UP); objects[obj] = instance; return instance; } public static function detach(obj:InteractiveObject):Boolean { if(objects[obj]) { objects[obj].destroyImpl(); delete objects[obj]; return true; } else { return false; } } protected var obj:InteractiveObject; protected var currentTarget:Object; public var ignoreTargets:Array = []; private var _forceStop:Boolean = true; public function get forceStop():Boolean { return _forceStop; } public function set forceStop(forceStop:Boolean):void { this._forceStop = forceStop; } private var reflection:Reflection; private var callableCache:Object = {}; private var useCapture:Boolean; private var priority:int; private var useWeakReference:Boolean; public function KeyTypeListener(obj:InteractiveObject, currentTarget:Object = null, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void { this.obj = obj; this.useCapture = useCapture; this.priority = priority; this.useWeakReference = useWeakReference; if (currentTarget == null) { this.currentTarget = obj; } else { this.currentTarget = currentTarget; } reflection = Reflection.factory(this.currentTarget); } public function bindKey(type:String):void { - obj.addEventListener(type, KeyboardEvent.KEY_DOWN == type ? keyDownHandler : keyUpHandler, useCapture, priority, useWeakReference); + obj.addEventListener(type, keyHandler, useCapture, priority, useWeakReference); } public function destroy():void { KeyTypeListener.detach(obj); } internal function destroyImpl():void { - obj.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, useCapture); - obj.removeEventListener(KeyboardEvent.KEY_UP, keyUpHandler, useCapture); + obj.removeEventListener(KeyboardEvent.KEY_DOWN, keyHandler, useCapture); + obj.removeEventListener(KeyboardEvent.KEY_UP, keyHandler, useCapture); } - // みじかくできる - protected function keyDownHandler(e:KeyboardEvent):void { - keyHandlerDelegeter(e, key_down); - } - - protected function keyUpHandler(e:KeyboardEvent):void { - keyHandlerDelegeter(e, key_up); - } - protected function isIgnore(o:*):Boolean { if (ignoreTargets.length) { for each(var klass:Class in ignoreTargets) { if (o is klass) return true; } } return false; } - protected function keyHandlerDelegeter(e:KeyboardEvent, ns:Namespace):void { + protected function keyHandler(e:KeyboardEvent):void { if (isIgnore(e.target)) return; + var ns:Namespace = e.type == KeyboardEvent.KEY_DOWN ? key_down : key_up; + if (!(e.target == this.currentTarget || e.target == this.obj)) { if (e.target.stage && this.obj == e.target.stage) { // ... } else { return; } } // log(String.fromCharCode(e.charCode)); var methodName:String = getMethodName(e); // log(methodName, ns); methodCall(e, 'before', ns); methodCall(e, methodName, ns); methodCall(e, 'after', ns); } private function methodCall(e:KeyboardEvent, methodName:String, ns:Namespace):void { var argsNum:int = reflection.methodArgs(methodName, ns); if(argsNum >= 0) { switch(argsNum) { case 0: currentTarget.ns::[methodName].call(currentTarget); break; case 1: currentTarget.ns::[methodName].call(currentTarget, e); break; default: throw new Error(methodName + ' arguments should be 0 or 1'); break; } } else if(methodName == 'after') { // default after call stopPropagation because always looping event... if (forceStop) e.stopPropagation(); } } private const RE_NUM_CHAR:RegExp = /^\d$/; public function getMethodName(e:KeyboardEvent):String { if (keyboardConstfromCharCode(e.keyCode)) { return keyboardConstfromCharCode(e.keyCode); } var char:String = String.fromCharCode(e.keyCode); if (!e.shiftKey) char = char.toLowerCase(); if (e.ctrlKey) char = 'CTRL_' + char; if (RE_NUM_CHAR.test(char)) char = '_' + char; return char; } public static function keyboardConstfromCharCode(code:uint):String { return Reflection.factory(Keyboard).constantsTable[code]; } } }
hotchpotch/as3rails2u
ff0ae885f23d089ccf02b2f706ca7d1112144d6b
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@81 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/typofy/TypofyCharSprite.as b/src/com/rails2u/typofy/TypofyCharSprite.as index 01a638a..da4d0b7 100644 --- a/src/com/rails2u/typofy/TypofyCharSprite.as +++ b/src/com/rails2u/typofy/TypofyCharSprite.as @@ -1,161 +1,162 @@ package com.rails2u.typofy { import flash.display.Sprite; import flash.geom.Point; import flash.geom.Rectangle; import flash.text.TextField; import flash.text.TextFormat; import flash.display.BitmapData; import mx.containers.Canvas; import flash.geom.Matrix; import flash.geom.ColorTransform; import flash.filters.BlurFilter; import flash.display.Bitmap; import flash.filters.BitmapFilterQuality; public class TypofyCharSprite extends Sprite { public static const PADDING_MAGIC_NUMBER:int = 2; // why? Bug? (193249) public var textField:TextField; public var typofy:Typofy; private var _char:String; public function get char():String { return _char; } public function set char(newchar:String):void { this.textField.text = newchar; this._char = newchar; if (bitmapFont) renderBitmapFont(); } public function setDefaultChar():void { char = defaultChar; } public function get row():uint { return this.charIndex - typofy.getLineOffset(col); } public function get col():uint { return typofy.getLineIndexOfChar(this.charIndex); } public var boundaries:Rectangle; public var charIndex:uint; public var extra:Object = {}; protected var _centerPoint:Point; public function get centerPoint():Point { return _centerPoint; } public var defaultChar:String; public function TypofyCharSprite(_char:String, typofy:Typofy, _index:uint, boundaries:Rectangle) { super(); textField = new TextField; textField.selectable = false; + textField.embedFonts = typofy.embedFonts; this.addChild(textField); this.boundaries = boundaries; this.charIndex = _index; this.typofy = typofy; init(); defaultChar = _char; setDefaultChar(); } public function drawBorder(... args):void { if (args.length > 0) { graphics.lineStyle.apply(null, args); } else { graphics.lineStyle(0, 0xEEEEEE); } graphics.drawRect(-boundaries.width / 2, -boundaries.height / 2, boundaries.width, boundaries.height); } public function drawBorderWithCrossLine(... args):void { drawBorder.apply(this, args); graphics.moveTo(-boundaries.width / 2, -boundaries.height / 2); graphics.lineTo(boundaries.width / 2, boundaries.height / 2); graphics.moveTo(boundaries.width / 2, -boundaries.height / 2); graphics.lineTo(-boundaries.width / 2, boundaries.height / 2); } public var bitmapFont:Bitmap; public function replaceBitmap(blurX:Number = 2, blurY:Number = 2, blurQuality:uint = 3):void { if (!bitmapFont) { renderBitmapFont(blurX, blurY, blurQuality); textField.visible = false; } } private function renderBitmapFont(blurX:Number = 2, blurY:Number = 2, blurQuality:uint = 1):void { if (bitmapFont) { removeChild(bitmapFont); } var bd:BitmapData = getAAText(textField, blurX, blurY, blurQuality); bitmapFont = new Bitmap(bd, 'never', true); bitmapFont.x = textField.x; bitmapFont.y = textField.y; addChild(bitmapFont); } protected function init():void { var textFormat:TextFormat = typofy.getTextFormat(this.charIndex); this.x = boundaries.x + boundaries.width / 2; this.y = boundaries.y + boundaries.height / 2; this._centerPoint = new Point(this.x, this.y); textField.x -= boundaries.width / 2 + PADDING_MAGIC_NUMBER; textField.y -= boundaries.height / 2 + PADDING_MAGIC_NUMBER; textField.width = boundaries.width + PADDING_MAGIC_NUMBER * 2; textField.height = boundaries.height + PADDING_MAGIC_NUMBER * 2; this.width = boundaries.width + PADDING_MAGIC_NUMBER * 2; this.height = boundaries.height + PADDING_MAGIC_NUMBER * 2; textFormat.align = 'left'; textField.defaultTextFormat = textFormat; } public static var AA_MARGIN:Number = 16; public static var AA_BMP_MAX:Number = 2800; public static var AA_MAX_SCALE:Number = 3; // Device font apply Anti-Alias tips by F-SITE. // http://f-site.org/articles/2007/04/08165536.html public static function getAAText(textField:TextField, blurX:Number = 2, blurY:Number = 2, blurQuality:uint = 2):BitmapData { var aaWidth:Number = textField.textWidth + AA_MARGIN; var aaHeight:Number = textField.textHeight + AA_MARGIN; var aaScale:Number = Math.min(AA_MAX_SCALE, Math.min(AA_BMP_MAX / aaWidth, AA_BMP_MAX / aaHeight)); var bmpCanvas:BitmapData = new BitmapData(aaWidth * aaScale, aaHeight * aaScale, true, 0x00000000); var bmpResult:BitmapData = new BitmapData(aaWidth, aaHeight, true, 0x00000000); var myMatrix:Matrix = new Matrix(); myMatrix.scale(aaScale, aaScale); bmpCanvas.draw(textField, myMatrix); var myFilter:BlurFilter = new BlurFilter(blurX, blurY, blurQuality); bmpCanvas.applyFilter(bmpCanvas, new Rectangle(0, 0, bmpCanvas.width, bmpCanvas.height), new Point(0, 0), myFilter); bmpCanvas.draw(textField, myMatrix); var myColor:ColorTransform = new ColorTransform(); myColor.alphaMultiplier= 1.1; myMatrix.a = myMatrix.d = 1; myMatrix.scale(1 / aaScale, 1 / aaScale); bmpResult.draw(bmpCanvas, myMatrix, myColor); bmpResult.draw(bmpCanvas, myMatrix); bmpCanvas.dispose(); return bmpResult; } } } diff --git a/src/com/rails2u/utils/JSUtil.as b/src/com/rails2u/utils/JSUtil.as index 3a31905..5c1c3b9 100644 --- a/src/com/rails2u/utils/JSUtil.as +++ b/src/com/rails2u/utils/JSUtil.as @@ -1,67 +1,67 @@ package com.rails2u.utils { import flash.external.ExternalInterface; import flash.utils.describeType; public class JSUtil { public static function attachCallbacks(target:*):void { if (!ExternalInterface.available) return; var res:XMLList = describeType(target).method. (String(attribute('uri')) == js_callback.uri); for each (var n:* in res) { var method:String = [email protected](); ExternalInterface.addCallback(method, target.js_callback::[method]); } } public static function getObjectID():String { return ExternalInterface.objectID; } public static function selfCallJS(cmd:String):* { cmd = "return document.getElementById('" + getObjectID() + "')." + cmd; return callJS(cmd); } public static function callJS(cmd:String, ...args):* { if (!ExternalInterface.available) return null; if (args.length > 0) { cmd = "(function() {" + cmd + ".apply(null, arguments);})"; return ExternalInterface.call.apply(null, [cmd].concat(args)); } else { cmd = "(function() {" + cmd + ";})"; return ExternalInterface.call(cmd); } } public static function bindCallJS(bindName:String):Function { return function(cmd:String):* { return callJS(bindName + cmd); }; } public static function buildQueryString(hash:Object):String { var res:Array = []; for (var key:String in hash) { res.push(encodeURIComponent(key) + '=' + encodeURIComponent(hash[key])); } return res.join('&'); } public static function restoreQueryString(str:String):Object { var hash:Object = {}; - var res:Array = str.replace(/^#/, '').split('&'); + var res:Array = str.replace(/^[#?]/, '').split('&'); for each(var s:String in res) { if (s.indexOf('=') > 0 && s.length >= 2) { var keyval:Array = s.split('=', 2); hash[keyval[0]] = keyval[1]; } } return hash; } } } diff --git a/src/com/rails2u/utils/KeyTypeListener.as b/src/com/rails2u/utils/KeyTypeListener.as index 7dcf6d0..ca3f40a 100644 --- a/src/com/rails2u/utils/KeyTypeListener.as +++ b/src/com/rails2u/utils/KeyTypeListener.as @@ -1,148 +1,166 @@ package com.rails2u.utils { import flash.events.KeyboardEvent; import flash.utils.describeType; import flash.ui.Keyboard; import flash.display.InteractiveObject; import flash.utils.Dictionary; use namespace key_down; use namespace key_up; /** * KeyTypeListener attach keytype events(KEY_DOWN, KEY_UP) utility. * * How to use: * please see examples dir. */ public class KeyTypeListener { private static var objects:Dictionary = new Dictionary; public static function attach( obj:InteractiveObject, currentTarget:Object = null, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false ):KeyTypeListener { var instance:KeyTypeListener = new KeyTypeListener(obj, currentTarget, useCapture, priority, useWeakReference); instance.bindKey(KeyboardEvent.KEY_DOWN); instance.bindKey(KeyboardEvent.KEY_UP); objects[obj] = instance; return instance; } public static function detach(obj:InteractiveObject):Boolean { if(objects[obj]) { objects[obj].destroyImpl(); delete objects[obj]; return true; } else { return false; } } protected var obj:InteractiveObject; protected var currentTarget:Object; + public var ignoreTargets:Array = []; + + private var _forceStop:Boolean = true; + public function get forceStop():Boolean { + return _forceStop; + } + public function set forceStop(forceStop:Boolean):void { + this._forceStop = forceStop; + } + private var reflection:Reflection; private var callableCache:Object = {}; private var useCapture:Boolean; private var priority:int; private var useWeakReference:Boolean; public function KeyTypeListener(obj:InteractiveObject, currentTarget:Object = null, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void { this.obj = obj; this.useCapture = useCapture; this.priority = priority; this.useWeakReference = useWeakReference; if (currentTarget == null) { this.currentTarget = obj; } else { this.currentTarget = currentTarget; } reflection = Reflection.factory(this.currentTarget); } public function bindKey(type:String):void { - if(type == KeyboardEvent.KEY_DOWN) { - obj.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, useCapture, priority, useWeakReference); - } else { - obj.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler, useCapture, priority, useWeakReference); - } + obj.addEventListener(type, KeyboardEvent.KEY_DOWN == type ? keyDownHandler : keyUpHandler, useCapture, priority, useWeakReference); } public function destroy():void { KeyTypeListener.detach(obj); } internal function destroyImpl():void { obj.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, useCapture); obj.removeEventListener(KeyboardEvent.KEY_UP, keyUpHandler, useCapture); } + // みじかくできる protected function keyDownHandler(e:KeyboardEvent):void { keyHandlerDelegeter(e, key_down); } protected function keyUpHandler(e:KeyboardEvent):void { keyHandlerDelegeter(e, key_up); } + + protected function isIgnore(o:*):Boolean { + if (ignoreTargets.length) { + for each(var klass:Class in ignoreTargets) { + if (o is klass) return true; + } + } + return false; + } protected function keyHandlerDelegeter(e:KeyboardEvent, ns:Namespace):void { + if (isIgnore(e.target)) return; + if (!(e.target == this.currentTarget || e.target == this.obj)) { if (e.target.stage && this.obj == e.target.stage) { // ... } else { return; } } // log(String.fromCharCode(e.charCode)); var methodName:String = getMethodName(e); // log(methodName, ns); methodCall(e, 'before', ns); methodCall(e, methodName, ns); methodCall(e, 'after', ns); } private function methodCall(e:KeyboardEvent, methodName:String, ns:Namespace):void { var argsNum:int = reflection.methodArgs(methodName, ns); if(argsNum >= 0) { switch(argsNum) { case 0: currentTarget.ns::[methodName].call(currentTarget); break; case 1: currentTarget.ns::[methodName].call(currentTarget, e); break; default: throw new Error(methodName + ' arguments should be 0 or 1'); break; } } else if(methodName == 'after') { // default after call stopPropagation because always looping event... - e.stopPropagation(); + if (forceStop) e.stopPropagation(); } } private const RE_NUM_CHAR:RegExp = /^\d$/; public function getMethodName(e:KeyboardEvent):String { if (keyboardConstfromCharCode(e.keyCode)) { return keyboardConstfromCharCode(e.keyCode); } var char:String = String.fromCharCode(e.keyCode); if (!e.shiftKey) char = char.toLowerCase(); if (e.ctrlKey) char = 'CTRL_' + char; if (RE_NUM_CHAR.test(char)) char = '_' + char; return char; } public static function keyboardConstfromCharCode(code:uint):String { return Reflection.factory(Keyboard).constantsTable[code]; } } } diff --git a/src/com/rails2u/utils/MathUtil.as b/src/com/rails2u/utils/MathUtil.as index 037af40..0962623 100644 --- a/src/com/rails2u/utils/MathUtil.as +++ b/src/com/rails2u/utils/MathUtil.as @@ -1,93 +1,97 @@ package com.rails2u.utils { public class MathUtil { public static function randomPlusMinus(val:Number = 1):Number { if (randomBoolean() ) { return val; } else { return val * -1; } } /* * randomBoolean(-100, 100); // retun value is between -100 and 100; */ public static function randomBetween(s:Number, e:Number = 0):Number { return s + (e - s) * Math.random(); } /* * randomBetween(); // return value is true or false. */ public static function randomBoolean():Boolean { return (Math.round(Math.random()) == 1) ? true : false; } + public static function minMax(val:Number, min:Number, max:Number):Number { + return Math.min(max, Math.max(min, val)); + } + /* * randomPickup(1,2,3,4); // return value is 1 or 2 or 3 or 4 */ public static function randomPickup(... args):* { var len:uint = args.length; if (len == 1) { return args[0]; } else { return args[Math.round(Math.random() * (len - 1))]; } } /* * var cycleABC = MathUtil.cycle('a', 'b', 'c'); * cycleABC(); // 'a' * cycleABC(); // 'b' * cycleABC(); // 'c' * cycleABC(); // 'a' * cycleABC(); // 'b' */ public static function cycle(... args):Function { var len:uint = args.length; var i:uint = 0; if (len == 1) { return function():Object { return args[0]; } } else { return function():Object { var res:Object = args[i]; i++; if (i >= len) i = 0; return res; }; } } public static function bezier3(t:Number, x0:Number, x1:Number, x2:Number, x3:Number):Number { return x0 * Math.pow(1-t, 3) + 3 * x1 * t *Math.pow(1-t, 2) + 3 * x2 * Math.pow(t, 2) * 1-t + x3 * Math.pow(t, 3); } public static function quadraticBezier(t:Number, x0:Number, x1:Number, x2:Number, x3:Number):Number { return x0 * Math.pow(1-t, 3) + 3 * x1 * t *Math.pow(1-t, 2) + 3 * x2 * Math.pow(t, 2) * 1-t + x3 * Math.pow(t, 3); } public static function bezierN(t:Number, points:Array):Number { var res:Number = 0; var len:uint = points.length; var tm:Number = 1 - t; for (var i:uint=0; i < len;i++) { var pos:Number = points[i]; var tmp:Number = 1.0; var a:Number = len - 1; var b:Number = i; var c:Number = a - b; while (a > 1) { if(a > 1) tmp *= a; a -= 1; if(b > 1) tmp /= b; b -= 1; if(c > 1) tmp /= c; c -= 1; } tmp *= Math.pow(t, i) * Math.pow(tm, len -1 -i); res += tmp * pos; } return res; } } }
hotchpotch/as3rails2u
02f08229ab866b46534719cf63f4ef29348ef530
add attach JSCallback func
diff --git a/src/com/rails2u/debug/DebugWatcher.as b/src/com/rails2u/debug/DebugWatcher.as index 70da031..ffa17c3 100644 --- a/src/com/rails2u/debug/DebugWatcher.as +++ b/src/com/rails2u/debug/DebugWatcher.as @@ -1,39 +1,40 @@ package com.rails2u.debug { import flash.events.IEventDispatcher; import com.rails2u.utils.Reflection; import flash.events.Event; + import com.rails2u.utils.ObjectUtil; public class DebugWatcher { public static function monitorEvents(target:IEventDispatcher, ... arg):void { if ( arg.length > 0 ) { for each(var evName:String in arg) { target.addEventListener(evName, eventLog); } } else { var targetRefrection:Reflection = Reflection.factory(target); var eventlist:Array = targetRefrection.getAllDispatchEvents(); for each(var ary:Object in eventlist) { if(ary.name != Event.ENTER_FRAME) target.addEventListener(ary.name, eventLog); } } } public static function unmonitorEvents(target:IEventDispatcher, ... arg):void { if ( arg.length > 0 ) { for each(var evName:String in arg) { target.removeEventListener(evName, eventLog); } } else { var targetRefrection:Reflection = Reflection.factory(target); var eventlist:Array = targetRefrection.getAllDispatchEvents(); for each(var ary:Object in eventlist) { if(ary.name != Event.ENTER_FRAME) target.removeEventListener(ary.name, eventLog); } } } protected static function eventLog(e:Event):void { - log(e); + log(ObjectUtil.inspect(e)); } } } diff --git a/src/com/rails2u/utils/JSUtil.as b/src/com/rails2u/utils/JSUtil.as index 5f67c94..3a31905 100644 --- a/src/com/rails2u/utils/JSUtil.as +++ b/src/com/rails2u/utils/JSUtil.as @@ -1,53 +1,67 @@ package com.rails2u.utils { import flash.external.ExternalInterface; + import flash.utils.describeType; public class JSUtil { + public static function attachCallbacks(target:*):void { + if (!ExternalInterface.available) + return; + + var res:XMLList = describeType(target).method. + (String(attribute('uri')) == js_callback.uri); + + for each (var n:* in res) { + var method:String = [email protected](); + ExternalInterface.addCallback(method, target.js_callback::[method]); + } + } + public static function getObjectID():String { return ExternalInterface.objectID; } public static function selfCallJS(cmd:String):* { cmd = "return document.getElementById('" + getObjectID() + "')." + cmd; return callJS(cmd); } public static function callJS(cmd:String, ...args):* { if (!ExternalInterface.available) return null; if (args.length > 0) { cmd = "(function() {" + cmd + ".apply(null, arguments);})"; return ExternalInterface.call.apply(null, [cmd].concat(args)); } else { cmd = "(function() {" + cmd + ";})"; return ExternalInterface.call(cmd); } } public static function bindCallJS(bindName:String):Function { return function(cmd:String):* { return callJS(bindName + cmd); }; } public static function buildQueryString(hash:Object):String { var res:Array = []; for (var key:String in hash) { res.push(encodeURIComponent(key) + '=' + encodeURIComponent(hash[key])); } return res.join('&'); } public static function restoreQueryString(str:String):Object { var hash:Object = {}; var res:Array = str.replace(/^#/, '').split('&'); for each(var s:String in res) { if (s.indexOf('=') > 0 && s.length >= 2) { var keyval:Array = s.split('=', 2); hash[keyval[0]] = keyval[1]; } } return hash; } } } diff --git a/src/com/rails2u/utils/js_callback.as b/src/com/rails2u/utils/js_callback.as new file mode 100644 index 0000000..df3e97d --- /dev/null +++ b/src/com/rails2u/utils/js_callback.as @@ -0,0 +1,3 @@ +package com.rails2u.utils { + public namespace js_callback = 'http://rails2u.com/utils/js_callback'; +}
hotchpotch/as3rails2u
5e0430f5c880c47c02780c41d1ff084d938c0018
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@79 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/geom/RMatrix4.as b/src/com/rails2u/geom/RMatrix4.as index a92d7fb..ebea4bd 100644 --- a/src/com/rails2u/geom/RMatrix4.as +++ b/src/com/rails2u/geom/RMatrix4.as @@ -1,360 +1,399 @@ package com.rails2u.geom { import com.rails2u.utils.ObjectUtil; import flash.geom.Matrix; public class RMatrix4 { public var a00:Number = 1, a01:Number = 0, a02:Number = 0, a03:Number = 0; public var a10:Number = 0, a11:Number = 1, a12:Number = 0, a13:Number = 0; public var a20:Number = 0, a21:Number = 0, a22:Number = 1, a23:Number = 0; public function RMatrix4(args:Array = null) { if (args && args.length == 12) { a00 = args[0]; a01 = args[1]; a02 = args[2]; a03 = args[3]; a10 = args[4]; a11 = args[5]; a12 = args[6]; a13 = args[7]; a20 = args[8]; a21 = args[9]; a22 = args[10]; a23 = args[11]; } } public function identity():RMatrix4 { a01, a02, a03, a10, a12, a13, a20, a21, a23 = 0 a00, a11, a22 = 1; return this; } public static function identity():RMatrix4 { return new RMatrix4(); } public static function translation(tx:Number = 0, ty:Number = 0, tz:Number = 0):RMatrix4 { return new RMatrix4([ - 1, 0, 0, tx, - 0, 1, 0, ty, - 0, 0, 1, tz - ]); - } + 1, 0, 0, tx, + 0, 1, 0, ty, + 0, 0, 1, tz + ]); + } public function clone():RMatrix4 { return new RMatrix4([ - a00, a01, a02, a03, - a10, a11, a12, a13, - a20, a21, a22, a23 + a00, a01, a02, a03, + a10, a11, a12, a13, + a20, a21, a22, a23 ]); } public function equals(m:RMatrix4):Boolean { return a00 == m.a00 && a01 == m.a01 && a02 == m.a02 && a03 == m.a03 && a10 == m.a10 && a11 == m.a11 && a12 == m.a12 && a13 == m.a13 && a20 == m.a20 && a21 == m.a21 && a22 == m.a22 && a23 == m.a23; } public function add(m:RMatrix4):RMatrix4 { return new RMatrix4([ a00 + m.a00, a01 + m.a01, a02 + m.a02, a03 + m.a03, a10 + m.a10, a11 + m.a11, a12 + m.a12, a13 + m.a13, a20 + m.a20, a21 + m.a21, a22 + m.a22, a23 + m.a23 ]); } public function subtract(m:RMatrix4):RMatrix4 { return new RMatrix4([ a00 - m.a00, a01 - m.a01, a02 - m.a02, a03 - m.a03, a10 - m.a10, a11 - m.a11, a12 - m.a12, a13 - m.a13, a20 - m.a20, a21 - m.a21, a22 - m.a22, a23 - m.a23 ]); } public function scalerMultiply(scale:Number):RMatrix4 { return new RMatrix4([ a00 * scale,a01 * scale,a02 * scale,a03 * scale, a10 * scale,a11 * scale,a12 * scale,a13 * scale, a20 * scale,a21 * scale,a22 * scale,a23 * scale ]); } /* public function scalerVector3(v:RVector3):RMatrix4 { var m:RMatrix4 = new RMatrix4(); m.a00 = v.x; m.a11 = v.y; m.a22 = v.z; return clone().multiply(m); } */ public function multiply(m:RMatrix4):RMatrix4 { return new RMatrix4([ this.a00 * m.a00 + this.a01 * m.a10 + this.a02 * m.a20, this.a00 * m.a01 + this.a01 * m.a11 + this.a02 * m.a21, this.a00 * m.a02 + this.a01 * m.a12 + this.a02 * m.a22, this.a00 * m.a03 + this.a01 * m.a13 + this.a02 * m.a23 + this.a03, this.a10 * m.a00 + this.a11 * m.a10 + this.a12 * m.a20, this.a10 * m.a01 + this.a11 * m.a11 + this.a12 * m.a21, this.a10 * m.a02 + this.a11 * m.a12 + this.a12 * m.a22, this.a10 * m.a03 + this.a11 * m.a13 + this.a12 * m.a23 + this.a13, this.a20 * m.a00 + this.a21 * m.a10 + this.a22 * m.a20, this.a20 * m.a01 + this.a21 * m.a11 + this.a22 * m.a21, this.a20 * m.a02 + this.a21 * m.a12 + this.a22 * m.a22, this.a20 * m.a03 + this.a21 * m.a13 + this.a22 * m.a23 + this.a23 ]); } public function multiply3x3(m:RMatrix4):RMatrix4 { return new RMatrix4([ this.a00 * m.a00 + this.a01 * m.a10 + this.a02 * m.a20, this.a00 * m.a01 + this.a01 * m.a11 + this.a02 * m.a21, this.a00 * m.a02 + this.a01 * m.a12 + this.a02 * m.a22, this.a03, this.a10 * m.a00 + this.a11 * m.a10 + this.a12 * m.a20, this.a10 * m.a01 + this.a11 * m.a11 + this.a12 * m.a21, this.a10 * m.a02 + this.a11 * m.a12 + this.a12 * m.a22, this.a13, this.a20 * m.a00 + this.a21 * m.a10 + this.a22 * m.a20, this.a20 * m.a01 + this.a21 * m.a11 + this.a22 * m.a21, this.a20 * m.a02 + this.a21 * m.a12 + this.a22 * m.a22, this.a23, ]); } /* * return @self */ public function copy3x3(m:RMatrix4):RMatrix4 { a00 = m.a00; a01 = m.a01; a02 = m.a02; a10 = m.a10; a11 = m.a11; a12 = m.a12; a20 = m.a20; a21 = m.a21; a22 = m.a22; return this; } + public function copy(m:RMatrix4):RMatrix4 { + a00 = m.a00; a01 = m.a01; a02 = m.a02; a03 = m.a03; + a10 = m.a10; a11 = m.a11; a12 = m.a12; a13 = m.a13; + a20 = m.a20; a21 = m.a21; a22 = m.a22; a23 = m.a23; + return this; + } + + public function clear():RMatrix4 { + a00 = 1; a01 = 0; a02 = 0; a03 = 0; + a10 = 0; a11 = 1; a12 = 0; a13 = 0; + a20 = 0; a21 = 0; a22 = 1; a23 = 0; + return this; + } + public function multiplyVector3(v:RVector3):RMatrix4 { - return multiply(v.matrix4()); + return multiply(v.matrix()); } public function concatVector3(v:RVector3):RMatrix4 { - return concat(v.matrix4()); + return concat(v.matrix()); + } + + public function toArray():Array { + return [ + a00, a01,a02, a03, + a10, a11,a12, a13, + a20, a21,a22, a23 + ]; } public function concat(m:RMatrix4):RMatrix4 { var _a00:Number = this.a00 * m.a00 + this.a01 * m.a10 + this.a02 * m.a20; var _a01:Number = this.a00 * m.a01 + this.a01 * m.a11 + this.a02 * m.a21; var _a02:Number = this.a00 * m.a02 + this.a01 * m.a12 + this.a02 * m.a22; var _a03:Number = this.a00 * m.a03 + this.a01 * m.a13 + this.a02 * m.a23 + this.a03; var _a10:Number = this.a10 * m.a00 + this.a11 * m.a10 + this.a12 * m.a20; var _a11:Number = this.a10 * m.a01 + this.a11 * m.a11 + this.a12 * m.a21; var _a12:Number = this.a10 * m.a02 + this.a11 * m.a12 + this.a12 * m.a22; var _a13:Number = this.a10 * m.a03 + this.a11 * m.a13 + this.a12 * m.a23 + this.a13; var _a20:Number = this.a20 * m.a00 + this.a21 * m.a10 + this.a22 * m.a20; var _a21:Number = this.a20 * m.a01 + this.a21 * m.a11 + this.a22 * m.a21; var _a22:Number = this.a20 * m.a02 + this.a21 * m.a12 + this.a22 * m.a22; var _a23:Number = this.a20 * m.a03 + this.a21 * m.a13 + this.a22 * m.a23 + this.a23; a00 = _a00, a01 = _a01, a02 = _a02, a03 = _a03; a10 = _a10, a11 = _a11, a12 = _a12, a13 = _a13; a20 = _a20, a21 = _a21, a22 = _a22, a23 = _a23; return this; } public function get det():Number { return (a00 * a11 - a10 * a01) * a22 - (a00 * a21 - a20 * a01) * a12 + (a10 * a21 - a20 * a11) * a02; } public function inverse():RMatrix4 { if (Math.abs(det) <= 1.0e-64) { return new RMatrix4([0,0,0,0, 0,0,0,0, 0,0,0,0]); } else { var invDet:Number = 1/det; return new RMatrix4([ invDet * (a11 * a22 - a21 * a12), invDet * -(a01 * a22 - a21 * a02), invDet * (a01 * a12 - a11 * a02), invDet * -(a01 * (a12 * a23 - a22 * a13) - a11 * (a02 * a23 - a22 * a03) + a21 * (a02 * a13 - a12 * a03)), invDet * -(a10 * a22 - a20 * a12), invDet * (a00 * a22 - a20 * a02), invDet * -(a00 * a12 - a10 * a02), invDet * (a00 * (a12 * a23 - a22 * a13) - a10 * (a02 * a23 - a22 * a03) + a20 * (a02 * a13 - a12 * a03)), invDet * (a10 * a21 - a20 * a11), invDet * -(a00 * a21 - a20 * a01), invDet * (a00 * a11 - a10 * a01), invDet * -(a00 * (a11 * a23 - a21 * a13) - a10 * (a01 * a23 - a21 * a03) + a20 * (a01 * a13 - a11 * a03)), ]); } } public function get tx():Number { return a03; } public function get ty():Number { return a13; } public function get tz():Number { return a23; } public function set tx(v:Number):void { a03 = v; } public function set ty(v:Number):void { a13 = v; } public function set tz(v:Number):void { a23 = v; } - public function vector3():RVector3 { + public function vector():RVector3 { + //return transformVector3(new RVector3(tx, ty, tz)); return transformVector3(new RVector3(tx, ty, tz)); //var m:RMatrix4 = new RMatrix4(); //m.tx = tx; //m.ty = ty; //m.tz = tz; //var m2:RMatrix4 = multiply(m); //return new RVector3(m2.tx, m2.ty, m2.tz); } public function transformVector3(v:RVector3):RVector3 { - var vx:Number = v.x; - var vy:Number = v.y; - var vz:Number = v.z; - v.x = vx * a00 + vy * a01 + vz * a02;// + a03; - v.y = vx * a10 + vy * a11 + vz * a12;// + a13; - v.z = vx * a20 + vy * a21 + vz * a22;// + a23; + v = v.clone(); + var vx:Number = v.x + tx; + var vy:Number = v.y + ty; + var vz:Number = v.z + tz; + v.x = vx * a00 + vy * a01 + vz * a02 ; + v.y = vx * a10 + vy * a11 + vz * a12 ; + v.z = vx * a20 + vy * a21 + vz * a22 ; return v; //return new RVector3( // v.x * a00 + v.y * a01 + v.z * a02 + a03, // v.x * a10 + v.y * a11 + v.z * a12 + a13, // v.x * a20 + v.y * a21 + v.z * a22 + a23 //); } public function transformXYZ(x:Number, y:Number, z:Number):Array { - var vx:Number = x; - var vy:Number = y; - var vz:Number = z; - x = vx * a00 + vy * a01 + vz * a02; - y = vx * a10 + vy * a11 + vz * a12; - z = vx * a20 + vy * a21 + vz * a22; + var vx:Number = x + tx; + var vy:Number = y + ty; + var vz:Number = z + tz; + x = vx * a00 + vy * a01 + vz * a02 + a03; + y = vx * a10 + vy * a11 + vz * a12 + a13; + z = vx * a20 + vy * a21 + vz * a22 + a23; return [x, y, z]; } public function transformXY(x:Number, y:Number, vz:Number):Array { - var vx:Number = x; - var vy:Number = y; - x = vx * a00 + vy * a01 + vz * a02; - y = vx * a10 + vy * a11 + vz * a12; + var vx:Number = x + tx; + var vy:Number = y + ty; + x = vx * a00 + vy * a01 + vz * a02 + a03; + y = vx * a10 + vy * a11 + vz * a12 + a13; return [x, y]; } public function rotateX(rad:Number):RMatrix4 { return concat(rotationX(rad)); } public function rotateY(rad:Number):RMatrix4 { return concat(rotationY(rad)); } public function rotateZ(rad:Number):RMatrix4 { return concat(rotationZ(rad)); } public function scaleX(factor:Number):RMatrix4 { return concat(RMatrix4.scaleX(factor)); } public function scaleY(factor:Number):RMatrix4 { return concat(RMatrix4.scaleY(factor)); } public function scaleZ(factor:Number):RMatrix4 { return concat(RMatrix4.scaleZ(factor)); } public function scale(fx:Number, fy:Number = NaN, fz:Number = NaN):RMatrix4 { if (isNaN(fy)) fy = fz = fx; return scaleX(fx).scaleY(fy).scaleZ(fz); } public function toString():String { return "RMatrix4: [\n" + "[" + [a00,a01,a02,a03].join(", ") + "]\n" + "[" + [a10,a11,a12,a13].join(", ") + "]\n" + "[" + [a02,a21,a22,a23].join(", ") + "]]"; } public function flMatrix():Matrix { //return new Matrix(values[0][0], values[0][1], values[1][0], // values[1][1], values[3][0], values[3][1]); //return new Matrix(a00, a01, tx, // a10, a11, ty); return new Matrix(a00, a01, a10, a11, 0, 0); } public static function scaleX(factor:Number):RMatrix4 { var m:RMatrix4 = identity(); m.a00 = factor; return m; } public static function scaleY(factor:Number):RMatrix4 { var m:RMatrix4 = identity(); m.a11 = factor; return m; } public static function scaleZ(factor:Number):RMatrix4 { var m:RMatrix4 = identity(); m.a22 = factor; return m; } public static function rotationX(rad:Number):RMatrix4 { var cos:Number = Math.cos(rad); var sin:Number = Math.sin(rad); return new RMatrix4([ 1 , 0 , 0 , 0 , 0 , cos , -sin , 0 , 0 , sin , cos , 0 , ]); } public static function rotationY(rad:Number):RMatrix4 { var cos:Number = Math.cos(rad); var sin:Number = Math.sin(rad); return new RMatrix4([ cos , 0 , sin , 0 , 0 , 1 , 0 , 0 , -sin , 0 , cos , 0 , ]); } public static function rotationZ(rad:Number):RMatrix4 { var cos:Number = Math.cos(rad); var sin:Number = Math.sin(rad); return new RMatrix4([ cos , -sin , 0 , 0 , sin , cos , 0 , 0 , 0 , 0 , 1 , 0 , ]); } + + public static function eulerRotation(a:Number, b:Number, c:Number):RMatrix4 { + var ca:Number = Math.cos(a); + var sa:Number = Math.sin(a); + var cb:Number = Math.cos(b); + var sb:Number = Math.sin(b); + var cc:Number = Math.cos(c); + var sc:Number = Math.sin(c); + return new RMatrix4([ + cb*cc , sa*sb*cc + ca*sc , -ca*sb*cc + sa*sc , 0 , + - cb*sc , -sa*sb*sc + ca*cc , ca*sb*sc + sa*cc , 0 , + sb , -sa*cb , ca*cb , 0 + ]); + + } } } diff --git a/src/com/rails2u/geom/RVector.as b/src/com/rails2u/geom/RVector.as index c1b5a2a..32d0c84 100644 --- a/src/com/rails2u/geom/RVector.as +++ b/src/com/rails2u/geom/RVector.as @@ -1,91 +1,99 @@ package com.rails2u.geom { import flash.geom.Point; public class RVector { public static const ZERO:RVector = new RVector(0, 0); public var x:Number = 0; public var y:Number = 0; public var stash:Object; public function RVector(x:Number = 0, y:Number = 0) { this.x = x; this.y = y; } + public static function newObj2(p1:Object, p2:Object):RVector { + return new RVector(p2.x - p1.x, p2.y - p1.y); + } + + public static function newObj(p1:Object):RVector { + return new RVector(p1.x, p1.y); + } + public function clone():RVector { return new RVector(x, y); } public function add(v:RVector):RVector { return new RVector(x + v.x, y + v.y); } public function subtract(v:RVector):RVector { return new RVector(x - v.x, y - v.y); } public function inverse():RVector { return new RVector(x * -1, y * -1); } public function multiply(n:Number):RVector { return new RVector(x * n, y * n); } public function get length():Number { return Math.sqrt(x*x + y*y); } public function equals(v:RVector):Boolean { return (x == v.x) && (y == v.y); } public function normalize(len:Number = 1):RVector { var l:Number = length / len; return l == 0 ? ZERO.clone() : new RVector(x / l, y / l); } public function dot(v:RVector):Number { return x * v.x + y * v.y; } public function distance(v:RVector):Number { return subtract(v).length; } public function degree(v:RVector):Number { var n0:RVector = normalize(); var n1:RVector = v.normalize(); // (n1.y < n0.y && n1.x > n0.x) || if (n1.y > n0.y && n1.x < n0.x) { return -1 * Math.acos(dot(v) / (length * v.length)); } else { return Math.acos(dot(v) / (length * v.length)); } } public function angle(v:RVector):Number { return degree(v) * 180/Math.PI; } public function toString():String { return 'RVector[x:' + x + ', y:' + y + ']'; } public function point():Point { return new Point(x, y); } public static function create(o:*):RVector { if (o.hasOwnProperty('x') && o.hasOwnProperty('y')) { return new RVector(o.x, o.y); } else if (o is Array && o.length == 2) { return new RVector(o[0], o[1]); } else { return null; } } } } diff --git a/src/com/rails2u/geom/RVector3.as b/src/com/rails2u/geom/RVector3.as index be76c14..6ca9851 100644 --- a/src/com/rails2u/geom/RVector3.as +++ b/src/com/rails2u/geom/RVector3.as @@ -1,101 +1,107 @@ package com.rails2u.geom { import flash.geom.Point; + import flash.utils.Dictionary; public class RVector3 { public static const ZERO:RVector3 = new RVector3(0, 0, 0); public var x:Number = 0; public var y:Number = 0; public var z:Number = 0; - public var stash:Object; + public var stash:Dictionary; public function RVector3(x:Number = 0, y:Number = 0, z:Number = 0) { this.x = x; this.y = y; this.z = z; + this.stash = new Dictionary(); } public function clone():RVector3 { return new RVector3(x, y, z); } public function add(v:RVector3):RVector3 { return new RVector3(x + v.x, y + v.y, z + v.z); } public function concat(v:RVector3):RVector3 { x += v.x; y += v.y; z += v.z; return this; } public function subtract(v:RVector3):RVector3 { return new RVector3(x - v.x, y - v.y, z - v.z); } public function inverse():RVector3 { return new RVector3(x * -1, y * -1, z * -1); } public function multiply(n:Number):RVector3 { return new RVector3(x * n, y * n, z * n); } public function get length():Number { return Math.sqrt(x*x + y*y + z*z); } public function equals(v:RVector3):Boolean { return (x == v.x) && (y == v.y) && (z == v.z); } public function normalize(len:Number = 1):RVector3 { var l:Number = length / len; return l == 0 ? ZERO.clone() : new RVector3(x / l, y / l, z / l); } public function dot(v:RVector3):Number { return x * v.x + y * v.y + z * v.z; } public function cross(v:RVector3):RVector3 { return new RVector3(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x); } public function distance(v:RVector3):Number { return subtract(v).length; } + public function vector2():RVector { + return new RVector(x, y); + } + public function degree(v:RVector3):Number { /* var n0:RVector3 = normalize(); var n1:RVector3 = v.normalize(); // (n1.y < n0.y && n1.x > n0.x) || if (n1.y > n0.y && n1.x < n0.x) { return -1 * Math.acos(dot(v) / (length * v.length)); } else { return Math.acos(dot(v) / (length * v.length)); } */ return Math.acos(dot(v) / (length * v.length)); } public function angle(v:RVector3):Number { return degree(v) * 180/Math.PI; } // not test.. - public function matrix4():RMatrix4 { + public function matrix():RMatrix4 { var m:RMatrix4 = new RMatrix4(); m.tx = x; m.ty = y; m.tz = z; return m; } public function toString():String { return 'RVector3[x:' + x + ', y:' + y + ', z:' + z + ']'; } } } diff --git a/src/com/rails2u/record/MouseRecordPlayer.as b/src/com/rails2u/record/MouseRecordPlayer.as new file mode 100644 index 0000000..7045faa --- /dev/null +++ b/src/com/rails2u/record/MouseRecordPlayer.as @@ -0,0 +1,99 @@ +package com.rails2u.record { + import flash.display.InteractiveObject; + import flash.utils.ByteArray; + import flash.events.Event; + import flash.utils.getTimer; + import flash.events.MouseEvent; + import flash.display.DisplayObjectContainer; + import flash.events.EventDispatcher; + + public class MouseRecordPlayer extends EventDispatcher { + protected var _canvas:InteractiveObject; + protected var records:Array; + protected var originalRecords:Array; + public function MouseRecordPlayer(canvas:InteractiveObject) { + _canvas = canvas; + } + + public function setRecords(records:ByteArray):void { + var ba:ByteArray = ByteArray(records); + ba.uncompress(); + ba.position = 0; + this.records = ba.readObject(); + originalRecords = this.records.slice(0); + } + + protected var _playing:Boolean = false; + public function get playing():Boolean { + return _playing; + } + + public function play():Boolean { + if (playing) return false; + + _playing = true; + _canvas.addEventListener(Event.ENTER_FRAME, enterFrameHandler); + dispatchEvent(new RecordEvent(RecordEvent.PLAY)); + return true; + } + + public function stop():Boolean { + if (!playing) return false; + _playing = false; + _canvas.removeEventListener(Event.ENTER_FRAME, enterFrameHandler); + dispatchEvent(new RecordEvent(RecordEvent.STOP)); + return true; + } + + public function pause():void { + // ToDo + } + + public function forceFinish():void { + while(records.length > 0) { + var cur:Array = records.shift(); + var ev:MouseEvent = objectToMouseEvent(cur[1]); + var t:InteractiveObject = InteractiveObject(DisplayObjectContainer(_canvas).getChildByName(cur[1].name)) || _canvas; + t.dispatchEvent(ev); + } + dispatchEvent(new RecordEvent(RecordEvent.FINISH)); + } + + protected var playStart:uint; + protected function enterFrameHandler(e:Event):void { + playStart ||= getTimer(); + var now:uint = getTimer(); + + while(records.length > 0 && (records[0][0] <= (now - playStart))) { + var cur:Array = records.shift(); + var ev:MouseEvent = objectToMouseEvent(cur[1]); + //log(ev.type, ev); + //var t:InteractiveObject = (typeObject(cur[2]) as InteractiveObject); + //if(t) t.dispatchEvent(ev); + //log(cur[1].name); + var t:InteractiveObject = InteractiveObject(DisplayObjectContainer(_canvas).getChildByName(cur[1].name)) || _canvas; + t.dispatchEvent(ev); + } + if (records.length == 0) + dispatchEvent(new RecordEvent(RecordEvent.FINISH)); + } + + private function objectToMouseEvent(o:Object):MouseEvent { + var e:MouseEvent = new MouseEvent(o.type, true, false, o.localX, o.localY, + o.relatedObject, o.ctrlKey, o.altKey, o.shiftKey, o.buttonDown, o.delta + ); + /* + delete o['type']; + delete o['name']; + delete o['target']; + delete o['relatedObject']; + + for (var key:String in o) { + if (o[key] !== null) + e[key] = o[key]; + } + */ + return e; + } + } +} diff --git a/src/com/rails2u/record/ObjectRecordPlayer.as b/src/com/rails2u/record/ObjectRecordPlayer.as new file mode 100644 index 0000000..f0b2445 --- /dev/null +++ b/src/com/rails2u/record/ObjectRecordPlayer.as @@ -0,0 +1,19 @@ +package com.rails2u.record { + import flash.utils.ByteArray; + + public class ObjectRecordPlayer extends RecordPlayer { + public var targetObject:Object; + + public function ObjectRecordPlayer(records:Array, targetObject:Object) { + super(records); + this.targetObject = targetObject; + addEventListener(RecordEvent.EVENT, methodDispatchHandler); + } + + protected function methodDispatchHandler(e:RecordEvent):void { + var record:Array = e.record.slice(0); + var methodName:String = record.splice(0, 1); + targetObject[methodName].apply(targetObject, record); + } + } +} diff --git a/src/com/rails2u/record/RecordEvent.as b/src/com/rails2u/record/RecordEvent.as index ba7393f..042f7d1 100644 --- a/src/com/rails2u/record/RecordEvent.as +++ b/src/com/rails2u/record/RecordEvent.as @@ -1,14 +1,21 @@ package com.rails2u.record { import flash.events.Event; public class RecordEvent extends Event { - public static const PLAY:String = 'start'; + public static const START:String = 'start'; + public static const PLAY:String = 'play'; public static const STOP:String = 'stop'; public static const PAUSE:String = 'pause'; public static const FINISH:String = 'finish'; - public function RecordEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false):void { + public static const EVENT:String = 'event'; + + public function RecordEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, record:Array = null):void { super(type, bubbles, cancelable); + + if (record) + this.record = record; } + public var record:Array; } } diff --git a/src/com/rails2u/record/RecordPlayer.as b/src/com/rails2u/record/RecordPlayer.as index b0c7e5c..a0d468f 100644 --- a/src/com/rails2u/record/RecordPlayer.as +++ b/src/com/rails2u/record/RecordPlayer.as @@ -1,99 +1,75 @@ package com.rails2u.record { - import flash.display.InteractiveObject; - import flash.utils.ByteArray; import flash.events.Event; import flash.utils.getTimer; - import flash.events.MouseEvent; - import flash.display.DisplayObjectContainer; - import flash.events.EventDispatcher; + import flash.utils.Timer; + import flash.events.TimerEvent; - public class RecordPlayer extends EventDispatcher { - protected var _canvas:InteractiveObject; + public class RecordPlayer extends Timer { protected var records:Array; protected var originalRecords:Array; - public function RecordPlayer(canvas:InteractiveObject) { - _canvas = canvas; + + public function RecordPlayer(records:Array) { + super(10, 0); + setRecords(records); + addEventListener(TimerEvent.TIMER, timerHander); } - public function setRecords(records:ByteArray):void { + public function setRecords(records:Array):void { + /* var ba:ByteArray = ByteArray(records); ba.uncompress(); ba.position = 0; this.records = ba.readObject(); + */ + this.records = records.splice(0); originalRecords = this.records.slice(0); } - protected var _playing:Boolean = false; - public function get playing():Boolean { - return _playing; + public override function start():void { + super.start(); + dispatchEvent(new RecordEvent(RecordEvent.START)); } - public function play():Boolean { - if (playing) return false; - - _playing = true; - _canvas.addEventListener(Event.ENTER_FRAME, enterFrameHandler); - dispatchEvent(new RecordEvent(RecordEvent.PLAY)); - return true; + public function get totalTime():uint { + return records[records.length-1][0]; } - public function stop():Boolean { - if (!playing) return false; - _playing = false; - _canvas.removeEventListener(Event.ENTER_FRAME, enterFrameHandler); + public override function stop():void { + super.stop(); dispatchEvent(new RecordEvent(RecordEvent.STOP)); - return true; } public function pause():void { // ToDo } public function forceFinish():void { while(records.length > 0) { - var cur:Array = records.shift(); - var ev:MouseEvent = objectToMouseEvent(cur[1]); - var t:InteractiveObject = InteractiveObject(DisplayObjectContainer(_canvas).getChildByName(cur[1].name)) || _canvas; - t.dispatchEvent(ev); + sendEvent(); } dispatchEvent(new RecordEvent(RecordEvent.FINISH)); + stop(); } + public var playSpeed:Number = 1; protected var playStart:uint; - protected function enterFrameHandler(e:Event):void { + protected function timerHander(e:Event):void { playStart ||= getTimer(); - var now:uint = getTimer(); + var now:uint = getTimer() * playSpeed; while(records.length > 0 && (records[0][0] <= (now - playStart))) { - var cur:Array = records.shift(); - var ev:MouseEvent = objectToMouseEvent(cur[1]); - //log(ev.type, ev); - //var t:InteractiveObject = (typeObject(cur[2]) as InteractiveObject); - //if(t) t.dispatchEvent(ev); - //log(cur[1].name); - var t:InteractiveObject = InteractiveObject(DisplayObjectContainer(_canvas).getChildByName(cur[1].name)) || _canvas; - t.dispatchEvent(ev); + sendEvent(); } - if (records.length == 0) + if (records.length == 0) { + stop(); dispatchEvent(new RecordEvent(RecordEvent.FINISH)); + } } - private function objectToMouseEvent(o:Object):MouseEvent { - var e:MouseEvent = new MouseEvent(o.type, true, false, o.localX, o.localY, - o.relatedObject, o.ctrlKey, o.altKey, o.shiftKey, o.buttonDown, o.delta - ); - /* - delete o['type']; - delete o['name']; - delete o['target']; - delete o['relatedObject']; - - for (var key:String in o) { - if (o[key] !== null) - e[key] = o[key]; - } - */ - return e; + protected function sendEvent():void { + var record:Array = records.shift(); + // record = [currentTime, args] + dispatchEvent(new RecordEvent(RecordEvent.EVENT, false, false, record[1])); } } } diff --git a/src/com/rails2u/record/Recorder.as b/src/com/rails2u/record/Recorder.as index 4c413c2..ccc1245 100644 --- a/src/com/rails2u/record/Recorder.as +++ b/src/com/rails2u/record/Recorder.as @@ -1,4 +1,56 @@ package com.rails2u.record { + import flash.utils.ByteArray; + import flash.utils.getTimer; public class Recorder { + protected var records:Array = []; + + public function Recorder() { + } + + protected var _started:Boolean = false; + public function get started():Boolean { + return _started; + } + + public function start():Boolean { + if (_started) { + return false; + } else { + _started = true; + return true; + } + } + + public function stop():Boolean { + if (started) { + _started = false; + return true; + } else { + return false; + } + } + + protected var _startRecordTime:uint; + public function get startRecordTime():uint { + return _startRecordTime; + } + + public function addRecord(...args):void { + _startRecordTime ||= getTimer(); + records.push([getTimer() - startRecordTime, args]); + } + + public function getRecords():Array { + return records.slice(0); + } + + public function getRecordsByteArra():ByteArray { + var b:ByteArray = new ByteArray; + b.writeObject(records); + b.position = 0; + b.compress(); + return b; + } + } } diff --git a/src/com/rails2u/utils/ColorUtil.as b/src/com/rails2u/utils/ColorUtil.as index a651729..3016bd3 100644 --- a/src/com/rails2u/utils/ColorUtil.as +++ b/src/com/rails2u/utils/ColorUtil.as @@ -1,57 +1,61 @@ package com.rails2u.utils { public class ColorUtil { public static function random( rMin:uint = 0, gMin:uint = 0, bMin:uint = 0, rMax:uint = 255, gMax:uint = 255, bMax:uint = 255 ):uint { return (uint(Math.random() * (rMax - rMin)) + rMin) << 16 | (uint(Math.random() * (gMax - gMin)) + gMin) << 8 | (uint(Math.random() * (bMax - bMin)) + bMin); } public static function random32( rMin:uint = 0, gMin:uint = 0, bMin:uint = 0, aMin:uint = 0, rMax:uint = 255, gMax:uint = 255, bMax:uint = 255, aMax:uint = 255 ):uint { return (uint(Math.random() * (aMax - aMin)) + aMin) << 24 | (uint(Math.random() * (rMax - rMin)) + rMin) << 16 | (uint(Math.random() * (gMax - gMin)) + gMin) << 8 | (uint(Math.random() * (bMax - bMin)) + bMin); } + public static function gray(col:uint):uint { + return col << 16 | col << 8 | col; + } + public static function sinArray(start:int = 255, end:int = 0, cycle:uint = 90):Array { var f:Function = sinGenerator(start, end, cycle); var a:Array = []; for (var i:uint = 0; i < cycle; i++) { // a.push(f( } return []; } public static function sinGenerator(start:int = 255, end:int = 0, cycle:uint = 90):Function { var times:uint = 0; var diff:int = start - end; var p:Number; return function():uint { p = (Math.sin(Math.PI/2 + Math.PI * 2 * (360 / cycle * times) / 360) + 1) / 2; times++; if(times >= cycle) times = 0; return end + (diff * p); } } } } diff --git a/src/com/rails2u/utils/JSUtil.as b/src/com/rails2u/utils/JSUtil.as index 1c83597..5f67c94 100644 --- a/src/com/rails2u/utils/JSUtil.as +++ b/src/com/rails2u/utils/JSUtil.as @@ -1,33 +1,53 @@ package com.rails2u.utils { import flash.external.ExternalInterface; public class JSUtil { public static function getObjectID():String { return ExternalInterface.objectID; } public static function selfCallJS(cmd:String):* { cmd = "return document.getElementById('" + getObjectID() + "')." + cmd; return callJS(cmd); } public static function callJS(cmd:String, ...args):* { if (!ExternalInterface.available) return null; if (args.length > 0) { cmd = "(function() {" + cmd + ".apply(null, arguments);})"; return ExternalInterface.call.apply(null, [cmd].concat(args)); } else { cmd = "(function() {" + cmd + ";})"; return ExternalInterface.call(cmd); } } public static function bindCallJS(bindName:String):Function { return function(cmd:String):* { return callJS(bindName + cmd); }; } + + public static function buildQueryString(hash:Object):String { + var res:Array = []; + for (var key:String in hash) { + res.push(encodeURIComponent(key) + '=' + encodeURIComponent(hash[key])); + } + return res.join('&'); + } + + public static function restoreQueryString(str:String):Object { + var hash:Object = {}; + var res:Array = str.replace(/^#/, '').split('&'); + for each(var s:String in res) { + if (s.indexOf('=') > 0 && s.length >= 2) { + var keyval:Array = s.split('=', 2); + hash[keyval[0]] = keyval[1]; + } + } + return hash; + } } }
hotchpotch/as3rails2u
347b6befad206ffde2c9b43633180111fdc38b0e
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@78 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/chain/Chain.as b/src/com/rails2u/chain/Chain.as index 0f60f59..26d0978 100644 --- a/src/com/rails2u/chain/Chain.as +++ b/src/com/rails2u/chain/Chain.as @@ -1,57 +1,123 @@ package com.rails2u.chain { import flash.events.EventDispatcher; import flash.events.Event; + import flash.events.IEventDispatcher; public class Chain extends EventDispatcher { - /* - * ToDo - * ErrorBack - */ - private var _parent:Chain; + public var results:*; + + public function Chain() { + } + + protected var _running:Boolean = false; + public function get running():Boolean { + return parent ? parent.running : _running; + } + public function set running(r:Boolean):void { + if (parent) { + parent.running = r; + } else { + _running = r; + } + } + public function get parent():Chain { return _parent; } public function set parent(__parent:Chain):void { _parent = __parent; _parent.setChild(this); } + public function get parentsResults():Array { + var p:Chain = parent; + var res:Array = []; + while (p) { + res.push(p.results); + p = p.parent; + } + return res; + } + protected var child:Chain; public function setChild(child:Chain):void { this.child = child; } public function chain(_chain:Chain):Chain { _chain.parent = this; return _chain; } public function start():Chain { + running = true; if (parent) { return parent.start(); } else { - execute(); + if (running) { + execute(); + } return this; } } + public function stop():Chain { + running = false; + return this; + } + protected function execute():void { finish(); next(); } protected function next():void { + //if (child && child.running) child.execute(); if (child) child.execute(); } protected function finish():void { + if (!child) _running = false; dispatchEvent(new Event(Event.COMPLETE)); } - //public function hasNext():Boolean { - // return _chains.length > _chainCounter; - //} + /* shortcut */ + public function parallel(...chains):ParallelChain { + return chain(new ParallelChain(chains)) as ParallelChain; + } + + public function eventChain( + target:IEventDispatcher, + executeFunction:Function = null, + completeEventName:String = Event.COMPLETE + ):EventChain { + return chain(new EventChain(target, executeFunction, completeEventName)) as EventChain; + } + + public function e( + target:IEventDispatcher, + executeFunction:Function = null, + completeEventName:String = Event.COMPLETE + ):EventChain { + return chain(new EventChain(target, executeFunction, completeEventName)) as EventChain; + } + + public function functionChain(executeFunction:Function, callNotify:Boolean = false):FunctionChain { + return chain(new FunctionChain(executeFunction, callNotify)) as FunctionChain; + } + + public function f(executeFunction:Function, callNotify:Boolean = false):FunctionChain { + return chain(new FunctionChain(executeFunction, callNotify)) as FunctionChain; + } + + public function loop(times:uint = 0):LoopChain { + return chain(new LoopChain(times)) as LoopChain; + } + + public function delay(msec:uint):DelayChain { + return chain(new DelayChain(msec)) as DelayChain; + } } } diff --git a/src/com/rails2u/chain/DelayChain.as b/src/com/rails2u/chain/DelayChain.as new file mode 100644 index 0000000..0485ac9 --- /dev/null +++ b/src/com/rails2u/chain/DelayChain.as @@ -0,0 +1,14 @@ +package com.rails2u.chain { + import flash.events.Event; + import flash.utils.Timer; + import flash.events.TimerEvent; + + public class DelayChain extends EventChain { + public function DelayChain(delay:uint) { + super(new Timer(delay, 1), function(c:Chain, t:Timer):void { + t.start(); + }, TimerEvent.TIMER_COMPLETE); + } + + } +} diff --git a/src/com/rails2u/chain/EventChain.as b/src/com/rails2u/chain/EventChain.as index a749d0d..e7e406b 100644 --- a/src/com/rails2u/chain/EventChain.as +++ b/src/com/rails2u/chain/EventChain.as @@ -1,28 +1,28 @@ package com.rails2u.chain { import flash.events.IEventDispatcher; import flash.events.Event; public class EventChain extends Chain { protected var target:IEventDispatcher; protected var executeFunction:Function; protected var completeEventName:String; public function EventChain(target:IEventDispatcher, executeFunction:Function = null, completeEventName:String = Event.COMPLETE) { super(); this.target = target; this.executeFunction = executeFunction as Function; this.completeEventName = completeEventName; } protected override function execute():void { target.addEventListener(completeEventName, completeHandler); - executeFunction.call(target); + executeFunction.call(null, this, target); } protected function completeHandler(e:Event):void { target.removeEventListener(completeEventName, completeHandler); finish(); next(); } } } diff --git a/src/com/rails2u/chain/FunctionChain.as b/src/com/rails2u/chain/FunctionChain.as index 988c8b8..19be92e 100644 --- a/src/com/rails2u/chain/FunctionChain.as +++ b/src/com/rails2u/chain/FunctionChain.as @@ -1,25 +1,34 @@ package com.rails2u.chain { import flash.events.EventDispatcher; import flash.events.Event; public class FunctionChain extends Chain { protected var executeFunction:Function; - public function FunctionChain(executeFunction:Function):void { + public var callNotify:Boolean; + public function FunctionChain(executeFunction:Function, callNotify:Boolean = false):void { super(); + this.callNotify = callNotify; this.executeFunction = executeFunction; } protected override function execute():void { - executeFunction.call(this, this); + executeFunction.call(null, this); + if (!callNotify) notify(); } + public function notify():void { + finish(); + next(); + } + + /* public function get completeNotifier():Function { var self:FunctionChain = this; return function():void { - self.finish(); - self.next(); + self.notify(); }; } + */ } } diff --git a/src/com/rails2u/chain/LoopChain.as b/src/com/rails2u/chain/LoopChain.as new file mode 100644 index 0000000..124d26c --- /dev/null +++ b/src/com/rails2u/chain/LoopChain.as @@ -0,0 +1,38 @@ +package com.rails2u.chain { + import flash.events.Event; + import flash.utils.setTimeout; + + public class LoopChain extends DelayChain { + public var repeatTimes:uint; + private var _currentTimes:uint = 0; + public function get currentTimes():uint { + return _currentTimes; + } + + public function LoopChain(times:uint = 0) { + repeatTimes = times; + super(0); // for async + } + + /* + public override function stop():Chain { + super.stop(); + finish(); + return this; + } + */ + + protected override function completeHandler(e:Event):void { + target.removeEventListener(completeEventName, completeHandler); + if (!running) return; + + _currentTimes++; + if (repeatTimes == 0 || currentTimes < repeatTimes) { + start(); + } else { + finish(); + next(); + } + } + } +} diff --git a/src/com/rails2u/chain/ParallelChain.as b/src/com/rails2u/chain/ParallelChain.as index c87752f..6d34d5f 100644 --- a/src/com/rails2u/chain/ParallelChain.as +++ b/src/com/rails2u/chain/ParallelChain.as @@ -1,40 +1,52 @@ package com.rails2u.chain { import flash.events.Event; + import flash.utils.Dictionary; public class ParallelChain extends Chain { - /* - * 実装は Chain#addCallback を追加してやるべき? - * この実装では一階層目のチェインだけで終わってしまう? - */ - protected var _chainCounter:uint = 0; + protected var finishedChains:Array = []; protected var _chains:Array = []; + public function ParallelChain(chains:Array = null) { + if (chains) addParallelChains(chains); + } + public function addParallelChain(c:Chain):ParallelChain { c.addEventListener(Event.COMPLETE, completeHandler); _chains.push(c); return this; } public function addParallelChains(args:Array):ParallelChain { for each(var c:Chain in args) { addParallelChain(c); } return this; } protected override function execute():void { for each(var c:Chain in _chains) { c.start(); } } protected function completeHandler(e:Event):void { - e.target.removeEventListener(Event.COMPLETE, completeHandler); - _chainCounter++; - if (_chains.length <= _chainCounter) { + // e.target.removeEventListener(Event.COMPLETE, completeHandler); + if (finishedChains.indexOf(e.target) == -1) + finishedChains.push(Chain(e.target)); + + results = getSortedResults(); + if (_chains.length <= finishedChains.length) { finish(); next(); } } + + protected function getSortedResults():Array { + var res:Array = []; + for each(var c:Chain in _chains) { + if (finishedChains.indexOf(c) != -1) res.push(c.results); + } + return res; + } } }
hotchpotch/as3rails2u
465f3308ab24177ab947467b7c61b380eca98b6c
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@77 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/geom/RMatrix4.as b/src/com/rails2u/geom/RMatrix4.as index 4f5ee4b..a92d7fb 100644 --- a/src/com/rails2u/geom/RMatrix4.as +++ b/src/com/rails2u/geom/RMatrix4.as @@ -1,350 +1,360 @@ package com.rails2u.geom { import com.rails2u.utils.ObjectUtil; + import flash.geom.Matrix; public class RMatrix4 { public var a00:Number = 1, a01:Number = 0, a02:Number = 0, a03:Number = 0; public var a10:Number = 0, a11:Number = 1, a12:Number = 0, a13:Number = 0; public var a20:Number = 0, a21:Number = 0, a22:Number = 1, a23:Number = 0; public function RMatrix4(args:Array = null) { if (args && args.length == 12) { a00 = args[0]; a01 = args[1]; a02 = args[2]; a03 = args[3]; a10 = args[4]; a11 = args[5]; a12 = args[6]; a13 = args[7]; a20 = args[8]; a21 = args[9]; a22 = args[10]; a23 = args[11]; } } public function identity():RMatrix4 { a01, a02, a03, a10, a12, a13, a20, a21, a23 = 0 a00, a11, a22 = 1; return this; } public static function identity():RMatrix4 { return new RMatrix4(); } public static function translation(tx:Number = 0, ty:Number = 0, tz:Number = 0):RMatrix4 { return new RMatrix4([ 1, 0, 0, tx, 0, 1, 0, ty, 0, 0, 1, tz ]); } public function clone():RMatrix4 { return new RMatrix4([ a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23 ]); } public function equals(m:RMatrix4):Boolean { return a00 == m.a00 && a01 == m.a01 && a02 == m.a02 && a03 == m.a03 && a10 == m.a10 && a11 == m.a11 && a12 == m.a12 && a13 == m.a13 && a20 == m.a20 && a21 == m.a21 && a22 == m.a22 && a23 == m.a23; } public function add(m:RMatrix4):RMatrix4 { return new RMatrix4([ a00 + m.a00, a01 + m.a01, a02 + m.a02, a03 + m.a03, a10 + m.a10, a11 + m.a11, a12 + m.a12, a13 + m.a13, a20 + m.a20, a21 + m.a21, a22 + m.a22, a23 + m.a23 ]); } public function subtract(m:RMatrix4):RMatrix4 { return new RMatrix4([ a00 - m.a00, a01 - m.a01, a02 - m.a02, a03 - m.a03, a10 - m.a10, a11 - m.a11, a12 - m.a12, a13 - m.a13, a20 - m.a20, a21 - m.a21, a22 - m.a22, a23 - m.a23 ]); } public function scalerMultiply(scale:Number):RMatrix4 { return new RMatrix4([ a00 * scale,a01 * scale,a02 * scale,a03 * scale, a10 * scale,a11 * scale,a12 * scale,a13 * scale, a20 * scale,a21 * scale,a22 * scale,a23 * scale ]); } /* public function scalerVector3(v:RVector3):RMatrix4 { var m:RMatrix4 = new RMatrix4(); m.a00 = v.x; m.a11 = v.y; m.a22 = v.z; return clone().multiply(m); } */ public function multiply(m:RMatrix4):RMatrix4 { return new RMatrix4([ this.a00 * m.a00 + this.a01 * m.a10 + this.a02 * m.a20, this.a00 * m.a01 + this.a01 * m.a11 + this.a02 * m.a21, this.a00 * m.a02 + this.a01 * m.a12 + this.a02 * m.a22, this.a00 * m.a03 + this.a01 * m.a13 + this.a02 * m.a23 + this.a03, this.a10 * m.a00 + this.a11 * m.a10 + this.a12 * m.a20, this.a10 * m.a01 + this.a11 * m.a11 + this.a12 * m.a21, this.a10 * m.a02 + this.a11 * m.a12 + this.a12 * m.a22, this.a10 * m.a03 + this.a11 * m.a13 + this.a12 * m.a23 + this.a13, this.a20 * m.a00 + this.a21 * m.a10 + this.a22 * m.a20, this.a20 * m.a01 + this.a21 * m.a11 + this.a22 * m.a21, this.a20 * m.a02 + this.a21 * m.a12 + this.a22 * m.a22, this.a20 * m.a03 + this.a21 * m.a13 + this.a22 * m.a23 + this.a23 ]); } public function multiply3x3(m:RMatrix4):RMatrix4 { return new RMatrix4([ this.a00 * m.a00 + this.a01 * m.a10 + this.a02 * m.a20, this.a00 * m.a01 + this.a01 * m.a11 + this.a02 * m.a21, this.a00 * m.a02 + this.a01 * m.a12 + this.a02 * m.a22, this.a03, this.a10 * m.a00 + this.a11 * m.a10 + this.a12 * m.a20, this.a10 * m.a01 + this.a11 * m.a11 + this.a12 * m.a21, this.a10 * m.a02 + this.a11 * m.a12 + this.a12 * m.a22, this.a13, this.a20 * m.a00 + this.a21 * m.a10 + this.a22 * m.a20, this.a20 * m.a01 + this.a21 * m.a11 + this.a22 * m.a21, this.a20 * m.a02 + this.a21 * m.a12 + this.a22 * m.a22, this.a23, ]); } /* * return @self */ public function copy3x3(m:RMatrix4):RMatrix4 { a00 = m.a00; a01 = m.a01; a02 = m.a02; a10 = m.a10; a11 = m.a11; a12 = m.a12; a20 = m.a20; a21 = m.a21; a22 = m.a22; return this; } public function multiplyVector3(v:RVector3):RMatrix4 { return multiply(v.matrix4()); } public function concatVector3(v:RVector3):RMatrix4 { return concat(v.matrix4()); } public function concat(m:RMatrix4):RMatrix4 { var _a00:Number = this.a00 * m.a00 + this.a01 * m.a10 + this.a02 * m.a20; var _a01:Number = this.a00 * m.a01 + this.a01 * m.a11 + this.a02 * m.a21; var _a02:Number = this.a00 * m.a02 + this.a01 * m.a12 + this.a02 * m.a22; var _a03:Number = this.a00 * m.a03 + this.a01 * m.a13 + this.a02 * m.a23 + this.a03; var _a10:Number = this.a10 * m.a00 + this.a11 * m.a10 + this.a12 * m.a20; var _a11:Number = this.a10 * m.a01 + this.a11 * m.a11 + this.a12 * m.a21; var _a12:Number = this.a10 * m.a02 + this.a11 * m.a12 + this.a12 * m.a22; var _a13:Number = this.a10 * m.a03 + this.a11 * m.a13 + this.a12 * m.a23 + this.a13; var _a20:Number = this.a20 * m.a00 + this.a21 * m.a10 + this.a22 * m.a20; var _a21:Number = this.a20 * m.a01 + this.a21 * m.a11 + this.a22 * m.a21; var _a22:Number = this.a20 * m.a02 + this.a21 * m.a12 + this.a22 * m.a22; var _a23:Number = this.a20 * m.a03 + this.a21 * m.a13 + this.a22 * m.a23 + this.a23; a00 = _a00, a01 = _a01, a02 = _a02, a03 = _a03; a10 = _a10, a11 = _a11, a12 = _a12, a13 = _a13; a20 = _a20, a21 = _a21, a22 = _a22, a23 = _a23; return this; } public function get det():Number { return (a00 * a11 - a10 * a01) * a22 - (a00 * a21 - a20 * a01) * a12 + (a10 * a21 - a20 * a11) * a02; } public function inverse():RMatrix4 { if (Math.abs(det) <= 1.0e-64) { return new RMatrix4([0,0,0,0, 0,0,0,0, 0,0,0,0]); } else { var invDet:Number = 1/det; return new RMatrix4([ invDet * (a11 * a22 - a21 * a12), invDet * -(a01 * a22 - a21 * a02), invDet * (a01 * a12 - a11 * a02), invDet * -(a01 * (a12 * a23 - a22 * a13) - a11 * (a02 * a23 - a22 * a03) + a21 * (a02 * a13 - a12 * a03)), invDet * -(a10 * a22 - a20 * a12), invDet * (a00 * a22 - a20 * a02), invDet * -(a00 * a12 - a10 * a02), invDet * (a00 * (a12 * a23 - a22 * a13) - a10 * (a02 * a23 - a22 * a03) + a20 * (a02 * a13 - a12 * a03)), invDet * (a10 * a21 - a20 * a11), invDet * -(a00 * a21 - a20 * a01), invDet * (a00 * a11 - a10 * a01), invDet * -(a00 * (a11 * a23 - a21 * a13) - a10 * (a01 * a23 - a21 * a03) + a20 * (a01 * a13 - a11 * a03)), ]); } } public function get tx():Number { return a03; } public function get ty():Number { return a13; } public function get tz():Number { return a23; } public function set tx(v:Number):void { a03 = v; } public function set ty(v:Number):void { a13 = v; } public function set tz(v:Number):void { a23 = v; } public function vector3():RVector3 { return transformVector3(new RVector3(tx, ty, tz)); //var m:RMatrix4 = new RMatrix4(); //m.tx = tx; //m.ty = ty; //m.tz = tz; //var m2:RMatrix4 = multiply(m); //return new RVector3(m2.tx, m2.ty, m2.tz); } public function transformVector3(v:RVector3):RVector3 { var vx:Number = v.x; var vy:Number = v.y; var vz:Number = v.z; v.x = vx * a00 + vy * a01 + vz * a02;// + a03; v.y = vx * a10 + vy * a11 + vz * a12;// + a13; v.z = vx * a20 + vy * a21 + vz * a22;// + a23; return v; //return new RVector3( // v.x * a00 + v.y * a01 + v.z * a02 + a03, // v.x * a10 + v.y * a11 + v.z * a12 + a13, // v.x * a20 + v.y * a21 + v.z * a22 + a23 //); } public function transformXYZ(x:Number, y:Number, z:Number):Array { var vx:Number = x; var vy:Number = y; var vz:Number = z; x = vx * a00 + vy * a01 + vz * a02; y = vx * a10 + vy * a11 + vz * a12; z = vx * a20 + vy * a21 + vz * a22; return [x, y, z]; } public function transformXY(x:Number, y:Number, vz:Number):Array { var vx:Number = x; var vy:Number = y; x = vx * a00 + vy * a01 + vz * a02; y = vx * a10 + vy * a11 + vz * a12; return [x, y]; } public function rotateX(rad:Number):RMatrix4 { return concat(rotationX(rad)); } public function rotateY(rad:Number):RMatrix4 { return concat(rotationY(rad)); } public function rotateZ(rad:Number):RMatrix4 { return concat(rotationZ(rad)); } public function scaleX(factor:Number):RMatrix4 { return concat(RMatrix4.scaleX(factor)); } public function scaleY(factor:Number):RMatrix4 { return concat(RMatrix4.scaleY(factor)); } public function scaleZ(factor:Number):RMatrix4 { return concat(RMatrix4.scaleZ(factor)); } public function scale(fx:Number, fy:Number = NaN, fz:Number = NaN):RMatrix4 { if (isNaN(fy)) fy = fz = fx; - var m:RMatrix4 = identity(); - m.a00 = fx; - m.a11 = fy; - m.a22 = fz; - return concat(m); + + return scaleX(fx).scaleY(fy).scaleZ(fz); } public function toString():String { - return 'RMatrix4: ' + ObjectUtil.inspect([[a00, a01, a02, a03], [a10, a11, a12, a13],[a20, a21, a22, a23]]); + return "RMatrix4: [\n" + + "[" + [a00,a01,a02,a03].join(", ") + "]\n" + + "[" + [a10,a11,a12,a13].join(", ") + "]\n" + + "[" + [a02,a21,a22,a23].join(", ") + "]]"; + } + + public function flMatrix():Matrix { + //return new Matrix(values[0][0], values[0][1], values[1][0], + // values[1][1], values[3][0], values[3][1]); + //return new Matrix(a00, a01, tx, + // a10, a11, ty); + return new Matrix(a00, a01, a10, + a11, 0, 0); } public static function scaleX(factor:Number):RMatrix4 { var m:RMatrix4 = identity(); m.a00 = factor; return m; } public static function scaleY(factor:Number):RMatrix4 { var m:RMatrix4 = identity(); m.a11 = factor; return m; } public static function scaleZ(factor:Number):RMatrix4 { var m:RMatrix4 = identity(); m.a22 = factor; return m; } public static function rotationX(rad:Number):RMatrix4 { var cos:Number = Math.cos(rad); var sin:Number = Math.sin(rad); return new RMatrix4([ 1 , 0 , 0 , 0 , 0 , cos , -sin , 0 , 0 , sin , cos , 0 , ]); } public static function rotationY(rad:Number):RMatrix4 { var cos:Number = Math.cos(rad); var sin:Number = Math.sin(rad); return new RMatrix4([ cos , 0 , sin , 0 , 0 , 1 , 0 , 0 , -sin , 0 , cos , 0 , ]); } public static function rotationZ(rad:Number):RMatrix4 { var cos:Number = Math.cos(rad); var sin:Number = Math.sin(rad); return new RMatrix4([ cos , -sin , 0 , 0 , sin , cos , 0 , 0 , 0 , 0 , 1 , 0 , ]); } } } diff --git a/src/com/rails2u/geom/RVector3.as b/src/com/rails2u/geom/RVector3.as index de598b3..be76c14 100644 --- a/src/com/rails2u/geom/RVector3.as +++ b/src/com/rails2u/geom/RVector3.as @@ -1,94 +1,101 @@ package com.rails2u.geom { import flash.geom.Point; public class RVector3 { public static const ZERO:RVector3 = new RVector3(0, 0, 0); public var x:Number = 0; public var y:Number = 0; public var z:Number = 0; public var stash:Object; public function RVector3(x:Number = 0, y:Number = 0, z:Number = 0) { this.x = x; this.y = y; this.z = z; } public function clone():RVector3 { return new RVector3(x, y, z); } public function add(v:RVector3):RVector3 { return new RVector3(x + v.x, y + v.y, z + v.z); } + public function concat(v:RVector3):RVector3 { + x += v.x; + y += v.y; + z += v.z; + return this; + } + public function subtract(v:RVector3):RVector3 { return new RVector3(x - v.x, y - v.y, z - v.z); } public function inverse():RVector3 { return new RVector3(x * -1, y * -1, z * -1); } public function multiply(n:Number):RVector3 { return new RVector3(x * n, y * n, z * n); } public function get length():Number { return Math.sqrt(x*x + y*y + z*z); } public function equals(v:RVector3):Boolean { return (x == v.x) && (y == v.y) && (z == v.z); } public function normalize(len:Number = 1):RVector3 { var l:Number = length / len; return l == 0 ? ZERO.clone() : new RVector3(x / l, y / l, z / l); } public function dot(v:RVector3):Number { return x * v.x + y * v.y + z * v.z; } public function cross(v:RVector3):RVector3 { return new RVector3(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x); } public function distance(v:RVector3):Number { return subtract(v).length; } public function degree(v:RVector3):Number { /* var n0:RVector3 = normalize(); var n1:RVector3 = v.normalize(); // (n1.y < n0.y && n1.x > n0.x) || if (n1.y > n0.y && n1.x < n0.x) { return -1 * Math.acos(dot(v) / (length * v.length)); } else { return Math.acos(dot(v) / (length * v.length)); } */ return Math.acos(dot(v) / (length * v.length)); } public function angle(v:RVector3):Number { return degree(v) * 180/Math.PI; } // not test.. public function matrix4():RMatrix4 { var m:RMatrix4 = new RMatrix4(); m.tx = x; m.ty = y; m.tz = z; return m; } public function toString():String { return 'RVector3[x:' + x + ', y:' + y + ', z:' + z + ']'; } } }
hotchpotch/as3rails2u
826962d31c38131ec31ae1b31c7fbf9e7e6b71d0
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@76 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/geom/RMatrix4.as b/src/com/rails2u/geom/RMatrix4.as index b0b6430..4f5ee4b 100644 --- a/src/com/rails2u/geom/RMatrix4.as +++ b/src/com/rails2u/geom/RMatrix4.as @@ -1,336 +1,350 @@ package com.rails2u.geom { import com.rails2u.utils.ObjectUtil; public class RMatrix4 { public var a00:Number = 1, a01:Number = 0, a02:Number = 0, a03:Number = 0; public var a10:Number = 0, a11:Number = 1, a12:Number = 0, a13:Number = 0; public var a20:Number = 0, a21:Number = 0, a22:Number = 1, a23:Number = 0; public function RMatrix4(args:Array = null) { if (args && args.length == 12) { a00 = args[0]; a01 = args[1]; a02 = args[2]; a03 = args[3]; a10 = args[4]; a11 = args[5]; a12 = args[6]; a13 = args[7]; a20 = args[8]; a21 = args[9]; a22 = args[10]; a23 = args[11]; } } public function identity():RMatrix4 { a01, a02, a03, a10, a12, a13, a20, a21, a23 = 0 a00, a11, a22 = 1; return this; } public static function identity():RMatrix4 { return new RMatrix4(); } public static function translation(tx:Number = 0, ty:Number = 0, tz:Number = 0):RMatrix4 { return new RMatrix4([ 1, 0, 0, tx, 0, 1, 0, ty, 0, 0, 1, tz ]); } public function clone():RMatrix4 { return new RMatrix4([ a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23 ]); } public function equals(m:RMatrix4):Boolean { return a00 == m.a00 && a01 == m.a01 && a02 == m.a02 && a03 == m.a03 && a10 == m.a10 && a11 == m.a11 && a12 == m.a12 && a13 == m.a13 && a20 == m.a20 && a21 == m.a21 && a22 == m.a22 && a23 == m.a23; } public function add(m:RMatrix4):RMatrix4 { return new RMatrix4([ a00 + m.a00, a01 + m.a01, a02 + m.a02, a03 + m.a03, a10 + m.a10, a11 + m.a11, a12 + m.a12, a13 + m.a13, a20 + m.a20, a21 + m.a21, a22 + m.a22, a23 + m.a23 ]); } public function subtract(m:RMatrix4):RMatrix4 { return new RMatrix4([ a00 - m.a00, a01 - m.a01, a02 - m.a02, a03 - m.a03, a10 - m.a10, a11 - m.a11, a12 - m.a12, a13 - m.a13, a20 - m.a20, a21 - m.a21, a22 - m.a22, a23 - m.a23 ]); } public function scalerMultiply(scale:Number):RMatrix4 { return new RMatrix4([ a00 * scale,a01 * scale,a02 * scale,a03 * scale, a10 * scale,a11 * scale,a12 * scale,a13 * scale, a20 * scale,a21 * scale,a22 * scale,a23 * scale ]); } + /* + public function scalerVector3(v:RVector3):RMatrix4 { + var m:RMatrix4 = new RMatrix4(); + m.a00 = v.x; + m.a11 = v.y; + m.a22 = v.z; + return clone().multiply(m); + } + */ + public function multiply(m:RMatrix4):RMatrix4 { return new RMatrix4([ this.a00 * m.a00 + this.a01 * m.a10 + this.a02 * m.a20, this.a00 * m.a01 + this.a01 * m.a11 + this.a02 * m.a21, this.a00 * m.a02 + this.a01 * m.a12 + this.a02 * m.a22, this.a00 * m.a03 + this.a01 * m.a13 + this.a02 * m.a23 + this.a03, this.a10 * m.a00 + this.a11 * m.a10 + this.a12 * m.a20, this.a10 * m.a01 + this.a11 * m.a11 + this.a12 * m.a21, this.a10 * m.a02 + this.a11 * m.a12 + this.a12 * m.a22, this.a10 * m.a03 + this.a11 * m.a13 + this.a12 * m.a23 + this.a13, this.a20 * m.a00 + this.a21 * m.a10 + this.a22 * m.a20, this.a20 * m.a01 + this.a21 * m.a11 + this.a22 * m.a21, this.a20 * m.a02 + this.a21 * m.a12 + this.a22 * m.a22, this.a20 * m.a03 + this.a21 * m.a13 + this.a22 * m.a23 + this.a23 ]); } public function multiply3x3(m:RMatrix4):RMatrix4 { return new RMatrix4([ this.a00 * m.a00 + this.a01 * m.a10 + this.a02 * m.a20, this.a00 * m.a01 + this.a01 * m.a11 + this.a02 * m.a21, this.a00 * m.a02 + this.a01 * m.a12 + this.a02 * m.a22, this.a03, this.a10 * m.a00 + this.a11 * m.a10 + this.a12 * m.a20, this.a10 * m.a01 + this.a11 * m.a11 + this.a12 * m.a21, this.a10 * m.a02 + this.a11 * m.a12 + this.a12 * m.a22, this.a13, this.a20 * m.a00 + this.a21 * m.a10 + this.a22 * m.a20, this.a20 * m.a01 + this.a21 * m.a11 + this.a22 * m.a21, this.a20 * m.a02 + this.a21 * m.a12 + this.a22 * m.a22, this.a23, ]); } /* * return @self */ public function copy3x3(m:RMatrix4):RMatrix4 { a00 = m.a00; a01 = m.a01; a02 = m.a02; a10 = m.a10; a11 = m.a11; a12 = m.a12; a20 = m.a20; a21 = m.a21; a22 = m.a22; return this; } - public function multiplyVector3(v:RVector3):RVector3 { - return null; + public function multiplyVector3(v:RVector3):RMatrix4 { + return multiply(v.matrix4()); + } + + public function concatVector3(v:RVector3):RMatrix4 { + return concat(v.matrix4()); } public function concat(m:RMatrix4):RMatrix4 { var _a00:Number = this.a00 * m.a00 + this.a01 * m.a10 + this.a02 * m.a20; var _a01:Number = this.a00 * m.a01 + this.a01 * m.a11 + this.a02 * m.a21; var _a02:Number = this.a00 * m.a02 + this.a01 * m.a12 + this.a02 * m.a22; var _a03:Number = this.a00 * m.a03 + this.a01 * m.a13 + this.a02 * m.a23 + this.a03; var _a10:Number = this.a10 * m.a00 + this.a11 * m.a10 + this.a12 * m.a20; var _a11:Number = this.a10 * m.a01 + this.a11 * m.a11 + this.a12 * m.a21; var _a12:Number = this.a10 * m.a02 + this.a11 * m.a12 + this.a12 * m.a22; var _a13:Number = this.a10 * m.a03 + this.a11 * m.a13 + this.a12 * m.a23 + this.a13; var _a20:Number = this.a20 * m.a00 + this.a21 * m.a10 + this.a22 * m.a20; var _a21:Number = this.a20 * m.a01 + this.a21 * m.a11 + this.a22 * m.a21; var _a22:Number = this.a20 * m.a02 + this.a21 * m.a12 + this.a22 * m.a22; var _a23:Number = this.a20 * m.a03 + this.a21 * m.a13 + this.a22 * m.a23 + this.a23; a00 = _a00, a01 = _a01, a02 = _a02, a03 = _a03; a10 = _a10, a11 = _a11, a12 = _a12, a13 = _a13; a20 = _a20, a21 = _a21, a22 = _a22, a23 = _a23; return this; } public function get det():Number { return (a00 * a11 - a10 * a01) * a22 - (a00 * a21 - a20 * a01) * a12 + (a10 * a21 - a20 * a11) * a02; } public function inverse():RMatrix4 { if (Math.abs(det) <= 1.0e-64) { return new RMatrix4([0,0,0,0, 0,0,0,0, 0,0,0,0]); } else { var invDet:Number = 1/det; return new RMatrix4([ invDet * (a11 * a22 - a21 * a12), invDet * -(a01 * a22 - a21 * a02), invDet * (a01 * a12 - a11 * a02), invDet * -(a01 * (a12 * a23 - a22 * a13) - a11 * (a02 * a23 - a22 * a03) + a21 * (a02 * a13 - a12 * a03)), invDet * -(a10 * a22 - a20 * a12), invDet * (a00 * a22 - a20 * a02), invDet * -(a00 * a12 - a10 * a02), invDet * (a00 * (a12 * a23 - a22 * a13) - a10 * (a02 * a23 - a22 * a03) + a20 * (a02 * a13 - a12 * a03)), invDet * (a10 * a21 - a20 * a11), invDet * -(a00 * a21 - a20 * a01), invDet * (a00 * a11 - a10 * a01), invDet * -(a00 * (a11 * a23 - a21 * a13) - a10 * (a01 * a23 - a21 * a03) + a20 * (a01 * a13 - a11 * a03)), ]); } } public function get tx():Number { return a03; } public function get ty():Number { return a13; } public function get tz():Number { return a23; } public function set tx(v:Number):void { a03 = v; } public function set ty(v:Number):void { a13 = v; } public function set tz(v:Number):void { a23 = v; } public function vector3():RVector3 { return transformVector3(new RVector3(tx, ty, tz)); //var m:RMatrix4 = new RMatrix4(); //m.tx = tx; //m.ty = ty; //m.tz = tz; //var m2:RMatrix4 = multiply(m); //return new RVector3(m2.tx, m2.ty, m2.tz); } public function transformVector3(v:RVector3):RVector3 { var vx:Number = v.x; var vy:Number = v.y; var vz:Number = v.z; v.x = vx * a00 + vy * a01 + vz * a02;// + a03; v.y = vx * a10 + vy * a11 + vz * a12;// + a13; v.z = vx * a20 + vy * a21 + vz * a22;// + a23; return v; //return new RVector3( // v.x * a00 + v.y * a01 + v.z * a02 + a03, // v.x * a10 + v.y * a11 + v.z * a12 + a13, // v.x * a20 + v.y * a21 + v.z * a22 + a23 //); } public function transformXYZ(x:Number, y:Number, z:Number):Array { var vx:Number = x; var vy:Number = y; var vz:Number = z; x = vx * a00 + vy * a01 + vz * a02; y = vx * a10 + vy * a11 + vz * a12; z = vx * a20 + vy * a21 + vz * a22; return [x, y, z]; } public function transformXY(x:Number, y:Number, vz:Number):Array { var vx:Number = x; var vy:Number = y; x = vx * a00 + vy * a01 + vz * a02; y = vx * a10 + vy * a11 + vz * a12; return [x, y]; } public function rotateX(rad:Number):RMatrix4 { return concat(rotationX(rad)); } public function rotateY(rad:Number):RMatrix4 { return concat(rotationY(rad)); } public function rotateZ(rad:Number):RMatrix4 { return concat(rotationZ(rad)); } public function scaleX(factor:Number):RMatrix4 { return concat(RMatrix4.scaleX(factor)); } public function scaleY(factor:Number):RMatrix4 { return concat(RMatrix4.scaleY(factor)); } public function scaleZ(factor:Number):RMatrix4 { return concat(RMatrix4.scaleZ(factor)); } public function scale(fx:Number, fy:Number = NaN, fz:Number = NaN):RMatrix4 { if (isNaN(fy)) fy = fz = fx; var m:RMatrix4 = identity(); m.a00 = fx; m.a11 = fy; m.a22 = fz; return concat(m); } public function toString():String { return 'RMatrix4: ' + ObjectUtil.inspect([[a00, a01, a02, a03], [a10, a11, a12, a13],[a20, a21, a22, a23]]); } public static function scaleX(factor:Number):RMatrix4 { var m:RMatrix4 = identity(); m.a00 = factor; return m; } public static function scaleY(factor:Number):RMatrix4 { var m:RMatrix4 = identity(); m.a11 = factor; return m; } public static function scaleZ(factor:Number):RMatrix4 { var m:RMatrix4 = identity(); m.a22 = factor; return m; } public static function rotationX(rad:Number):RMatrix4 { var cos:Number = Math.cos(rad); var sin:Number = Math.sin(rad); return new RMatrix4([ 1 , 0 , 0 , 0 , 0 , cos , -sin , 0 , 0 , sin , cos , 0 , ]); } public static function rotationY(rad:Number):RMatrix4 { var cos:Number = Math.cos(rad); var sin:Number = Math.sin(rad); return new RMatrix4([ cos , 0 , sin , 0 , 0 , 1 , 0 , 0 , -sin , 0 , cos , 0 , ]); } public static function rotationZ(rad:Number):RMatrix4 { var cos:Number = Math.cos(rad); var sin:Number = Math.sin(rad); return new RMatrix4([ cos , -sin , 0 , 0 , sin , cos , 0 , 0 , 0 , 0 , 1 , 0 , ]); } } } diff --git a/src/com/rails2u/geom/RVector3.as b/src/com/rails2u/geom/RVector3.as index c7ad819..de598b3 100644 --- a/src/com/rails2u/geom/RVector3.as +++ b/src/com/rails2u/geom/RVector3.as @@ -1,85 +1,94 @@ package com.rails2u.geom { import flash.geom.Point; public class RVector3 { public static const ZERO:RVector3 = new RVector3(0, 0, 0); public var x:Number = 0; public var y:Number = 0; public var z:Number = 0; public var stash:Object; public function RVector3(x:Number = 0, y:Number = 0, z:Number = 0) { this.x = x; this.y = y; this.z = z; } public function clone():RVector3 { return new RVector3(x, y, z); } public function add(v:RVector3):RVector3 { return new RVector3(x + v.x, y + v.y, z + v.z); } public function subtract(v:RVector3):RVector3 { return new RVector3(x - v.x, y - v.y, z - v.z); } public function inverse():RVector3 { return new RVector3(x * -1, y * -1, z * -1); } public function multiply(n:Number):RVector3 { return new RVector3(x * n, y * n, z * n); } public function get length():Number { return Math.sqrt(x*x + y*y + z*z); } public function equals(v:RVector3):Boolean { return (x == v.x) && (y == v.y) && (z == v.z); } public function normalize(len:Number = 1):RVector3 { var l:Number = length / len; return l == 0 ? ZERO.clone() : new RVector3(x / l, y / l, z / l); } public function dot(v:RVector3):Number { return x * v.x + y * v.y + z * v.z; } public function cross(v:RVector3):RVector3 { return new RVector3(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x); } public function distance(v:RVector3):Number { return subtract(v).length; } public function degree(v:RVector3):Number { /* var n0:RVector3 = normalize(); var n1:RVector3 = v.normalize(); // (n1.y < n0.y && n1.x > n0.x) || if (n1.y > n0.y && n1.x < n0.x) { return -1 * Math.acos(dot(v) / (length * v.length)); } else { return Math.acos(dot(v) / (length * v.length)); } */ return Math.acos(dot(v) / (length * v.length)); } public function angle(v:RVector3):Number { return degree(v) * 180/Math.PI; } + // not test.. + public function matrix4():RMatrix4 { + var m:RMatrix4 = new RMatrix4(); + m.tx = x; + m.ty = y; + m.tz = z; + return m; + } + public function toString():String { return 'RVector3[x:' + x + ', y:' + y + ', z:' + z + ']'; } } }
hotchpotch/as3rails2u
f33357f525cc2d369caca79f77c461971bc6260c
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@75 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/debug/PerformanceViewer.as b/src/com/rails2u/debug/PerformanceViewer.as index 7c60c88..6c89f1c 100644 --- a/src/com/rails2u/debug/PerformanceViewer.as +++ b/src/com/rails2u/debug/PerformanceViewer.as @@ -1,88 +1,93 @@ package com.rails2u.debug { import flash.events.Event; import flash.text.TextField; import flash.text.TextFormat; import flash.utils.getTimer; import flash.system.System; import flash.utils.Timer; /** * PerformanceViewer * * PerformanceViewer show FPS, used memory size. * * example: * <listing version="3.0"> * var pv:PerformanceViewer = new PerformanceViewer; * stage.addChild(pv); * pv.show(); * pv.hide(); * pv.toggle(); * </listing> */ public class PerformanceViewer extends TextField { private var lastTime:uint; private var _fps:Number = 60; public function get fps():Number { return _fps; } private var timer:Timer; + public var textFunction:Function; public function PerformanceViewer(color:uint = 0xFFFFFF, delay:Number = 200) { super(); visible = false; width = 150; height = 40; background = false; backgroundColor = 0x555555; var format:TextFormat = new TextFormat(); format.color = color; format.size = 12; format.bold = true; format.font = 'Arial'; defaultTextFormat = format; lastTime = getTimer(); timer = new Timer(delay); timer.addEventListener('timer', render); timer.start(); addEventListener(Event.ENTER_FRAME, countHandler); } private var _fpss:Array = []; private function countHandler(e:Event):void { var time:int = getTimer(); _fpss.push(time - lastTime); lastTime = time; } private function render(e:Event):void { _fps = 0; for each(var v:Number in _fpss) { _fps += v; } _fps /= _fpss.length; var rCount:int = _fpss.length; _fpss = []; text = String(1000 / (_fps)).substring(0, 6) + ' FPS' + "\n" + Number(System.totalMemory) / 1000 + " KB"; + if (textFunction != null) { + appendText("\n" + textFunction()); + } + height = textHeight + defaultTextFormat.size + 5; } private function init():void { } public function show():void { visible = true; } public function hide():void { visible = false; } public function toggle():void { visible ? visible = false : visible = true; } } } diff --git a/src/com/rails2u/geom/RMatrix4.as b/src/com/rails2u/geom/RMatrix4.as index d31dc5e..b0b6430 100644 --- a/src/com/rails2u/geom/RMatrix4.as +++ b/src/com/rails2u/geom/RMatrix4.as @@ -1,282 +1,336 @@ package com.rails2u.geom { import com.rails2u.utils.ObjectUtil; public class RMatrix4 { public var a00:Number = 1, a01:Number = 0, a02:Number = 0, a03:Number = 0; public var a10:Number = 0, a11:Number = 1, a12:Number = 0, a13:Number = 0; public var a20:Number = 0, a21:Number = 0, a22:Number = 1, a23:Number = 0; public function RMatrix4(args:Array = null) { if (args && args.length == 12) { a00 = args[0]; a01 = args[1]; a02 = args[2]; a03 = args[3]; a10 = args[4]; a11 = args[5]; a12 = args[6]; a13 = args[7]; a20 = args[8]; a21 = args[9]; a22 = args[10]; a23 = args[11]; } } public function identity():RMatrix4 { a01, a02, a03, a10, a12, a13, a20, a21, a23 = 0 a00, a11, a22 = 1; return this; } public static function identity():RMatrix4 { return new RMatrix4(); } public static function translation(tx:Number = 0, ty:Number = 0, tz:Number = 0):RMatrix4 { return new RMatrix4([ 1, 0, 0, tx, 0, 1, 0, ty, 0, 0, 1, tz ]); } public function clone():RMatrix4 { return new RMatrix4([ a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23 ]); } public function equals(m:RMatrix4):Boolean { return a00 == m.a00 && a01 == m.a01 && a02 == m.a02 && a03 == m.a03 && a10 == m.a10 && a11 == m.a11 && a12 == m.a12 && a13 == m.a13 && a20 == m.a20 && a21 == m.a21 && a22 == m.a22 && a23 == m.a23; } public function add(m:RMatrix4):RMatrix4 { return new RMatrix4([ a00 + m.a00, a01 + m.a01, a02 + m.a02, a03 + m.a03, a10 + m.a10, a11 + m.a11, a12 + m.a12, a13 + m.a13, a20 + m.a20, a21 + m.a21, a22 + m.a22, a23 + m.a23 ]); } public function subtract(m:RMatrix4):RMatrix4 { return new RMatrix4([ a00 - m.a00, a01 - m.a01, a02 - m.a02, a03 - m.a03, a10 - m.a10, a11 - m.a11, a12 - m.a12, a13 - m.a13, a20 - m.a20, a21 - m.a21, a22 - m.a22, a23 - m.a23 ]); } public function scalerMultiply(scale:Number):RMatrix4 { return new RMatrix4([ a00 * scale,a01 * scale,a02 * scale,a03 * scale, a10 * scale,a11 * scale,a12 * scale,a13 * scale, a20 * scale,a21 * scale,a22 * scale,a23 * scale ]); } public function multiply(m:RMatrix4):RMatrix4 { return new RMatrix4([ this.a00 * m.a00 + this.a01 * m.a10 + this.a02 * m.a20, this.a00 * m.a01 + this.a01 * m.a11 + this.a02 * m.a21, this.a00 * m.a02 + this.a01 * m.a12 + this.a02 * m.a22, this.a00 * m.a03 + this.a01 * m.a13 + this.a02 * m.a23 + this.a03, this.a10 * m.a00 + this.a11 * m.a10 + this.a12 * m.a20, this.a10 * m.a01 + this.a11 * m.a11 + this.a12 * m.a21, this.a10 * m.a02 + this.a11 * m.a12 + this.a12 * m.a22, this.a10 * m.a03 + this.a11 * m.a13 + this.a12 * m.a23 + this.a13, this.a20 * m.a00 + this.a21 * m.a10 + this.a22 * m.a20, this.a20 * m.a01 + this.a21 * m.a11 + this.a22 * m.a21, this.a20 * m.a02 + this.a21 * m.a12 + this.a22 * m.a22, this.a20 * m.a03 + this.a21 * m.a13 + this.a22 * m.a23 + this.a23 ]); } + public function multiply3x3(m:RMatrix4):RMatrix4 { + return new RMatrix4([ + this.a00 * m.a00 + this.a01 * m.a10 + this.a02 * m.a20, + this.a00 * m.a01 + this.a01 * m.a11 + this.a02 * m.a21, + this.a00 * m.a02 + this.a01 * m.a12 + this.a02 * m.a22, + this.a03, + + this.a10 * m.a00 + this.a11 * m.a10 + this.a12 * m.a20, + this.a10 * m.a01 + this.a11 * m.a11 + this.a12 * m.a21, + this.a10 * m.a02 + this.a11 * m.a12 + this.a12 * m.a22, + this.a13, + + this.a20 * m.a00 + this.a21 * m.a10 + this.a22 * m.a20, + this.a20 * m.a01 + this.a21 * m.a11 + this.a22 * m.a21, + this.a20 * m.a02 + this.a21 * m.a12 + this.a22 * m.a22, + this.a23, + ]); + } + + /* + * return @self + */ + public function copy3x3(m:RMatrix4):RMatrix4 { + a00 = m.a00; a01 = m.a01; a02 = m.a02; + a10 = m.a10; a11 = m.a11; a12 = m.a12; + a20 = m.a20; a21 = m.a21; a22 = m.a22; + return this; + } + public function multiplyVector3(v:RVector3):RVector3 { return null; } public function concat(m:RMatrix4):RMatrix4 { var _a00:Number = this.a00 * m.a00 + this.a01 * m.a10 + this.a02 * m.a20; var _a01:Number = this.a00 * m.a01 + this.a01 * m.a11 + this.a02 * m.a21; var _a02:Number = this.a00 * m.a02 + this.a01 * m.a12 + this.a02 * m.a22; var _a03:Number = this.a00 * m.a03 + this.a01 * m.a13 + this.a02 * m.a23 + this.a03; var _a10:Number = this.a10 * m.a00 + this.a11 * m.a10 + this.a12 * m.a20; var _a11:Number = this.a10 * m.a01 + this.a11 * m.a11 + this.a12 * m.a21; var _a12:Number = this.a10 * m.a02 + this.a11 * m.a12 + this.a12 * m.a22; var _a13:Number = this.a10 * m.a03 + this.a11 * m.a13 + this.a12 * m.a23 + this.a13; var _a20:Number = this.a20 * m.a00 + this.a21 * m.a10 + this.a22 * m.a20; var _a21:Number = this.a20 * m.a01 + this.a21 * m.a11 + this.a22 * m.a21; var _a22:Number = this.a20 * m.a02 + this.a21 * m.a12 + this.a22 * m.a22; var _a23:Number = this.a20 * m.a03 + this.a21 * m.a13 + this.a22 * m.a23 + this.a23; a00 = _a00, a01 = _a01, a02 = _a02, a03 = _a03; a10 = _a10, a11 = _a11, a12 = _a12, a13 = _a13; a20 = _a20, a21 = _a21, a22 = _a22, a23 = _a23; return this; } public function get det():Number { return (a00 * a11 - a10 * a01) * a22 - (a00 * a21 - a20 * a01) * a12 + (a10 * a21 - a20 * a11) * a02; } public function inverse():RMatrix4 { if (Math.abs(det) <= 1.0e-64) { return new RMatrix4([0,0,0,0, 0,0,0,0, 0,0,0,0]); } else { var invDet:Number = 1/det; return new RMatrix4([ invDet * (a11 * a22 - a21 * a12), invDet * -(a01 * a22 - a21 * a02), invDet * (a01 * a12 - a11 * a02), invDet * -(a01 * (a12 * a23 - a22 * a13) - a11 * (a02 * a23 - a22 * a03) + a21 * (a02 * a13 - a12 * a03)), invDet * -(a10 * a22 - a20 * a12), invDet * (a00 * a22 - a20 * a02), invDet * -(a00 * a12 - a10 * a02), invDet * (a00 * (a12 * a23 - a22 * a13) - a10 * (a02 * a23 - a22 * a03) + a20 * (a02 * a13 - a12 * a03)), invDet * (a10 * a21 - a20 * a11), invDet * -(a00 * a21 - a20 * a01), invDet * (a00 * a11 - a10 * a01), invDet * -(a00 * (a11 * a23 - a21 * a13) - a10 * (a01 * a23 - a21 * a03) + a20 * (a01 * a13 - a11 * a03)), ]); } } public function get tx():Number { return a03; } public function get ty():Number { return a13; } public function get tz():Number { return a23; } public function set tx(v:Number):void { a03 = v; } public function set ty(v:Number):void { a13 = v; } public function set tz(v:Number):void { a23 = v; } - public function get vector3():RVector3 { - return new RVector3(a03, a13, a23); + public function vector3():RVector3 { + return transformVector3(new RVector3(tx, ty, tz)); + + //var m:RMatrix4 = new RMatrix4(); + //m.tx = tx; + //m.ty = ty; + //m.tz = tz; + //var m2:RMatrix4 = multiply(m); + //return new RVector3(m2.tx, m2.ty, m2.tz); } - public function tranformVector3(v:RVector3):RVector3 { + public function transformVector3(v:RVector3):RVector3 { var vx:Number = v.x; var vy:Number = v.y; var vz:Number = v.z; v.x = vx * a00 + vy * a01 + vz * a02;// + a03; v.y = vx * a10 + vy * a11 + vz * a12;// + a13; v.z = vx * a20 + vy * a21 + vz * a22;// + a23; return v; //return new RVector3( // v.x * a00 + v.y * a01 + v.z * a02 + a03, // v.x * a10 + v.y * a11 + v.z * a12 + a13, // v.x * a20 + v.y * a21 + v.z * a22 + a23 //); } + public function transformXYZ(x:Number, y:Number, z:Number):Array { + var vx:Number = x; + var vy:Number = y; + var vz:Number = z; + x = vx * a00 + vy * a01 + vz * a02; + y = vx * a10 + vy * a11 + vz * a12; + z = vx * a20 + vy * a21 + vz * a22; + return [x, y, z]; + } + + public function transformXY(x:Number, y:Number, vz:Number):Array { + var vx:Number = x; + var vy:Number = y; + x = vx * a00 + vy * a01 + vz * a02; + y = vx * a10 + vy * a11 + vz * a12; + return [x, y]; + } + public function rotateX(rad:Number):RMatrix4 { return concat(rotationX(rad)); } public function rotateY(rad:Number):RMatrix4 { return concat(rotationY(rad)); } public function rotateZ(rad:Number):RMatrix4 { return concat(rotationZ(rad)); } public function scaleX(factor:Number):RMatrix4 { return concat(RMatrix4.scaleX(factor)); } public function scaleY(factor:Number):RMatrix4 { return concat(RMatrix4.scaleY(factor)); } public function scaleZ(factor:Number):RMatrix4 { return concat(RMatrix4.scaleZ(factor)); } public function scale(fx:Number, fy:Number = NaN, fz:Number = NaN):RMatrix4 { if (isNaN(fy)) fy = fz = fx; var m:RMatrix4 = identity(); m.a00 = fx; m.a11 = fy; m.a22 = fz; return concat(m); } public function toString():String { return 'RMatrix4: ' + ObjectUtil.inspect([[a00, a01, a02, a03], [a10, a11, a12, a13],[a20, a21, a22, a23]]); } public static function scaleX(factor:Number):RMatrix4 { var m:RMatrix4 = identity(); m.a00 = factor; return m; } public static function scaleY(factor:Number):RMatrix4 { var m:RMatrix4 = identity(); m.a11 = factor; return m; } public static function scaleZ(factor:Number):RMatrix4 { var m:RMatrix4 = identity(); m.a22 = factor; return m; } public static function rotationX(rad:Number):RMatrix4 { var cos:Number = Math.cos(rad); var sin:Number = Math.sin(rad); return new RMatrix4([ 1 , 0 , 0 , 0 , 0 , cos , -sin , 0 , 0 , sin , cos , 0 , ]); } public static function rotationY(rad:Number):RMatrix4 { var cos:Number = Math.cos(rad); var sin:Number = Math.sin(rad); return new RMatrix4([ cos , 0 , sin , 0 , 0 , 1 , 0 , 0 , -sin , 0 , cos , 0 , ]); } public static function rotationZ(rad:Number):RMatrix4 { var cos:Number = Math.cos(rad); var sin:Number = Math.sin(rad); return new RMatrix4([ cos , -sin , 0 , 0 , sin , cos , 0 , 0 , 0 , 0 , 1 , 0 , ]); } } }
hotchpotch/as3rails2u
da3eb19e1c3c9b7507e9e449e1bfd5ae044249b1
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@74 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/geom/RMatrix4.as b/src/com/rails2u/geom/RMatrix4.as new file mode 100644 index 0000000..d31dc5e --- /dev/null +++ b/src/com/rails2u/geom/RMatrix4.as @@ -0,0 +1,282 @@ +package com.rails2u.geom { + import com.rails2u.utils.ObjectUtil; + + public class RMatrix4 { + public var a00:Number = 1, a01:Number = 0, a02:Number = 0, a03:Number = 0; + public var a10:Number = 0, a11:Number = 1, a12:Number = 0, a13:Number = 0; + public var a20:Number = 0, a21:Number = 0, a22:Number = 1, a23:Number = 0; + + public function RMatrix4(args:Array = null) { + if (args && args.length == 12) { + a00 = args[0]; a01 = args[1]; a02 = args[2]; a03 = args[3]; + a10 = args[4]; a11 = args[5]; a12 = args[6]; a13 = args[7]; + a20 = args[8]; a21 = args[9]; a22 = args[10]; a23 = args[11]; + } + } + + public function identity():RMatrix4 { + a01, a02, a03, a10, a12, a13, a20, a21, a23 = 0 + a00, a11, a22 = 1; + return this; + } + + public static function identity():RMatrix4 { + return new RMatrix4(); + } + + public static function translation(tx:Number = 0, ty:Number = 0, tz:Number = 0):RMatrix4 { + return new RMatrix4([ + 1, 0, 0, tx, + 0, 1, 0, ty, + 0, 0, 1, tz + ]); + } + + public function clone():RMatrix4 { + return new RMatrix4([ + a00, a01, a02, a03, + a10, a11, a12, a13, + a20, a21, a22, a23 + ]); + } + + public function equals(m:RMatrix4):Boolean { + return a00 == m.a00 && + a01 == m.a01 && + a02 == m.a02 && + a03 == m.a03 && + a10 == m.a10 && + a11 == m.a11 && + a12 == m.a12 && + a13 == m.a13 && + a20 == m.a20 && + a21 == m.a21 && + a22 == m.a22 && + a23 == m.a23; + } + + public function add(m:RMatrix4):RMatrix4 { + return new RMatrix4([ + a00 + m.a00, a01 + m.a01, a02 + m.a02, a03 + m.a03, + a10 + m.a10, a11 + m.a11, a12 + m.a12, a13 + m.a13, + a20 + m.a20, a21 + m.a21, a22 + m.a22, a23 + m.a23 + ]); + } + + public function subtract(m:RMatrix4):RMatrix4 { + return new RMatrix4([ + a00 - m.a00, a01 - m.a01, a02 - m.a02, a03 - m.a03, + a10 - m.a10, a11 - m.a11, a12 - m.a12, a13 - m.a13, + a20 - m.a20, a21 - m.a21, a22 - m.a22, a23 - m.a23 + ]); + } + + public function scalerMultiply(scale:Number):RMatrix4 { + return new RMatrix4([ + a00 * scale,a01 * scale,a02 * scale,a03 * scale, + a10 * scale,a11 * scale,a12 * scale,a13 * scale, + a20 * scale,a21 * scale,a22 * scale,a23 * scale + ]); + } + + public function multiply(m:RMatrix4):RMatrix4 { + return new RMatrix4([ + this.a00 * m.a00 + this.a01 * m.a10 + this.a02 * m.a20, + this.a00 * m.a01 + this.a01 * m.a11 + this.a02 * m.a21, + this.a00 * m.a02 + this.a01 * m.a12 + this.a02 * m.a22, + this.a00 * m.a03 + this.a01 * m.a13 + this.a02 * m.a23 + this.a03, + + this.a10 * m.a00 + this.a11 * m.a10 + this.a12 * m.a20, + this.a10 * m.a01 + this.a11 * m.a11 + this.a12 * m.a21, + this.a10 * m.a02 + this.a11 * m.a12 + this.a12 * m.a22, + this.a10 * m.a03 + this.a11 * m.a13 + this.a12 * m.a23 + this.a13, + + this.a20 * m.a00 + this.a21 * m.a10 + this.a22 * m.a20, + this.a20 * m.a01 + this.a21 * m.a11 + this.a22 * m.a21, + this.a20 * m.a02 + this.a21 * m.a12 + this.a22 * m.a22, + this.a20 * m.a03 + this.a21 * m.a13 + this.a22 * m.a23 + this.a23 + ]); + } + + public function multiplyVector3(v:RVector3):RVector3 { + return null; + } + + public function concat(m:RMatrix4):RMatrix4 { + var _a00:Number = this.a00 * m.a00 + this.a01 * m.a10 + this.a02 * m.a20; + var _a01:Number = this.a00 * m.a01 + this.a01 * m.a11 + this.a02 * m.a21; + var _a02:Number = this.a00 * m.a02 + this.a01 * m.a12 + this.a02 * m.a22; + var _a03:Number = this.a00 * m.a03 + this.a01 * m.a13 + this.a02 * m.a23 + this.a03; + + var _a10:Number = this.a10 * m.a00 + this.a11 * m.a10 + this.a12 * m.a20; + var _a11:Number = this.a10 * m.a01 + this.a11 * m.a11 + this.a12 * m.a21; + var _a12:Number = this.a10 * m.a02 + this.a11 * m.a12 + this.a12 * m.a22; + var _a13:Number = this.a10 * m.a03 + this.a11 * m.a13 + this.a12 * m.a23 + this.a13; + + var _a20:Number = this.a20 * m.a00 + this.a21 * m.a10 + this.a22 * m.a20; + var _a21:Number = this.a20 * m.a01 + this.a21 * m.a11 + this.a22 * m.a21; + var _a22:Number = this.a20 * m.a02 + this.a21 * m.a12 + this.a22 * m.a22; + var _a23:Number = this.a20 * m.a03 + this.a21 * m.a13 + this.a22 * m.a23 + this.a23; + + a00 = _a00, a01 = _a01, a02 = _a02, a03 = _a03; + a10 = _a10, a11 = _a11, a12 = _a12, a13 = _a13; + a20 = _a20, a21 = _a21, a22 = _a22, a23 = _a23; + return this; + } + + public function get det():Number { + return (a00 * a11 - a10 * a01) * a22 + - (a00 * a21 - a20 * a01) * a12 + + (a10 * a21 - a20 * a11) * a02; + } + + public function inverse():RMatrix4 { + if (Math.abs(det) <= 1.0e-64) { + return new RMatrix4([0,0,0,0, 0,0,0,0, 0,0,0,0]); + } else { + var invDet:Number = 1/det; + + return new RMatrix4([ + invDet * (a11 * a22 - a21 * a12), + invDet * -(a01 * a22 - a21 * a02), + invDet * (a01 * a12 - a11 * a02), + invDet * -(a01 * (a12 * a23 - a22 * a13) - a11 * (a02 * a23 - a22 * a03) + a21 * (a02 * a13 - a12 * a03)), + + invDet * -(a10 * a22 - a20 * a12), + invDet * (a00 * a22 - a20 * a02), + invDet * -(a00 * a12 - a10 * a02), + invDet * (a00 * (a12 * a23 - a22 * a13) - a10 * (a02 * a23 - a22 * a03) + a20 * (a02 * a13 - a12 * a03)), + + invDet * (a10 * a21 - a20 * a11), + invDet * -(a00 * a21 - a20 * a01), + invDet * (a00 * a11 - a10 * a01), + invDet * -(a00 * (a11 * a23 - a21 * a13) - a10 * (a01 * a23 - a21 * a03) + a20 * (a01 * a13 - a11 * a03)), + ]); + } + } + + public function get tx():Number { + return a03; + } + public function get ty():Number { + return a13; + } + public function get tz():Number { + return a23; + } + public function set tx(v:Number):void { + a03 = v; + } + public function set ty(v:Number):void { + a13 = v; + } + public function set tz(v:Number):void { + a23 = v; + } + + public function get vector3():RVector3 { + return new RVector3(a03, a13, a23); + } + + public function tranformVector3(v:RVector3):RVector3 { + var vx:Number = v.x; + var vy:Number = v.y; + var vz:Number = v.z; + v.x = vx * a00 + vy * a01 + vz * a02;// + a03; + v.y = vx * a10 + vy * a11 + vz * a12;// + a13; + v.z = vx * a20 + vy * a21 + vz * a22;// + a23; + return v; + + //return new RVector3( + // v.x * a00 + v.y * a01 + v.z * a02 + a03, + // v.x * a10 + v.y * a11 + v.z * a12 + a13, + // v.x * a20 + v.y * a21 + v.z * a22 + a23 + //); + } + + public function rotateX(rad:Number):RMatrix4 { + return concat(rotationX(rad)); + } + + public function rotateY(rad:Number):RMatrix4 { + return concat(rotationY(rad)); + } + + public function rotateZ(rad:Number):RMatrix4 { + return concat(rotationZ(rad)); + } + + public function scaleX(factor:Number):RMatrix4 { + return concat(RMatrix4.scaleX(factor)); + } + + public function scaleY(factor:Number):RMatrix4 { + return concat(RMatrix4.scaleY(factor)); + } + + public function scaleZ(factor:Number):RMatrix4 { + return concat(RMatrix4.scaleZ(factor)); + } + + public function scale(fx:Number, fy:Number = NaN, fz:Number = NaN):RMatrix4 { + if (isNaN(fy)) fy = fz = fx; + var m:RMatrix4 = identity(); + m.a00 = fx; + m.a11 = fy; + m.a22 = fz; + return concat(m); + } + + public function toString():String { + return 'RMatrix4: ' + ObjectUtil.inspect([[a00, a01, a02, a03], [a10, a11, a12, a13],[a20, a21, a22, a23]]); + } + + public static function scaleX(factor:Number):RMatrix4 { + var m:RMatrix4 = identity(); + m.a00 = factor; + return m; + } + + public static function scaleY(factor:Number):RMatrix4 { + var m:RMatrix4 = identity(); + m.a11 = factor; + return m; + } + + public static function scaleZ(factor:Number):RMatrix4 { + var m:RMatrix4 = identity(); + m.a22 = factor; + return m; + } + + public static function rotationX(rad:Number):RMatrix4 { + var cos:Number = Math.cos(rad); + var sin:Number = Math.sin(rad); + return new RMatrix4([ + 1 , 0 , 0 , 0 , + 0 , cos , -sin , 0 , + 0 , sin , cos , 0 , + ]); + } + + public static function rotationY(rad:Number):RMatrix4 { + var cos:Number = Math.cos(rad); + var sin:Number = Math.sin(rad); + return new RMatrix4([ + cos , 0 , sin , 0 , + 0 , 1 , 0 , 0 , + -sin , 0 , cos , 0 , + ]); + } + + public static function rotationZ(rad:Number):RMatrix4 { + var cos:Number = Math.cos(rad); + var sin:Number = Math.sin(rad); + return new RMatrix4([ + cos , -sin , 0 , 0 , + sin , cos , 0 , 0 , + 0 , 0 , 1 , 0 , + ]); + } + } +} diff --git a/src/com/rails2u/geom/RVertex3.as b/src/com/rails2u/geom/RVertex3.as new file mode 100644 index 0000000..bfb3f0c --- /dev/null +++ b/src/com/rails2u/geom/RVertex3.as @@ -0,0 +1,17 @@ +package com.rails2u.geom { + public class RVertex3 extends RVector3 { + public function RVertex3(x:Number = 0, y:Number = 0, z:Number = 0) { + this.x = x; + this.y = y; + this.z = z; + } + + public override function toString():String { + return 'RVertex3[x:' + x + ', y:' + y + ', z:' + z + ']'; + } + + public function toVector3():RVector3 { + return new RVector3(x, y, z); + } + } +}
hotchpotch/as3rails2u
315432480bd7656d0084bcb74627e09404928610
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@73 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/tests/RMatrix4Test.as b/tests/RMatrix4Test.as new file mode 100644 index 0000000..2ee8092 --- /dev/null +++ b/tests/RMatrix4Test.as @@ -0,0 +1,93 @@ +package { + import flash.display.Sprite; + import flash.display.StageAlign; + import flash.display.StageScaleMode; + import com.rails2u.geom.*; + + [SWF(frameRate=60, background=0x000000)] + public class RMatrix4Test extends Sprite { + public function RMatrix4Test() { + stage.align = StageAlign.TOP_LEFT; + stage.scaleMode = StageScaleMode.NO_SCALE; + rmatrix4(); + } + + public function rmatrix4():void { + var m:RMatrix4; + var t:SimpleTest = new SimpleTest('RMatrix4Test'); + t.run(function():void { + t.notEquals(m1create(), m2create()); + t.equals(m1create(), m1create()); + t.equals(m2create(), m2create()); + + t.equals(m1create().add(m2create()), new RMatrix4([ + 3,0,6,8, + 3,8,2,15, + 12,18,7,21 + ])); + t.equals(m2create().add(m1create()), new RMatrix4([ + 3,0,6,8, + 3,8,2,15, + 12,18,7,21 + ])); + t.equals(m1create().subtract(m2create()), new RMatrix4([ + -1,4,0,0, + 7,4,12,1, + 6,2,15,3 + ])); + + t.equals(m1create().scalerMultiply(10), new RMatrix4([ + 10,20,30,40, + 50,60,70,80, + 90,100,110,120 + ])); + + t.equals(m1create().multiply(m2create()), new RMatrix4([ + 7, 26, -19, 49, + 19, 58, -43, 133, + 31, 90, -67, 217 + ])); + t.equals(m2create().multiply(m1create()), new RMatrix4([ + 19, 22, 25, 32, + -37, -42, -47, -45, + 7, 14, 21, 37 + ])); + + m = m1create(); + var m2:RMatrix4 = m2create(); + m.concat(m2); + t.equals(m, new RMatrix4([ + 7, 26, -19, 49, + 19, 58, -43, 133, + 31, 90, -67, 217 + ])); + t.equals(m2, m2create()); + + t.opEquals(0, m1create().det); + t.opEquals(44, m2create().det); + + t.equals(m2create().inverse(), new RMatrix4([ + 8/11, 4/11, 1/11, -69/11, + -23/44, -17/44, 1/11, 3.9772727272727275, + -1/2, -1/2, 0, 11/2 + ])); + }); + } + + public function m1create():RMatrix4 { + return new RMatrix4([ + 1,2,3,4, + 5,6,7,8, + 9,10,11,12 + ]); + } + + public function m2create():RMatrix4 { + return new RMatrix4([ + 2,-2,3,4, + -2,2,-5,7, + 3,8,-4,9 + ]); + } + } +} diff --git a/tests/rmatrix4test_values.rb b/tests/rmatrix4test_values.rb new file mode 100644 index 0000000..e8b0cd0 --- /dev/null +++ b/tests/rmatrix4test_values.rb @@ -0,0 +1,25 @@ +#!/usr/bin/env ruby + +require 'matrix' +require 'mathn' + +m1 = Matrix[ + [1,2,3,4], + [5,6,7,8], + [9,10,11,12], + [0,0,0,1] +] + +m2 = Matrix[ + [2,-2,3,4], + [-2,2,-5,7], + [3,8,-4,9], + [0,0,0,1] +] + +p m1 * m2 +p (m2 * m1).to_a.flatten +p m1.det +p m2.det +#p m1.inverse +p m2.inverse
hotchpotch/as3rails2u
580833456e0a433d7c244d0545119e607cef18bd
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@72 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/geom/RVector.as b/src/com/rails2u/geom/RVector.as index 173d790..c1b5a2a 100644 --- a/src/com/rails2u/geom/RVector.as +++ b/src/com/rails2u/geom/RVector.as @@ -1,89 +1,91 @@ package com.rails2u.geom { import flash.geom.Point; public class RVector { public static const ZERO:RVector = new RVector(0, 0); public var x:Number = 0; public var y:Number = 0; + public var stash:Object; + public function RVector(x:Number = 0, y:Number = 0) { this.x = x; this.y = y; } public function clone():RVector { return new RVector(x, y); } public function add(v:RVector):RVector { return new RVector(x + v.x, y + v.y); } public function subtract(v:RVector):RVector { return new RVector(x - v.x, y - v.y); } public function inverse():RVector { return new RVector(x * -1, y * -1); } public function multiply(n:Number):RVector { return new RVector(x * n, y * n); } public function get length():Number { return Math.sqrt(x*x + y*y); } public function equals(v:RVector):Boolean { return (x == v.x) && (y == v.y); } public function normalize(len:Number = 1):RVector { var l:Number = length / len; return l == 0 ? ZERO.clone() : new RVector(x / l, y / l); } public function dot(v:RVector):Number { return x * v.x + y * v.y; } public function distance(v:RVector):Number { return subtract(v).length; } public function degree(v:RVector):Number { var n0:RVector = normalize(); var n1:RVector = v.normalize(); // (n1.y < n0.y && n1.x > n0.x) || if (n1.y > n0.y && n1.x < n0.x) { return -1 * Math.acos(dot(v) / (length * v.length)); } else { return Math.acos(dot(v) / (length * v.length)); } } public function angle(v:RVector):Number { return degree(v) * 180/Math.PI; } public function toString():String { return 'RVector[x:' + x + ', y:' + y + ']'; } public function point():Point { return new Point(x, y); } public static function create(o:*):RVector { if (o.hasOwnProperty('x') && o.hasOwnProperty('y')) { return new RVector(o.x, o.y); } else if (o is Array && o.length == 2) { return new RVector(o[0], o[1]); } else { return null; } } } } diff --git a/src/com/rails2u/geom/RVector3.as b/src/com/rails2u/geom/RVector3.as index 4d46900..c7ad819 100644 --- a/src/com/rails2u/geom/RVector3.as +++ b/src/com/rails2u/geom/RVector3.as @@ -1,83 +1,85 @@ package com.rails2u.geom { import flash.geom.Point; public class RVector3 { public static const ZERO:RVector3 = new RVector3(0, 0, 0); public var x:Number = 0; public var y:Number = 0; public var z:Number = 0; + public var stash:Object; + public function RVector3(x:Number = 0, y:Number = 0, z:Number = 0) { this.x = x; this.y = y; this.z = z; } public function clone():RVector3 { return new RVector3(x, y, z); } public function add(v:RVector3):RVector3 { return new RVector3(x + v.x, y + v.y, z + v.z); } public function subtract(v:RVector3):RVector3 { return new RVector3(x - v.x, y - v.y, z - v.z); } public function inverse():RVector3 { return new RVector3(x * -1, y * -1, z * -1); } public function multiply(n:Number):RVector3 { return new RVector3(x * n, y * n, z * n); } public function get length():Number { return Math.sqrt(x*x + y*y + z*z); } public function equals(v:RVector3):Boolean { return (x == v.x) && (y == v.y) && (z == v.z); } public function normalize(len:Number = 1):RVector3 { var l:Number = length / len; return l == 0 ? ZERO.clone() : new RVector3(x / l, y / l, z / l); } public function dot(v:RVector3):Number { return x * v.x + y * v.y + z * v.z; } - public function cross(v:RVector3):Number { - return 0;//x * v.x + y * v.y + z * v.z; + public function cross(v:RVector3):RVector3 { + return new RVector3(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x); } public function distance(v:RVector3):Number { return subtract(v).length; } public function degree(v:RVector3):Number { /* var n0:RVector3 = normalize(); var n1:RVector3 = v.normalize(); // (n1.y < n0.y && n1.x > n0.x) || if (n1.y > n0.y && n1.x < n0.x) { return -1 * Math.acos(dot(v) / (length * v.length)); } else { return Math.acos(dot(v) / (length * v.length)); } */ return Math.acos(dot(v) / (length * v.length)); } public function angle(v:RVector3):Number { return degree(v) * 180/Math.PI; } public function toString():String { return 'RVector3[x:' + x + ', y:' + y + ', z:' + z + ']'; } } } diff --git a/tests/RVector3Test.as b/tests/RVector3Test.as index ed43085..a6d1f66 100644 --- a/tests/RVector3Test.as +++ b/tests/RVector3Test.as @@ -1,60 +1,60 @@ package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import com.rails2u.geom.*; [SWF(frameRate=60, background=0x000000)] public class RVector3Test extends Sprite { public function RVector3Test (){ stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; rvector3(); } public function rvector3(): void { var t:SimpleTest = new SimpleTest('RVector3'); t.run(function():void { var v1:RVector3 = new RVector3(3,2,4); var v2:RVector3 = new RVector3(2,-1,-5); t.equals(v1.add(v2), new RVector3(5,1,-1)); t.equals(v2.add(v1), new RVector3(5,1,-1)); t.equals(v1.subtract(v2), new RVector3(1,3,9)); t.equals(v2.subtract(v1), new RVector3(-1,-3,-9)); t.equals(v1.inverse(), new RVector3(-3,-2,-4)); t.equals(v2.inverse(), new RVector3(-2,1,5)); t.equals(v2.add(v1), v1.subtract(v2.inverse())); t.equals(v1.multiply(2), new RVector3(6, 4, 8)); t.equals(v1.multiply(-2), new RVector3(-6, -4,-8)); t.equals(v2.multiply(-2), new RVector3(-4, 2,10)); t.ok(v1.equals(new RVector3(3, 2, 4))); t.opEquals(v1.length, Math.sqrt(9 + 4 + 16)); t.opEquals(1, v1.normalize().length); t.opEquals(1/3, v2.normalize().length/3); // for round... t.opEquals(3, v1.normalize(3).length); t.equals(RVector3.ZERO, (new RVector3(0,0,0)).normalize()); t.equals(v1.dot(v2), -16); t.equals(v2.dot(v1), -16); var angle:Number = (new RVector3(5,2,-3)).angle(new RVector3(8, 1, -4)); t.ok(angle > 13 && angle < 14); angle = (new RVector3(-1,4,2)).angle(new RVector3(3,0,5)); t.ok(angle > 74 && angle < 75); - //t.opEquals(Math.sqrt(2), (new RVector3(0,1)).distance(new RVector(1,0))); - //t.opEquals(1, (new RVector3(0,0)).distance(new RVector(1,0))); - //t.opEquals(0, (new RVector3(0,0)).distance(new RVector(0,0))); + t.equals( + new RVector3(-18, -15, 16), (new RVector3(5,-6,0)).cross(new RVector3(1,2,3)) + ); }); } } }
hotchpotch/as3rails2u
c2f00923be32150c82ab74c17a57563058e4e6a3
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@71 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/geom/RVector.as b/src/com/rails2u/geom/RVector.as index 532bfaf..173d790 100644 --- a/src/com/rails2u/geom/RVector.as +++ b/src/com/rails2u/geom/RVector.as @@ -1,88 +1,89 @@ -package com.rails2u.math { +package com.rails2u.geom { import flash.geom.Point; + public class RVector { public static const ZERO:RVector = new RVector(0, 0); public var x:Number = 0; public var y:Number = 0; public function RVector(x:Number = 0, y:Number = 0) { this.x = x; this.y = y; } public function clone():RVector { return new RVector(x, y); } public function add(v:RVector):RVector { return new RVector(x + v.x, y + v.y); } public function subtract(v:RVector):RVector { return new RVector(x - v.x, y - v.y); } public function inverse():RVector { return new RVector(x * -1, y * -1); } public function multiply(n:Number):RVector { return new RVector(x * n, y * n); } public function get length():Number { return Math.sqrt(x*x + y*y); } public function equals(v:RVector):Boolean { return (x == v.x) && (y == v.y); } public function normalize(len:Number = 1):RVector { var l:Number = length / len; return l == 0 ? ZERO.clone() : new RVector(x / l, y / l); } public function dot(v:RVector):Number { return x * v.x + y * v.y; } public function distance(v:RVector):Number { return subtract(v).length; } public function degree(v:RVector):Number { var n0:RVector = normalize(); var n1:RVector = v.normalize(); // (n1.y < n0.y && n1.x > n0.x) || if (n1.y > n0.y && n1.x < n0.x) { return -1 * Math.acos(dot(v) / (length * v.length)); } else { return Math.acos(dot(v) / (length * v.length)); } } public function angle(v:RVector):Number { return degree(v) * 180/Math.PI; } public function toString():String { return 'RVector[x:' + x + ', y:' + y + ']'; } public function point():Point { return new Point(x, y); } public static function create(o:*):RVector { if (o.hasOwnProperty('x') && o.hasOwnProperty('y')) { return new RVector(o.x, o.y); } else if (o is Array && o.length == 2) { return new RVector(o[0], o[1]); } else { return null; } } } } diff --git a/src/com/rails2u/geom/RVector3.as b/src/com/rails2u/geom/RVector3.as index 14d573f..4d46900 100644 --- a/src/com/rails2u/geom/RVector3.as +++ b/src/com/rails2u/geom/RVector3.as @@ -1,83 +1,83 @@ -package com.rails2u.math { +package com.rails2u.geom { import flash.geom.Point; public class RVector3 { public static const ZERO:RVector3 = new RVector3(0, 0, 0); public var x:Number = 0; public var y:Number = 0; public var z:Number = 0; public function RVector3(x:Number = 0, y:Number = 0, z:Number = 0) { this.x = x; this.y = y; this.z = z; } public function clone():RVector3 { return new RVector3(x, y, z); } public function add(v:RVector3):RVector3 { return new RVector3(x + v.x, y + v.y, z + v.z); } public function subtract(v:RVector3):RVector3 { return new RVector3(x - v.x, y - v.y, z - v.z); } public function inverse():RVector3 { return new RVector3(x * -1, y * -1, z * -1); } public function multiply(n:Number):RVector3 { return new RVector3(x * n, y * n, z * n); } public function get length():Number { return Math.sqrt(x*x + y*y + z*z); } public function equals(v:RVector3):Boolean { return (x == v.x) && (y == v.y) && (z == v.z); } public function normalize(len:Number = 1):RVector3 { var l:Number = length / len; return l == 0 ? ZERO.clone() : new RVector3(x / l, y / l, z / l); } public function dot(v:RVector3):Number { return x * v.x + y * v.y + z * v.z; } public function cross(v:RVector3):Number { return 0;//x * v.x + y * v.y + z * v.z; } public function distance(v:RVector3):Number { return subtract(v).length; } public function degree(v:RVector3):Number { /* var n0:RVector3 = normalize(); var n1:RVector3 = v.normalize(); // (n1.y < n0.y && n1.x > n0.x) || if (n1.y > n0.y && n1.x < n0.x) { return -1 * Math.acos(dot(v) / (length * v.length)); } else { return Math.acos(dot(v) / (length * v.length)); } */ return Math.acos(dot(v) / (length * v.length)); } public function angle(v:RVector3):Number { return degree(v) * 180/Math.PI; } public function toString():String { return 'RVector3[x:' + x + ', y:' + y + ', z:' + z + ']'; } } } diff --git a/tests/RVector3Test.as b/tests/RVector3Test.as index 19f88f0..ed43085 100644 --- a/tests/RVector3Test.as +++ b/tests/RVector3Test.as @@ -1,60 +1,60 @@ package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; - import com.rails2u.math.*; + import com.rails2u.geom.*; [SWF(frameRate=60, background=0x000000)] public class RVector3Test extends Sprite { public function RVector3Test (){ stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; rvector3(); } public function rvector3(): void { var t:SimpleTest = new SimpleTest('RVector3'); t.run(function():void { var v1:RVector3 = new RVector3(3,2,4); var v2:RVector3 = new RVector3(2,-1,-5); t.equals(v1.add(v2), new RVector3(5,1,-1)); t.equals(v2.add(v1), new RVector3(5,1,-1)); t.equals(v1.subtract(v2), new RVector3(1,3,9)); t.equals(v2.subtract(v1), new RVector3(-1,-3,-9)); t.equals(v1.inverse(), new RVector3(-3,-2,-4)); t.equals(v2.inverse(), new RVector3(-2,1,5)); t.equals(v2.add(v1), v1.subtract(v2.inverse())); t.equals(v1.multiply(2), new RVector3(6, 4, 8)); t.equals(v1.multiply(-2), new RVector3(-6, -4,-8)); t.equals(v2.multiply(-2), new RVector3(-4, 2,10)); t.ok(v1.equals(new RVector3(3, 2, 4))); t.opEquals(v1.length, Math.sqrt(9 + 4 + 16)); t.opEquals(1, v1.normalize().length); t.opEquals(1/3, v2.normalize().length/3); // for round... t.opEquals(3, v1.normalize(3).length); t.equals(RVector3.ZERO, (new RVector3(0,0,0)).normalize()); t.equals(v1.dot(v2), -16); t.equals(v2.dot(v1), -16); var angle:Number = (new RVector3(5,2,-3)).angle(new RVector3(8, 1, -4)); t.ok(angle > 13 && angle < 14); angle = (new RVector3(-1,4,2)).angle(new RVector3(3,0,5)); t.ok(angle > 74 && angle < 75); //t.opEquals(Math.sqrt(2), (new RVector3(0,1)).distance(new RVector(1,0))); //t.opEquals(1, (new RVector3(0,0)).distance(new RVector(1,0))); //t.opEquals(0, (new RVector3(0,0)).distance(new RVector(0,0))); }); } } } diff --git a/tests/RVectorTest.as b/tests/RVectorTest.as index 72b9611..88c3d09 100644 --- a/tests/RVectorTest.as +++ b/tests/RVectorTest.as @@ -1,84 +1,84 @@ package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; - import com.rails2u.math.*; + import com.rails2u.geom.*; import flash.geom.Point; import flash.display.Shape; [SWF(frameRate=60, background=0x000000)] public class RVectorTest extends Sprite { public function RVectorTest (){ stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; rvector(); } public function rvector(): void { var t:SimpleTest = new SimpleTest('RVector'); //t.verbose = true; t.run(function():void { var v1:RVector = new RVector(3,2); var v2:RVector = new RVector(2,-1); t.equals(v1.add(v2), new RVector(5,1)); t.equals(v2.add(v1), new RVector(5,1)); t.equals(v1.subtract(v2), new RVector(1,3)); t.equals(v2.subtract(v1), new RVector(-1,-3)); t.equals(v1.inverse(), new RVector(-3,-2)); t.equals(v2.inverse(), new RVector(-2,1)); t.equals(v2.add(v1), v1.subtract(v2.inverse())); t.equals(v1.multiply(2), new RVector(6, 4)); t.equals(v1.multiply(-2), new RVector(-6, -4)); t.equals(v2.multiply(-2), new RVector(-4, 2)); t.ok(v1.equals(new RVector(3, 2))); t.opEquals(v1.length, Math.sqrt(9 + 4)); t.opEquals(1, v1.normalize().length); t.opEquals(1/3, v2.normalize().length/3); // for round... t.equals(RVector.ZERO, (new RVector(0,0)).normalize()); t.equals(v1.dot(v2), 4); t.equals(v2.dot(v1), 4); t.opEquals(Math.sqrt(2), (new RVector(0,1)).distance(new RVector(1,0))); t.opEquals(1, (new RVector(0,0)).distance(new RVector(1,0))); t.opEquals(0, (new RVector(0,0)).distance(new RVector(0,0))); // degree t.opEquals(-Math.PI/2, (new RVector(1,0).degree(new RVector(0,1)))); t.opEquals(Math.PI/2, (new RVector(1,0).degree(new RVector(0,-1)))); t.opEquals(Math.PI, (new RVector(1,0).degree(new RVector(-100,0)))); t.opEquals(0, (new RVector(100,0).degree(new RVector(100,0)))); t.opEquals(0, (new RVector(100,0).degree(new RVector(101,0)))); t.opEquals(0, (new RVector(0,10).degree(new RVector(0,100)))); // angle t.opEquals(-135, (new RVector(1,0).angle(new RVector(-1, 1)))); var angle:Number = (new RVector(1,1).angle(new RVector(0.5, 1))); t.ok(angle > -45 && angle < -1); angle = (new RVector(1,1).angle(new RVector(1.5, 1))); t.ok(angle < 45 && angle > 1); angle = (new RVector(-1,-3).angle(new RVector(-3, -1))); t.ok(angle < -1 && angle > -90); angle = (new RVector(-3,-1).angle(new RVector(-1, -3))); t.ok(angle < 90 && angle > 1); // factory t.equals(new RVector(1,2), RVector.create(new Point(1,2))); t.ok(new Point(1,2).equals(RVector.create(new Point(1,2)).point())); var d:Shape = new Shape; d.x = 1; d.y = 2; t.equals(new RVector(1,2), RVector.create(d)); t.equals(new RVector(1,2), RVector.create([1,2])); t.opEquals(null, RVector.create([1,2,3])); }); } } }
hotchpotch/as3rails2u
a32abfe37c934cc3b6fced915152492edad8b8e4
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@69 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/math/RVector.as b/src/com/rails2u/math/RVector.as index c01798e..532bfaf 100644 --- a/src/com/rails2u/math/RVector.as +++ b/src/com/rails2u/math/RVector.as @@ -1,66 +1,88 @@ package com.rails2u.math { + import flash.geom.Point; public class RVector { public static const ZERO:RVector = new RVector(0, 0); public var x:Number = 0; public var y:Number = 0; public function RVector(x:Number = 0, y:Number = 0) { this.x = x; this.y = y; } public function clone():RVector { return new RVector(x, y); } public function add(v:RVector):RVector { return new RVector(x + v.x, y + v.y); } public function subtract(v:RVector):RVector { return new RVector(x - v.x, y - v.y); } public function inverse():RVector { return new RVector(x * -1, y * -1); } public function multiply(n:Number):RVector { return new RVector(x * n, y * n); } public function get length():Number { return Math.sqrt(x*x + y*y); } public function equals(v:RVector):Boolean { return (x == v.x) && (y == v.y); } public function normalize(len:Number = 1):RVector { var l:Number = length / len; return l == 0 ? ZERO.clone() : new RVector(x / l, y / l); } - public function innerProduct(v:RVector):Number { + public function dot(v:RVector):Number { return x * v.x + y * v.y; } public function distance(v:RVector):Number { return subtract(v).length; } public function degree(v:RVector):Number { - if ((v.y < y && v.x > x) || (v.y > y && v.x < x)) { - return -1 * Math.acos(innerProduct(v) / (length * v.length)); + var n0:RVector = normalize(); + var n1:RVector = v.normalize(); + // (n1.y < n0.y && n1.x > n0.x) || + if (n1.y > n0.y && n1.x < n0.x) { + return -1 * Math.acos(dot(v) / (length * v.length)); } else { - return Math.acos(innerProduct(v) / (length * v.length)); + return Math.acos(dot(v) / (length * v.length)); } } + public function angle(v:RVector):Number { + return degree(v) * 180/Math.PI; + } + public function toString():String { return 'RVector[x:' + x + ', y:' + y + ']'; } + + public function point():Point { + return new Point(x, y); + } + + public static function create(o:*):RVector { + if (o.hasOwnProperty('x') && o.hasOwnProperty('y')) { + return new RVector(o.x, o.y); + } else if (o is Array && o.length == 2) { + return new RVector(o[0], o[1]); + } else { + return null; + } + } } } diff --git a/src/com/rails2u/math/RVector3.as b/src/com/rails2u/math/RVector3.as new file mode 100644 index 0000000..14d573f --- /dev/null +++ b/src/com/rails2u/math/RVector3.as @@ -0,0 +1,83 @@ +package com.rails2u.math { + import flash.geom.Point; + public class RVector3 { + public static const ZERO:RVector3 = new RVector3(0, 0, 0); + + public var x:Number = 0; + public var y:Number = 0; + public var z:Number = 0; + + public function RVector3(x:Number = 0, y:Number = 0, z:Number = 0) { + this.x = x; + this.y = y; + this.z = z; + } + + public function clone():RVector3 { + return new RVector3(x, y, z); + } + + public function add(v:RVector3):RVector3 { + return new RVector3(x + v.x, y + v.y, z + v.z); + } + + public function subtract(v:RVector3):RVector3 { + return new RVector3(x - v.x, y - v.y, z - v.z); + } + + public function inverse():RVector3 { + return new RVector3(x * -1, y * -1, z * -1); + } + + public function multiply(n:Number):RVector3 { + return new RVector3(x * n, y * n, z * n); + } + + public function get length():Number { + return Math.sqrt(x*x + y*y + z*z); + } + + public function equals(v:RVector3):Boolean { + return (x == v.x) && (y == v.y) && (z == v.z); + } + + public function normalize(len:Number = 1):RVector3 { + var l:Number = length / len; + return l == 0 ? ZERO.clone() : new RVector3(x / l, y / l, z / l); + } + + public function dot(v:RVector3):Number { + return x * v.x + y * v.y + z * v.z; + } + + public function cross(v:RVector3):Number { + return 0;//x * v.x + y * v.y + z * v.z; + } + + public function distance(v:RVector3):Number { + return subtract(v).length; + } + + public function degree(v:RVector3):Number { + /* + var n0:RVector3 = normalize(); + var n1:RVector3 = v.normalize(); + // (n1.y < n0.y && n1.x > n0.x) || + if (n1.y > n0.y && n1.x < n0.x) { + return -1 * Math.acos(dot(v) / (length * v.length)); + } else { + return Math.acos(dot(v) / (length * v.length)); + } + */ + return Math.acos(dot(v) / (length * v.length)); + } + + public function angle(v:RVector3):Number { + return degree(v) * 180/Math.PI; + } + + public function toString():String { + return 'RVector3[x:' + x + ', y:' + y + ', z:' + z + ']'; + } + } +} diff --git a/tests/RVector3Test.as b/tests/RVector3Test.as new file mode 100644 index 0000000..19f88f0 --- /dev/null +++ b/tests/RVector3Test.as @@ -0,0 +1,60 @@ +package { + import flash.display.Sprite; + import flash.display.StageAlign; + import flash.display.StageScaleMode; + import com.rails2u.math.*; + + [SWF(frameRate=60, background=0x000000)] + public class RVector3Test extends Sprite { + public function RVector3Test (){ + stage.align = StageAlign.TOP_LEFT; + stage.scaleMode = StageScaleMode.NO_SCALE; + rvector3(); + } + + public function rvector3(): void { + var t:SimpleTest = new SimpleTest('RVector3'); + t.run(function():void { + var v1:RVector3 = new RVector3(3,2,4); + var v2:RVector3 = new RVector3(2,-1,-5); + + t.equals(v1.add(v2), new RVector3(5,1,-1)); + t.equals(v2.add(v1), new RVector3(5,1,-1)); + + t.equals(v1.subtract(v2), new RVector3(1,3,9)); + t.equals(v2.subtract(v1), new RVector3(-1,-3,-9)); + + t.equals(v1.inverse(), new RVector3(-3,-2,-4)); + t.equals(v2.inverse(), new RVector3(-2,1,5)); + + t.equals(v2.add(v1), v1.subtract(v2.inverse())); + + t.equals(v1.multiply(2), new RVector3(6, 4, 8)); + t.equals(v1.multiply(-2), new RVector3(-6, -4,-8)); + t.equals(v2.multiply(-2), new RVector3(-4, 2,10)); + + t.ok(v1.equals(new RVector3(3, 2, 4))); + t.opEquals(v1.length, Math.sqrt(9 + 4 + 16)); + + t.opEquals(1, v1.normalize().length); + t.opEquals(1/3, v2.normalize().length/3); // for round... + t.opEquals(3, v1.normalize(3).length); + + t.equals(RVector3.ZERO, (new RVector3(0,0,0)).normalize()); + + t.equals(v1.dot(v2), -16); + t.equals(v2.dot(v1), -16); + + var angle:Number = (new RVector3(5,2,-3)).angle(new RVector3(8, 1, -4)); + t.ok(angle > 13 && angle < 14); + angle = (new RVector3(-1,4,2)).angle(new RVector3(3,0,5)); + t.ok(angle > 74 && angle < 75); + + //t.opEquals(Math.sqrt(2), (new RVector3(0,1)).distance(new RVector(1,0))); + //t.opEquals(1, (new RVector3(0,0)).distance(new RVector(1,0))); + //t.opEquals(0, (new RVector3(0,0)).distance(new RVector(0,0))); + }); + } + + } +} diff --git a/tests/RVectorTest.as b/tests/RVectorTest.as index 43a9dcd..72b9611 100644 --- a/tests/RVectorTest.as +++ b/tests/RVectorTest.as @@ -1,62 +1,84 @@ package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import com.rails2u.math.*; + import flash.geom.Point; + import flash.display.Shape; [SWF(frameRate=60, background=0x000000)] public class RVectorTest extends Sprite { public function RVectorTest (){ stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; rvector(); } public function rvector(): void { var t:SimpleTest = new SimpleTest('RVector'); + //t.verbose = true; t.run(function():void { var v1:RVector = new RVector(3,2); var v2:RVector = new RVector(2,-1); t.equals(v1.add(v2), new RVector(5,1)); t.equals(v2.add(v1), new RVector(5,1)); t.equals(v1.subtract(v2), new RVector(1,3)); t.equals(v2.subtract(v1), new RVector(-1,-3)); t.equals(v1.inverse(), new RVector(-3,-2)); t.equals(v2.inverse(), new RVector(-2,1)); t.equals(v2.add(v1), v1.subtract(v2.inverse())); t.equals(v1.multiply(2), new RVector(6, 4)); t.equals(v1.multiply(-2), new RVector(-6, -4)); t.equals(v2.multiply(-2), new RVector(-4, 2)); t.ok(v1.equals(new RVector(3, 2))); t.opEquals(v1.length, Math.sqrt(9 + 4)); t.opEquals(1, v1.normalize().length); t.opEquals(1/3, v2.normalize().length/3); // for round... t.equals(RVector.ZERO, (new RVector(0,0)).normalize()); - t.equals(v1.innerProduct(v2), 4); - t.equals(v2.innerProduct(v1), 4); + t.equals(v1.dot(v2), 4); + t.equals(v2.dot(v1), 4); t.opEquals(Math.sqrt(2), (new RVector(0,1)).distance(new RVector(1,0))); t.opEquals(1, (new RVector(0,0)).distance(new RVector(1,0))); t.opEquals(0, (new RVector(0,0)).distance(new RVector(0,0))); // degree t.opEquals(-Math.PI/2, (new RVector(1,0).degree(new RVector(0,1)))); t.opEquals(Math.PI/2, (new RVector(1,0).degree(new RVector(0,-1)))); t.opEquals(Math.PI, (new RVector(1,0).degree(new RVector(-100,0)))); t.opEquals(0, (new RVector(100,0).degree(new RVector(100,0)))); t.opEquals(0, (new RVector(100,0).degree(new RVector(101,0)))); t.opEquals(0, (new RVector(0,10).degree(new RVector(0,100)))); - t.opEquals(-135*Math.PI/180, (new RVector(1,0).degree(new RVector(-1, 1)))); + + // angle + t.opEquals(-135, (new RVector(1,0).angle(new RVector(-1, 1)))); + var angle:Number = (new RVector(1,1).angle(new RVector(0.5, 1))); + t.ok(angle > -45 && angle < -1); + angle = (new RVector(1,1).angle(new RVector(1.5, 1))); + t.ok(angle < 45 && angle > 1); + angle = (new RVector(-1,-3).angle(new RVector(-3, -1))); + t.ok(angle < -1 && angle > -90); + angle = (new RVector(-3,-1).angle(new RVector(-1, -3))); + t.ok(angle < 90 && angle > 1); + + // factory + t.equals(new RVector(1,2), RVector.create(new Point(1,2))); + t.ok(new Point(1,2).equals(RVector.create(new Point(1,2)).point())); + var d:Shape = new Shape; + d.x = 1; + d.y = 2; + t.equals(new RVector(1,2), RVector.create(d)); + t.equals(new RVector(1,2), RVector.create([1,2])); + t.opEquals(null, RVector.create([1,2,3])); }); } - } } diff --git a/tests/SimpleTest.as b/tests/SimpleTest.as index 4913f57..20a8688 100644 --- a/tests/SimpleTest.as +++ b/tests/SimpleTest.as @@ -1,127 +1,130 @@ package { import com.rails2u.utils.ObjectUtil; public class SimpleTest { - public var detail:Boolean = false; + public var verbose:Boolean = false; public var count:uint = 0; public var successedCount:uint = 0; public var failedCount:uint = 0; public var testName:String = ''; public function SimpleTest(testName:String = '') { this.testName = testName; } public function run(f:Function):void { try { - log(testName + ' test start.'); - // log(testName + '[' + count.toString() +' test(s)] start.'); + showMessage(testName + ' test start.'); + // showMessage(testName + '[' + String(count) +' test(s)] start.'); f.call(this); finish(); } catch(e:Error) { - log(e.getStackTrace()); + showMessage(e.getStackTrace()); } } public function ok(res:*):void { count++; if (res) { - success(res.toString() + " is ok."); + success(String(res) + " is ok."); } else { - fail(res.toString() + " is not ok."); + fail(String(res) + " is not ok."); } } public function notOk(res:*):void { count++; if (res) { - success(res.toString() + " is not ok."); + success(String(res) + " is not ok."); } else { - fail(res.toString() + " is ok."); + fail(String(res) + " is ok."); } } public function opEquals(a:*, b:*):void { count++; if (a == b) { - success(a.toString() + " is " + b + '.'); + success(String(a) + " is " + b + '.'); } else { - fail(a.toString() + " is not " + b + '.'); + fail(String(a) + " is not " + b + '.'); } } public function notOpEquals(a:*, b:*):void { count++; if (a != b) { - success(a.toString() + " is not " + b + '.'); + success(String(a) + " is not " + b + '.'); } else { - fail(a.toString() + " is " + b + '.'); + fail(String(a) + " is " + b + '.'); } } public function equals(a:*, b:*):void { count++; var _a:String = ObjectUtil.inspect(a); var _b:String = ObjectUtil.inspect(b); if (_a == _b) { - success(a.toString() + " is " + b + '.'); + success(String(a) + " is " + b + '.'); } else { - fail(a.toString() + " is not " + b + '.'); + fail(String(a) + " is not " + b + '.'); } } public function notEquals(a:*, b:*):void { count++; var _a:String = ObjectUtil.inspect(a); var _b:String = ObjectUtil.inspect(b); if (_a != _b) { - success(a.toString() + " is not " + b + '.'); + success(String(a) + " is not " + b + '.'); } else { - fail(a.toString() + " is " + b + '.'); + fail(String(a) + " is " + b + '.'); } } public function finish():void { if (count == successedCount) { - log(count.toString() + " test(s) is all successed!"); + showMessage(String(count) + " test(s) is all successed!"); } else { - log(count.toString() + " test(s) running: " + failedCount.toString() +" error: " + successedCount.toString() + " success."); + showMessage(String(count) + " test(s) running: " + String(failedCount) +" error: " + String(successedCount) + " success."); } } protected function success(s:String):void { successedCount++; - if (detail) { + if (verbose) { showSuccess(s); } } protected function fail(s:String):void { failedCount++; var mes:String = (new SimpleTestError(s)).getStackTrace(); var at:String = 'at SimpleTest'; var buildinCall:String = '2006/builtin::'; showFail( mes.split("\n").filter(function(i:String, ind:int, a:Array):Boolean { return i.indexOf(at) == -1 && i.indexOf(buildinCall) == -1 - }).join("\n") + }).join("\n") ); } - protected function showFail(mes:String):void { + protected function showMessage(mes:String):void { log(mes); } + protected function showFail(mes:String):void { + showMessage(mes); + } protected function showSuccess(mes:String):void { - log(mes); + showMessage(mes); } } } class SimpleTestError extends Error { public function SimpleTestError(m:String="", id:int=0) { super(m, id); name = 'SimpleTestError'; } }
hotchpotch/as3rails2u
f057a2e050233ea9e133bd056ad89727a8f64952
append vector2
diff --git a/src/com/rails2u/math/RVector.as b/src/com/rails2u/math/RVector.as new file mode 100644 index 0000000..c01798e --- /dev/null +++ b/src/com/rails2u/math/RVector.as @@ -0,0 +1,66 @@ +package com.rails2u.math { + public class RVector { + public static const ZERO:RVector = new RVector(0, 0); + + public var x:Number = 0; + public var y:Number = 0; + + public function RVector(x:Number = 0, y:Number = 0) { + this.x = x; + this.y = y; + } + + public function clone():RVector { + return new RVector(x, y); + } + + public function add(v:RVector):RVector { + return new RVector(x + v.x, y + v.y); + } + + public function subtract(v:RVector):RVector { + return new RVector(x - v.x, y - v.y); + } + + public function inverse():RVector { + return new RVector(x * -1, y * -1); + } + + public function multiply(n:Number):RVector { + return new RVector(x * n, y * n); + } + + public function get length():Number { + return Math.sqrt(x*x + y*y); + } + + public function equals(v:RVector):Boolean { + return (x == v.x) && (y == v.y); + } + + public function normalize(len:Number = 1):RVector { + var l:Number = length / len; + return l == 0 ? ZERO.clone() : new RVector(x / l, y / l); + } + + public function innerProduct(v:RVector):Number { + return x * v.x + y * v.y; + } + + public function distance(v:RVector):Number { + return subtract(v).length; + } + + public function degree(v:RVector):Number { + if ((v.y < y && v.x > x) || (v.y > y && v.x < x)) { + return -1 * Math.acos(innerProduct(v) / (length * v.length)); + } else { + return Math.acos(innerProduct(v) / (length * v.length)); + } + } + + public function toString():String { + return 'RVector[x:' + x + ', y:' + y + ']'; + } + } +} diff --git a/src/com/rails2u/utils/JSUtil.as b/src/com/rails2u/utils/JSUtil.as index 0edf4b3..1c83597 100644 --- a/src/com/rails2u/utils/JSUtil.as +++ b/src/com/rails2u/utils/JSUtil.as @@ -1,25 +1,33 @@ package com.rails2u.utils { import flash.external.ExternalInterface; public class JSUtil { public static function getObjectID():String { return ExternalInterface.objectID; } public static function selfCallJS(cmd:String):* { cmd = "return document.getElementById('" + getObjectID() + "')." + cmd; return callJS(cmd); } - public static function callJS(cmd:String):* { - cmd = "(function() {" + cmd + ";})"; - return ExternalInterface.call(cmd); + public static function callJS(cmd:String, ...args):* { + if (!ExternalInterface.available) + return null; + + if (args.length > 0) { + cmd = "(function() {" + cmd + ".apply(null, arguments);})"; + return ExternalInterface.call.apply(null, [cmd].concat(args)); + } else { + cmd = "(function() {" + cmd + ";})"; + return ExternalInterface.call(cmd); + } } public static function bindCallJS(bindName:String):Function { return function(cmd:String):* { return callJS(bindName + cmd); }; } } } diff --git a/src/com/rails2u/utils/KeyTypeListener.as b/src/com/rails2u/utils/KeyTypeListener.as index a98b3f4..7dcf6d0 100644 --- a/src/com/rails2u/utils/KeyTypeListener.as +++ b/src/com/rails2u/utils/KeyTypeListener.as @@ -1,145 +1,148 @@ package com.rails2u.utils { import flash.events.KeyboardEvent; import flash.utils.describeType; import flash.ui.Keyboard; import flash.display.InteractiveObject; import flash.utils.Dictionary; use namespace key_down; use namespace key_up; /** * KeyTypeListener attach keytype events(KEY_DOWN, KEY_UP) utility. * * How to use: * please see examples dir. */ public class KeyTypeListener { private static var objects:Dictionary = new Dictionary; public static function attach( obj:InteractiveObject, currentTarget:Object = null, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false ):KeyTypeListener { var instance:KeyTypeListener = new KeyTypeListener(obj, currentTarget, useCapture, priority, useWeakReference); instance.bindKey(KeyboardEvent.KEY_DOWN); instance.bindKey(KeyboardEvent.KEY_UP); objects[obj] = instance; return instance; } public static function detach(obj:InteractiveObject):Boolean { if(objects[obj]) { objects[obj].destroyImpl(); delete objects[obj]; return true; } else { return false; } } protected var obj:InteractiveObject; protected var currentTarget:Object; private var reflection:Reflection; private var callableCache:Object = {}; private var useCapture:Boolean; private var priority:int; private var useWeakReference:Boolean; public function KeyTypeListener(obj:InteractiveObject, currentTarget:Object = null, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void { this.obj = obj; this.useCapture = useCapture; this.priority = priority; this.useWeakReference = useWeakReference; if (currentTarget == null) { this.currentTarget = obj; } else { this.currentTarget = currentTarget; } reflection = Reflection.factory(this.currentTarget); } public function bindKey(type:String):void { if(type == KeyboardEvent.KEY_DOWN) { obj.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, useCapture, priority, useWeakReference); } else { obj.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler, useCapture, priority, useWeakReference); } } public function destroy():void { KeyTypeListener.detach(obj); } internal function destroyImpl():void { obj.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, useCapture); obj.removeEventListener(KeyboardEvent.KEY_UP, keyUpHandler, useCapture); } protected function keyDownHandler(e:KeyboardEvent):void { keyHandlerDelegeter(e, key_down); } protected function keyUpHandler(e:KeyboardEvent):void { keyHandlerDelegeter(e, key_up); } protected function keyHandlerDelegeter(e:KeyboardEvent, ns:Namespace):void { - // log(e.currentTarget, e.target, this.currentTarget, this.obj); if (!(e.target == this.currentTarget || e.target == this.obj)) { - return; + if (e.target.stage && this.obj == e.target.stage) { + // ... + } else { + return; + } } // log(String.fromCharCode(e.charCode)); var methodName:String = getMethodName(e); // log(methodName, ns); methodCall(e, 'before', ns); methodCall(e, methodName, ns); methodCall(e, 'after', ns); } private function methodCall(e:KeyboardEvent, methodName:String, ns:Namespace):void { var argsNum:int = reflection.methodArgs(methodName, ns); if(argsNum >= 0) { switch(argsNum) { case 0: currentTarget.ns::[methodName].call(currentTarget); break; case 1: currentTarget.ns::[methodName].call(currentTarget, e); break; default: throw new Error(methodName + ' arguments should be 0 or 1'); break; } } else if(methodName == 'after') { // default after call stopPropagation because always looping event... e.stopPropagation(); } } private const RE_NUM_CHAR:RegExp = /^\d$/; public function getMethodName(e:KeyboardEvent):String { if (keyboardConstfromCharCode(e.keyCode)) { return keyboardConstfromCharCode(e.keyCode); } var char:String = String.fromCharCode(e.keyCode); if (!e.shiftKey) char = char.toLowerCase(); if (e.ctrlKey) char = 'CTRL_' + char; if (RE_NUM_CHAR.test(char)) char = '_' + char; return char; } public static function keyboardConstfromCharCode(code:uint):String { return Reflection.factory(Keyboard).constantsTable[code]; } } } diff --git a/tests/RVectorTest.as b/tests/RVectorTest.as new file mode 100644 index 0000000..43a9dcd --- /dev/null +++ b/tests/RVectorTest.as @@ -0,0 +1,62 @@ +package { + import flash.display.Sprite; + import flash.display.StageAlign; + import flash.display.StageScaleMode; + import com.rails2u.math.*; + + [SWF(frameRate=60, background=0x000000)] + public class RVectorTest extends Sprite { + public function RVectorTest (){ + stage.align = StageAlign.TOP_LEFT; + stage.scaleMode = StageScaleMode.NO_SCALE; + rvector(); + } + + public function rvector(): void { + var t:SimpleTest = new SimpleTest('RVector'); + t.run(function():void { + var v1:RVector = new RVector(3,2); + var v2:RVector = new RVector(2,-1); + t.equals(v1.add(v2), new RVector(5,1)); + t.equals(v2.add(v1), new RVector(5,1)); + + t.equals(v1.subtract(v2), new RVector(1,3)); + t.equals(v2.subtract(v1), new RVector(-1,-3)); + + t.equals(v1.inverse(), new RVector(-3,-2)); + t.equals(v2.inverse(), new RVector(-2,1)); + + t.equals(v2.add(v1), v1.subtract(v2.inverse())); + + t.equals(v1.multiply(2), new RVector(6, 4)); + t.equals(v1.multiply(-2), new RVector(-6, -4)); + t.equals(v2.multiply(-2), new RVector(-4, 2)); + + t.ok(v1.equals(new RVector(3, 2))); + t.opEquals(v1.length, Math.sqrt(9 + 4)); + + t.opEquals(1, v1.normalize().length); + t.opEquals(1/3, v2.normalize().length/3); // for round... + + t.equals(RVector.ZERO, (new RVector(0,0)).normalize()); + + t.equals(v1.innerProduct(v2), 4); + t.equals(v2.innerProduct(v1), 4); + + t.opEquals(Math.sqrt(2), (new RVector(0,1)).distance(new RVector(1,0))); + t.opEquals(1, (new RVector(0,0)).distance(new RVector(1,0))); + t.opEquals(0, (new RVector(0,0)).distance(new RVector(0,0))); + + // degree + t.opEquals(-Math.PI/2, (new RVector(1,0).degree(new RVector(0,1)))); + t.opEquals(Math.PI/2, (new RVector(1,0).degree(new RVector(0,-1)))); + t.opEquals(Math.PI, (new RVector(1,0).degree(new RVector(-100,0)))); + t.opEquals(0, (new RVector(100,0).degree(new RVector(100,0)))); + t.opEquals(0, (new RVector(100,0).degree(new RVector(101,0)))); + t.opEquals(0, (new RVector(0,10).degree(new RVector(0,100)))); + t.opEquals(-135*Math.PI/180, (new RVector(1,0).degree(new RVector(-1, 1)))); + }); + } + + } +} diff --git a/tests/SimpleTest.as b/tests/SimpleTest.as new file mode 100644 index 0000000..4913f57 --- /dev/null +++ b/tests/SimpleTest.as @@ -0,0 +1,127 @@ +package { + import com.rails2u.utils.ObjectUtil; + + public class SimpleTest { + public var detail:Boolean = false; + + public var count:uint = 0; + public var successedCount:uint = 0; + public var failedCount:uint = 0; + + public var testName:String = ''; + + public function SimpleTest(testName:String = '') { + this.testName = testName; + } + + public function run(f:Function):void { + try { + log(testName + ' test start.'); + // log(testName + '[' + count.toString() +' test(s)] start.'); + f.call(this); + finish(); + } catch(e:Error) { + log(e.getStackTrace()); + } + } + + public function ok(res:*):void { + count++; + if (res) { + success(res.toString() + " is ok."); + } else { + fail(res.toString() + " is not ok."); + } + } + + public function notOk(res:*):void { + count++; + if (res) { + success(res.toString() + " is not ok."); + } else { + fail(res.toString() + " is ok."); + } + } + + public function opEquals(a:*, b:*):void { + count++; + if (a == b) { + success(a.toString() + " is " + b + '.'); + } else { + fail(a.toString() + " is not " + b + '.'); + } + } + + public function notOpEquals(a:*, b:*):void { + count++; + if (a != b) { + success(a.toString() + " is not " + b + '.'); + } else { + fail(a.toString() + " is " + b + '.'); + } + } + + public function equals(a:*, b:*):void { + count++; + var _a:String = ObjectUtil.inspect(a); + var _b:String = ObjectUtil.inspect(b); + if (_a == _b) { + success(a.toString() + " is " + b + '.'); + } else { + fail(a.toString() + " is not " + b + '.'); + } + } + + public function notEquals(a:*, b:*):void { + count++; + var _a:String = ObjectUtil.inspect(a); + var _b:String = ObjectUtil.inspect(b); + if (_a != _b) { + success(a.toString() + " is not " + b + '.'); + } else { + fail(a.toString() + " is " + b + '.'); + } + } + + public function finish():void { + if (count == successedCount) { + log(count.toString() + " test(s) is all successed!"); + } else { + log(count.toString() + " test(s) running: " + failedCount.toString() +" error: " + successedCount.toString() + " success."); + } + } + + protected function success(s:String):void { + successedCount++; + if (detail) { + showSuccess(s); + } + } + + protected function fail(s:String):void { + failedCount++; + var mes:String = (new SimpleTestError(s)).getStackTrace(); + var at:String = 'at SimpleTest'; + var buildinCall:String = '2006/builtin::'; + showFail( + mes.split("\n").filter(function(i:String, ind:int, a:Array):Boolean { + return i.indexOf(at) == -1 && i.indexOf(buildinCall) == -1 + }).join("\n") + ); + } + + protected function showFail(mes:String):void { + log(mes); + } + protected function showSuccess(mes:String):void { + log(mes); + } + } +} + +class SimpleTestError extends Error { + public function SimpleTestError(m:String="", id:int=0) { + super(m, id); + name = 'SimpleTestError'; + } +} diff --git a/tests/TestEnum.as b/tests/TestEnum.as index 68b5614..574cc6d 100644 --- a/tests/TestEnum.as +++ b/tests/TestEnum.as @@ -1,55 +1,58 @@ package { import flash.display.Sprite; import com.rails2u.core.*; public class TestEnum extends Sprite { public var res:String = ''; public function TestEnum() { + Enumerable.implementation(Array); + var ary:Array = [1,2,3]; + var e1:Enumerator = new Enumerator([1,2,3]); equ(e1.next(), 1); equ(e1.hasNext(), true); equ(e1.next(), 2); equ(e1.hasNext(), true); equ(e1.next(), 3); equ(e1.hasNext(), false); equ(e1.count, 3); equ([[1,4],[2,5],[3,6]], Enumerable.zip([1,2,3], [4,5,6]).to_a(), true); equ([[1,4,7],[2,5,8],[3,6,9]], Enumerable.zip([1,2,3], [4,5,6], [7,8,9]).to_a(), true); equ([[1,4,7],[2,5,8],[3,6,9]], Enumerable.zip([1,2,3], [4,5,6,10], [7,8,9]).to_a(), true); var cycle:Enumerator = Enumerable.cycle([1,2,3]); equ(cycle.next(), 1); equ(cycle.next(), 2); equ(cycle.next(), 3); equ(cycle.next(), 1); equ(cycle.next(), 2); equ(cycle.next(), 3); equ(cycle.next(), 1); equ(cycle.count, Infinity); equ([[1,1],[2,2],[3,3],[4,1]], Enumerable.zip([1,2,3,4], cycle).to_a(), true) equ(cycle.next(), 2); showResult(); } public function showResult():void { log(res); } public function equ(a:*, b:*, stringnize:Boolean = false):void { if(stringnize) { a = a.toString(); b = b.toString(); } if (a==b) { res += '.'; } else { log('Error:', a, b); } } } }
hotchpotch/as3rails2u
b7c8c46f778bc587ff7eb3bb8058e346113ebab7
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@67 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/bridge/JSProxy.as b/src/com/rails2u/bridge/JSProxy.as index 5fb6a88..333f013 100644 --- a/src/com/rails2u/bridge/JSProxy.as +++ b/src/com/rails2u/bridge/JSProxy.as @@ -1,171 +1,182 @@ package com.rails2u.bridge { import flash.utils.Proxy; import flash.external.ExternalInterface; import flash.utils.flash_proxy; public dynamic class JSProxy extends Proxy { use namespace flash_proxy; public static var proxyLogger:Function = function(...args):void {}; private var _stack:Array; private var _nextCallIsstack:Boolean = false; + public var forceAsync:Boolean = false; - public function JSProxy(stack:Array = null) { + public function JSProxy(stack:Array = null, forceAsync:Boolean = false) { _stack = stack || []; + this.forceAsync = forceAsync; } public function get proxy():JSProxy { return getProperty('proxy'); } public static function get proxy():JSProxy { return new JSProxy(); } flash_proxy override function callProperty(name:*, ...args):* { var $name:* = $check(name); if ($name) { return callJS(newStack($name, args)); } else { - return new JSProxy(newStack(name, args)); + return new JSProxy(newStack(name, args), forceAsync); } } flash_proxy function $check(name:*):* { if (name.toString().indexOf('$') == 0 && name.toString().length >= 2) { var r:String = name.toString().replace(/^\$+/, ''); if (name is QName) { return new QName(name.uri, r); } else { return r; } } else { return ''; } } flash_proxy override function getProperty(name:*):* { var $name:* = $check(name); if ($name) { return callJS(newStack($name)); } else { - return new JSProxy(newStack(name)); + return new JSProxy(newStack(name), forceAsync); } } flash_proxy override function getDescendants(name:*):* { return callJS(newStack(name)); } flash_proxy function newStack(name:*, args:Array = null):Array { var stack:Array = _stack.slice(); if (args != null) { stack.push([name, args.slice()]); } else { stack.push(name); } return stack; } flash_proxy override function hasProperty(name:*):Boolean { return callJS(newStack(new QName('', name))) !== undefined; } flash_proxy override function setProperty(name:*, value:*):void { var $name:* = $check(name); if ($name) { callJSSetProperty(newStack($name), value); } else { callJSSetProperty(newStack(name), value); } } flash_proxy override function deleteProperty(name:*):Boolean { return false; } public function toString():String { var res:Array = createCommand(_stack.slice()); var cmd:String = res[0]; var args:Array = res[1]; return '[JSProxy] ' + cmd + ' :: ' + args.join(', '); } flash_proxy function callJSSetProperty(stack:Array, value:*):void { if (!ExternalInterface.available) return; var res:Array = createCommand(stack); var cmd:String = res[0]; var args:Array = res[1]; args.push(value); var argsString:String = createArgsString(args.length); - cmd = "(function(" + argsString + ") {setTimeout(function(){try{" + cmd + " = _" + (args.length - 1).toString() + "}catch(e){};}, 0);})"; + //cmd = "(function(" + argsString + ") {setTimeout(function(){try{" + cmd + " = _" + (args.length - 1).toString() + "}catch(e){};}, 0);})"; + cmd = "(function(" + argsString + ") {" + asyncFunc(cmd + " = _" + (args.length - 1).toString()) + ";})"; proxyLogger(cmd); ExternalInterface.call.apply(null, [cmd].concat(args)); } + flash_proxy function asyncFunc(cmd:String):String { + return "setTimeout(function(){ try{" + cmd + "} catch(e) {};}, 0)"; + } + flash_proxy function callJS(stack:Array):* { if (!ExternalInterface.available) return null; var res:Array = createCommand(stack); var cmd:String = res[0]; var args:Array = res[1]; var argsString:String = createArgsString(args.length); + var result:*; + + if (forceAsync) cmd = asyncFunc(cmd); if (args.length > 0) { cmd = "(function(" + argsString + ") {return " + cmd + ";})"; proxyLogger(cmd); proxyLogger(args); - return ExternalInterface.call.apply(null, [cmd].concat(args)); + result = ExternalInterface.call.apply(null, [cmd].concat(args)); } else { cmd = "(function() {return " + cmd + ";})"; proxyLogger(cmd); - return ExternalInterface.call(cmd); + result = ExternalInterface.call(cmd); } + return forceAsync ? null : result; } flash_proxy function createArgsString(len:uint):String { var res:Array = []; for (var i:uint = 0; i < len; i++) { res.push('_' + i); } return res.join(', '); } flash_proxy function createCommand(stack:Array):Array { var receivers:Array = []; var args:Array = []; var argsStrings:Array = []; while (stack.length) { var o:* = stack.shift(); if (o is Array) { o = o as Array; var cmd:String = nameToString(o[0]) + '('; var cmdArgs:Array = []; var a:Array = o[1].slice(); while (a.length) { cmdArgs.push('_' + args.length); args.push(a.shift()); } cmd += cmdArgs.join(', '); cmd += ')'; receivers.push(cmd); } else { receivers.push(nameToString(o)); } } return [receivers.join('.').replace(/\.\[/g, '['), args]; } flash_proxy function nameToString(name:*):String { if (name is QName) { return name.localName.toString(); } else { return '[' + name.toString() + ']'; } } } }
hotchpotch/as3rails2u
3cdb386f63d98b6f367a9f362e559a2f1811c3d2
append setter setTimeout()
diff --git a/src/com/rails2u/bridge/JSProxy.as b/src/com/rails2u/bridge/JSProxy.as index 0e7b127..5fb6a88 100644 --- a/src/com/rails2u/bridge/JSProxy.as +++ b/src/com/rails2u/bridge/JSProxy.as @@ -1,166 +1,171 @@ package com.rails2u.bridge { import flash.utils.Proxy; import flash.external.ExternalInterface; import flash.utils.flash_proxy; public dynamic class JSProxy extends Proxy { use namespace flash_proxy; public static var proxyLogger:Function = function(...args):void {}; private var _stack:Array; private var _nextCallIsstack:Boolean = false; public function JSProxy(stack:Array = null) { _stack = stack || []; } public function get proxy():JSProxy { return getProperty('proxy'); } public static function get proxy():JSProxy { return new JSProxy(); } flash_proxy override function callProperty(name:*, ...args):* { var $name:* = $check(name); if ($name) { return callJS(newStack($name, args)); } else { return new JSProxy(newStack(name, args)); } } flash_proxy function $check(name:*):* { if (name.toString().indexOf('$') == 0 && name.toString().length >= 2) { var r:String = name.toString().replace(/^\$+/, ''); if (name is QName) { return new QName(name.uri, r); } else { return r; } } else { return ''; } } flash_proxy override function getProperty(name:*):* { var $name:* = $check(name); if ($name) { return callJS(newStack($name)); } else { return new JSProxy(newStack(name)); } } flash_proxy override function getDescendants(name:*):* { return callJS(newStack(name)); } flash_proxy function newStack(name:*, args:Array = null):Array { var stack:Array = _stack.slice(); if (args != null) { stack.push([name, args.slice()]); } else { stack.push(name); } return stack; } flash_proxy override function hasProperty(name:*):Boolean { return callJS(newStack(new QName('', name))) !== undefined; } flash_proxy override function setProperty(name:*, value:*):void { - callJSSetProperty(newStack(name), value); + var $name:* = $check(name); + if ($name) { + callJSSetProperty(newStack($name), value); + } else { + callJSSetProperty(newStack(name), value); + } } flash_proxy override function deleteProperty(name:*):Boolean { return false; } public function toString():String { var res:Array = createCommand(_stack.slice()); var cmd:String = res[0]; var args:Array = res[1]; return '[JSProxy] ' + cmd + ' :: ' + args.join(', '); } - flash_proxy function callJSSetProperty(stack:Array, value:*):* { + flash_proxy function callJSSetProperty(stack:Array, value:*):void { if (!ExternalInterface.available) - return null; + return; var res:Array = createCommand(stack); var cmd:String = res[0]; var args:Array = res[1]; args.push(value); var argsString:String = createArgsString(args.length); - cmd = "(function(" + argsString + ") {return " + cmd + " = _" + (args.length - 1).toString() + ";})"; + cmd = "(function(" + argsString + ") {setTimeout(function(){try{" + cmd + " = _" + (args.length - 1).toString() + "}catch(e){};}, 0);})"; proxyLogger(cmd); - return ExternalInterface.call.apply(null, [cmd].concat(args)); + ExternalInterface.call.apply(null, [cmd].concat(args)); } flash_proxy function callJS(stack:Array):* { if (!ExternalInterface.available) return null; var res:Array = createCommand(stack); var cmd:String = res[0]; var args:Array = res[1]; var argsString:String = createArgsString(args.length); if (args.length > 0) { cmd = "(function(" + argsString + ") {return " + cmd + ";})"; proxyLogger(cmd); proxyLogger(args); return ExternalInterface.call.apply(null, [cmd].concat(args)); } else { cmd = "(function() {return " + cmd + ";})"; proxyLogger(cmd); return ExternalInterface.call(cmd); } } flash_proxy function createArgsString(len:uint):String { var res:Array = []; for (var i:uint = 0; i < len; i++) { res.push('_' + i); } return res.join(', '); } flash_proxy function createCommand(stack:Array):Array { var receivers:Array = []; var args:Array = []; var argsStrings:Array = []; while (stack.length) { var o:* = stack.shift(); if (o is Array) { o = o as Array; var cmd:String = nameToString(o[0]) + '('; var cmdArgs:Array = []; var a:Array = o[1].slice(); while (a.length) { cmdArgs.push('_' + args.length); args.push(a.shift()); } cmd += cmdArgs.join(', '); cmd += ')'; receivers.push(cmd); } else { receivers.push(nameToString(o)); } } return [receivers.join('.').replace(/\.\[/g, '['), args]; } flash_proxy function nameToString(name:*):String { if (name is QName) { return name.localName.toString(); } else { return '[' + name.toString() + ']'; } } } }
hotchpotch/as3rails2u
1a01299660730a3a123f518d840acf7d9d4443de
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@65 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/bridge/JSProxy.as b/src/com/rails2u/bridge/JSProxy.as index c7d24ba..0e7b127 100644 --- a/src/com/rails2u/bridge/JSProxy.as +++ b/src/com/rails2u/bridge/JSProxy.as @@ -1,157 +1,166 @@ package com.rails2u.bridge { import flash.utils.Proxy; import flash.external.ExternalInterface; import flash.utils.flash_proxy; public dynamic class JSProxy extends Proxy { use namespace flash_proxy; public static var proxyLogger:Function = function(...args):void {}; private var _stack:Array; private var _nextCallIsstack:Boolean = false; public function JSProxy(stack:Array = null) { _stack = stack || []; } - public function get _():JSProxy { - _nextCallIsstack = true; - return this; - } - public function get proxy():JSProxy { return getProperty('proxy'); } public static function get proxy():JSProxy { return new JSProxy(); } flash_proxy override function callProperty(name:*, ...args):* { - if (_nextCallIsstack) { - _nextCallIsstack = false; - _stack.push([name, args]); - return this; + var $name:* = $check(name); + if ($name) { + return callJS(newStack($name, args)); + } else { + return new JSProxy(newStack(name, args)); + } + } + + flash_proxy function $check(name:*):* { + if (name.toString().indexOf('$') == 0 && name.toString().length >= 2) { + var r:String = name.toString().replace(/^\$+/, ''); + if (name is QName) { + return new QName(name.uri, r); + } else { + return r; + } } else { - return callJS(newStack.apply(null, [name].concat(args))); + return ''; } } flash_proxy override function getProperty(name:*):* { - _nextCallIsstack = false; - return new JSProxy(newStack(name)); + var $name:* = $check(name); + if ($name) { + return callJS(newStack($name)); + } else { + return new JSProxy(newStack(name)); + } } flash_proxy override function getDescendants(name:*):* { - _nextCallIsstack = false; return callJS(newStack(name)); } - flash_proxy function newStack(name:*, ...args):Array { + flash_proxy function newStack(name:*, args:Array = null):Array { var stack:Array = _stack.slice(); - if (args.length > 0) { + if (args != null) { stack.push([name, args.slice()]); } else { stack.push(name); } return stack; } flash_proxy override function hasProperty(name:*):Boolean { - return false; + return callJS(newStack(new QName('', name))) !== undefined; } flash_proxy override function setProperty(name:*, value:*):void { - _nextCallIsstack = false; callJSSetProperty(newStack(name), value); } flash_proxy override function deleteProperty(name:*):Boolean { return false; } public function toString():String { var res:Array = createCommand(_stack.slice()); var cmd:String = res[0]; var args:Array = res[1]; return '[JSProxy] ' + cmd + ' :: ' + args.join(', '); } flash_proxy function callJSSetProperty(stack:Array, value:*):* { if (!ExternalInterface.available) return null; var res:Array = createCommand(stack); var cmd:String = res[0]; var args:Array = res[1]; args.push(value); var argsString:String = createArgsString(args.length); cmd = "(function(" + argsString + ") {return " + cmd + " = _" + (args.length - 1).toString() + ";})"; proxyLogger(cmd); return ExternalInterface.call.apply(null, [cmd].concat(args)); } flash_proxy function callJS(stack:Array):* { if (!ExternalInterface.available) return null; var res:Array = createCommand(stack); var cmd:String = res[0]; var args:Array = res[1]; var argsString:String = createArgsString(args.length); if (args.length > 0) { cmd = "(function(" + argsString + ") {return " + cmd + ";})"; proxyLogger(cmd); proxyLogger(args); return ExternalInterface.call.apply(null, [cmd].concat(args)); } else { cmd = "(function() {return " + cmd + ";})"; proxyLogger(cmd); return ExternalInterface.call(cmd); } } flash_proxy function createArgsString(len:uint):String { var res:Array = []; for (var i:uint = 0; i < len; i++) { res.push('_' + i); } return res.join(', '); } flash_proxy function createCommand(stack:Array):Array { var receivers:Array = []; var args:Array = []; var argsStrings:Array = []; while (stack.length) { var o:* = stack.shift(); if (o is Array) { o = o as Array; var cmd:String = nameToString(o[0]) + '('; var cmdArgs:Array = []; var a:Array = o[1].slice(); while (a.length) { cmdArgs.push('_' + args.length); args.push(a.shift()); } cmd += cmdArgs.join(', '); cmd += ')'; receivers.push(cmd); } else { receivers.push(nameToString(o)); } } return [receivers.join('.').replace(/\.\[/g, '['), args]; } flash_proxy function nameToString(name:*):String { if (name is QName) { return name.localName.toString(); } else { return '[' + name.toString() + ']'; } } } }
hotchpotch/as3rails2u
5b0a75054da586b3f93c8a5856054e4bb4553508
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@64 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/bridge/JSProxy.as b/src/com/rails2u/bridge/JSProxy.as new file mode 100644 index 0000000..c7d24ba --- /dev/null +++ b/src/com/rails2u/bridge/JSProxy.as @@ -0,0 +1,157 @@ +package com.rails2u.bridge { + import flash.utils.Proxy; + import flash.external.ExternalInterface; + import flash.utils.flash_proxy; + + public dynamic class JSProxy extends Proxy { + use namespace flash_proxy; + + public static var proxyLogger:Function = function(...args):void {}; + private var _stack:Array; + private var _nextCallIsstack:Boolean = false; + + public function JSProxy(stack:Array = null) { + _stack = stack || []; + } + + public function get _():JSProxy { + _nextCallIsstack = true; + return this; + } + + public function get proxy():JSProxy { + return getProperty('proxy'); + } + + public static function get proxy():JSProxy { + return new JSProxy(); + } + + flash_proxy override function callProperty(name:*, ...args):* { + if (_nextCallIsstack) { + _nextCallIsstack = false; + _stack.push([name, args]); + return this; + } else { + return callJS(newStack.apply(null, [name].concat(args))); + } + } + + flash_proxy override function getProperty(name:*):* { + _nextCallIsstack = false; + return new JSProxy(newStack(name)); + } + + flash_proxy override function getDescendants(name:*):* { + _nextCallIsstack = false; + return callJS(newStack(name)); + } + + flash_proxy function newStack(name:*, ...args):Array { + var stack:Array = _stack.slice(); + if (args.length > 0) { + stack.push([name, args.slice()]); + } else { + stack.push(name); + } + return stack; + } + + flash_proxy override function hasProperty(name:*):Boolean { + return false; + } + + flash_proxy override function setProperty(name:*, value:*):void { + _nextCallIsstack = false; + callJSSetProperty(newStack(name), value); + } + + flash_proxy override function deleteProperty(name:*):Boolean { + return false; + } + + public function toString():String { + var res:Array = createCommand(_stack.slice()); + var cmd:String = res[0]; + var args:Array = res[1]; + return '[JSProxy] ' + cmd + ' :: ' + args.join(', '); + } + + flash_proxy function callJSSetProperty(stack:Array, value:*):* { + if (!ExternalInterface.available) + return null; + + var res:Array = createCommand(stack); + var cmd:String = res[0]; + var args:Array = res[1]; + args.push(value); + var argsString:String = createArgsString(args.length); + + cmd = "(function(" + argsString + ") {return " + cmd + " = _" + (args.length - 1).toString() + ";})"; + proxyLogger(cmd); + return ExternalInterface.call.apply(null, [cmd].concat(args)); + } + + flash_proxy function callJS(stack:Array):* { + if (!ExternalInterface.available) + return null; + + var res:Array = createCommand(stack); + var cmd:String = res[0]; + var args:Array = res[1]; + var argsString:String = createArgsString(args.length); + + if (args.length > 0) { + cmd = "(function(" + argsString + ") {return " + cmd + ";})"; + proxyLogger(cmd); + proxyLogger(args); + return ExternalInterface.call.apply(null, [cmd].concat(args)); + } else { + cmd = "(function() {return " + cmd + ";})"; + proxyLogger(cmd); + return ExternalInterface.call(cmd); + } + } + + flash_proxy function createArgsString(len:uint):String { + var res:Array = []; + for (var i:uint = 0; i < len; i++) { + res.push('_' + i); + } + return res.join(', '); + } + + flash_proxy function createCommand(stack:Array):Array { + var receivers:Array = []; + var args:Array = []; + var argsStrings:Array = []; + while (stack.length) { + var o:* = stack.shift(); + if (o is Array) { + o = o as Array; + var cmd:String = nameToString(o[0]) + '('; + var cmdArgs:Array = []; + var a:Array = o[1].slice(); + while (a.length) { + cmdArgs.push('_' + args.length); + args.push(a.shift()); + } + cmd += cmdArgs.join(', '); + cmd += ')'; + receivers.push(cmd); + } else { + receivers.push(nameToString(o)); + } + } + return [receivers.join('.').replace(/\.\[/g, '['), args]; + } + + flash_proxy function nameToString(name:*):String { + if (name is QName) { + return name.localName.toString(); + } else { + return '[' + name.toString() + ']'; + } + } + } +}
hotchpotch/as3rails2u
be0c8f24486723168a12538134cbfeb9c44a3e5a
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@63 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/chain/Chain.as b/src/com/rails2u/chain/Chain.as new file mode 100644 index 0000000..0f60f59 --- /dev/null +++ b/src/com/rails2u/chain/Chain.as @@ -0,0 +1,57 @@ +package com.rails2u.chain { + import flash.events.EventDispatcher; + import flash.events.Event; + public class Chain extends EventDispatcher { + /* + * ToDo + * ErrorBack + */ + + private var _parent:Chain; + public function get parent():Chain { + return _parent; + } + + public function set parent(__parent:Chain):void { + _parent = __parent; + _parent.setChild(this); + } + + protected var child:Chain; + public function setChild(child:Chain):void { + this.child = child; + } + + + public function chain(_chain:Chain):Chain { + _chain.parent = this; + return _chain; + } + + public function start():Chain { + if (parent) { + return parent.start(); + } else { + execute(); + return this; + } + } + + protected function execute():void { + finish(); + next(); + } + + protected function next():void { + if (child) child.execute(); + } + + protected function finish():void { + dispatchEvent(new Event(Event.COMPLETE)); + } + + //public function hasNext():Boolean { + // return _chains.length > _chainCounter; + //} + } +} diff --git a/src/com/rails2u/chain/EventChain.as b/src/com/rails2u/chain/EventChain.as new file mode 100644 index 0000000..a749d0d --- /dev/null +++ b/src/com/rails2u/chain/EventChain.as @@ -0,0 +1,28 @@ +package com.rails2u.chain { + import flash.events.IEventDispatcher; + import flash.events.Event; + public class EventChain extends Chain { + protected var target:IEventDispatcher; + protected var executeFunction:Function; + protected var completeEventName:String; + + public function EventChain(target:IEventDispatcher, executeFunction:Function = null, completeEventName:String = Event.COMPLETE) { + super(); + this.target = target; + this.executeFunction = executeFunction as Function; + this.completeEventName = completeEventName; + } + + protected override function execute():void { + target.addEventListener(completeEventName, completeHandler); + executeFunction.call(target); + } + + protected function completeHandler(e:Event):void { + target.removeEventListener(completeEventName, completeHandler); + finish(); + next(); + } + } +} + diff --git a/src/com/rails2u/chain/FunctionChain.as b/src/com/rails2u/chain/FunctionChain.as new file mode 100644 index 0000000..988c8b8 --- /dev/null +++ b/src/com/rails2u/chain/FunctionChain.as @@ -0,0 +1,25 @@ +package com.rails2u.chain { + import flash.events.EventDispatcher; + import flash.events.Event; + public class FunctionChain extends Chain { + protected var executeFunction:Function; + public function FunctionChain(executeFunction:Function):void { + super(); + this.executeFunction = executeFunction; + } + + protected override function execute():void { + executeFunction.call(this, this); + } + + public function get completeNotifier():Function { + var self:FunctionChain = this; + return function():void { + self.finish(); + self.next(); + }; + } + } +} + + diff --git a/src/com/rails2u/chain/ParallelChain.as b/src/com/rails2u/chain/ParallelChain.as new file mode 100644 index 0000000..c87752f --- /dev/null +++ b/src/com/rails2u/chain/ParallelChain.as @@ -0,0 +1,40 @@ +package com.rails2u.chain { + import flash.events.Event; + public class ParallelChain extends Chain { + /* + * 実装は Chain#addCallback を追加してやるべき? + * この実装では一階層目のチェインだけで終わってしまう? + */ + protected var _chainCounter:uint = 0; + protected var _chains:Array = []; + + public function addParallelChain(c:Chain):ParallelChain { + c.addEventListener(Event.COMPLETE, completeHandler); + _chains.push(c); + return this; + } + + public function addParallelChains(args:Array):ParallelChain { + for each(var c:Chain in args) { + addParallelChain(c); + } + return this; + } + + protected override function execute():void { + for each(var c:Chain in _chains) { + c.start(); + } + } + + protected function completeHandler(e:Event):void { + e.target.removeEventListener(Event.COMPLETE, completeHandler); + _chainCounter++; + if (_chains.length <= _chainCounter) { + finish(); + next(); + } + } + } +} + diff --git a/src/com/rails2u/component/SimpleButton.as b/src/com/rails2u/component/SimpleButton.as index a3eec1f..8d326f1 100644 --- a/src/com/rails2u/component/SimpleButton.as +++ b/src/com/rails2u/component/SimpleButton.as @@ -1,96 +1,96 @@ package com.rails2u.component { import flash.display.Sprite; import flash.events.MouseEvent; import flash.geom.ColorTransform; import flash.net.navigateToURL; import flash.net.URLRequest; import flash.text.TextField; public class SimpleButton extends Sprite { public function SimpleButton() { init(); } public var defaultColorTransform:ColorTransform; public var tmpColorTransform:ColorTransform; public var openURL:String; - public var targetURLType:String = 'blank'; + public var targetURLType:String = null; protected var _textField:TextField; public function get textField():TextField { return _textField; } public function set textField(__textField:TextField):void { addChild(__textField); __textField.mouseEnabled = false; _textField = __textField; } protected var _text:String; public function get text():String { return _text; } public function set text(__text:String):void { _text = __text; if (!textField) textField = new TextField(); textField.text = _text; autoTextPosition(); } public function autoTextPosition():void { textField.width = textField.textWidth; textField.height = textField.textHeight; } public function drawBackground(width:Number, height:Number, round:Number = NaN):void { if (isNaN(round)) { graphics.drawRect(0, 0, width, height); } else { graphics.drawRoundRect(0, 0, width, height, round, round); } } public function textCentering():void { if (textField) { if (textField.textHeight < height) { textField.y = (height - textField.textHeight) / 2; } if (textField.textWidth < width) { textField.x = (width - textField.textWidth) / 2; } } } protected function init():void { buttonMode = true; addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler); addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler); } protected function mouseDownHandler(e:MouseEvent):void { if (openURL) navigateToURL(new URLRequest(openURL), targetURLType); } protected function mouseOverHandler(e:MouseEvent):void { if (defaultColorTransform) { tmpColorTransform = transform.colorTransform; transform.colorTransform = defaultColorTransform; } } protected function mouseOutHandler(e:MouseEvent):void { if (tmpColorTransform) { transform.colorTransform = tmpColorTransform; } } } } diff --git a/src/com/rails2u/debug/PerformanceViewer.as b/src/com/rails2u/debug/PerformanceViewer.as index 6d2fe58..7c60c88 100644 --- a/src/com/rails2u/debug/PerformanceViewer.as +++ b/src/com/rails2u/debug/PerformanceViewer.as @@ -1,78 +1,88 @@ package com.rails2u.debug { import flash.events.Event; import flash.text.TextField; import flash.text.TextFormat; import flash.utils.getTimer; import flash.system.System; + import flash.utils.Timer; /** * PerformanceViewer * * PerformanceViewer show FPS, used memory size. * * example: * <listing version="3.0"> * var pv:PerformanceViewer = new PerformanceViewer; * stage.addChild(pv); * pv.show(); * pv.hide(); * pv.toggle(); * </listing> */ public class PerformanceViewer extends TextField { private var lastTime:uint; - private var lastTimeSecond:uint; + private var _fps:Number = 60; + public function get fps():Number { + return _fps; + } - public function PerformanceViewer(color:uint = 0xFFFFFF) { + private var timer:Timer; + public function PerformanceViewer(color:uint = 0xFFFFFF, delay:Number = 200) { super(); visible = false; width = 150; height = 40; background = false; backgroundColor = 0x555555; var format:TextFormat = new TextFormat(); format.color = color; format.size = 12; format.bold = true; format.font = 'Arial'; defaultTextFormat = format; lastTime = getTimer(); - lastTimeSecond = lastTime; - addEventListener(Event.ENTER_FRAME, refresh); + + timer = new Timer(delay); + timer.addEventListener('timer', render); + timer.start(); + addEventListener(Event.ENTER_FRAME, countHandler); } private var _fpss:Array = []; - private function refresh(event:Event):void { + private function countHandler(e:Event):void { var time:int = getTimer(); - if (time - lastTimeSecond > 200) { - var _fps:Number = 0; - _fpss.forEach(function(v:Number, ... args):void { _fps += v }); - _fps /= _fpss.length; - _fpss = []; - text = String(1000 / (_fps)).substring(0, 6) + ' FPS' + "\n" + Number(System.totalMemory) / 1000 + " KB"; - lastTimeSecond = time; - } else { - _fpss.push(time - lastTime); - } + _fpss.push(time - lastTime); lastTime = time; } + private function render(e:Event):void { + _fps = 0; + for each(var v:Number in _fpss) { + _fps += v; + } + _fps /= _fpss.length; + var rCount:int = _fpss.length; + _fpss = []; + text = String(1000 / (_fps)).substring(0, 6) + ' FPS' + "\n" + Number(System.totalMemory) / 1000 + " KB"; + } + private function init():void { } public function show():void { visible = true; } public function hide():void { visible = false; } public function toggle():void { visible ? visible = false : visible = true; } } } diff --git a/src/com/rails2u/net/navigateToURL.as b/src/com/rails2u/net/navigateToURL.as index a34a6b3..451863e 100644 --- a/src/com/rails2u/net/navigateToURL.as +++ b/src/com/rails2u/net/navigateToURL.as @@ -1,50 +1,50 @@ package com.rails2u.net { import flash.net.URLRequest; import flash.net.URLRequestMethod; import flash.net.URLVariables; import flash.net.navigateToURL; import flash.external.ExternalInterface; import com.rails2u.utils.Browser; /* * Popup a window through popup blockers. * Base by http://d.hatena.ne.jp/os0x/20070812/1186941620 */ public function navigateToURL(request:URLRequest, windows:String = ''):void { if (windows == '_self') flash.net.navigateToURL(request, '_self'); var browser:String = Browser.browser; if (browser == Browser.FIREFOX || browser == Browser.MSIE) { var url:String = request.url; if (request.method == URLRequestMethod.GET) { var uv:URLVariables = request.data as URLVariables; if (!uv) { uv = new URLVariables; for (var key:String in request.data) { uv[key] = request.data[key]; } } var query:String = uv.toString(); if (query.length > 0) { url += '?' + query; } } if (browser == Browser.FIREFOX) { // FIREFOX var res:String = ExternalInterface.call( 'function(url, tg){return window.open(url, tg);}', url, windows ); } else { // IE var jsURL:String = 'javascript:(function(){window.open("' + url + '", "' + windows + '")})();' var req:URLRequest = new URLRequest(jsURL); - flash.net.navigateToURL(req, windows); + flash.net.navigateToURL(req, '_self'); } } else { // Opera, Safari - flash.net.navigateToURL(request, windows); + flash.net.navigateToURL(request, null); } } } diff --git a/src/com/rails2u/typofy/TypofyCharSprite.as b/src/com/rails2u/typofy/TypofyCharSprite.as index e721311..01a638a 100644 --- a/src/com/rails2u/typofy/TypofyCharSprite.as +++ b/src/com/rails2u/typofy/TypofyCharSprite.as @@ -1,161 +1,161 @@ package com.rails2u.typofy { import flash.display.Sprite; import flash.geom.Point; import flash.geom.Rectangle; import flash.text.TextField; import flash.text.TextFormat; import flash.display.BitmapData; import mx.containers.Canvas; import flash.geom.Matrix; import flash.geom.ColorTransform; import flash.filters.BlurFilter; import flash.display.Bitmap; import flash.filters.BitmapFilterQuality; public class TypofyCharSprite extends Sprite { public static const PADDING_MAGIC_NUMBER:int = 2; // why? Bug? (193249) public var textField:TextField; public var typofy:Typofy; private var _char:String; public function get char():String { return _char; } public function set char(newchar:String):void { this.textField.text = newchar; this._char = newchar; if (bitmapFont) renderBitmapFont(); } public function setDefaultChar():void { char = defaultChar; } public function get row():uint { return this.charIndex - typofy.getLineOffset(col); } public function get col():uint { return typofy.getLineIndexOfChar(this.charIndex); } public var boundaries:Rectangle; public var charIndex:uint; public var extra:Object = {}; protected var _centerPoint:Point; public function get centerPoint():Point { return _centerPoint; } public var defaultChar:String; public function TypofyCharSprite(_char:String, typofy:Typofy, _index:uint, boundaries:Rectangle) { super(); textField = new TextField; textField.selectable = false; this.addChild(textField); this.boundaries = boundaries; this.charIndex = _index; this.typofy = typofy; init(); defaultChar = _char; setDefaultChar(); } public function drawBorder(... args):void { if (args.length > 0) { graphics.lineStyle.apply(null, args); } else { graphics.lineStyle(0, 0xEEEEEE); } graphics.drawRect(-boundaries.width / 2, -boundaries.height / 2, boundaries.width, boundaries.height); } public function drawBorderWithCrossLine(... args):void { drawBorder.apply(this, args); graphics.moveTo(-boundaries.width / 2, -boundaries.height / 2); graphics.lineTo(boundaries.width / 2, boundaries.height / 2); graphics.moveTo(boundaries.width / 2, -boundaries.height / 2); graphics.lineTo(-boundaries.width / 2, boundaries.height / 2); } public var bitmapFont:Bitmap; public function replaceBitmap(blurX:Number = 2, blurY:Number = 2, blurQuality:uint = 3):void { if (!bitmapFont) { renderBitmapFont(blurX, blurY, blurQuality); textField.visible = false; } } - private function renderBitmapFont(blurX:Number = 2, blurY:Number = 2, blurQuality:uint = BitmapFilterQuality.HIGH):void { + private function renderBitmapFont(blurX:Number = 2, blurY:Number = 2, blurQuality:uint = 1):void { if (bitmapFont) { removeChild(bitmapFont); } var bd:BitmapData = getAAText(textField, blurX, blurY, blurQuality); bitmapFont = new Bitmap(bd, 'never', true); bitmapFont.x = textField.x; bitmapFont.y = textField.y; addChild(bitmapFont); } protected function init():void { var textFormat:TextFormat = typofy.getTextFormat(this.charIndex); this.x = boundaries.x + boundaries.width / 2; this.y = boundaries.y + boundaries.height / 2; this._centerPoint = new Point(this.x, this.y); textField.x -= boundaries.width / 2 + PADDING_MAGIC_NUMBER; textField.y -= boundaries.height / 2 + PADDING_MAGIC_NUMBER; textField.width = boundaries.width + PADDING_MAGIC_NUMBER * 2; textField.height = boundaries.height + PADDING_MAGIC_NUMBER * 2; this.width = boundaries.width + PADDING_MAGIC_NUMBER * 2; this.height = boundaries.height + PADDING_MAGIC_NUMBER * 2; textFormat.align = 'left'; textField.defaultTextFormat = textFormat; } public static var AA_MARGIN:Number = 16; public static var AA_BMP_MAX:Number = 2800; public static var AA_MAX_SCALE:Number = 3; // Device font apply Anti-Alias tips by F-SITE. // http://f-site.org/articles/2007/04/08165536.html public static function getAAText(textField:TextField, blurX:Number = 2, blurY:Number = 2, blurQuality:uint = 2):BitmapData { var aaWidth:Number = textField.textWidth + AA_MARGIN; var aaHeight:Number = textField.textHeight + AA_MARGIN; var aaScale:Number = Math.min(AA_MAX_SCALE, Math.min(AA_BMP_MAX / aaWidth, AA_BMP_MAX / aaHeight)); var bmpCanvas:BitmapData = new BitmapData(aaWidth * aaScale, aaHeight * aaScale, true, 0x00000000); var bmpResult:BitmapData = new BitmapData(aaWidth, aaHeight, true, 0x00000000); var myMatrix:Matrix = new Matrix(); myMatrix.scale(aaScale, aaScale); bmpCanvas.draw(textField, myMatrix); var myFilter:BlurFilter = new BlurFilter(blurX, blurY, blurQuality); bmpCanvas.applyFilter(bmpCanvas, new Rectangle(0, 0, bmpCanvas.width, bmpCanvas.height), new Point(0, 0), myFilter); bmpCanvas.draw(textField, myMatrix); var myColor:ColorTransform = new ColorTransform(); myColor.alphaMultiplier= 1.1; myMatrix.a = myMatrix.d = 1; myMatrix.scale(1 / aaScale, 1 / aaScale); bmpResult.draw(bmpCanvas, myMatrix, myColor); bmpResult.draw(bmpCanvas, myMatrix); bmpCanvas.dispose(); return bmpResult; } } }
hotchpotch/as3rails2u
74ef60779499e5c5f439c1df11b000bee198c3e9
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@62 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/utils/JSUtil.as b/src/com/rails2u/utils/JSUtil.as new file mode 100644 index 0000000..0edf4b3 --- /dev/null +++ b/src/com/rails2u/utils/JSUtil.as @@ -0,0 +1,25 @@ +package com.rails2u.utils { + import flash.external.ExternalInterface; + + public class JSUtil { + public static function getObjectID():String { + return ExternalInterface.objectID; + } + + public static function selfCallJS(cmd:String):* { + cmd = "return document.getElementById('" + getObjectID() + "')." + cmd; + return callJS(cmd); + } + + public static function callJS(cmd:String):* { + cmd = "(function() {" + cmd + ";})"; + return ExternalInterface.call(cmd); + } + + public static function bindCallJS(bindName:String):Function { + return function(cmd:String):* { + return callJS(bindName + cmd); + }; + } + } +} diff --git a/src/com/rails2u/utils/ObjectInspecter.as b/src/com/rails2u/utils/ObjectInspecter.as index 0901f84..c8f9ced 100644 --- a/src/com/rails2u/utils/ObjectInspecter.as +++ b/src/com/rails2u/utils/ObjectInspecter.as @@ -1,65 +1,12 @@ package com.rails2u.utils { import flash.utils.getQualifiedClassName; import flash.utils.ByteArray; public class ObjectInspecter { /* * */ - public static function inspect(... args):String { - return inspectImpl(args, false); - } - - public static function serialize(arg:Object):Object { - var b:ByteArray = new ByteArray(); - b.writeObject(arg); - b.position = 0; - return b.readObject(); - } - - internal static function inspectImpl(arg:*, bracket:Boolean = true):String { - var className:String = getQualifiedClassName(arg); - var str:String; var results:Array; - - switch(getQualifiedClassName(arg)) { - case 'Object': - case 'Dictionary': - results = []; - for (var key:* in arg) { - results.push(inspectImpl(key) + ':' + inspectImpl(arg[key], false)); - } - str = classFormat(className, '{' + results.join(', ') + '}'); - // str = classFormat(className, arg); - break; - case 'Array': - results = []; - for (var i:uint = 0; i < arg.length; i++) { - results.push(inspectImpl(arg[i])); - } - if (bracket) { - str = '[' + results.join(', ') + ']'; - } else { - str = results.join(', '); - } - break; - case 'int': - case 'uint': - case 'Number': - str = arg.toString(); - break; - case 'String': - str = arg; - break; - default: - str = classFormat(className, arg); - } - return str; - } - - internal static function classFormat(className:String, arg:*):String { - return '#<' + className + ':' + String(arg) + '>'; - } } } diff --git a/src/com/rails2u/utils/ObjectUtil.as b/src/com/rails2u/utils/ObjectUtil.as new file mode 100644 index 0000000..6d1a122 --- /dev/null +++ b/src/com/rails2u/utils/ObjectUtil.as @@ -0,0 +1,62 @@ +package com.rails2u.utils +{ + import flash.utils.getQualifiedClassName; + import flash.utils.ByteArray; + + public class ObjectUtil { + public static function clone(arg:*):* { + var b:ByteArray = new ByteArray(); + b.writeObject(arg); + b.position = 0; + return b.readObject(); + } + + public static function inspect(... args):String { + return inspectImpl(args, false); + } + + internal static function inspectImpl(arg:*, bracket:Boolean = true):String { + var className:String = getQualifiedClassName(arg); + var str:String; var results:Array; + + switch(getQualifiedClassName(arg)) { + case 'Object': + case 'Dictionary': + results = []; + for (var key:* in arg) { + results.push(inspectImpl(key) + ':' + inspectImpl(arg[key], false)); + } + str = classFormat(className, '{' + results.join(', ') + '}'); + // str = classFormat(className, arg); + break; + case 'Array': + results = []; + for (var i:uint = 0; i < arg.length; i++) { + results.push(inspectImpl(arg[i])); + } + if (bracket) { + str = '[' + results.join(', ') + ']'; + } else { + str = results.join(', '); + } + break; + case 'int': + case 'uint': + case 'Number': + str = arg.toString(); + break; + case 'String': + str = arg; + break; + default: + str = classFormat(className, arg); + } + return str; + } + + internal static function classFormat(className:String, arg:*):String { + return '#<' + className + ':' + String(arg) + '>'; + } + } +} + diff --git a/src/log.as b/src/log.as index 21fdbfc..15d58ca 100644 --- a/src/log.as +++ b/src/log.as @@ -1,41 +1,41 @@ package { import flash.external.ExternalInterface; - import com.rails2u.utils.ObjectInspecter; + import com.rails2u.utils.ObjectUtil; import flash.utils.getQualifiedClassName; /** * log() is Object inspect dump output to trace() and use * Browser(FireFox, Safari and more) External API console.log. * * example * <listing version="3.0"> * var a:Array = [[1,2,3], [4,[5,6]]]; * var sprite:Sprite = new Sprite; * log(a, sprite); * # output * [[1, 2, 3], [4, [5, 6]]], #&lt;flash.display::Sprite:[object Sprite]&gt; * </listing> */ public function log(... args):String { - var r:String = ObjectInspecter.inspect.apply(null, args); + var r:String = ObjectUtil.inspect.apply(null, args); trace(r) if (ExternalInterface.available) { var arg:* = args.length == 1 ? args[0] : args; try { ExternalInterface.call(<><![CDATA[ (function(obj, klassName) { obj.toString = function() { return klassName }; console.log(obj); ;}) ]]></>.toString(), - ObjectInspecter.serialize(arg), + ObjectUtil.clone(arg), getQualifiedClassName(arg) ); } catch(e:Error) { ExternalInterface.call('console.log', r); } } return r; } }
hotchpotch/as3rails2u
829b43fbdd4df54e4d7d66343c9fc67bec08b740
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@61 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/component/SimpleButton.as b/src/com/rails2u/component/SimpleButton.as new file mode 100644 index 0000000..a3eec1f --- /dev/null +++ b/src/com/rails2u/component/SimpleButton.as @@ -0,0 +1,96 @@ +package com.rails2u.component { + import flash.display.Sprite; + import flash.events.MouseEvent; + import flash.geom.ColorTransform; + import flash.net.navigateToURL; + import flash.net.URLRequest; + import flash.text.TextField; + + public class SimpleButton extends Sprite { + public function SimpleButton() { + init(); + } + + public var defaultColorTransform:ColorTransform; + public var tmpColorTransform:ColorTransform; + public var openURL:String; + public var targetURLType:String = 'blank'; + + protected var _textField:TextField; + + public function get textField():TextField { + return _textField; + } + + public function set textField(__textField:TextField):void { + addChild(__textField); + __textField.mouseEnabled = false; + _textField = __textField; + } + + + protected var _text:String; + public function get text():String { + return _text; + } + + public function set text(__text:String):void { + _text = __text; + if (!textField) textField = new TextField(); + + textField.text = _text; + autoTextPosition(); + } + + public function autoTextPosition():void { + textField.width = textField.textWidth; + textField.height = textField.textHeight; + } + + + public function drawBackground(width:Number, height:Number, round:Number = NaN):void { + if (isNaN(round)) { + graphics.drawRect(0, 0, width, height); + } else { + graphics.drawRoundRect(0, 0, width, height, round, round); + } + } + + public function textCentering():void { + if (textField) { + if (textField.textHeight < height) { + textField.y = (height - textField.textHeight) / 2; + } + + if (textField.textWidth < width) { + textField.x = (width - textField.textWidth) / 2; + } + } + } + + protected function init():void { + buttonMode = true; + addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); + addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler); + addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler); + } + + protected function mouseDownHandler(e:MouseEvent):void { + if (openURL) + navigateToURL(new URLRequest(openURL), targetURLType); + } + + protected function mouseOverHandler(e:MouseEvent):void { + if (defaultColorTransform) { + tmpColorTransform = transform.colorTransform; + transform.colorTransform = defaultColorTransform; + } + } + + protected function mouseOutHandler(e:MouseEvent):void { + if (tmpColorTransform) { + transform.colorTransform = tmpColorTransform; + } + } + } +} diff --git a/src/com/rails2u/debug/PerformanceViewer.as b/src/com/rails2u/debug/PerformanceViewer.as index 9736cb4..6d2fe58 100644 --- a/src/com/rails2u/debug/PerformanceViewer.as +++ b/src/com/rails2u/debug/PerformanceViewer.as @@ -1,78 +1,78 @@ package com.rails2u.debug { import flash.events.Event; import flash.text.TextField; import flash.text.TextFormat; import flash.utils.getTimer; - import flash.system.System; + import flash.system.System; /** * PerformanceViewer * * PerformanceViewer show FPS, used memory size. * * example: * <listing version="3.0"> * var pv:PerformanceViewer = new PerformanceViewer; * stage.addChild(pv); * pv.show(); * pv.hide(); * pv.toggle(); * </listing> */ public class PerformanceViewer extends TextField { private var lastTime:uint; private var lastTimeSecond:uint; public function PerformanceViewer(color:uint = 0xFFFFFF) { super(); visible = false; width = 150; height = 40; background = false; backgroundColor = 0x555555; var format:TextFormat = new TextFormat(); format.color = color; format.size = 12; format.bold = true; format.font = 'Arial'; defaultTextFormat = format; lastTime = getTimer(); lastTimeSecond = lastTime; addEventListener(Event.ENTER_FRAME, refresh); } private var _fpss:Array = []; private function refresh(event:Event):void { var time:int = getTimer(); - if (time - lastTimeSecond > 1000) { + if (time - lastTimeSecond > 200) { var _fps:Number = 0; _fpss.forEach(function(v:Number, ... args):void { _fps += v }); _fps /= _fpss.length; _fpss = []; text = String(1000 / (_fps)).substring(0, 6) + ' FPS' + "\n" + Number(System.totalMemory) / 1000 + " KB"; lastTimeSecond = time; } else { _fpss.push(time - lastTime); } lastTime = time; } private function init():void { } public function show():void { visible = true; } public function hide():void { visible = false; } public function toggle():void { visible ? visible = false : visible = true; } } } diff --git a/src/com/rails2u/record/RecordEvent.as b/src/com/rails2u/record/RecordEvent.as new file mode 100644 index 0000000..ba7393f --- /dev/null +++ b/src/com/rails2u/record/RecordEvent.as @@ -0,0 +1,14 @@ +package com.rails2u.record { + import flash.events.Event; + + public class RecordEvent extends Event { + public static const PLAY:String = 'start'; + public static const STOP:String = 'stop'; + public static const PAUSE:String = 'pause'; + public static const FINISH:String = 'finish'; + + public function RecordEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false):void { + super(type, bubbles, cancelable); + } + } +} diff --git a/src/com/rails2u/record/RecordPlayer.as b/src/com/rails2u/record/RecordPlayer.as new file mode 100644 index 0000000..b0c7e5c --- /dev/null +++ b/src/com/rails2u/record/RecordPlayer.as @@ -0,0 +1,99 @@ +package com.rails2u.record { + import flash.display.InteractiveObject; + import flash.utils.ByteArray; + import flash.events.Event; + import flash.utils.getTimer; + import flash.events.MouseEvent; + import flash.display.DisplayObjectContainer; + import flash.events.EventDispatcher; + + public class RecordPlayer extends EventDispatcher { + protected var _canvas:InteractiveObject; + protected var records:Array; + protected var originalRecords:Array; + public function RecordPlayer(canvas:InteractiveObject) { + _canvas = canvas; + } + + public function setRecords(records:ByteArray):void { + var ba:ByteArray = ByteArray(records); + ba.uncompress(); + ba.position = 0; + this.records = ba.readObject(); + originalRecords = this.records.slice(0); + } + + protected var _playing:Boolean = false; + public function get playing():Boolean { + return _playing; + } + + public function play():Boolean { + if (playing) return false; + + _playing = true; + _canvas.addEventListener(Event.ENTER_FRAME, enterFrameHandler); + dispatchEvent(new RecordEvent(RecordEvent.PLAY)); + return true; + } + + public function stop():Boolean { + if (!playing) return false; + _playing = false; + _canvas.removeEventListener(Event.ENTER_FRAME, enterFrameHandler); + dispatchEvent(new RecordEvent(RecordEvent.STOP)); + return true; + } + + public function pause():void { + // ToDo + } + + public function forceFinish():void { + while(records.length > 0) { + var cur:Array = records.shift(); + var ev:MouseEvent = objectToMouseEvent(cur[1]); + var t:InteractiveObject = InteractiveObject(DisplayObjectContainer(_canvas).getChildByName(cur[1].name)) || _canvas; + t.dispatchEvent(ev); + } + dispatchEvent(new RecordEvent(RecordEvent.FINISH)); + } + + protected var playStart:uint; + protected function enterFrameHandler(e:Event):void { + playStart ||= getTimer(); + var now:uint = getTimer(); + + while(records.length > 0 && (records[0][0] <= (now - playStart))) { + var cur:Array = records.shift(); + var ev:MouseEvent = objectToMouseEvent(cur[1]); + //log(ev.type, ev); + //var t:InteractiveObject = (typeObject(cur[2]) as InteractiveObject); + //if(t) t.dispatchEvent(ev); + //log(cur[1].name); + var t:InteractiveObject = InteractiveObject(DisplayObjectContainer(_canvas).getChildByName(cur[1].name)) || _canvas; + t.dispatchEvent(ev); + } + if (records.length == 0) + dispatchEvent(new RecordEvent(RecordEvent.FINISH)); + } + + private function objectToMouseEvent(o:Object):MouseEvent { + var e:MouseEvent = new MouseEvent(o.type, true, false, o.localX, o.localY, + o.relatedObject, o.ctrlKey, o.altKey, o.shiftKey, o.buttonDown, o.delta + ); + /* + delete o['type']; + delete o['name']; + delete o['target']; + delete o['relatedObject']; + + for (var key:String in o) { + if (o[key] !== null) + e[key] = o[key]; + } + */ + return e; + } + } +} diff --git a/src/com/rails2u/tracer/LineTracer.as b/src/com/rails2u/tracer/LineTracer.as index 52271d9..7550569 100644 --- a/src/com/rails2u/tracer/LineTracer.as +++ b/src/com/rails2u/tracer/LineTracer.as @@ -1,21 +1,25 @@ package com.rails2u.tracer { import flash.geom.Point; public class LineTracer extends Tracer { private var _length:Number; public function get length():Number { return _length; } + public function set length(__length:Number):void { + _length = __length; + } + public function LineTracer(length:Number) { super(); this._length = length; } protected override function getPoint():Point { var p:Point = new Point( length * (times - 1) / tracePoints, 0 ); return matrix.transformPoint(p); } } } diff --git a/src/com/rails2u/typofy/TypofyCharSprite.as b/src/com/rails2u/typofy/TypofyCharSprite.as index b6ee9ee..e721311 100644 --- a/src/com/rails2u/typofy/TypofyCharSprite.as +++ b/src/com/rails2u/typofy/TypofyCharSprite.as @@ -1,161 +1,161 @@ package com.rails2u.typofy { import flash.display.Sprite; import flash.geom.Point; import flash.geom.Rectangle; import flash.text.TextField; import flash.text.TextFormat; import flash.display.BitmapData; import mx.containers.Canvas; import flash.geom.Matrix; import flash.geom.ColorTransform; import flash.filters.BlurFilter; import flash.display.Bitmap; import flash.filters.BitmapFilterQuality; public class TypofyCharSprite extends Sprite { public static const PADDING_MAGIC_NUMBER:int = 2; // why? Bug? (193249) public var textField:TextField; public var typofy:Typofy; private var _char:String; public function get char():String { return _char; } public function set char(newchar:String):void { this.textField.text = newchar; this._char = newchar; if (bitmapFont) renderBitmapFont(); } public function setDefaultChar():void { char = defaultChar; } public function get row():uint { return this.charIndex - typofy.getLineOffset(col); } public function get col():uint { return typofy.getLineIndexOfChar(this.charIndex); } public var boundaries:Rectangle; public var charIndex:uint; public var extra:Object = {}; protected var _centerPoint:Point; public function get centerPoint():Point { return _centerPoint; } public var defaultChar:String; public function TypofyCharSprite(_char:String, typofy:Typofy, _index:uint, boundaries:Rectangle) { super(); textField = new TextField; textField.selectable = false; this.addChild(textField); this.boundaries = boundaries; this.charIndex = _index; this.typofy = typofy; init(); defaultChar = _char; setDefaultChar(); } public function drawBorder(... args):void { if (args.length > 0) { graphics.lineStyle.apply(null, args); } else { graphics.lineStyle(0, 0xEEEEEE); } graphics.drawRect(-boundaries.width / 2, -boundaries.height / 2, boundaries.width, boundaries.height); } public function drawBorderWithCrossLine(... args):void { drawBorder.apply(this, args); graphics.moveTo(-boundaries.width / 2, -boundaries.height / 2); graphics.lineTo(boundaries.width / 2, boundaries.height / 2); graphics.moveTo(boundaries.width / 2, -boundaries.height / 2); graphics.lineTo(-boundaries.width / 2, boundaries.height / 2); } public var bitmapFont:Bitmap; - public function replaceBitmap(blurX:Number = 2, blurY:Number = 2, blurQuality:uint = BitmapFilterQuality.HIGH):void { + public function replaceBitmap(blurX:Number = 2, blurY:Number = 2, blurQuality:uint = 3):void { if (!bitmapFont) { renderBitmapFont(blurX, blurY, blurQuality); textField.visible = false; } } private function renderBitmapFont(blurX:Number = 2, blurY:Number = 2, blurQuality:uint = BitmapFilterQuality.HIGH):void { if (bitmapFont) { removeChild(bitmapFont); } var bd:BitmapData = getAAText(textField, blurX, blurY, blurQuality); bitmapFont = new Bitmap(bd, 'never', true); bitmapFont.x = textField.x; bitmapFont.y = textField.y; addChild(bitmapFont); } protected function init():void { var textFormat:TextFormat = typofy.getTextFormat(this.charIndex); this.x = boundaries.x + boundaries.width / 2; this.y = boundaries.y + boundaries.height / 2; this._centerPoint = new Point(this.x, this.y); textField.x -= boundaries.width / 2 + PADDING_MAGIC_NUMBER; textField.y -= boundaries.height / 2 + PADDING_MAGIC_NUMBER; textField.width = boundaries.width + PADDING_MAGIC_NUMBER * 2; textField.height = boundaries.height + PADDING_MAGIC_NUMBER * 2; this.width = boundaries.width + PADDING_MAGIC_NUMBER * 2; this.height = boundaries.height + PADDING_MAGIC_NUMBER * 2; textFormat.align = 'left'; textField.defaultTextFormat = textFormat; } public static var AA_MARGIN:Number = 16; public static var AA_BMP_MAX:Number = 2800; public static var AA_MAX_SCALE:Number = 3; // Device font apply Anti-Alias tips by F-SITE. // http://f-site.org/articles/2007/04/08165536.html - public static function getAAText(textField:TextField, blurX:Number = 2, blurY:Number = 2, blurQuality:uint = BitmapFilterQuality.HIGH):BitmapData { + public static function getAAText(textField:TextField, blurX:Number = 2, blurY:Number = 2, blurQuality:uint = 2):BitmapData { var aaWidth:Number = textField.textWidth + AA_MARGIN; var aaHeight:Number = textField.textHeight + AA_MARGIN; var aaScale:Number = Math.min(AA_MAX_SCALE, Math.min(AA_BMP_MAX / aaWidth, AA_BMP_MAX / aaHeight)); var bmpCanvas:BitmapData = new BitmapData(aaWidth * aaScale, aaHeight * aaScale, true, 0x00000000); var bmpResult:BitmapData = new BitmapData(aaWidth, aaHeight, true, 0x00000000); var myMatrix:Matrix = new Matrix(); myMatrix.scale(aaScale, aaScale); bmpCanvas.draw(textField, myMatrix); var myFilter:BlurFilter = new BlurFilter(blurX, blurY, blurQuality); bmpCanvas.applyFilter(bmpCanvas, new Rectangle(0, 0, bmpCanvas.width, bmpCanvas.height), new Point(0, 0), myFilter); bmpCanvas.draw(textField, myMatrix); var myColor:ColorTransform = new ColorTransform(); myColor.alphaMultiplier= 1.1; myMatrix.a = myMatrix.d = 1; myMatrix.scale(1 / aaScale, 1 / aaScale); bmpResult.draw(bmpCanvas, myMatrix, myColor); bmpResult.draw(bmpCanvas, myMatrix); bmpCanvas.dispose(); return bmpResult; } } } diff --git a/src/com/rails2u/utils/BitmapUtil.as b/src/com/rails2u/utils/BitmapUtil.as index 08e2087..bc23e8b 100644 --- a/src/com/rails2u/utils/BitmapUtil.as +++ b/src/com/rails2u/utils/BitmapUtil.as @@ -1,22 +1,36 @@ package com.rails2u.utils { import flash.display.BitmapData; import flash.display.Bitmap; import flash.geom.Matrix; + import flash.geom.Rectangle; public class BitmapUtil { public static function mozaic(bd:BitmapData, scale:Number = 10, doubleParam:Number = 1.00):BitmapData { var tmp:Bitmap = new Bitmap(); var miniBD:BitmapData = new BitmapData(bd.width/scale, bd.height/scale, true, 0x00FFFFF); var mozBD:BitmapData = new BitmapData(bd.width, bd.height, true, 0x00FFFFFF); tmp.bitmapData = bd.clone(); miniBD.draw(tmp, new Matrix(1/scale,0,0,1/scale,0,0)); tmp.bitmapData = miniBD; mozBD.draw(tmp, new Matrix(scale * doubleParam,0,0,scale * doubleParam,0,0)); return mozBD; } + + public static function maskFill(bd:BitmapData, size:uint, col1:uint, col2:uint):void { + var r:Rectangle = new Rectangle(0,0,size,size); + for (var x:uint = 0; x < bd.width; x+=size) { + for (var y:uint = 0; y < bd.height; y+=size) { + r.x = x; + r.y = y; + bd.fillRect(r, x / size % 2 ? y / size % 2 == 1 ? col1 : col2 + : y / size % 2 == 0 ? col1 : col2 + ); + } + } + } } } diff --git a/src/com/rails2u/utils/DrawUtil.as b/src/com/rails2u/utils/DrawUtil.as index 3228e1b..de035cc 100644 --- a/src/com/rails2u/utils/DrawUtil.as +++ b/src/com/rails2u/utils/DrawUtil.as @@ -1,92 +1,108 @@ package com.rails2u.utils { import flash.display.Graphics; import flash.geom.Rectangle; import flash.display.Shape; public class DrawUtil { public static function drawStar(graphics:Graphics, xPos:Number = 0, yPos:Number = 0, sides:uint = 5, innerRadius:Number = 20, outerRadius:Number = 50, type:String = 'line' ):void { var theta:Number = 0.0; var incr:Number = Math.PI * 2.0 / sides; var halfIncr:Number = incr / 2.0; for (var i:uint = 0; i <= sides; i++) { if(i == 0) { if (type == 'curve') { graphics.moveTo(innerRadius * Math.cos(theta + halfIncr) + xPos, innerRadius * Math.sin(theta + halfIncr) + yPos); } else { graphics.moveTo(outerRadius * Math.cos(theta) + xPos, outerRadius * Math.sin(theta) + yPos); } } if (type == 'curve') { graphics.curveTo(outerRadius * Math.cos(theta) + xPos, outerRadius * Math.sin(theta) + yPos, innerRadius * Math.cos(theta + halfIncr) + xPos, innerRadius * Math.sin(theta + halfIncr) + yPos); } else { graphics.lineTo(outerRadius * Math.cos(theta) + xPos, outerRadius * Math.sin(theta) + yPos); graphics.lineTo(innerRadius * Math.cos(theta + halfIncr) + xPos, innerRadius * Math.sin(theta + halfIncr) + yPos); } theta += incr; } } public static function drawStarLight(graphics:Graphics, xPos:Number = 0, yPos:Number = 0, sides:uint = 10, innerRadius:Number = 10, outerRadius:Number = 30, type:String = 'line', sizePercent:Number = 4/5 ):void { var theta:Number = 0.0; var incr:Number = Math.PI * 2.0 / sides; var halfIncr:Number = incr / 2.0; for (var i:uint = 0; i <= sides; i++) { var rOuterRadius:Number = MathUtil.randomBetween(outerRadius * sizePercent, outerRadius); if(i == 0) { if (type == 'curve') { graphics.moveTo(innerRadius * Math.cos(theta + halfIncr) + xPos, innerRadius * Math.sin(theta + halfIncr) + yPos); } else { graphics.moveTo(rOuterRadius * Math.cos(theta) + xPos, rOuterRadius * Math.sin(theta) + yPos); } } if (type == 'curve') { graphics.curveTo(rOuterRadius * Math.cos(theta) + xPos, rOuterRadius * Math.sin(theta) + yPos, innerRadius * Math.cos(theta + halfIncr) + xPos, innerRadius * Math.sin(theta + halfIncr) + yPos); } else { graphics.lineTo(rOuterRadius * Math.cos(theta) + xPos, rOuterRadius* Math.sin(theta) + yPos); graphics.lineTo(innerRadius * Math.cos(theta + halfIncr) + xPos, innerRadius * Math.sin(theta + halfIncr) + yPos); } theta += incr; } } public static function drawCenterSquare(graphics:Graphics, size:uint = 10, autoLineStyle:Boolean = true):void { if (autoLineStyle) simpleLineStyle(graphics); graphics.drawRect(-size / 2, -size / 2, size, size); graphics.moveTo(-size / 2, -size / 2); graphics.lineTo(size / 2, size / 2); graphics.moveTo(-size / 2, size / 2); graphics.lineTo(size / 2, -size / 2); } public static function drawRectangle(graphics:Graphics, rec:Rectangle, autoLineStyle:Boolean = true):void { if (autoLineStyle) simpleLineStyle(graphics); graphics.drawRect(rec.x, rec.y, rec.width, rec.height); } public static function drawFrame(d:Shape, autoLineStyle:Boolean = true):void { drawRectangle(d.graphics, d.getRect(d), autoLineStyle); } public static function simpleLineStyle(graphics:Graphics):void { graphics.lineStyle(0, 0xEEEEEE); } + + public static function drawQuadraticBezier(graphics:Graphics, x0:Number, y0:Number, x1:Number, y1:Number, x2:Number, y2:Number, x3:Number, y3:Number, points:uint = 20):void { + graphics.moveTo(x0, y0); + var t:Number; + for (var i:uint = 1; i < points; i++) { + t = 1 / points * i; + graphics.lineTo( + MathUtil.bezierN(t,[x0,x1,x2,x3]), + MathUtil.bezierN(t,[y0,y1,y2,y3]) + ); + } + graphics.lineTo( + MathUtil.bezierN(1,[x0,x1,x2,x3]), + MathUtil.bezierN(1,[y0,y1,y2,y3]) + ); + } } } diff --git a/src/com/rails2u/utils/MathUtil.as b/src/com/rails2u/utils/MathUtil.as index 4fcf705..037af40 100644 --- a/src/com/rails2u/utils/MathUtil.as +++ b/src/com/rails2u/utils/MathUtil.as @@ -1,90 +1,93 @@ package com.rails2u.utils { public class MathUtil { public static function randomPlusMinus(val:Number = 1):Number { if (randomBoolean() ) { return val; } else { return val * -1; } } /* * randomBoolean(-100, 100); // retun value is between -100 and 100; */ public static function randomBetween(s:Number, e:Number = 0):Number { return s + (e - s) * Math.random(); } /* * randomBetween(); // return value is true or false. */ public static function randomBoolean():Boolean { return (Math.round(Math.random()) == 1) ? true : false; } /* * randomPickup(1,2,3,4); // return value is 1 or 2 or 3 or 4 */ public static function randomPickup(... args):* { var len:uint = args.length; if (len == 1) { return args[0]; } else { return args[Math.round(Math.random() * (len - 1))]; } } /* * var cycleABC = MathUtil.cycle('a', 'b', 'c'); * cycleABC(); // 'a' * cycleABC(); // 'b' * cycleABC(); // 'c' * cycleABC(); // 'a' * cycleABC(); // 'b' */ public static function cycle(... args):Function { var len:uint = args.length; var i:uint = 0; if (len == 1) { return function():Object { return args[0]; } } else { return function():Object { var res:Object = args[i]; i++; if (i >= len) i = 0; return res; }; } } public static function bezier3(t:Number, x0:Number, x1:Number, x2:Number, x3:Number):Number { return x0 * Math.pow(1-t, 3) + 3 * x1 * t *Math.pow(1-t, 2) + 3 * x2 * Math.pow(t, 2) * 1-t + x3 * Math.pow(t, 3); } + public static function quadraticBezier(t:Number, x0:Number, x1:Number, x2:Number, x3:Number):Number { + return x0 * Math.pow(1-t, 3) + 3 * x1 * t *Math.pow(1-t, 2) + 3 * x2 * Math.pow(t, 2) * 1-t + x3 * Math.pow(t, 3); + } public static function bezierN(t:Number, points:Array):Number { var res:Number = 0; var len:uint = points.length; var tm:Number = 1 - t; for (var i:uint=0; i < len;i++) { var pos:Number = points[i]; var tmp:Number = 1.0; var a:Number = len - 1; var b:Number = i; var c:Number = a - b; while (a > 1) { if(a > 1) tmp *= a; a -= 1; if(b > 1) tmp /= b; b -= 1; if(c > 1) tmp /= c; c -= 1; } tmp *= Math.pow(t, i) * Math.pow(tm, len -1 -i); res += tmp * pos; } return res; } } }
hotchpotch/as3rails2u
ef2b4529fe6da3a6fabce7b2acf59616af8afc1b
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@60 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/tracer/CenterTracer.as b/src/com/rails2u/tracer/CenterTracer.as index c021776..2fa480c 100644 --- a/src/com/rails2u/tracer/CenterTracer.as +++ b/src/com/rails2u/tracer/CenterTracer.as @@ -1,4 +1,13 @@ package com.rails2u.tracer { public class CenterTracer extends Tracer { + private var _radius:Number; + public function get radius():Number { + return _radius; + } + + public function CircleTracer(radius:Number) { + super(); + this._radius = radius; + } } }
hotchpotch/as3rails2u
8cf5cf0194ef76b5daf5ff544f9107039b2ca1f5
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@59 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/tracer/CircleTracer.as b/src/com/rails2u/tracer/CircleTracer.as index c75d821..ed3e920 100644 --- a/src/com/rails2u/tracer/CircleTracer.as +++ b/src/com/rails2u/tracer/CircleTracer.as @@ -1,24 +1,17 @@ package com.rails2u.tracer { import flash.geom.Point; public class CircleTracer extends CenterTracer { - - private var _radius:Number; - public function get radius():Number { - return _radius; - } - public function CircleTracer(radius:Number) { - super(); - this._radius = radius; + super(radius); } protected override function getPoint():Point { // slow: ToDo var p:Point = new Point( - Math.cos(360 / distance * (times - 1) * Math.PI / 180) * _radius, - Math.sin(360 / distance * (times - 1) * Math.PI / 180) * _radius + Math.cos(360 / tracePoints * (times - 1) * Math.PI / 180) * radius, + Math.sin(360 / tracePoints * (times - 1) * Math.PI / 180) * radius ); return matrix.transformPoint(p); } } } diff --git a/src/com/rails2u/tracer/LineTracer.as b/src/com/rails2u/tracer/LineTracer.as new file mode 100644 index 0000000..52271d9 --- /dev/null +++ b/src/com/rails2u/tracer/LineTracer.as @@ -0,0 +1,21 @@ +package com.rails2u.tracer { + import flash.geom.Point; + public class LineTracer extends Tracer { + private var _length:Number; + public function get length():Number { + return _length; + } + + public function LineTracer(length:Number) { + super(); + this._length = length; + } + + protected override function getPoint():Point { + var p:Point = new Point( + length * (times - 1) / tracePoints, 0 + ); + return matrix.transformPoint(p); + } + } +} diff --git a/src/com/rails2u/tracer/Tracer.as b/src/com/rails2u/tracer/Tracer.as index 9d02b95..225b9c2 100644 --- a/src/com/rails2u/tracer/Tracer.as +++ b/src/com/rails2u/tracer/Tracer.as @@ -1,83 +1,87 @@ package com.rails2u.tracer { import flash.events.EventDispatcher; import flash.geom.Matrix; import flash.geom.Point; public class Tracer extends EventDispatcher { private var _repeat:uint = 1; public function get repeat():uint { return _repeat; } public function set repeat(__repeat:uint):void { _repeat = __repeat; } - private var _distance:uint = 10; - public function get distance():uint { - return _distance; + private var _tracePoints:uint = 10; + public function get tracePoints():uint { + return _tracePoints; } - public function set distance(__distance:uint):void { - _distance = __distance; + public function set tracePoints(__tracePoints:uint):void { + _tracePoints = __tracePoints; } private var _started:Boolean = false; public function get started():Boolean { return _started; } public function set started(__started:Boolean):void { _started = __started; } private var _repeatCount:uint = 0; public function get repeatCount():uint { return _repeatCount; } public function set repeatCount(__repeatCount:uint):void { _repeatCount = __repeatCount; } protected var times:uint = 0; public function start():void { + if (started) return; + started = true; while (repeat == 0 || repeatCount < repeat) { run(); repeatCount++; } started = false; } protected function run():void { times = 0; - while(started && times < distance) { + while(started && times < tracePoints) { times++; dispatchEvent(getTraceEvent()); } } protected function getTraceEvent():TraceEvent { return new TraceEvent(TraceEvent.TRACE,times,repeatCount, getPoint() ); } protected function getPoint():Point{ return matrix.transformPoint(new Point()); } private var _matrix:Matrix = new Matrix; public function get matrix():Matrix { - return _matrix; + return _matrix.clone(); } public function set matrix(__matrix:Matrix):void { - _matrix = __matrix; + _matrix = __matrix.clone(); + } + + public function reset():void { + times = 0; + repeatCount = 0; } - /* * ToDo * - wait (delay) - * - matrix * - next (iterator) - * */ } }
hotchpotch/as3rails2u
d2e40e1b1d6c55b777b78635415c450318a7b6fe
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@58 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/tracer/CenterTracer.as b/src/com/rails2u/tracer/CenterTracer.as new file mode 100644 index 0000000..c021776 --- /dev/null +++ b/src/com/rails2u/tracer/CenterTracer.as @@ -0,0 +1,4 @@ +package com.rails2u.tracer { + public class CenterTracer extends Tracer { + } +} diff --git a/src/com/rails2u/tracer/CircleTracer.as b/src/com/rails2u/tracer/CircleTracer.as new file mode 100644 index 0000000..c75d821 --- /dev/null +++ b/src/com/rails2u/tracer/CircleTracer.as @@ -0,0 +1,24 @@ +package com.rails2u.tracer { + import flash.geom.Point; + public class CircleTracer extends CenterTracer { + + private var _radius:Number; + public function get radius():Number { + return _radius; + } + + public function CircleTracer(radius:Number) { + super(); + this._radius = radius; + } + + protected override function getPoint():Point { + // slow: ToDo + var p:Point = new Point( + Math.cos(360 / distance * (times - 1) * Math.PI / 180) * _radius, + Math.sin(360 / distance * (times - 1) * Math.PI / 180) * _radius + ); + return matrix.transformPoint(p); + } + } +} diff --git a/src/com/rails2u/tracer/TraceEvent.as b/src/com/rails2u/tracer/TraceEvent.as new file mode 100644 index 0000000..26af338 --- /dev/null +++ b/src/com/rails2u/tracer/TraceEvent.as @@ -0,0 +1,37 @@ +package com.rails2u.tracer { + import flash.events.Event; + import flash.geom.Point; + + public class TraceEvent extends Event { + public static const TRACE:String = 'trace'; + + public function TraceEvent(type:String, + times:uint, + repeatCount:uint, + point:Point, + bublles:Boolean = false, cancelable:Boolean = false + ) { + super(type, bubbles, cancelable); + _times = times; + _repeatCount = repeatCount; + _point = point; + } + + public var stash:Object; + + private var _point:Point; + public function get point():Point { + return _point; + } + + private var _times:uint; + public function get times():uint { + return _times; + } + + private var _repeatCount:uint; + public function get repeatCount():uint { + return _repeatCount; + } + } +} diff --git a/src/com/rails2u/tracer/Tracer.as b/src/com/rails2u/tracer/Tracer.as new file mode 100644 index 0000000..9d02b95 --- /dev/null +++ b/src/com/rails2u/tracer/Tracer.as @@ -0,0 +1,83 @@ +package com.rails2u.tracer { + import flash.events.EventDispatcher; + import flash.geom.Matrix; + import flash.geom.Point; + + public class Tracer extends EventDispatcher { + private var _repeat:uint = 1; + public function get repeat():uint { + return _repeat; + } + public function set repeat(__repeat:uint):void { + _repeat = __repeat; + } + + private var _distance:uint = 10; + public function get distance():uint { + return _distance; + } + public function set distance(__distance:uint):void { + _distance = __distance; + } + + private var _started:Boolean = false; + public function get started():Boolean { + return _started; + } + public function set started(__started:Boolean):void { + _started = __started; + } + + private var _repeatCount:uint = 0; + public function get repeatCount():uint { + return _repeatCount; + } + public function set repeatCount(__repeatCount:uint):void { + _repeatCount = __repeatCount; + } + + protected var times:uint = 0; + public function start():void { + started = true; + while (repeat == 0 || repeatCount < repeat) { + run(); + repeatCount++; + } + started = false; + } + + protected function run():void { + times = 0; + while(started && times < distance) { + times++; + dispatchEvent(getTraceEvent()); + } + } + + protected function getTraceEvent():TraceEvent { + return new TraceEvent(TraceEvent.TRACE,times,repeatCount, getPoint() ); + } + + protected function getPoint():Point{ + return matrix.transformPoint(new Point()); + } + + private var _matrix:Matrix = new Matrix; + public function get matrix():Matrix { + return _matrix; + } + + public function set matrix(__matrix:Matrix):void { + _matrix = __matrix; + } + + + /* + * ToDo + * - wait (delay) + * - matrix + * - next (iterator) + * + */ + } +}
hotchpotch/as3rails2u
c4673793748f6b07e0c59bbc8846b2f4ba3bc39d
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@57 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/bridge/ExportJS.as b/src/com/rails2u/bridge/ExportJS.as index 14c2528..40f0842 100644 --- a/src/com/rails2u/bridge/ExportJS.as +++ b/src/com/rails2u/bridge/ExportJS.as @@ -1,194 +1,195 @@ package com.rails2u.bridge { import flash.errors.IllegalOperationError; import flash.external.ExternalInterface; import flash.utils.ByteArray; import flash.utils.getQualifiedClassName; import flash.utils.Dictionary; import flash.utils.describeType; public class ExportJS { private static var inited:Boolean = false; private static var readOnlyObjectCache:Object; public static var objects:Object; public static var dict:Dictionary; public static function reloadObject(jsName:String):void { export(objects[jsName], jsName); ExternalInterface.call('console.info', 'reloaded: ' + jsName); } public static function getASObject(jsName:String):* { return objects[jsName]; } public static function getJSName(targetObject:*):* { return dict[targetObject]; } private static var cNum:uint = 0; private static function anonCounter():uint { return cNum++; } public static function export(targetObject:*, jsName:String = undefined):String { init(); if (dict[targetObject]) jsName = dict[targetObject]; if (!jsName) jsName = '__as3__.' + anonCounter(); var b:ByteArray = new ByteArray(); b.writeObject(targetObject); b.position = 0; var obj:Object = b.readObject(); //var readOnlyObject:Object = getReadOnlyObject(targetObject); // custom for Sprite/Shape if (!obj.hasOwnProperty('graphics') && targetObject.hasOwnProperty('graphics')) obj.graphics = {}; objects[jsName] = targetObject; dict[targetObject] = jsName; ExternalInterface.call(<><![CDATA[ (function(target, objectID, jsName, klassName) { try { var swfObject = document.getElementsByName(objectID)[0]; var defineAttr = function(obj, parentProperties) { var tmp = {}; for (var i in obj) { if (obj[i] && (typeof(obj[i]) == "object" || typeof(obj[i]) == "array")) { var pp = parentProperties.slice(); pp.push(i); defineAttr(obj[i], pp); continue; } tmp[i] = obj[i]; obj.__defineGetter__(i, (function(attrName) { return function() { return this.__tmpProperties__[attrName] } })(i) ); obj.__defineSetter__(i, (function(attrName) { return function(val) { if (swfObject.updateProperty(jsName, [].concat(parentProperties).concat(attrName), val)) { return this.__tmpProperties__[attrName] = val; } else { return this.__tmpProperties__[attrName]; } } })(i) ); } obj.__noSuchMethod__ = function(attrName, args) { swfObject.callMethod(jsName, [].concat(parentProperties).concat(attrName), args); } obj.__tmpProperties__ = tmp; } defineAttr(target, []); target.__reload = function() { return swfObject.reloadObject(jsName) }; if (!target.hasOwnProperty('reload')) target.reload = target.__reload; target.toString = function() { return klassName }; var chainProperties = jsName.split('.'); var windowTarget = window; while (chainProperties.length > 1) { var prop = chainProperties.shift(); if (typeof windowTarget[prop] == 'undefined') windowTarget[prop] = {}; windowTarget = windowTarget[prop]; } windowTarget[chainProperties.shift()] = target; } catch(e) { console.error(e.message, jsName); } ;}) ]]></>.toString(), obj, ExternalInterface.objectID, jsName, getQualifiedClassName(targetObject) ); return jsName; } private static function init():void { if (!ExternalInterface.available) throw (new IllegalOperationError('ExternalInterface.available should be true.')); if (inited) return; objects = {}; dict = new Dictionary(); readOnlyObjectCache = {}; ExternalInterface.addCallback('updateProperty', updateProperty); ExternalInterface.addCallback('callMethod', callMethod); ExternalInterface.addCallback('reloadObject', reloadObject); + ExternalInterface.call('function() { window.__as3__ = []}'); inited = true; } private static function updateProperty(jsName:String, chainProperties:Array, value:Object):Boolean { var obj:Object = objects[jsName]; while (chainProperties.length > 1) { var prop:String = chainProperties.shift(); obj = obj[prop]; } try { obj[chainProperties.shift()] = value; } catch(e:Error) { ExternalInterface.call('console.error', e.message); return false; } return true; } private static function callMethod(jsName:String, chainProperties:Array, args:Object):* { var obj:Object = objects[jsName]; var klassName:String = getQualifiedClassName(obj); var tmp:Array = chainProperties.slice(); var prop:String; while (chainProperties.length > 1) { prop = chainProperties.shift(); obj = obj[prop]; } prop = chainProperties.shift(); if(!obj.hasOwnProperty(prop)) { ExternalInterface.call('console.error', jsName + '(' + [klassName].concat(tmp).join('.') + ') is undefined.'); return; } var func:Function = obj[prop] as Function; try { if (func is Function) { return func.apply(obj, args); } else { ExternalInterface.call('console.error', jsName + '(' + [klassName].concat(tmp).join('.') + ') is not function.'); } } catch(e:Error) { ExternalInterface.call('console.error', e.message); } } /* private static var readOnlyObjectRegexp:RegExp = new RegExp('name="([^"]+?)" .*access="readonly" .*type="([^"]+?)"'); private static function getReadOnlyObject(target:*):Object { var klassName:String = getQualifiedClassName(target); if (!readOnlyObjectCache[klassName]) { // don't use E4X. readOnlyObjectCache[klassName] = {}; var xmlLines:Array = describeType(target).toString().split("\n"); for each(var line:String in xmlLines) { line.replace(readOnlyObjectRegexp, function(_trash, name, _type, ...trashes):void { readOnlyObjectCache[klassName][name] = _type; }); } } return readOnlyObjectCache[klassName]; } */ } } diff --git a/src/com/rails2u/core/Enumerable.as b/src/com/rails2u/core/Enumerable.as index 14e31e2..2ebe6aa 100644 --- a/src/com/rails2u/core/Enumerable.as +++ b/src/com/rails2u/core/Enumerable.as @@ -1,59 +1,70 @@ package com.rails2u.core { public class Enumerable { + public static function implementation(klass:Class):void { + klass.prototype.zip = function(...args):Enumerable { + return zip.apply(null, [klass].concat(args)); + }; + } + public static function zip(t:*, ...args):Enumerator { - var ary:Array = take(t); + log(1, args, 4); + var ary:Array = getValues(t); var res:Array = []; var num:uint = Math.min.apply(null, [ary.length].concat(args.map(function(e:*, ...a):Number { return e.length }))); - args = args.map(function(e:*, ...a):Array { return take(e, num) }); + args = args.map(function(e:*, ...a):Array { return getValues(e, num) }); for (var i:uint = 0; i < num; i++) { var r:Array = [ary[i]]; for each(var a:Array in args) { r.push(a[i]); } res.push(r); } return new Enumerator(res); } public static function cycle(t:*):Enumerator { - var ary:Array = take(t); + var ary:Array = getValues(t); return new Enumerator(ary, iCycle, valReturn(true), valReturn(Infinity)); } private static function iCycle(e:Enumerator):* { if(! (e._ary.length > e.index)) { e.rewind(); } return e._ary[e.index++]; } private static function valReturn(v:*):Function { return function(...args):* { return v; } } - public static function take(t:*, maxValue:Number = Infinity):Array { + public static function take(t:*, maxValue:Number = Infinity):Enumerator { + return new Enumerator(getValues(t, maxValue)); + } + + private static function getValues(t:*, maxValue:Number = Infinity):Array { var res:Array = []; try { if (t is Array) { t.forEach(function(e:*, i:int, ...args):void { if (i++ > maxValue) throw new StopIteration; res.push(e); }); } else { var i:uint = 0; t.each(function(e:*, ...args):void { if (i++ > maxValue) throw new StopIteration; res.push(e) }); } } catch(e:StopIteration) { // } return res; } } } diff --git a/src/com/rails2u/record/MouseRecorder.as b/src/com/rails2u/record/MouseRecorder.as index b3a3757..f2e3e79 100644 --- a/src/com/rails2u/record/MouseRecorder.as +++ b/src/com/rails2u/record/MouseRecorder.as @@ -1,123 +1,162 @@ package com.rails2u.record { import flash.display.InteractiveObject; import flash.events.MouseEvent; import flash.events.IEventDispatcher; import flash.utils.Dictionary; + import flash.utils.getTimer; + import flash.events.Event; + import flash.utils.ByteArray; public class MouseRecorder { public static const MOUSE_EVENT_NAMES:Array = [ + MouseEvent.DOUBLE_CLICK, MouseEvent.MOUSE_DOWN, MouseEvent.MOUSE_MOVE, MouseEvent.MOUSE_UP, MouseEvent.MOUSE_OUT, MouseEvent.MOUSE_OVER, MouseEvent.MOUSE_WHEEL, MouseEvent.ROLL_OVER, MouseEvent.ROLL_OUT ]; public var priority:int = -1; public var useWeakReference:Boolean = false; protected var _canvas:InteractiveObject; protected var _eventNames:Array = []; + protected var records:Array = []; public function MouseRecorder(canvas:InteractiveObject) { _canvas = canvas; - eventNames = MOUSE_EVENT_NAMES.splice(0); + setEvents(MOUSE_EVENT_NAMES.splice(0)); } protected var _started:Boolean = false; public function get started():Boolean { return _started; } protected var _recordTypes:Dictionary; public function get recordTypess():Dictionary{ return _recordTypes; } public static const BUBBLES_TRUE:uint = 1; public static const BUBBLES_FALSE:uint = 2; public static const BUBBLES_BOTH:uint = 0; protected var _recordBubblesType:uint = BUBBLES_TRUE; + // ToDo public function set recordBubblesType(u:uint):void { _recordBubblesType = u; } public function get recordBubblesType():uint { return _recordBubblesType; } public function get eventNames():Array { return _eventNames; } - public function set eventNames(n:Array):void { + public function setEvents(n:Array):void { _recordTypes = new Dictionary(); for each(var evName:String in n) { _recordTypes[evName] = true; } _eventNames = n; } public function recordOn(name:String):Boolean { if (_recordTypes.hasOwnProperty(name)) { _recordTypes[name] = true; return true; } return false; } public function recordOff(name:String):Boolean { if (_recordTypes.hasOwnProperty(name)) { _recordTypes[name] = false; return true; } return false; } + protected var _startRecordTime:uint; + public function get startRecordTime():uint { + return _startRecordTime; + } + public function start():Boolean { if (_started) { return false; } else { addHandlers(_canvas, eventNames); _started = true; return true; } } public function stop():Boolean { if (started) { _started = false; removeHandlers(_canvas, eventNames); return true; } else { return false; } } + // ToDo + public function pause():Boolean { + return false; + } + + public function getRecords():ByteArray { + var b:ByteArray = new ByteArray; + b.writeObject(records); + b.position = 0; + b.compress(); + return b; + } + protected function addHandlers(t:IEventDispatcher, ens:Array):void { for each(var evName:String in ens) { t.addEventListener(evName, recordHandler, false, priority, useWeakReference); - t.addEventListener(evName, recordHandler, true, priority, useWeakReference); + //t.addEventListener(evName, recordHandler, true, priority, useWeakReference); } } protected function removeHandlers(t:IEventDispatcher, ens:Array):void { for each(var evName:String in ens) { t.removeEventListener(evName, recordHandler, false); - t.removeEventListener(evName, recordHandler, true); + //t.removeEventListener(evName, recordHandler, true); } } protected function recordHandler(e:MouseEvent):void { if (!_recordTypes[e.type] || ( recordBubblesType != BUBBLES_BOTH && (e.bubbles == true ? BUBBLES_TRUE : BUBBLES_FALSE) != recordBubblesType ) ) return; + + _startRecordTime ||= getTimer(); + records.push([getTimer() - startRecordTime, event2object(e)]); + } + + protected var baTmp:ByteArray; + protected var objTmp:Object; + protected function event2object(e:MouseEvent):Object { + baTmp = new ByteArray(); + baTmp.writeObject(e); + baTmp.position = 0; + objTmp = baTmp.readObject(); + objTmp.type = e.type; + if (e.currentTarget) objTmp.name = e.currentTarget.name; + return objTmp; } } }
hotchpotch/as3rails2u
83291f1c19dbf952abb3823ff2fcb80c00f3eec5
git-svn-id: http://svn.rails2u.com/as3rails2u/trunk@56 96db6a20-122f-0410-8d9f-89437bbe4005
diff --git a/src/com/rails2u/record/MouseRecorder.as b/src/com/rails2u/record/MouseRecorder.as new file mode 100644 index 0000000..b3a3757 --- /dev/null +++ b/src/com/rails2u/record/MouseRecorder.as @@ -0,0 +1,123 @@ +package com.rails2u.record { + import flash.display.InteractiveObject; + import flash.events.MouseEvent; + import flash.events.IEventDispatcher; + import flash.utils.Dictionary; + + public class MouseRecorder { + public static const MOUSE_EVENT_NAMES:Array = [ + MouseEvent.MOUSE_DOWN, + MouseEvent.MOUSE_MOVE, + MouseEvent.MOUSE_UP, + MouseEvent.MOUSE_OUT, + MouseEvent.MOUSE_OVER, + MouseEvent.MOUSE_WHEEL, + MouseEvent.ROLL_OVER, + MouseEvent.ROLL_OUT + ]; + + public var priority:int = -1; + public var useWeakReference:Boolean = false; + + protected var _canvas:InteractiveObject; + protected var _eventNames:Array = []; + public function MouseRecorder(canvas:InteractiveObject) { + _canvas = canvas; + eventNames = MOUSE_EVENT_NAMES.splice(0); + } + + protected var _started:Boolean = false; + public function get started():Boolean { + return _started; + } + + protected var _recordTypes:Dictionary; + public function get recordTypess():Dictionary{ + return _recordTypes; + } + + public static const BUBBLES_TRUE:uint = 1; + public static const BUBBLES_FALSE:uint = 2; + public static const BUBBLES_BOTH:uint = 0; + protected var _recordBubblesType:uint = BUBBLES_TRUE; + + public function set recordBubblesType(u:uint):void { + _recordBubblesType = u; + } + + public function get recordBubblesType():uint { + return _recordBubblesType; + } + + public function get eventNames():Array { + return _eventNames; + } + + public function set eventNames(n:Array):void { + _recordTypes = new Dictionary(); + for each(var evName:String in n) { + _recordTypes[evName] = true; + } + _eventNames = n; + } + + public function recordOn(name:String):Boolean { + if (_recordTypes.hasOwnProperty(name)) { + _recordTypes[name] = true; + return true; + } + return false; + } + + public function recordOff(name:String):Boolean { + if (_recordTypes.hasOwnProperty(name)) { + _recordTypes[name] = false; + return true; + } + return false; + } + + public function start():Boolean { + if (_started) { + return false; + } else { + addHandlers(_canvas, eventNames); + _started = true; + return true; + } + } + + public function stop():Boolean { + if (started) { + _started = false; + removeHandlers(_canvas, eventNames); + return true; + } else { + return false; + } + } + + protected function addHandlers(t:IEventDispatcher, ens:Array):void { + for each(var evName:String in ens) { + t.addEventListener(evName, recordHandler, false, priority, useWeakReference); + t.addEventListener(evName, recordHandler, true, priority, useWeakReference); + } + } + + protected function removeHandlers(t:IEventDispatcher, ens:Array):void { + for each(var evName:String in ens) { + t.removeEventListener(evName, recordHandler, false); + t.removeEventListener(evName, recordHandler, true); + } + } + + protected function recordHandler(e:MouseEvent):void { + if (!_recordTypes[e.type] || + ( + recordBubblesType != BUBBLES_BOTH && + (e.bubbles == true ? BUBBLES_TRUE : BUBBLES_FALSE) != recordBubblesType + ) + ) return; + } + } +} diff --git a/src/com/rails2u/record/Recorder.as b/src/com/rails2u/record/Recorder.as new file mode 100644 index 0000000..4c413c2 --- /dev/null +++ b/src/com/rails2u/record/Recorder.as @@ -0,0 +1,4 @@ +package com.rails2u.record { + public class Recorder { + } +}